Changeset 3084 for code/trunk/src/network
- Timestamp:
- May 26, 2009, 9:20:57 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 27 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/CMakeLists.txt
r2748 r3084 25 25 ClientConnectionListener.cc 26 26 ConnectionManager.cc 27 FunctionCallManager.cc 27 28 GamestateManager.cc 28 29 GamestateClient.cc 29 30 GamestateHandler.cc 31 NetworkFunction.cc 32 Host.cc 30 33 PacketBuffer.cc 31 34 Server.cc 32 35 TrafficControl.cc 33 Host.cc34 36 ) 35 37 ADD_SUBDIRECTORY(packet) -
code/trunk/src/network/Client.cc
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 48 48 #include "core/CoreIncludes.h" 49 49 #include "packet/Packet.h" 50 #include "FunctionCallManager.h" 50 51 51 52 // #include "packet/Acknowledgement.h" … … 140 141 */ 141 142 void Client::update(const Clock& time){ 142 // COUT(3) << "."; 143 if(client_connection.isConnected() && isSynched_){ 144 COUT(4) << "popping partial gamestate: " << std::endl; 145 packet::Gamestate *gs = gamestate.getGamestate(); 146 if(gs){ 147 COUT(4) << "client tick: sending gs " << gs << std::endl; 148 if( !gs->send() ) 149 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 143 //this steers our network frequency 144 timeSinceLastUpdate_+=time.getDeltaTime(); 145 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 146 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 147 // COUT(3) << "."; 148 if(client_connection.isConnected() && isSynched_){ 149 COUT(4) << "popping partial gamestate: " << std::endl; 150 packet::Gamestate *gs = gamestate.getGamestate(); 151 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 152 if(gs){ 153 COUT(4) << "client tick: sending gs " << gs << std::endl; 154 if( !gs->send() ) 155 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 150 156 // gs gets automatically deleted by enet callback 157 } 158 FunctionCallManager::sendCalls(); 151 159 } 152 160 } 161 153 162 ENetEvent *event; 154 163 // stop if the packet queue is empty … … 167 176 } 168 177 gamestate.cleanup(); 178 169 179 return; 170 180 } -
code/trunk/src/network/Client.h
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 88 88 89 89 bool gameStateFailure_; 90 float timeSinceLastUpdate_; 90 91 }; 91 92 -
code/trunk/src/network/ClientConnection.cc
r2773 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 42 42 #include <enet/enet.h> 43 43 #include <iostream> 44 #include <cassert> 44 45 // boost.thread library for multithreading support 45 46 #include <boost/thread/thread.hpp> … … 57 58 58 59 ClientConnection::ClientConnection(int port, const std::string& address) { 59 quit =false;60 quit_=false; 60 61 server=NULL; 61 62 serverAddress = new ENetAddress(); … … 66 67 67 68 ClientConnection::ClientConnection(int port, const char *address) { 68 quit =false;69 quit_=false; 69 70 server=NULL; 70 71 serverAddress = new ENetAddress(); … … 106 107 107 108 bool ClientConnection::closeConnection() { 108 quit =true;109 quit_=true; 109 110 //network_threads.join_all(); 110 111 receiverThread_->join(); … … 150 151 COUT(2) << "ClientConnection: could not create client host" << std::endl; 151 152 // add some error handling here ========================== 152 quit =true;153 quit_=true; 153 154 } 154 155 //connect to the server 155 156 if(!establishConnection()){ 156 157 COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl; 157 quit =true;158 quit_=true; 158 159 return; 159 160 } 160 161 event = new ENetEvent; 161 162 //main loop 162 while(!quit ){163 while(!quit_){ 163 164 //std::cout << "connection loop" << std::endl; 164 165 { … … 166 167 if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){ 167 168 // we should never reach this point 168 quit=true; 169 continue; 169 // assert(0); 170 printf("ClientConnection: ENet returned with an error!\n"); 171 quit_=true; 172 break; 170 173 // add some error handling here ======================== 171 174 } … … 183 186 break; 184 187 case ENET_EVENT_TYPE_DISCONNECT: 185 quit=true; 188 quit_=true; 189 printf("Received disconnect Packet from Server!\n"); 186 190 // server closed the connection 187 191 return; … … 204 208 bool ClientConnection::disconnectConnection() { 205 209 ENetEvent event; 210 if(this->quit_) 211 return true; 206 212 boost::recursive_mutex::scoped_lock lock(enet_mutex_g); 207 213 enet_peer_disconnect(server, 0); 208 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){214 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){ 209 215 switch (event.type) 210 216 { … … 233 239 } 234 240 // handshake 235 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit ){241 while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){ 236 242 if( event.type == ENET_EVENT_TYPE_CONNECT ){ 237 243 established=true; -
code/trunk/src/network/ClientConnection.h
r2773 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 53 53 const int NETWORK_PORT = 55556; 54 54 const int NETWORK_CLIENT_MAX_CONNECTIONS = 5; 55 const int NETWORK_CLIENT_WAIT_TIME = 1 ;55 const int NETWORK_CLIENT_WAIT_TIME = 10; 56 56 const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds 57 57 const int NETWORK_CLIENT_CHANNELS = 2; … … 76 76 //bool sendPackets(ENetEvent *event); 77 77 bool waitEstablished(int milisec); 78 bool isConnected(){return established;} 78 inline bool isConnected(){return established;} 79 inline bool checkConnection(){ return !quit_ && isConnected(); } 79 80 private: 80 81 ClientConnection(const ClientConnection& copy); // not used … … 90 91 ENetAddress *serverAddress; 91 92 // quit-variable (communication with threads) 92 bool quit ;93 bool quit_; 93 94 bool established; 94 95 // clientlist -
code/trunk/src/network/ConnectionManager.cc
r2896 r3084 58 58 { 59 59 bool operator< (ENetAddress a, ENetAddress b) { 60 if(a.host <= b.host) 61 return true; 62 else 63 return false; 60 return a.host <= b.host; 64 61 } 65 62 } … … 75 72 assert(instance_==0); 76 73 instance_=this; 77 quit =false;74 quit_=false; 78 75 bindAddress = new ENetAddress(); 79 76 bindAddress->host = ENET_HOST_ANY; … … 84 81 assert(instance_==0); 85 82 instance_=this; 86 quit =false;83 quit_=false; 87 84 bindAddress = new ENetAddress(); 88 85 bindAddress->host = ENET_HOST_ANY; … … 93 90 assert(instance_==0); 94 91 instance_=this; 95 quit =false;92 quit_=false; 96 93 bindAddress = new ENetAddress(); 97 94 enet_address_set_host (bindAddress, address.c_str()); … … 102 99 assert(instance_==0); 103 100 instance_=this; 104 quit =false;101 quit_=false; 105 102 bindAddress = new ENetAddress(); 106 103 enet_address_set_host (bindAddress, address); … … 109 106 110 107 ConnectionManager::~ConnectionManager(){ 111 if(!quit )108 if(!quit_) 112 109 quitListener(); 113 110 instance_=0; … … 133 130 134 131 bool ConnectionManager::quitListener() { 135 quit =true;132 quit_=true; 136 133 receiverThread_->join(); 137 134 return true; … … 189 186 if(server==NULL){ 190 187 // add some error handling here ========================== 191 quit =true;188 quit_=true; 192 189 return; 193 190 } 194 191 195 192 event = new ENetEvent; 196 while(!quit){ 193 while(!quit_) 194 { 197 195 { //mutex scope 198 196 boost::recursive_mutex::scoped_lock lock(enet_mutex_g); 199 197 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 200 198 // we should never reach this point 201 quit=true; 199 printf("ConnectionManager: ENet returned with an error\n"); 200 quit_=true; 201 printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n"); 202 202 continue; 203 203 // add some error handling here ======================== … … 208 208 // log handling ================ 209 209 case ENET_EVENT_TYPE_CONNECT: 210 // printf("===================================================================="); 210 211 case ENET_EVENT_TYPE_DISCONNECT: 211 212 case ENET_EVENT_TYPE_RECEIVE: … … 215 216 case ENET_EVENT_TYPE_NONE: 216 217 //receiverThread_->yield(); 217 msleep(1 );218 msleep(10); 218 219 break; 219 220 } … … 267 268 } 268 269 269 bool ConnectionManager::processData(ENetEvent *event) {270 // just add packet to the buffer271 // this can be extended with some preprocessing272 return buffer.push(event);273 }274 275 276 270 277 271 int ConnectionManager::getClientID(ENetPeer* peer) { -
code/trunk/src/network/ConnectionManager.h
r2773 r3084 55 55 const int NETWORK_PORT = 55556; 56 56 const int NETWORK_MAX_CONNECTIONS = 50; 57 const int NETWORK_WAIT_TIMEOUT = 1 ;57 const int NETWORK_WAIT_TIMEOUT = 10; 58 58 const int NETWORK_DEFAULT_CHANNEL = 0; 59 59 … … 81 81 void disconnectClient(ClientInformation *client); 82 82 void syncClassid(unsigned int clientID); 83 bool checkReceiverThread(){ return !quit_; } 83 84 84 85 private: 85 86 ConnectionManager(const ConnectionManager& copy); // not used 86 bool processData(ENetEvent *event);87 inline bool processData(ENetEvent *event){ return buffer.push(event); } 87 88 void receiverThread(); 88 89 void disconnectClients(); … … 95 96 ENetAddress *bindAddress; 96 97 97 bool quit ; // quit-variable (communication with threads)98 bool quit_; // quit-variable (communication with threads) 98 99 99 100 boost::thread *receiverThread_; -
code/trunk/src/network/FunctionCallManager.cc
- Property svn:eol-style set to native
-
code/trunk/src/network/FunctionCallManager.h
- Property svn:eol-style set to native
-
code/trunk/src/network/GamestateManager.cc
r2710 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 132 132 if(client){ 133 133 // COUT(3) << "diffing" << std::endl; 134 // packet::Gamestate* gs1 = gs; 134 135 gs = gs->diff(client); 136 // packet::Gamestate* gs2 = gs->undiff(client); 135 137 // gs = new packet::Gamestate(*gs); 138 // assert(*gs1==*gs2); 136 139 } 137 140 else{ … … 161 164 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){ 162 165 delete it->second; 166 163 167 gamestateMap_[clientID].erase(it++); 164 168 } -
code/trunk/src/network/GamestateManager.h
r2662 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... -
code/trunk/src/network/Host.h
r2171 r3084 35 35 36 36 namespace orxonox { 37 38 const int CLIENTID_SERVER = 0; 39 const unsigned int NETWORK_FREQUENCY = 30; 40 const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY; 37 41 38 42 /** -
code/trunk/src/network/NetworkFunction.cc
- Property svn:eol-style set to native
-
code/trunk/src/network/NetworkFunction.h
- Property svn:eol-style set to native
-
code/trunk/src/network/NetworkPrereqs.h
r2773 r3084 90 90 class ClientInformation; 91 91 class ConnectionManager; 92 class FunctionCallManager; 92 93 class GamestateClient; 93 94 class GamestateManager; … … 96 97 template <class T> class NetworkCallback; 97 98 class NetworkCallbackManager; 99 class NetworkFunctionBase; 100 class NetworkFunctionStatic; 101 class NetworkMemberFunctionBase; 102 template <class T> class NetworkMemeberFunction; 103 struct NetworkFunctionPointer; 98 104 class PacketBuffer; 99 105 class Server; … … 112 118 namespace packet 113 119 { 120 class Acknowledgement; 121 class Chat; 122 class ClassID; 123 class FunctionCalls; 124 class FunctionIDs; 114 125 class Gamestate; 126 class NetworkIDs; 115 127 class Packet; 116 class Acknowledgement;117 class ClassID;118 128 class Welcome; 119 class Chat;120 129 } 121 130 } -
code/trunk/src/network/Server.cc
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 61 61 #include "util/Convert.h" 62 62 #include "ChatListener.h" 63 #include "FunctionCallManager.h" 64 #include "packet/FunctionIDs.h" 65 63 66 64 67 namespace orxonox … … 152 155 void Server::update(const Clock& time) { 153 156 processQueue(); 157 gamestates_->processGamestates(); 154 158 //this steers our network frequency 155 159 timeSinceLastUpdate_+=time.getDeltaTime(); 156 160 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 157 161 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 158 gamestates_->processGamestates();159 162 updateGamestate(); 163 FunctionCallManager::sendCalls(); 160 164 } 161 165 } … … 341 345 return false; 342 346 } 343 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 347 COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl; 348 349 // synchronise class ids 344 350 connection->syncClassid(temp->getID()); 351 352 // now synchronise functionIDs 353 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); 354 fIDs->setClientID(clientID); 355 bool b = fIDs->send(); 356 assert(b); 357 345 358 temp->setSynched(true); 346 COUT( 3) << "sending welcome" << std::endl;359 COUT(4) << "sending welcome" << std::endl; 347 360 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 348 361 w->setClientID(temp->getID()); 349 b ool b= w->send();362 b = w->send(); 350 363 assert(b); 351 364 packet::Gamestate *g = new packet::Gamestate(); -
code/trunk/src/network/Server.h
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200723 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... 26 26 * 27 27 */ 28 29 //30 // C++ Interface: Server31 //32 // Description:33 //34 //35 // Author: Oliver Scheuss, (C) 200736 //37 // Copyright: See COPYING file that comes with this distribution38 //39 //40 28 41 29 #ifndef _Server_H__ … … 51 39 namespace orxonox 52 40 { 53 const int CLIENTID_SERVER = 0;54 const unsigned int NETWORK_FREQUENCY = 25;55 const float NETWORK_PERIOD = 1.f/NETWORK_FREQUENCY;56 41 57 42 /** -
code/trunk/src/network/TrafficControl.cc
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss <scheusso [at] ee.ethz.ch> , (C) 200823 * Oliver Scheuss <scheusso [at] ee.ethz.ch> 24 24 * Co-authors: 25 25 * ... … … 91 91 void TrafficControl::setConfigValues() 92 92 { 93 SetConfigValue ( bActive_, true );94 SetConfigValue ( targetSize, 5000 );93 SetConfigValue ( bActive_, false ); 94 SetConfigValue ( targetSize, 10000 ); 95 95 } 96 96 … … 121 121 122 122 123 void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list) 124 { 125 // copiedVector = *list; 123 void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list) 124 { 126 125 currentClientID=clientID; 127 126 currentGamestateID=gamestateID; … … 143 142 assert(clientListTemp_.find(clientID) != clientListTemp_.end() ); 144 143 assert(clientListPerm_.find(clientID) != clientListPerm_.end() ); 145 assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() ); 146 147 for(itvec = clientListTemp_[clientID][gamestateID].begin(); itvec != clientListTemp_[clientID][gamestateID].end(); itvec++) 144 assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() ); 145 146 // shortcut for maps 147 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 148 std::map<unsigned int, std::list<obj> >& objectListTemp = clientListTemp_[clientID]; 149 150 for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++) 148 151 { 149 if( clientListPerm_[clientID].find((*itvec).objID) != clientListPerm_[clientID].end()) // check whether the obj already exists in our lists150 { 151 clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;152 clientListPerm_[clientID][(*itvec).objID].objValueSched = 0; //set scheduling value back152 if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists 153 { 154 objectListPerm[(*itvec).objID].objCurGS = gamestateID; 155 objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back 153 156 } 154 157 else 155 158 { 156 159 assert(0); 157 clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;158 clientListPerm_[clientID][(*itvec).objID].objID = (*itvec).objID;159 clientListPerm_[clientID][(*itvec).objID].objCreatorID = (*itvec).objCreatorID;160 clientListPerm_[clientID][(*itvec).objID].objSize = (*itvec).objSize;160 objectListPerm[(*itvec).objID].objCurGS = gamestateID; 161 objectListPerm[(*itvec).objID].objID = (*itvec).objID; 162 objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID; 163 objectListPerm[(*itvec).objID].objSize = (*itvec).objSize; 161 164 } 162 165 } 163 166 // remove temporary list (with acked objects) from the map 164 clientListTemp_[clientID].erase( clientListTemp_[clientID].find(gamestateID) );167 objectListTemp.erase( objectListTemp.find(gamestateID) ); 165 168 } 166 169 … … 176 179 { 177 180 std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs 178 // itperm = (clientListPerm_).find(clientID);179 // assert(itperm != clientListPerm_.end() );180 181 unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0; 181 182 clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom); 182 // itperm->second.insert(std::pair<unsigned int, objInfo>(objid,objinf));183 // permObjPrio_.insert(objid, objinf.objValuePerm);184 183 } 185 184 … … 188 187 * takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp 189 188 */ 190 void TrafficControl::updateClientListTemp(std::list<obj> *list)191 { 192 clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>( *list);189 void TrafficControl::updateClientListTemp(std::list<obj>& list) 190 { 191 clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list); 193 192 } 194 193 … … 197 196 *takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY) 198 197 */ 199 void TrafficControl::cut(std::list<obj> *list, unsigned int targetsize)198 void TrafficControl::cut(std::list<obj>& list, unsigned int targetsize) 200 199 { 201 200 unsigned int size=0; 202 201 std::list<obj>::iterator itvec, ittemp; 203 assert(!list ->empty());204 for(itvec = list ->begin(); itvec != list->end();)202 assert(!list.empty()); 203 for(itvec = list.begin(); itvec != list.end();) 205 204 { 206 205 assert( (*itvec).objSize < 1000); … … 213 212 { 214 213 clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative 215 list->erase(itvec++); 214 list.erase(itvec, list.end()); 215 break; 216 216 } 217 217 // printList(list, currentClientID); 218 218 } 219 assert(!list ->empty());219 assert(!list.empty()); 220 220 } 221 221 … … 224 224 *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. 225 225 */ 226 void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)226 void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list) 227 227 { 228 228 … … 232 232 //if listToProcess contains new Objects, add them to clientListPerm 233 233 std::list<obj>::iterator itvec; 234 for( itvec=list->begin(); itvec != list->end(); itvec++) 234 235 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 236 237 for( itvec=list.begin(); itvec != list.end(); itvec++) 235 238 { 236 if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )239 if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() ) 237 240 { 238 241 // we already have the object in our map 239 242 //obj bleibt in liste und permanente prio wird berechnet 240 clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS;243 objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS; 241 244 continue;//check next objId 242 245 } … … 254 257 //sort copied list according to priorities 255 258 // use boost bind here because we need to pass a memberfunction to stl sort 256 list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 259 // sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 260 list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 261 262 // list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 257 263 258 264 //now we check, that the creator of an object always exists on a client 259 265 std::list<obj>::iterator itcreator; 260 for(itvec = list ->begin(); itvec != list->end(); itvec++)266 for(itvec = list.begin(); itvec != list.end(); itvec++) 261 267 { 262 268 fixCreatorDependencies(itvec, list, clientID); … … 266 272 // printList(list, clientID); 267 273 cut(list, targetSize); 268 269 274 //now sort again after objDataOffset 270 list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 275 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 276 list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 271 277 } 272 278 //diese Funktion updateClientList muss noch gemacht werden … … 275 281 } 276 282 277 void TrafficControl::printList(std::list<obj> *list, unsigned int clientID)283 void TrafficControl::printList(std::list<obj>& list, unsigned int clientID) 278 284 { 279 285 std::list<obj>::iterator it; 280 286 COUT(0) << "=========== Objectlist ===========" << endl; 281 for( it=list ->begin(); it!=list->end(); it++)287 for( it=list.begin(); it!=list.end(); it++) 282 288 COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl; 283 289 } 284 290 285 void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj> *list, unsigned int clientID)291 void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID) 286 292 { 287 293 if ( (*it1).objCreatorID == OBJECTID_UNKNOWN ) … … 290 296 return; 291 297 std::list<obj>::iterator it2, it3=it1; 292 for( it2 = ++it3; it2 != list ->end(); it2++ )298 for( it2 = ++it3; it2 != list.end(); it2++ ) 293 299 { 294 300 if( (*it2).objID == (*it1).objCreatorID ) 295 301 { 296 it3 = list ->insert(it1, *it2); //insert creator before it1297 list ->erase(it2);302 it3 = list.insert(it1, *it2); //insert creator before it1 303 list.erase(it2); 298 304 // printList(list, clientID); 299 305 fixCreatorDependencies( it3, list, clientID ); -
code/trunk/src/network/TrafficControl.h
r2710 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss <scheusso [at] ee.ethz.ch> , (C) 200823 * Oliver Scheuss <scheusso [at] ee.ethz.ch> 24 24 * Co-authors: 25 25 * ... … … 83 83 84 84 /** 85 *Lists that will be used:86 *listToProcess87 *clientListPerm88 *clientListTemp89 *referenceList90 *permObjPrio list91 *schedObjPrio92 */93 //start: lists to be used94 /**95 *creates list (typ map) that contains objids, struct with info concerning object(objid)96 */97 // std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the list given by GS98 /**99 85 *permanent client list: contains client ids, object ids and objectInfos (in this order) 100 86 */ … … 106 92 */ 107 93 std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_; 108 /**109 *static priority list: contains obj id, basic priority (in this order)110 */111 // std::map<unsigned int, unsigned int> permObjPrio_;112 /**113 *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)114 */115 // std::map<unsigned int, unsigned int> schedObjPrio_;116 //end: lists to be used117 94 118 95 /**updateReferenceList … … 123 100 unsigned int targetSize; 124 101 bool bActive_; 125 /**126 *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed127 */128 // std::list<obj> copiedVector;129 130 // void updateReferenceList(std::map<unsigned int, objInfo> *list);//done131 void insertinClientListPerm(unsigned int clientID, obj objinf);//done132 /**133 *creates listToProcess, which can be easialy compared with other lists134 */135 // void copyList(std::list<obj> *list);//done136 102 137 void cut(std::list<obj> *list, unsigned int targetsize); 138 void updateClientListTemp(std::list<obj> *list);//done 103 void insertinClientListPerm(unsigned int clientID, obj objinf); 104 105 void cut(std::list<obj>& list, unsigned int targetsize); 106 void updateClientListTemp(std::list<obj>& list);//done 139 107 /** 140 108 *evaluates Data given (list) and produces result(->Data to be updated) 141 109 */ 142 void evaluateList(unsigned int clientID, std::list<obj> *list);//done110 void evaluateList(unsigned int clientID, std::list<obj>& list);//done 143 111 void ack(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client 144 112 … … 162 130 void setConfigValues(); 163 131 static TrafficControl *getInstance(); 164 void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it 165 //done 132 void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it 166 133 static void processAck(unsigned int clientID, unsigned int gamestateID) 167 134 { return instance_->ack(clientID, gamestateID); } 168 //done169 135 void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) 170 136 171 137 bool prioritySort(uint32_t clientID, obj i, obj j); 172 138 bool dataSort(obj i, obj j); 173 void printList(std::list<obj> *list, unsigned int clientID);174 void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);139 void printList(std::list<obj>& list, unsigned int clientID); 140 void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj>& list, unsigned int clientID); 175 141 }; 176 142 -
code/trunk/src/network/packet/CMakeLists.txt
r2710 r3084 1 1 ADD_SOURCE_FILES(NETWORK_SRC_FILES 2 2 Packet.cc 3 Acknowledgement.cc 3 4 Chat.cc 4 5 ClassID.cc 5 Acknowledgement.cc 6 DeleteObjects.cc 7 FunctionIDs.cc 8 FunctionCalls.cc 6 9 Gamestate.cc 7 10 Welcome.cc 8 DeleteObjects.cc9 11 ) -
code/trunk/src/network/packet/ClassID.cc
r2773 r3084 93 93 } 94 94 95 COUT( 0) << "classid packetSize is " << packetSize << endl;95 COUT(5) << "classid packetSize is " << packetSize << endl; 96 96 97 97 } -
code/trunk/src/network/packet/FunctionCalls.cc
- Property svn:eol-style set to native
-
code/trunk/src/network/packet/FunctionCalls.h
- Property svn:eol-style set to native
-
code/trunk/src/network/packet/FunctionIDs.cc
- Property svn:eol-style set to native
-
code/trunk/src/network/packet/FunctionIDs.h
- Property svn:eol-style set to native
-
code/trunk/src/network/packet/Gamestate.cc
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200823 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 107 107 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 108 108 109 tempsize=it->getSize(id, mode); 109 // tempsize=it->getSize(id, mode); 110 111 tempsize = it->getData(mem, id, mode); 112 if ( tempsize != 0 ) 113 dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 114 110 115 #ifndef NDEBUG 111 116 if(currentsize+tempsize > size){ … … 123 128 }// stop allocate additional memory 124 129 #endif 125 126 if ( it->doSync( id, mode ) ) 127 dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 128 if(!it->getData(mem, id, mode)) 129 return false; // mem pointer gets automatically increased because of call by reference 130 // if(!it->getData(mem, id, mode)) 131 // return false; // mem pointer gets automatically increased because of call by reference 130 132 // increase size counter by size of current synchronisable 131 133 currentsize+=tempsize; … … 177 179 } 178 180 } 179 180 181 // In debug mode, check first, whether there are no duplicate objectIDs 181 182 #ifndef NDEBUG 182 ObjectList<Synchronisable>::iterator it; 183 for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) { 184 if (it->getObjectID() == OBJECTID_UNKNOWN) { 185 if (it->objectMode_ != 0x0) { 186 COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl; 187 COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl; 188 COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl; 189 assert(false); 183 if(this->getID()%1000==0){ 184 std::list<uint32_t> v1; 185 ObjectList<Synchronisable>::iterator it; 186 for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) { 187 if (it->getObjectID() == OBJECTID_UNKNOWN) { 188 if (it->objectMode_ != 0x0) { 189 COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl; 190 COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl; 191 COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl; 192 assert(false); 193 } 190 194 } 191 }192 else {193 ObjectList<Synchronisable>::iterator it2;194 for (it2 = ObjectList<Synchronisable>::begin(); it2 != ObjectList<Synchronisable>::end(); ++it2) {195 if (it->getObjectID() == it2->getObjectID() && *it != *it2) {196 COUT(0) << "Found duplicate objectIDs on the client!" << std::endl197 << "Are you sure you don't create a Sychnronisable objcect with 'new' \198 that doesn't have objectMode = 0x0?" << std::endl;199 assert(false);195 else { 196 std::list<uint32_t>::iterator it2; 197 for (it2 = v1.begin(); it2 != v1.end(); ++it2) { 198 if (it->getObjectID() == *it2) { 199 COUT(0) << "Found duplicate objectIDs on the client!" << std::endl 200 << "Are you sure you don't create a Sychnronisable objcect with 'new' \ 201 that doesn't have objectMode = 0x0?" << std::endl; 202 assert(false); 203 } 200 204 } 205 v1.push_back(it->getObjectID()); 201 206 } 202 207 } … … 221 226 uint8_t *d1 = data_+GamestateHeader::getSize(); 222 227 uint8_t *d2 = gs.data_+GamestateHeader::getSize(); 228 GamestateHeader* h1 = new GamestateHeader(data_); 229 GamestateHeader* h2 = new GamestateHeader(gs.data_); 230 assert(h1->getDataSize() == h2->getDataSize()); 223 231 assert(!isCompressed()); 224 232 assert(!gs.isCompressed()); 225 while(d1<data_+header_->getDataSize()) 226 { 227 if(*d1!=*d2) 228 return false; 229 d1++; 230 d2++; 231 } 232 return true; 233 return memcmp(d1, d2, h1->getDataSize())==0; 233 234 } 234 235 … … 357 358 } 358 359 360 // Gamestate *Gamestate::diff(Gamestate *base) 361 // { 362 // assert(data_); 363 // assert(!header_->isCompressed()); 364 // assert(!header_->isDiffed()); 365 // GamestateHeader diffHeader(base->data_); 366 // uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 367 // uint32_t of=0; // pointers offset 368 // uint32_t dest_length=0; 369 // dest_length=header_->getDataSize(); 370 // if(dest_length==0) 371 // return NULL; 372 // uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 373 // uint8_t *dest = ndata + GamestateHeader::getSize(); 374 // 375 // 376 // // LOOP-UNROLLED DIFFING 377 // uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs; 378 // // diff in 4-byte steps 379 // while( of < (uint32_t)(header_->getDataSize())/4 ){ 380 // if( of < (uint32_t)(diffHeader.getDataSize())/4 ) 381 // { 382 // *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor 383 // ++of; 384 // } 385 // else 386 // { 387 // *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of) 388 // ++of; 389 // } 390 // } 391 // for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 ) 392 // { 393 // if( of*4+of2 < diffHeader.getDataSize() ) 394 // { 395 // *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor 396 // } 397 // else 398 // { 399 // *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of) 400 // } 401 // } 402 // 403 // Gamestate *g = new Gamestate(ndata, getClientID()); 404 // *(g->header_) = *header_; 405 // g->header_->setDiffed( true ); 406 // g->header_->setBaseID( base->getID() ); 407 // g->flags_=flags_; 408 // g->packetDirection_ = packetDirection_; 409 // return g; 410 // } 411 359 412 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 360 413 assert(data_); … … 378 431 379 432 //call TrafficControl 380 TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ );433 TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ ); 381 434 382 435 //copy in the zeros 383 for(it=dataMap_.begin(); it!=dataMap_.end();){ 436 // std::list<obj>::iterator itt; 437 // COUT(0) << "myvector contains:"; 438 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ ) 439 // COUT(0) << " " << (*itt).objID; 440 // COUT(0) << endl; 441 for(it=dataVector_.begin(); it!=dataVector_.end();){ 384 442 SynchronisableHeader oldobjectheader(origdata); 385 443 SynchronisableHeader newobjectheader(newdata); -
code/trunk/src/network/packet/Gamestate.h
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200823 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 37 37 #include <string.h> 38 38 #include <map> 39 #include < list>39 #include <vector> 40 40 #include <cassert> 41 41 #ifndef NDEBUG … … 120 120 bool compressData(); 121 121 bool decompressData(); 122 bool operator ==(packet::Gamestate gs); 122 123 123 124 // Packet functions … … 126 127 virtual inline bool process(); 127 128 128 bool operator ==(packet::Gamestate gs);129 129 private: 130 130 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 131 std::list<obj> data Map_;131 std::list<obj> dataVector_; 132 132 GamestateHeader* header_; 133 133 }; -
code/trunk/src/network/packet/Packet.cc
r2773 r3084 39 39 40 40 #include "Acknowledgement.h" 41 #include "DeleteObjects.h" 41 42 #include "Chat.h" 42 43 #include "ClassID.h" 44 #include "FunctionCalls.h" 45 #include "FunctionIDs.h" 43 46 #include "Gamestate.h" 44 47 #include "Welcome.h" 45 #include "DeleteObjects.h"46 48 #include "network/Host.h" 47 49 #include "core/CoreIncludes.h" … … 153 155 case ENUM::Welcome: 154 156 case ENUM::DeleteObjects: 157 case ENUM::FunctionIDs: 158 case ENUM::FunctionCalls: 155 159 break; 156 160 default: … … 170 174 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 171 175 Packet *p = 0; 172 COUT( 5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;176 COUT(6) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl; 173 177 switch( *(ENUM::Type *)(data + _PACKETID) ) 174 178 { 175 179 case ENUM::Acknowledgement: 176 COUT( 4) << "ack" << std::endl;180 COUT(5) << "ack" << std::endl; 177 181 p = new Acknowledgement( data, clientID ); 178 182 break; 179 183 case ENUM::Chat: 180 COUT( 4) << "chat" << std::endl;184 COUT(5) << "chat" << std::endl; 181 185 p = new Chat( data, clientID ); 182 186 break; 183 187 case ENUM::ClassID: 184 COUT( 4) << "classid" << std::endl;188 COUT(5) << "classid" << std::endl; 185 189 p = new ClassID( data, clientID ); 186 190 break; 187 191 case ENUM::Gamestate: 188 COUT( 4) << "gamestate" << std::endl;192 COUT(5) << "gamestate" << std::endl; 189 193 // TODO: remove brackets 190 194 p = new Gamestate( data, clientID ); 191 195 break; 192 196 case ENUM::Welcome: 193 COUT( 4) << "welcome" << std::endl;197 COUT(5) << "welcome" << std::endl; 194 198 p = new Welcome( data, clientID ); 195 199 break; 196 200 case ENUM::DeleteObjects: 197 COUT( 4) << "deleteobjects" << std::endl;201 COUT(5) << "deleteobjects" << std::endl; 198 202 p = new DeleteObjects( data, clientID ); 203 break; 204 case ENUM::FunctionCalls: 205 COUT(5) << "functionCalls" << std::endl; 206 p = new FunctionCalls( data, clientID ); 207 break; 208 case ENUM::FunctionIDs: 209 COUT(5) << "functionIDs" << std::endl; 210 p = new FunctionIDs( data, clientID ); 199 211 break; 200 212 default: -
code/trunk/src/network/packet/Packet.h
r2773 r3084 45 45 enum Type{ 46 46 Acknowledgement, 47 Chat, 48 ClassID, 49 DeleteObjects, 50 FunctionIDs, 51 FunctionCalls, 47 52 Gamestate, 48 ClassID, 49 Chat, 50 Welcome, 51 DeleteObjects 53 Welcome 52 54 }; 53 55 } … … 66 68 virtual unsigned int getSize() const =0; 67 69 virtual bool process()=0; 68 uint32_t getFlags()70 inline uint32_t getFlags() 69 71 { return flags_; } 70 in t getClientID()72 inline int getClientID() 71 73 { return clientID_; } 72 void setClientID( int id )74 inline void setClientID( int id ) 73 75 { clientID_ = id; } 74 76 … … 78 80 Packet(uint8_t *data, unsigned int clientID); 79 81 // Packet(ENetPacket *packet, ENetPeer *peer); 82 inline bool isDataENetAllocated() const 83 { return bDataENetAllocated_; } 84 80 85 uint32_t flags_; 81 86 unsigned int clientID_; -
code/trunk/src/network/synchronisable/NetworkCallbackManager.cc
r2662 r3084 32 32 33 33 namespace orxonox{ 34 34 35 35 std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_; 36 36 std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_; … … 60 60 while( triggeredCallbacks_.empty()==false ) 61 61 { 62 triggeredCallbacks_.front()->call(); 62 //make sure callback hasn't been deleted before 63 if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() ) 64 triggeredCallbacks_.front()->call(); 63 65 triggeredCallbacks_.pop(); 64 66 } -
code/trunk/src/network/synchronisable/Synchronisable.cc
r3068 r3084 66 66 objectID=OBJECTID_UNKNOWN; 67 67 classID = static_cast<uint32_t>(-1); 68 68 69 // set dataSize to 0 70 this->dataSize_ = 0; 69 71 // set standard priority 70 72 this->setPriority( priority::normal ); … … 96 98 // delete callback function objects 97 99 if(!Identifier::isCreatingHierarchy()){ 98 for(std:: list<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)100 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++) 99 101 delete (*it); 100 102 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) … … 236 238 * @return true: if !doSync or if everything was successfully saved 237 239 */ 238 boolSynchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){240 uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){ 239 241 if(mode==0x0) 240 242 mode=state_; 241 243 //if this tick is we dont synchronise, then abort now 242 244 if(!doSync(id, mode)) 243 return true;245 return 0; 244 246 uint32_t tempsize = 0; 245 247 if (this->classID==0) … … 250 252 251 253 assert(this->classID==this->getIdentifier()->getNetworkID()); 252 std::list<SynchronisableVariableBase*>::iterator i; 253 uint32_t size; 254 size=getSize(id, mode); 254 std::vector<SynchronisableVariableBase*>::iterator i; 255 255 256 256 // start copy header 257 257 SynchronisableHeader header(mem); 258 header.setDataSize( size ); 258 mem += SynchronisableHeader::getSize(); 259 // end copy header 260 261 262 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl; 263 // copy to location 264 for(i=syncList.begin(); i!=syncList.end(); ++i){ 265 tempsize += (*i)->getData( mem, mode ); 266 //tempsize += (*i)->getSize( mode ); 267 } 268 269 tempsize += SynchronisableHeader::getSize(); 259 270 header.setObjectID( this->objectID ); 260 271 header.setCreatorID( this->creatorID ); 261 272 header.setClassID( this->classID ); 262 273 header.setDataAvailable( true ); 263 tempsize += SynchronisableHeader::getSize(); 264 mem += SynchronisableHeader::getSize(); 265 // end copy header 266 267 268 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 269 // copy to location 270 for(i=syncList.begin(); i!=syncList.end(); ++i){ 271 (*i)->getData( mem, mode ); 272 tempsize += (*i)->getSize( mode ); 273 } 274 header.setDataSize( tempsize ); 275 276 #ifndef NDEBUG 277 uint32_t size; 278 size=getSize(id, mode); 274 279 assert(tempsize==size); 275 return true; 280 #endif 281 return tempsize; 276 282 } 277 283 … … 286 292 if(mode==0x0) 287 293 mode=state_; 288 std:: list<SynchronisableVariableBase *>::iterator i;294 std::vector<SynchronisableVariableBase *>::iterator i; 289 295 if(syncList.empty()){ 290 296 assert(0); … … 325 331 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 326 332 int tsize=SynchronisableHeader::getSize(); 327 if (mode==0x0)333 if (mode==0x0) 328 334 mode=state_; 329 if (!doSync(id, mode))335 if (!doSync(id, mode)) 330 336 return 0; 331 std::list<SynchronisableVariableBase*>::iterator i; 332 for(i=syncList.begin(); i!=syncList.end(); i++){ 337 assert( mode==state_ ); 338 tsize += this->dataSize_; 339 std::vector<SynchronisableVariableBase*>::iterator i; 340 for(i=stringList.begin(); i!=stringList.end(); ++i){ 333 341 tsize += (*i)->getSize( mode ); 334 342 } -
code/trunk/src/network/synchronisable/Synchronisable.h
r3068 r3084 33 33 34 34 #include <list> 35 #include <vector> 35 36 #include <map> 36 37 #include <queue> 37 38 #include <cassert> 39 #include <string> 38 40 #include "util/Math.h" 39 41 #include "util/mbool.h" … … 120 122 public: 121 123 friend class packet::Gamestate; 122 // friend class Server;123 124 virtual ~Synchronisable(); 124 125 … … 139 140 Synchronisable(BaseObject* creator); 140 141 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 141 template <class T> void unregisterVariable(T& var);142 //template <class T> void unregisterVariable(T& var); 142 143 void setObjectMode(uint8_t mode); 143 144 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 145 146 146 147 private: 147 boolgetData(uint8_t*& men, int32_t id, uint8_t mode=0x0);148 uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0); 148 149 uint32_t getSize(int32_t id, uint8_t mode=0x0); 149 150 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); … … 155 156 uint32_t classID; 156 157 157 std::list<SynchronisableVariableBase*> syncList; 158 std::vector<SynchronisableVariableBase*> syncList; 159 std::vector<SynchronisableVariableBase*> stringList; 160 uint32_t dataSize_; //size of all variables except strings 158 161 static uint8_t state_; // detemines wheter we are server (default) or client 159 162 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) … … 164 167 }; 165 168 166 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)167 {168 if (bidirectional)169 syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));170 else171 syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));172 }173 174 template <class T> void Synchronisable::unregisterVariable(T& var){175 std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();176 while(it!=syncList.end()){177 if( ((*it)->getReference()) == &var ){178 delete (*it);179 syncList.erase(it);180 return;181 }182 else183 it++;184 }185 bool unregistered_nonexistent_variable = false;186 assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:187 // the variable has not been registered before188 }189 190 169 // ================= Specialisation declarations 170 171 // template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 172 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 191 173 template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 192 174 template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); … … 200 182 template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 201 183 template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 184 185 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 186 { 187 if (bidirectional) 188 { 189 syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb)); 190 this->dataSize_ += syncList.back()->getSize(state_); 191 } 192 else 193 { 194 syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb)); 195 if ( this->state_ == mode ) 196 this->dataSize_ += syncList.back()->getSize(state_); 197 } 198 } 199 200 201 202 // template <class T> void Synchronisable::unregisterVariable(T& var){ 203 // std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); 204 // while(it!=syncList.end()){ 205 // if( ((*it)->getReference()) == &var ){ 206 // delete (*it); 207 // syncList.erase(it); 208 // return; 209 // } 210 // else 211 // it++; 212 // } 213 // bool unregistered_nonexistent_variable = false; 214 // assert(unregistered_nonexistent_variable); //if we reach this point something went wrong: 215 // // the variable has not been registered before 216 // } 217 218 202 219 } 203 220 -
code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
r2662 r3084 29 29 30 30 #include "network/synchronisable/Synchronisable.h" 31 #include <string> 31 32 32 33 // ================ template spezialisation … … 34 35 35 36 namespace orxonox{ 37 38 // template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 39 // { 40 // if (bidirectional) 41 // syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb)); 42 // else 43 // syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb)); 44 // stringList.push_back(syncList.back()); 45 // } 46 47 template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 48 { 49 if (bidirectional) 50 syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb)); 51 else 52 syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb)); 53 stringList.push_back(syncList.back()); 54 } 36 55 37 56 template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) … … 52 71 registerVariable(variable.y, mode, cb, bidirectional); 53 72 } 54 template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)55 {56 registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);57 }73 // template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) 74 // { 75 // registerVariable( (const ColourValue&)variable, mode, cb, bidirectional); 76 // } 58 77 59 78 template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) -
code/trunk/src/network/synchronisable/SynchronisableVariable.cc
- Property svn:eol-style set to native
-
code/trunk/src/network/synchronisable/SynchronisableVariable.h
r2896 r3084 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200823 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 35 35 #include <string> 36 36 #include <cassert> 37 #include "util/Math.h" 37 #include "util/Serialise.h" 38 #include "core/Core.h" 39 #include "core/CoreIncludes.h" 40 #include "core/GameMode.h" 38 41 #include "network/synchronisable/NetworkCallback.h" 39 42 #include "network/synchronisable/NetworkCallbackManager.h" … … 55 58 { 56 59 public: 57 virtual voidgetData(uint8_t*& mem, uint8_t mode)=0;60 virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0; 58 61 virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0; 59 62 virtual uint32_t getSize(uint8_t mode)=0; … … 62 65 virtual ~SynchronisableVariableBase() {} 63 66 protected: 64 static void setState();65 67 static uint8_t state_; 66 68 }; … … 74 76 75 77 virtual inline uint8_t getMode(){ return mode_; } 76 virtual inline voidgetData(uint8_t*& mem, uint8_t mode);78 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); 77 79 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 78 80 virtual inline uint32_t getSize(uint8_t mode); 79 81 virtual inline void* getReference(){ return (void *)&this->variable_; } 80 82 protected: 81 bool checkEquality(uint8_t* mem);82 void setAndIncrease(uint8_t*& mem);83 void getAndIncrease(uint8_t*& mem);84 uint32_t returnSize();85 83 86 84 T& variable_; … … 97 95 98 96 virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^ 99 virtual voidgetData(uint8_t*& mem, uint8_t mode);97 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); 100 98 virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 101 virtual uint32_t getSize(uint8_t mode);99 virtual inline uint32_t getSize(uint8_t mode); 102 100 private: 103 101 T varBuffer_; … … 110 108 variable_( variable ), mode_( syncDirection ), callback_( cb ) 111 109 { 112 setState(); 110 if ( state_ == 0x0 ) 111 { 112 state_ = GameMode::isMaster() ? 0x1 : 0x2; // set the appropriate mode here 113 } 113 114 } 114 115 … … 119 120 } 120 121 121 template <class T> voidSynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)122 template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode) 122 123 { 123 124 if ( state_ == this->mode_ ) 124 getAndIncrease( mem ); 125 // mem += SynchronisableVariable<T>::getSize(); 125 { 126 saveAndIncrease( this->variable_, mem ); 127 return returnSize( this->variable_ ); 128 } 129 else 130 return 0; 126 131 } 127 132 … … 135 140 if ( this->callback_ != 0 ) 136 141 { 137 if( forceCallback || !checkEquality( mem ) )142 if( forceCallback || !checkEquality( this->variable_, mem ) ) 138 143 callback = true; 139 144 } 140 145 // write the data 141 setAndIncrease( mem ); 142 // mem += SynchronisableVariable<T>::getSize(); 146 loadAndIncrease( this->variable_, mem ); 143 147 // now do a callback if neccessary 144 148 if ( callback ) 145 149 NetworkCallbackManager::triggerCallback( this->callback_ ); 146 //this->callback_->call(); 147 } 148 149 template <class T> uint32_t SynchronisableVariable<T>::getSize(uint8_t mode) 150 } 151 152 template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode) 150 153 { 151 154 if ( mode == this->mode_ ) 152 return returnSize( );155 return returnSize( this->variable_ ); 153 156 else 154 157 return 0; 155 158 } 156 159 157 template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize();158 template <> _NetworkExport void SynchronisableVariable<const bool>::setAndIncrease(uint8_t*& mem);159 template <> _NetworkExport void SynchronisableVariable<const bool>::getAndIncrease(uint8_t*& mem);160 template <> _NetworkExport bool SynchronisableVariable<const bool>::checkEquality(uint8_t* mem);161 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned char>::returnSize();162 template <> _NetworkExport void SynchronisableVariable<const unsigned char>::setAndIncrease(uint8_t*& mem);163 template <> _NetworkExport void SynchronisableVariable<const unsigned char>::getAndIncrease(uint8_t*& mem);164 template <> _NetworkExport bool SynchronisableVariable<const unsigned char>::checkEquality(uint8_t* mem);165 template <> _NetworkExport uint32_t SynchronisableVariable<const short>::returnSize();166 template <> _NetworkExport void SynchronisableVariable<const short>::setAndIncrease(uint8_t*& mem);167 template <> _NetworkExport void SynchronisableVariable<const short>::getAndIncrease(uint8_t*& mem);168 template <> _NetworkExport bool SynchronisableVariable<const short>::checkEquality(uint8_t* mem);169 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned short>::returnSize();170 template <> _NetworkExport void SynchronisableVariable<const unsigned short>::setAndIncrease(uint8_t*& mem);171 template <> _NetworkExport void SynchronisableVariable<const unsigned short>::getAndIncrease(uint8_t*& mem);172 template <> _NetworkExport bool SynchronisableVariable<const unsigned short>::checkEquality(uint8_t* mem);173 template <> _NetworkExport uint32_t SynchronisableVariable<const int>::returnSize();174 template <> _NetworkExport void SynchronisableVariable<const int>::setAndIncrease(uint8_t*& mem);175 template <> _NetworkExport void SynchronisableVariable<const int>::getAndIncrease(uint8_t*& mem);176 template <> _NetworkExport bool SynchronisableVariable<const int>::checkEquality(uint8_t* mem);177 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned int>::returnSize();178 template <> _NetworkExport void SynchronisableVariable<const unsigned int>::setAndIncrease(uint8_t*& mem);179 template <> _NetworkExport void SynchronisableVariable<const unsigned int>::getAndIncrease(uint8_t*& mem);180 template <> _NetworkExport bool SynchronisableVariable<const unsigned int>::checkEquality(uint8_t* mem);181 template <> _NetworkExport uint32_t SynchronisableVariable<const long>::returnSize();182 template <> _NetworkExport void SynchronisableVariable<const long>::setAndIncrease(uint8_t*& mem);183 template <> _NetworkExport void SynchronisableVariable<const long>::getAndIncrease(uint8_t*& mem);184 template <> _NetworkExport bool SynchronisableVariable<const long>::checkEquality(uint8_t* mem);185 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long>::returnSize();186 template <> _NetworkExport void SynchronisableVariable<const unsigned long>::setAndIncrease(uint8_t*& mem);187 template <> _NetworkExport void SynchronisableVariable<const unsigned long>::getAndIncrease(uint8_t*& mem);188 template <> _NetworkExport bool SynchronisableVariable<const unsigned long>::checkEquality(uint8_t* mem);189 template <> _NetworkExport uint32_t SynchronisableVariable<const long long>::returnSize();190 template <> _NetworkExport void SynchronisableVariable<const long long>::setAndIncrease(uint8_t*& mem);191 template <> _NetworkExport void SynchronisableVariable<const long long>::getAndIncrease(uint8_t*& mem);192 template <> _NetworkExport bool SynchronisableVariable<const long long>::checkEquality(uint8_t* mem);193 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long long>::returnSize();194 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>::setAndIncrease(uint8_t*& mem);195 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>::getAndIncrease(uint8_t*& mem);196 template <> _NetworkExport bool SynchronisableVariable<const unsigned long long>::checkEquality(uint8_t* mem);197 template <> _NetworkExport uint32_t SynchronisableVariable<const float>::returnSize();198 template <> _NetworkExport void SynchronisableVariable<const float>::setAndIncrease(uint8_t*& mem);199 template <> _NetworkExport void SynchronisableVariable<const float>::getAndIncrease(uint8_t*& mem);200 template <> _NetworkExport bool SynchronisableVariable<const float>::checkEquality(uint8_t* mem);201 template <> _NetworkExport uint32_t SynchronisableVariable<const double>::returnSize();202 template <> _NetworkExport void SynchronisableVariable<const double>::setAndIncrease(uint8_t*& mem);203 template <> _NetworkExport void SynchronisableVariable<const double>::getAndIncrease(uint8_t*& mem);204 template <> _NetworkExport bool SynchronisableVariable<const double>::checkEquality(uint8_t* mem);205 template <> _NetworkExport uint32_t SynchronisableVariable<const long double>::returnSize();206 template <> _NetworkExport void SynchronisableVariable<const long double>::setAndIncrease(uint8_t*& mem);207 template <> _NetworkExport void SynchronisableVariable<const long double>::getAndIncrease(uint8_t*& mem);208 template <> _NetworkExport bool SynchronisableVariable<const long double>::checkEquality(uint8_t* mem);209 template <> _NetworkExport uint32_t SynchronisableVariable<const std::string>::returnSize();210 template <> _NetworkExport void SynchronisableVariable<const std::string>::setAndIncrease(uint8_t*& mem);211 template <> _NetworkExport void SynchronisableVariable<const std::string>::getAndIncrease(uint8_t*& mem);212 template <> _NetworkExport bool SynchronisableVariable<const std::string>::checkEquality(uint8_t* mem);213 template <> _NetworkExport uint32_t SynchronisableVariable<const Degree>::returnSize();214 template <> _NetworkExport void SynchronisableVariable<const Degree>::setAndIncrease(uint8_t*& mem);215 template <> _NetworkExport void SynchronisableVariable<const Degree>::getAndIncrease(uint8_t*& mem);216 template <> _NetworkExport bool SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem);217 160 218 161 … … 229 172 } 230 173 231 template <class T> voidSynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)174 template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode) 232 175 { 233 176 if ( this->mode_ == mode ) … … 243 186 mem += sizeof(this->varReference_); 244 187 // now write the content 245 SynchronisableVariable<T>::getAndIncrease(mem );246 // mem += SynchronisableVariable<T>::getSize();188 saveAndIncrease( this->variable_, mem ); 189 return SynchronisableVariableBidirectional::getSize(mode); 247 190 } 248 191 … … 255 198 if ( *static_cast<uint8_t*>(mem) != this->varReference_ ) 256 199 { // wrong reference number, so discard the data 200 // COUT(0) << "discharding data" << endl; 257 201 mem += getSize( mode ); // SynchronisableVariableBidirectional::getSize returns size of variable + reference 258 202 return; … … 260 204 else{ 261 205 // apply data 262 mem += sizeof(varReference_); 263 if ( SynchronisableVariableBidirectional<T>::checkEquality( mem )==true ) 206 if ( checkEquality( this->variable_, mem+sizeof(varReference_) )==true ) 264 207 { 265 mem += SynchronisableVariable<T>::getSize( mode );208 mem += getSize( mode ); 266 209 return; 267 210 } 268 211 else 269 212 { 213 mem += sizeof(varReference_); 270 214 memcpy((void*)&this->varBuffer_, &this->variable_, sizeof(T)); 271 215 if ( this->callback_ != 0 ) … … 285 229 this->varReference_ = *static_cast<uint8_t*>(mem); 286 230 mem += sizeof(varReference_); 287 if ( SynchronisableVariable<T>::checkEquality(mem ) == false )231 if ( checkEquality( this->variable_, mem ) == false ) 288 232 { 289 233 // value changed so remark for callback … … 294 238 } 295 239 // now write the data 296 SynchronisableVariable<T>::setAndIncrease(mem);240 loadAndIncrease(this->variable_, mem); 297 241 // now do a callback if neccessary 298 242 if ( callback ) 299 243 NetworkCallbackManager::triggerCallback( this->callback_ ); 300 //this->callback_->call(); 301 } 302 303 template <class T> uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode) 304 { 305 return SynchronisableVariable<T>::returnSize() + sizeof(varReference_); 244 } 245 246 template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode) 247 { 248 return returnSize( this->variable_ ) + sizeof(varReference_); 306 249 } 307 250
Note: See TracChangeset
for help on using the changeset viewer.