1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | |
---|
12 | ### File Specific: |
---|
13 | main-programmer: Silvan Nellen |
---|
14 | co-programmer: Benjamin Wuest |
---|
15 | */ |
---|
16 | |
---|
17 | #define DEBUG_MODULE_NETWORK |
---|
18 | |
---|
19 | #include "shared_network_data.h" |
---|
20 | #include "network_stream.h" |
---|
21 | #include "netdefs.h" |
---|
22 | |
---|
23 | #include "state.h" |
---|
24 | |
---|
25 | #include <cassert> |
---|
26 | |
---|
27 | #include "synchronizeable.h" |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * default constructor |
---|
33 | */ |
---|
34 | Synchronizeable::Synchronizeable() |
---|
35 | { |
---|
36 | this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); |
---|
37 | this->owner = -1; |
---|
38 | this->hostID = SharedNetworkData::getInstance()->getHostID(); |
---|
39 | this->setIsServer(this->hostID == 0); |
---|
40 | this->uniqueID = NET_UID_UNASSIGNED; |
---|
41 | this->networkStream = NULL; |
---|
42 | this->bSynchronize = false; |
---|
43 | |
---|
44 | if( State::isOnline()) |
---|
45 | { |
---|
46 | NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream(); |
---|
47 | assert(nd != NULL); |
---|
48 | nd->connectSynchronizeable(*this); |
---|
49 | this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID()); |
---|
50 | } |
---|
51 | |
---|
52 | this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) ); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | /** |
---|
58 | * default destructor deletes all unneded stuff |
---|
59 | */ |
---|
60 | Synchronizeable::~Synchronizeable() |
---|
61 | { |
---|
62 | if ( this->networkStream ) |
---|
63 | this->networkStream->disconnectSynchronizeable(*this); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Sets the server flag to a given value |
---|
68 | * @param isServer: the boolean value which the server flag is to set to |
---|
69 | */ |
---|
70 | void Synchronizeable::setIsServer(bool isServer) |
---|
71 | { |
---|
72 | if( isServer ) |
---|
73 | this->state = this->state | STATE_SERVER; |
---|
74 | else |
---|
75 | this->state = this->state & (~STATE_SERVER); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | /** |
---|
80 | * Determines if the server flag is set |
---|
81 | * @return true, if the server flag is true, false else |
---|
82 | */ |
---|
83 | bool Synchronizeable::isServer() |
---|
84 | { |
---|
85 | return (this->state & STATE_SERVER) >0; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /** |
---|
90 | * get the diff to last acked state of userId |
---|
91 | * @param userId user to create diff for |
---|
92 | * @param data buffer to copy diff in |
---|
93 | * @param maxLength max bytes to copy into data |
---|
94 | * @param stateId id of current state |
---|
95 | * @param priorityTH tells getStateDiff to not send element with priority \< priorityTH |
---|
96 | * @return n bytes copied into data |
---|
97 | */ |
---|
98 | int Synchronizeable::getStateDiff( int userId, byte* data, int maxLength, int stateId, int priorityTH ) |
---|
99 | { |
---|
100 | #warning implement this |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * sets a new state out of a diff created on another host |
---|
105 | * @param userId hostId of user who send me that diff |
---|
106 | * @param data pointer to diff |
---|
107 | * @param length length of diff |
---|
108 | * @param stateId id of current state |
---|
109 | * @return true on success |
---|
110 | */ |
---|
111 | bool Synchronizeable::setStateDiff( int userId, byte* data, int length, int stateId ) |
---|
112 | { |
---|
113 | #warning implement this |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * override this function to be notified on change |
---|
118 | * of your registred variables. |
---|
119 | * @param id id's which have changed |
---|
120 | */ |
---|
121 | void Synchronizeable::varChangeHandler( std::list<int> & id ) |
---|
122 | { |
---|
123 | #warning implement this |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * registers a varable to be synchronized over network |
---|
128 | * @param var see src/lib/network/synchronizeable_var/ for available classes |
---|
129 | */ |
---|
130 | void Synchronizeable::registerVar( SynchronizeableVar * var ) |
---|
131 | { |
---|
132 | #warning implement this |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * registers a varable to be synchronized over network |
---|
137 | * return value is passed to varChangeHandler on change |
---|
138 | * @param var see src/lib/network/synchronizeable_var/ for available classes |
---|
139 | * @return handle passed to varChangeHandler on changes |
---|
140 | */ |
---|
141 | int Synchronizeable::registerVarId( SynchronizeableVar * var ) |
---|
142 | { |
---|
143 | #warning implement this |
---|
144 | } |
---|
145 | |
---|
146 | |
---|