SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetworkIDObject.cpp
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
18
19
20 #include "slikenet/NetworkIDObject.h"
21 #include "slikenet/NetworkIDManager.h"
22 #include "slikenet/assert.h"
23 #include "slikenet/alloca.h"
24
25 using namespace SLNet;
26
27 NetworkIDObject::NetworkIDObject()
28 {
29 networkID=UNASSIGNED_NETWORK_ID;
30 parent=0;
31 networkIDManager=0;
32 nextInstanceForNetworkIDManager=0;
33 }
34 NetworkIDObject::~NetworkIDObject()
35 {
36 if (networkIDManager)
37 networkIDManager->StopTrackingNetworkIDObject(this);
38 }
39 void NetworkIDObject::SetNetworkIDManager( NetworkIDManager *manager)
40 {
41 if (manager==networkIDManager)
42 return;
43
44 if (networkIDManager)
45 networkIDManager->StopTrackingNetworkIDObject(this);
46
47 networkIDManager=manager;
48 if (networkIDManager==0)
49 {
50 networkID = UNASSIGNED_NETWORK_ID;
51 return;
52 }
53
54 if (networkID == UNASSIGNED_NETWORK_ID)
55 {
56 // Prior ID not set
57 networkID = networkIDManager->GetNewNetworkID();
58 }
59
60 networkIDManager->TrackNetworkIDObject(this);
61 }
62 NetworkIDManager * NetworkIDObject::GetNetworkIDManager( void ) const
63 {
64 return networkIDManager;
65 }
66 NetworkID NetworkIDObject::GetNetworkID( void )
67 {
68 return networkID;
69 }
70 void NetworkIDObject::SetNetworkID( NetworkID id )
71 {
72 if (networkID==id)
73 return;
74
75 if ( id == UNASSIGNED_NETWORK_ID )
76 {
77 SetNetworkIDManager(0);
78 return;
79 }
80
81 if ( networkIDManager )
82 networkIDManager->StopTrackingNetworkIDObject(this);
83
84 networkID = id;
85
86 if (networkIDManager)
87 networkIDManager->TrackNetworkIDObject(this);
88 }
89 void NetworkIDObject::SetParent( void *_parent )
90 {
91 parent=_parent;
92 }
93 void* NetworkIDObject::GetParent( void ) const
94 {
95 return parent;
96 }