Changeset 6387 for code/branches/presentation2/src/libraries/network
- Timestamp:
- Dec 21, 2009, 1:18:36 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/network
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/network/Client.cc
r6134 r6387 113 113 return true; 114 114 } 115 115 116 116 void Client::printRTT(){ 117 117 COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl; … … 155 155 } 156 156 sendPackets(); // flush the enet queue 157 157 158 158 Connection::processQueue(); 159 159 if(gamestate.processGamestates()) … … 167 167 return; 168 168 } 169 169 170 170 void Client::connectionClosed() 171 171 { -
code/branches/presentation2/src/libraries/network/ClientConnection.cc
r5965 r6387 69 69 { 70 70 ENetEvent event; 71 71 72 72 this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 73 73 if ( this->host_ == NULL ) … … 99 99 bool ClientConnection::closeConnection() { 100 100 ENetEvent event; 101 101 102 102 if ( !this->established_ ) 103 103 return true; … … 146 146 this->connectionClosed(); 147 147 } 148 148 149 149 uint32_t ClientConnection::getRTT() 150 150 { -
code/branches/presentation2/src/libraries/network/ClientConnection.h
r5961 r6387 26 26 * 27 27 */ 28 28 29 29 #ifndef _ClientConnection_H__ 30 30 #define _ClientConnection_H__ … … 40 40 ClientConnection(); 41 41 virtual ~ClientConnection(); 42 42 43 43 void setServerAddress( const std::string& serverAddress ); 44 44 void setPort( unsigned int port ); 45 45 46 46 ENetEvent *getEvent(); 47 47 // check wheter the packet queue is empty … … 59 59 virtual void addPeer(ENetEvent* event); 60 60 virtual void removePeer(ENetEvent* event); 61 61 62 62 bool disconnectConnection(); 63 63 // enet stuff -
code/branches/presentation2/src/libraries/network/ClientConnectionListener.cc
r5929 r6387 45 45 it->clientConnected(clientID); 46 46 } 47 47 48 48 void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID) 49 49 { -
code/branches/presentation2/src/libraries/network/ClientConnectionListener.h
r5929 r6387 40 40 ClientConnectionListener(); 41 41 virtual ~ClientConnectionListener() {} 42 42 43 43 static void broadcastClientConnected(unsigned int clientID); 44 44 static void broadcastClientDisconnected(unsigned int clientID); -
code/branches/presentation2/src/libraries/network/ClientInformation.cc
r5961 r6387 46 46 namespace orxonox 47 47 { 48 48 49 49 50 50 ClientInformation *ClientInformation::head_=0; -
code/branches/presentation2/src/libraries/network/Connection.cc
r5929 r6387 75 75 void Connection::processQueue() { 76 76 ENetEvent event; 77 77 78 78 assert(this->host_); 79 79 -
code/branches/presentation2/src/libraries/network/Connection.h
r5929 r6387 54 54 public: 55 55 virtual ~Connection(); 56 56 57 57 static bool addPacket(ENetPacket *packet, ENetPeer *peer); 58 58 bool sendPackets(); … … 62 62 Connection(); 63 63 static Connection* getInstance(){ return Connection::instance_; } 64 64 65 65 int service(ENetEvent* event); 66 66 virtual void disconnectPeer(ENetPeer *peer); 67 67 68 68 void processQueue(); 69 69 virtual void addPeer(ENetEvent* event)=0; 70 70 virtual void removePeer(ENetEvent* event)=0; 71 71 virtual bool processPacket(ENetEvent* event); 72 72 73 73 ENetHost *host_; 74 74 private: -
code/branches/presentation2/src/libraries/network/FunctionCallManager.cc
r6073 r6387 31 31 32 32 namespace orxonox { 33 33 34 34 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::clientMap_; 35 35 -
code/branches/presentation2/src/libraries/network/FunctionCallManager.h
r6073 r6387 49 49 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 50 50 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 51 51 52 52 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID); 53 53 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1); … … 56 56 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 57 57 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 58 58 59 59 static void sendCalls(); 60 60 61 61 static std::map<uint32_t, packet::FunctionCalls*> clientMap_; 62 62 protected: -
code/branches/presentation2/src/libraries/network/GamestateClient.cc
r5929 r6387 81 81 packet::Gamestate *processed = processGamestate(tempGamestate_); 82 82 assert(processed); 83 83 84 84 //now call the queued callbacks 85 85 NetworkCallbackManager::callCallbacks(); 86 86 87 87 if (!processed){ 88 88 sendAck(0); -
code/branches/presentation2/src/libraries/network/GamestateHandler.cc
r5781 r6387 33 33 34 34 GamestateHandler *GamestateHandler::instance_=0; 35 35 36 36 GamestateHandler::GamestateHandler() 37 37 { -
code/branches/presentation2/src/libraries/network/GamestateManager.cc
r5929 r6387 126 126 return true; 127 127 } 128 128 129 129 void GamestateManager::sendGamestates() 130 130 { … … 142 142 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 143 143 int cid = temp->getID(); //get client id 144 144 145 145 unsigned int gID = temp->getGamestateID(); 146 146 if(!reference) 147 147 return; 148 148 149 149 packet::Gamestate *client=0; 150 150 if(gID != GAMESTATEID_INITIAL){ … … 156 156 } 157 157 } 158 158 159 159 clientGamestates.push(0); 160 160 finishGamestate( cid, &clientGamestates.back(), client, reference ); … … 165 165 // this->threadPool_->passFunction( executor, true ); 166 166 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 167 167 168 168 temp = temp->next(); 169 169 } 170 170 171 171 // threadPool_->synchronise(); 172 172 173 173 while( !clientGamestates.empty() ) 174 174 { … … 185 185 // save the (undiffed) gamestate in the clients gamestate map 186 186 //chose wheather the next gamestate is the first or not 187 187 188 188 packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 189 189 // packet::Gamestate *gs = new packet::Gamestate(*gamestate); … … 193 193 gamestateMap_[clientID][gamestate->getID()]=gs; 194 194 // this->threadMutex_->unlock(); 195 195 196 196 if(base) 197 197 { 198 198 199 199 // COUT(3) << "diffing" << std::endl; 200 200 // packet::Gamestate* gs1 = gs; … … 210 210 gs = new packet::Gamestate(*gs); 211 211 } 212 213 212 213 214 214 bool b = gs->compressData(); 215 215 assert(b); -
code/branches/presentation2/src/libraries/network/NetworkFunction.cc
r6160 r6387 33 33 { 34 34 std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_; 35 35 36 36 std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_; 37 37 std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_; … … 40 40 { 41 41 RegisterRootObject(NetworkFunctionBase); 42 42 43 43 static uint32_t networkID = 0; 44 44 this->networkID_ = networkID++; 45 45 46 46 this->name_ = name; 47 47 NetworkFunctionBase::getNameMap()[name] = this; … … 50 50 { 51 51 } 52 53 52 53 54 54 void NetworkFunctionBase::destroyAllNetworkFunctions() 55 55 { … … 59 59 it->second->destroy(); 60 60 } 61 62 61 62 63 63 /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap() 64 64 { … … 66 66 return nameMap_; 67 67 } 68 69 68 69 70 70 NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p): 71 71 NetworkFunctionBase(name) 72 72 { 73 73 RegisterObject(NetworkFunctionStatic); 74 74 75 75 this->functor_ = functor; 76 76 NetworkFunctionStatic::getFunctorMap()[p] = this; 77 77 NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this; 78 78 } 79 79 80 80 NetworkFunctionStatic::~NetworkFunctionStatic() 81 81 { 82 82 delete this->functor_; 83 83 } 84 84 85 85 /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap() 86 86 { … … 88 88 return functorMap_; 89 89 } 90 90 91 91 /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap() 92 92 { … … 94 94 return idMap_; 95 95 } 96 97 96 97 98 98 NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p): 99 99 NetworkFunctionBase(name) 100 100 { 101 101 RegisterObject(NetworkMemberFunctionBase); 102 102 103 103 this->functorMap_[p] = this; 104 104 this->idMap_[ this->getNetworkID() ] = this; 105 105 } 106 106 107 107 NetworkMemberFunctionBase::~NetworkMemberFunctionBase() 108 108 { 109 109 } 110 110 111 111 112 112 } -
code/branches/presentation2/src/libraries/network/NetworkFunction.h
r6160 r6387 74 74 NetworkFunctionBase(const std::string& name); 75 75 ~NetworkFunctionBase(); 76 76 77 77 virtual void setNetworkID(uint32_t id) { this->networkID_ = id; } 78 78 inline uint32_t getNetworkID() const { return this->networkID_; } 79 79 inline const std::string& getName() const { return name_; } 80 80 static inline bool isStatic( uint32_t networkID ) { return isStaticMap_[networkID]; } 81 81 82 82 static inline void setNetworkID(const std::string& name, uint32_t id) 83 83 { … … 86 86 map[name]->setNetworkID(id); 87 87 } 88 88 89 89 static void destroyAllNetworkFunctions(); 90 90 91 91 protected: 92 92 static std::map<uint32_t, bool> isStaticMap_; 93 93 94 94 private: 95 95 static std::map<std::string, NetworkFunctionBase*>& getNameMap(); 96 96 uint32_t networkID_; 97 97 std::string name_; 98 98 99 99 }; 100 100 … … 104 104 NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p); 105 105 ~NetworkFunctionStatic(); 106 106 107 107 inline void call(){ (*this->functor_)(); } 108 108 inline void call(const MultiType& mt1){ (*this->functor_)(mt1); } … … 111 111 inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); } 112 112 inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); } 113 113 114 114 virtual void setNetworkID( uint32_t id ) 115 115 { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; } … … 120 120 static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ) 121 121 { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; } 122 122 123 123 private: 124 124 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap(); 125 125 static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap(); 126 126 FunctorStatic* functor_; 127 127 128 128 }; 129 129 … … 133 133 NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p); 134 134 ~NetworkMemberFunctionBase(); 135 135 136 136 virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; } 137 137 static inline NetworkMemberFunctionBase* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; } 138 138 static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; } 139 139 static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; } 140 140 141 141 // 142 142 virtual void call(uint32_t objectID)=0; … … 146 146 virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0; 147 147 virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0; 148 148 149 149 private: 150 150 static std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> functorMap_; … … 157 157 NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p); 158 158 ~NetworkMemberFunction(); 159 159 160 160 inline void call(uint32_t objectID) 161 161 { … … 188 188 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5); 189 189 } 190 190 191 191 private: 192 192 FunctorMember<T>* functor_; -
code/branches/presentation2/src/libraries/network/Server.cc
r5961 r6387 137 137 // receive incoming packets 138 138 Connection::processQueue(); 139 139 140 140 if ( ClientInformation::hasClients() ) 141 141 { 142 142 // process incoming gamestates 143 143 GamestateManager::processGamestates(); 144 144 145 145 // send function calls to clients 146 146 FunctionCallManager::sendCalls(); 147 147 148 148 //this steers our network frequency 149 149 timeSinceLastUpdate_+=time.getDeltaTime(); … … 160 160 return ServerConnection::addPacket(packet, clientID); 161 161 } 162 162 163 163 /** 164 164 * @brief: returns ping time to client in milliseconds … … 168 168 return ClientInformation::findClient(clientID)->getRTT(); 169 169 } 170 170 171 171 void Server::printRTT() 172 172 { … … 317 317 } 318 318 COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl; 319 319 320 320 // synchronise class ids 321 321 syncClassid(temp->getID()); 322 322 323 323 // now synchronise functionIDs 324 324 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); … … 326 326 bool b = fIDs->send(); 327 327 assert(b); 328 328 329 329 temp->setSynched(true); 330 330 COUT(4) << "sending welcome" << std::endl; … … 344 344 return true; 345 345 } 346 346 347 347 void Server::disconnectClient( ClientInformation *client ){ 348 348 ServerConnection::disconnectClient( client ); -
code/branches/presentation2/src/libraries/network/Server.h
r5961 r6387 66 66 unsigned int shipID(){return 0;} 67 67 unsigned int playerID(){return 0;} 68 68 69 69 void addPeer(ENetEvent *event); 70 70 void removePeer(ENetEvent *event); 71 71 72 72 bool createClient(int clientID); 73 73 void disconnectClient( ClientInformation *client); -
code/branches/presentation2/src/libraries/network/ServerConnection.cc
r5929 r6387 99 99 return true; 100 100 } 101 101 102 102 void ServerConnection::disconnectClient(ClientInformation *client) 103 103 { 104 104 Connection::disconnectPeer( client->getPeer() ); 105 105 } 106 106 107 107 void ServerConnection::disconnectClient(int clientID){ 108 108 ClientInformation *client = ClientInformation::findClient(clientID); -
code/branches/presentation2/src/libraries/network/ServerConnection.h
r5929 r6387 50 50 public: 51 51 ~ServerConnection(); 52 52 53 53 void setBindAddress( const std::string& bindAddress ); 54 54 void setPort( unsigned int port ); 55 55 56 56 bool openListener(); 57 57 bool closeListener(); -
code/branches/presentation2/src/libraries/network/TrafficControl.cc
r6073 r6387 145 145 assert(clientListPerm_.find(clientID) != clientListPerm_.end() ); 146 146 assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() ); 147 147 148 148 // shortcut for maps 149 149 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; … … 236 236 //if listToProcess contains new Objects, add them to clientListPerm 237 237 std::list<obj>::iterator itvec; 238 238 239 239 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 240 240 241 241 for( itvec=list.begin(); itvec != list.end(); itvec++) 242 242 { … … 256 256 } 257 257 //end compare listToProcess vs clientListPerm 258 258 259 259 //sort copied list according to priorities 260 260 // use boost bind here because we need to pass a memberfunction to stl sort 261 261 // sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 262 262 list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 263 263 264 264 // list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) ); 265 265 … … 277 277 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 278 278 list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 279 279 280 280 //diese Funktion updateClientList muss noch gemacht werden 281 281 updateClientListTemp(list); -
code/branches/presentation2/src/libraries/network/TrafficControl.h
r6073 r6387 69 69 obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset ); 70 70 }; 71 71 72 72 73 73 … … 97 97 unsigned int targetSize; 98 98 bool bActive_; 99 99 100 100 void insertinClientListPerm(unsigned int clientID, obj objinf); 101 101 102 102 void cut(std::list<obj>& list, unsigned int targetsize); 103 103 void updateClientListTemp(std::list<obj>& list);//done … … 107 107 void evaluateList(unsigned int clientID, std::list<obj>& list);//done 108 108 void ack(unsigned int clientID, unsigned int gamestateID); // this function gets called when the server receives an ack from the client 109 109 110 110 //ClientConnectionListener functions 111 111 virtual void clientConnected(unsigned int clientID){}; 112 112 virtual void clientDisconnected(unsigned int clientID); 113 113 114 114 115 115 protected: 116 116 static TrafficControl *instance_; … … 131 131 { return instance_->ack(clientID, gamestateID); } 132 132 void deleteObject(unsigned int objectID); // this function gets called when an object has been deleted (in order to clean up lists and maps) 133 133 134 134 bool prioritySort(uint32_t clientID, obj i, obj j); 135 135 bool dataSort(obj i, obj j); -
code/branches/presentation2/src/libraries/network/packet/Acknowledgement.cc
r5781 r6387 38 38 #define _PACKETID 0 39 39 #define _ACKID _PACKETID + sizeof(packet::Type::Value) 40 40 41 41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID ) 42 42 : Packet() -
code/branches/presentation2/src/libraries/network/packet/Chat.cc
r5781 r6387 35 35 namespace orxonox { 36 36 namespace packet { 37 37 38 38 #define PACKET_FLAGS_CHAT PacketFlag::Reliable 39 39 #define _PACKETID 0 -
code/branches/presentation2/src/libraries/network/packet/ClassID.h
r6073 r6387 36 36 namespace packet { 37 37 38 38 39 39 /** 40 40 @author -
code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc
r6192 r6387 41 41 #define _QUANTITY _PACKETID + sizeof(Type::Value) 42 42 #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) 43 43 44 44 DeleteObjects::DeleteObjects() 45 45 : Packet() -
code/branches/presentation2/src/libraries/network/packet/FunctionCalls.cc
r5781 r6387 36 36 namespace orxonox { 37 37 namespace packet { 38 38 39 39 #define PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable 40 40 #define _PACKETID 0 41 41 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000; 42 42 43 43 FunctionCalls::FunctionCalls() 44 44 : Packet() … … 171 171 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 172 172 assert(!isDataENetAllocated()); 173 173 174 174 // first determine the size that has to be reserved for this call 175 175 uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic … … 200 200 } 201 201 } 202 202 203 203 // now allocated mem if neccessary 204 204 if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION ) … … 210 210 data_ = temp; 211 211 } 212 212 213 213 // now serialise the mt values and copy the function id and isStatic 214 214 uint8_t* temp = data_+currentSize_; … … 240 240 //currentSize_ += callsize; 241 241 currentSize_ = temp-data_; 242 242 243 243 } 244 244 245 245 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 246 246 assert(!isDataENetAllocated()); 247 247 248 248 // first determine the size that has to be reserved for this call 249 249 uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID … … 274 274 } 275 275 } 276 276 277 277 // now allocated mem if neccessary 278 278 if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION ) … … 284 284 data_ = temp; 285 285 } 286 286 287 287 // now serialise the mt values and copy the function id 288 288 uint8_t* temp = data_+currentSize_; … … 314 314 } 315 315 currentSize_ += callsize; 316 316 317 317 } 318 318 -
code/branches/presentation2/src/libraries/network/packet/FunctionIDs.cc
r5781 r6387 53 53 flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS; 54 54 std::queue<std::pair<uint32_t, std::string> > tempQueue; 55 55 56 56 //calculate total needed size (for all strings and integers) 57 57 ObjectList<NetworkFunctionBase>::iterator it; … … 64 64 packetSize += (functionname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t); // reserver size for the functionname string, the functionname length and the networkID 65 65 } 66 66 67 67 this->data_=new uint8_t[ packetSize ]; 68 68 //set the appropriate packet id 69 69 assert(this->data_); 70 70 *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs; 71 71 72 72 uint8_t *temp=data_+sizeof(uint32_t); 73 73 // save the number of all classes 74 74 *(uint32_t*)temp = nrOfFunctions; 75 75 temp += sizeof(uint32_t); 76 76 77 77 // now save all classids and classnames 78 78 std::pair<uint32_t, std::string> tempPair; … … 85 85 temp+=2*sizeof(uint32_t)+tempPair.second.size()+1; 86 86 } 87 87 88 88 COUT(5) << "FunctionIDs packetSize is " << packetSize << endl; 89 89 90 90 } 91 91 … … 106 106 temp += sizeof(uint32_t); 107 107 totalsize += sizeof(uint32_t); // storage size for nr of all classes 108 108 109 109 for(unsigned int i=0; i<nrOfFunctions; i++){ 110 110 totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); // for each network function add size for id, sizeof(string) and length of string itself to totalsize … … 121 121 uint32_t stringsize; 122 122 unsigned char *functionname; 123 123 124 124 COUT(4) << "=== processing functionids: " << endl; 125 125 std::pair<uint32_t, std::string> tempPair; … … 127 127 nrOfFunctions = *(uint32_t*)temp; 128 128 temp += sizeof(uint32_t); 129 129 130 130 for( int i=0; i<nrOfFunctions; i++){ 131 131 networkID = *(uint32_t*)temp; -
code/branches/presentation2/src/libraries/network/packet/FunctionIDs.h
r6073 r6387 36 36 namespace packet { 37 37 38 38 39 39 /** 40 40 @author -
code/branches/presentation2/src/libraries/network/packet/Gamestate.cc
r5929 r6387 95 95 return false; 96 96 } 97 97 98 98 // create the header object 99 99 assert( header_ == 0 ); … … 105 105 ObjectList<Synchronisable>::iterator it; 106 106 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 107 107 108 108 // tempsize=it->getSize(id, mode); 109 109 … … 111 111 if ( tempsize != 0 ) 112 112 dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 113 113 114 114 #ifndef NDEBUG 115 115 if(currentsize+tempsize > size){ … … 362 362 assert(!header_->isCompressed() && !base->header_->isCompressed()); 363 363 assert(!header_->isDiffed()); 364 364 365 365 uint8_t *basep = GAMESTATE_START(base->data_); 366 366 uint8_t *gs = GAMESTATE_START(this->data_); 367 367 uint32_t dest_length = header_->getDataSize(); 368 368 369 369 if(dest_length==0) 370 370 return NULL; 371 371 372 372 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 373 373 uint8_t *dest = GAMESTATE_START(ndata); 374 374 375 375 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 376 376 #ifndef NDEBUG … … 398 398 assert(!header_->isCompressed() && !base->header_->isCompressed()); 399 399 assert(header_->isDiffed()); 400 400 401 401 uint8_t *basep = GAMESTATE_START(base->data_); 402 402 uint8_t *gs = GAMESTATE_START(this->data_); 403 403 uint32_t dest_length = header_->getDataSize(); 404 404 405 405 if(dest_length==0) 406 406 return NULL; 407 407 408 408 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 409 409 uint8_t *dest = ndata + GamestateHeader::getSize(); 410 410 411 411 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 412 412 413 413 Gamestate *g = new Gamestate(ndata, getClientID()); 414 414 assert(g->header_); … … 481 481 uint64_t* bd = (uint64_t*)basedata; 482 482 uint64_t* nd = (uint64_t*)newdata; 483 483 484 484 unsigned int i; 485 485 for( i=0; i<datalength/8; i++ ) -
code/branches/presentation2/src/libraries/network/packet/Packet.cc
r6105 r6387 101 101 @brief 102 102 Destroys a packet completely. 103 103 104 104 That also means destroying the ENetPacket if one exists. There 105 105 */ -
code/branches/presentation2/src/libraries/network/synchronisable/NetworkCallback.h
r6192 r6387 36 36 37 37 namespace orxonox{ 38 38 39 39 struct EmptyType{}; 40 40 41 41 class _NetworkExport NetworkCallbackBase 42 42 { … … 60 60 void (T::*function_) (void); 61 61 }; 62 62 63 63 template <class T, class U> 64 64 class NetworkCallbackNotify: public NetworkCallbackBase -
code/branches/presentation2/src/libraries/network/synchronisable/NetworkCallbackManager.cc
r5781 r6387 26 26 * 27 27 */ 28 28 29 29 #include "NetworkCallbackManager.h" 30 30 #include "NetworkCallback.h" 31 31 32 32 namespace orxonox{ 33 33 34 34 std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_; 35 35 std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_; 36 36 37 37 void NetworkCallbackManager::registerCallback(NetworkCallbackBase *cb) 38 38 { … … 48 48 } 49 49 } 50 50 51 51 void NetworkCallbackManager::triggerCallback(NetworkCallbackBase *cb) 52 52 { -
code/branches/presentation2/src/libraries/network/synchronisable/NetworkCallbackManager.h
r5781 r6387 37 37 38 38 namespace orxonox{ 39 39 40 40 class _NetworkExport NetworkCallbackManager{ 41 41 public: … … 48 48 static std::queue<NetworkCallbackBase*> triggeredCallbacks_; 49 49 }; 50 50 51 51 52 52 } -
code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc
r6192 r6387 62 62 } 63 63 classID_ = static_cast<uint32_t>(-1); 64 64 65 65 // set dataSize to 0 66 66 this->dataSize_ = 0; … … 277 277 //tempsize += (*i)->getSize( mode ); 278 278 } 279 279 280 280 tempsize += SynchronisableHeader::getSize(); 281 281 header.setObjectID( this->objectID_ ); … … 284 284 header.setDataAvailable( true ); 285 285 header.setDataSize( tempsize ); 286 286 287 287 #ifndef NDEBUG 288 288 uint32_t size; -
code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
r6193 r6387 132 132 inline unsigned int getPriority() const { return this->objectFrequency_;} 133 133 inline uint8_t getSyncMode() const { return this->objectMode_; } 134 134 135 135 void setSyncMode(uint8_t mode); 136 136 … … 138 138 Synchronisable(BaseObject* creator); 139 139 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 140 140 141 141 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 142 142 … … 148 148 bool isMyData(uint8_t* mem); 149 149 bool doSync(int32_t id, uint8_t mode=0x0); 150 150 151 151 inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; } 152 152 inline void setClassID(uint32_t id){ this->classID_ = id; } … … 181 181 } 182 182 } 183 183 184 184 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 185 185 186 186 187 187 } 188 188 -
code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h
r6192 r6387 41 41 42 42 namespace orxonox{ 43 43 44 44 namespace VariableDirection{ 45 45 enum Value{ … … 54 54 }; 55 55 } 56 56 57 57 class _NetworkExport SynchronisableVariableBase 58 58 { … … 85 85 NetworkCallbackBase *callback_; 86 86 }; 87 87 88 88 template <class T> 89 89 class SynchronisableVariableBidirectional: public SynchronisableVariable<T> … … 92 92 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=0); 93 93 virtual ~SynchronisableVariableBidirectional(); 94 94 95 95 virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^ 96 96 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); … … 112 112 } 113 113 } 114 114 115 115 template <class T> SynchronisableVariable<T>::~SynchronisableVariable() 116 116 { … … 253 253 return returnSize( this->variable_ ) + sizeof(varReference_); 254 254 } 255 255 256 256 257 257 }
Note: See TracChangeset
for help on using the changeset viewer.