Changeset 6412 for code/branches/pickup2/src/libraries/network
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 1 deleted
- 51 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/libraries/network/Client.cc
r5929 r6412 62 62 Client::Client(): 63 63 isSynched_(false), 64 gameStateFailure_(false) 64 gameStateFailure_(false), 65 timeSinceLastUpdate_(0) 65 66 { 66 67 } … … 73 74 Client::Client(const std::string& address, int port): 74 75 isSynched_(false), 75 gameStateFailure_(false) 76 gameStateFailure_(false), 77 timeSinceLastUpdate_(0) 76 78 { 77 79 setPort( port ); … … 112 114 } 113 115 116 void Client::printRTT(){ 117 COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl; 118 } 119 114 120 /** 115 121 * This function implements the method of sending a chat message to the server … … 133 139 { 134 140 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 135 // COUT(3) << ".";141 // COUT(3) << '.'; 136 142 if ( isConnected() && isSynched_ ) 137 143 { … … 149 155 } 150 156 sendPackets(); // flush the enet queue 151 157 152 158 Connection::processQueue(); 153 159 if(gamestate.processGamestates()) … … 157 163 } 158 164 gamestate.cleanup(); 165 Connection::sendPackets(); 159 166 160 167 return; 161 168 } 162 169 163 170 void Client::connectionClosed() 164 171 { -
code/branches/pickup2/src/libraries/network/Client.h
r5929 r6412 72 72 virtual bool chat(const std::string& message); 73 73 virtual bool broadcast(const std::string& message) { return false; } 74 virtual void printRTT(); 74 75 75 76 void update(const Clock& time); -
code/branches/pickup2/src/libraries/network/ClientConnection.cc
r5929 r6412 38 38 const unsigned int NETWORK_CLIENT_WAIT_TIME = 1; 39 39 const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs 40 const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 5;41 const unsigned int NETWORK_CLIENT_CHANNELS = 2;40 const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 1; 41 const unsigned int NETWORK_CLIENT_CHANNELS = 1; 42 42 43 43 … … 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; … … 147 147 } 148 148 149 uint32_t ClientConnection::getRTT() 150 { 151 assert(server_); 152 return server_->roundTripTime; 153 } 154 149 155 } -
code/branches/pickup2/src/libraries/network/ClientConnection.h
r5929 r6412 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 … … 55 55 protected: 56 56 virtual void connectionClosed()=0; 57 uint32_t getRTT(); 57 58 private: 58 59 virtual void addPeer(ENetEvent* event); 59 60 virtual void removePeer(ENetEvent* event); 60 61 61 62 bool disconnectConnection(); 62 63 // enet stuff -
code/branches/pickup2/src/libraries/network/ClientConnectionListener.cc
r5929 r6412 36 36 { 37 37 ClientConnectionListener::ClientConnectionListener() 38 { 39 RegisterRootObject(ClientConnectionListener); 38 { 39 RegisterRootObject(ClientConnectionListener); 40 40 } 41 41 … … 45 45 it->clientConnected(clientID); 46 46 } 47 47 48 48 void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID) 49 49 { -
code/branches/pickup2/src/libraries/network/ClientConnectionListener.h
r5929 r6412 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/pickup2/src/libraries/network/ClientInformation.cc
r5781 r6412 42 42 #define WIN32_LEAN_AND_MEAN 43 43 #include <enet/enet.h> 44 #include "ClientConnectionListener.h" 44 45 45 46 namespace orxonox 46 47 { 47 48 48 49 49 50 ClientInformation *ClientInformation::head_=0; … … 66 67 if(this==head_) 67 68 head_=next(); 69 ClientConnectionListener::broadcastClientDisconnected( this->getID() ); 68 70 } 69 71 -
code/branches/pickup2/src/libraries/network/Connection.cc
r5929 r6412 75 75 void Connection::processQueue() { 76 76 ENetEvent event; 77 77 78 78 assert(this->host_); 79 79 -
code/branches/pickup2/src/libraries/network/Connection.h
r5929 r6412 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/pickup2/src/libraries/network/FunctionCallManager.cc
r5781 r6412 31 31 32 32 namespace orxonox { 33 33 34 34 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::clientMap_; 35 35 … … 37 37 38 38 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID) 39 { 40 if(clientMap_.find(clientID)==clientMap_.end()) 39 { 40 if(clientMap_.find(clientID)==clientMap_.end()) 41 41 { 42 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 43 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 44 } 45 FunctionCallManager:: 42 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 43 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 44 } 45 FunctionCallManager::clientMap_[clientID]->addCallStatic(functionID); 46 46 } 47 47 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1) 48 { 49 if(clientMap_.find(clientID)==clientMap_.end()) 48 { 49 if(clientMap_.find(clientID)==clientMap_.end()) 50 50 { 51 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 52 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 53 } 51 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 52 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 53 } 54 54 FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1); 55 55 } 56 56 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2) 57 { 58 if(clientMap_.find(clientID)==clientMap_.end()) 57 { 58 if(clientMap_.find(clientID)==clientMap_.end()) 59 59 { 60 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 61 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 62 } 60 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 61 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 62 } 63 63 FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2); 64 64 } 65 65 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 66 { 67 if(clientMap_.find(clientID)==clientMap_.end()) 66 { 67 if(clientMap_.find(clientID)==clientMap_.end()) 68 68 { 69 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 70 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 71 } 69 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 70 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 71 } 72 72 FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3); 73 73 } 74 74 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 75 { 76 if(clientMap_.find(clientID)==clientMap_.end()) 75 { 76 if(clientMap_.find(clientID)==clientMap_.end()) 77 77 { 78 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 79 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 80 } 78 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 79 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 80 } 81 81 FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4); 82 82 } 83 83 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 84 { 85 if(clientMap_.find(clientID)==clientMap_.end()) 84 { 85 if(clientMap_.find(clientID)==clientMap_.end()) 86 86 { 87 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 88 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 89 } 87 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 88 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 89 } 90 90 FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5); 91 91 } … … 95 95 96 96 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID) 97 { 98 if(clientMap_.find(clientID)==clientMap_.end()) 97 { 98 if(clientMap_.find(clientID)==clientMap_.end()) 99 99 { 100 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 101 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 102 } 100 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 101 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 102 } 103 103 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID); 104 104 } 105 105 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1) 106 { 107 if(clientMap_.find(clientID)==clientMap_.end()) 106 { 107 if(clientMap_.find(clientID)==clientMap_.end()) 108 108 { 109 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 110 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 111 } 109 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 110 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 111 } 112 112 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1); 113 113 } 114 114 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2) 115 { 116 if(clientMap_.find(clientID)==clientMap_.end()) 115 { 116 if(clientMap_.find(clientID)==clientMap_.end()) 117 117 { 118 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 119 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 120 } 118 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 119 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 120 } 121 121 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2); 122 122 } 123 123 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 124 { 125 if(clientMap_.find(clientID)==clientMap_.end()) 124 { 125 if(clientMap_.find(clientID)==clientMap_.end()) 126 126 { 127 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 128 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 129 } 127 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 128 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 129 } 130 130 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3); 131 131 } 132 132 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 133 { 134 if(clientMap_.find(clientID)==clientMap_.end()) 133 { 134 if(clientMap_.find(clientID)==clientMap_.end()) 135 135 { 136 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 137 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 138 } 136 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 137 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 138 } 139 139 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4); 140 140 } 141 141 void FunctionCallManager::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) 142 { 143 if(clientMap_.find(clientID)==clientMap_.end()) 142 { 143 if(clientMap_.find(clientID)==clientMap_.end()) 144 144 { 145 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 146 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 147 } 145 FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 146 FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 147 } 148 148 FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5); 149 149 } -
code/branches/pickup2/src/libraries/network/FunctionCallManager.h
r5781 r6412 37 37 namespace orxonox { 38 38 /** 39 39 @author 40 40 */ 41 41 … … 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/pickup2/src/libraries/network/GamestateClient.cc
r5929 r6412 54 54 std::map<unsigned int, packet::Gamestate *>::iterator it; 55 55 for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it ) 56 delete (*it).second;56 delete it->second; 57 57 if( this->tempGamestate_ ) 58 58 delete this->tempGamestate_; … … 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); … … 126 126 break; 127 127 // otherwise delete that stuff 128 delete (*it).second;128 delete it->second; 129 129 temp=it++; 130 130 gamestateMap_.erase(temp); … … 137 137 COUT(4) << "gamestates: "; 138 138 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){ 139 COUT(4) << it->first << ":" << it->second << "|";139 COUT(4) << it->first << ':' << it->second << '|'; 140 140 } 141 141 COUT(4) << std::endl; -
code/branches/pickup2/src/libraries/network/GamestateHandler.cc
r5781 r6412 33 33 34 34 GamestateHandler *GamestateHandler::instance_=0; 35 35 36 36 GamestateHandler::GamestateHandler() 37 37 { -
code/branches/pickup2/src/libraries/network/GamestateHandler.h
r5781 r6412 35 35 36 36 /** 37 37 @author Oliver Scheuss 38 38 */ 39 39 class _NetworkExport GamestateHandler{ -
code/branches/pickup2/src/libraries/network/GamestateManager.cc
r5929 r6412 69 69 delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it; 70 70 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 71 delete (*it).second;71 delete it->second; 72 72 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1; 73 73 std::map<unsigned int, packet::Gamestate*>::iterator it2; … … 75 75 { 76 76 for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 ) 77 delete (*it2).second;77 delete it2->second; 78 78 } 79 79 this->trafficControl_->destroy(); … … 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 ); 161 //FunctorMember<GamestateManager>* functor = 161 //FunctorMember<GamestateManager>* functor = 162 162 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) ); 163 163 // executor->setDefaultValues( 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/pickup2/src/libraries/network/Host.cc
r5781 r6412 50 50 assert(instance_==0); 51 51 instance_=this; 52 this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" ); 53 CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ ); 52 54 } 53 55 … … 59 61 { 60 62 instance_=0; 63 if( this->printRTTCC_ ) 64 delete this->printRTTCC_; 61 65 } 62 66 -
code/branches/pickup2/src/libraries/network/Host.h
r5781 r6412 31 31 32 32 #include "NetworkPrereqs.h" 33 #include "core/CorePrereqs.h" 33 34 34 35 namespace orxonox { … … 44 45 * - defines static functions available on both server and client 45 46 * - is the interface to be used when communicating with the network 46 * 47 * @author Oliver Scheuss 47 48 */ 48 49 class _NetworkExport Host{ … … 79 80 static bool Broadcast(const std::string& message); 80 81 static bool incomingChat(const std::string& message, unsigned int playerID); 82 virtual void printRTT()=0; 81 83 private: 84 ConsoleCommand* printRTTCC_; 82 85 }; 83 86 -
code/branches/pickup2/src/libraries/network/NetworkFunction.cc
r5929 r6412 32 32 namespace orxonox 33 33 { 34 std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;35 34 std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_; 36 37 std::map<NetworkFunctionPointer, NetworkFunctionStatic*> NetworkFunctionStatic::functorMap_; 38 std::map<uint32_t, NetworkFunctionStatic*> NetworkFunctionStatic::idMap_; 39 35 40 36 std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_; 41 37 std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_; … … 44 40 { 45 41 RegisterRootObject(NetworkFunctionBase); 46 42 47 43 static uint32_t networkID = 0; 48 44 this->networkID_ = networkID++; 49 45 50 46 this->name_ = name; 51 nameMap_[name] = this;47 NetworkFunctionBase::getNameMap()[name] = this; 52 48 } 53 49 NetworkFunctionBase::~NetworkFunctionBase() 54 50 { 55 51 } 56 57 52 53 58 54 void NetworkFunctionBase::destroyAllNetworkFunctions() 59 55 { 56 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap(); 60 57 std::map<std::string, NetworkFunctionBase*>::iterator it; 61 for( it= NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )58 for( it=map.begin(); it!=map.end(); ++it ) 62 59 it->second->destroy(); 63 60 } 64 65 61 62 63 /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap() 64 { 65 static std::map<std::string, NetworkFunctionBase*> nameMap_; 66 return nameMap_; 67 } 68 69 66 70 NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p): 67 71 NetworkFunctionBase(name) 68 72 { 69 73 RegisterObject(NetworkFunctionStatic); 70 74 71 75 this->functor_ = functor; 72 functorMap_[p] = this;73 idMap_[ this->getNetworkID() ] = this;76 NetworkFunctionStatic::getFunctorMap()[p] = this; 77 NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this; 74 78 } 75 79 76 80 NetworkFunctionStatic::~NetworkFunctionStatic() 77 81 { 78 82 delete this->functor_; 79 83 } 80 81 82 84 85 /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap() 86 { 87 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_; 88 return functorMap_; 89 } 90 91 /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap() 92 { 93 static std::map<uint32_t, NetworkFunctionStatic*> idMap_; 94 return idMap_; 95 } 96 97 83 98 NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p): 84 99 NetworkFunctionBase(name) 85 100 { 86 101 RegisterObject(NetworkMemberFunctionBase); 87 88 functorMap_[p] = this;89 idMap_[ this->getNetworkID() ] = this;102 103 this->functorMap_[p] = this; 104 this->idMap_[ this->getNetworkID() ] = this; 90 105 } 91 106 92 107 NetworkMemberFunctionBase::~NetworkMemberFunctionBase() 93 108 { 94 109 } 95 110 96 111 97 112 } -
code/branches/pickup2/src/libraries/network/NetworkFunction.h
r5781 r6412 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 82 static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); } 83 81 82 static inline void setNetworkID(const std::string& name, uint32_t id) 83 { 84 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap(); 85 assert( map.find(name)!=map.end() ); 86 map[name]->setNetworkID(id); 87 } 88 84 89 static void destroyAllNetworkFunctions(); 85 90 86 91 protected: 87 92 static std::map<uint32_t, bool> isStaticMap_; 88 89 private: 90 static std::map<std::string, NetworkFunctionBase*> nameMap_;93 94 private: 95 static std::map<std::string, NetworkFunctionBase*>& getNameMap(); 91 96 uint32_t networkID_; 92 97 std::string name_; 93 98 94 99 }; 95 100 … … 99 104 NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p); 100 105 ~NetworkFunctionStatic(); 101 106 102 107 inline void call(){ (*this->functor_)(); } 103 108 inline void call(const MultiType& mt1){ (*this->functor_)(mt1); } … … 106 111 inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); } 107 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); } 108 109 virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; } 110 static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; } 111 static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; } 112 static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; } 113 114 private: 115 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_; 116 static std::map<uint32_t, NetworkFunctionStatic*> idMap_; 117 113 114 virtual void setNetworkID( uint32_t id ) 115 { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; } 116 static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id) 117 { assert( NetworkFunctionStatic::getIdMap().find(id)!=NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; } 118 static NetworkFunctionStatic* getFunction( uint32_t id ) 119 { assert( NetworkFunctionStatic::getIdMap().find(id) != NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; } 120 static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ) 121 { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; } 122 123 private: 124 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap(); 125 static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap(); 118 126 FunctorStatic* functor_; 119 127 120 128 }; 121 129 … … 125 133 NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p); 126 134 ~NetworkMemberFunctionBase(); 127 135 128 136 virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; } 129 137 static inline NetworkMemberFunctionBase* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; } 130 138 static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; } 131 139 static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; } 132 133 // 140 141 // 134 142 virtual void call(uint32_t objectID)=0; 135 143 virtual void call(uint32_t objectID, const MultiType& mt1)=0; … … 138 146 virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0; 139 147 virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0; 140 148 141 149 private: 142 150 static std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> functorMap_; … … 149 157 NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p); 150 158 ~NetworkMemberFunction(); 151 159 152 160 inline void call(uint32_t objectID) 153 { 161 { 154 162 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 155 163 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID))); 156 164 } 157 165 inline void call(uint32_t objectID, const MultiType& mt1) 158 { 166 { 159 167 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 160 168 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1); 161 169 } 162 170 inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) 163 { 171 { 164 172 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 165 173 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2); 166 174 } 167 175 inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 168 { 176 { 169 177 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 170 178 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3); 171 179 } 172 180 inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 173 { 181 { 174 182 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 175 183 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4); 176 184 } 177 185 inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 178 { 186 { 179 187 if ( Synchronisable::getSynchronisable(objectID)!=0 ) 180 188 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5); 181 189 } 182 190 183 191 private: 184 192 FunctorMember<T>* functor_; -
code/branches/pickup2/src/libraries/network/NetworkPrereqs.h
r5929 r6412 144 144 template <class T> 145 145 class NetworkCallback; 146 template <class T, class U> 147 class NetworkCallbackNotify; 146 148 class NetworkCallbackBase; 147 149 class NetworkCallbackManager; -
code/branches/pickup2/src/libraries/network/Server.cc
r5929 r6412 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 163 /** 164 * @brief: returns ping time to client in milliseconds 162 163 /** 164 * @brief: returns ping time to client in milliseconds 165 165 */ 166 unsigned int Server::get Ping(unsigned int clientID){166 unsigned int Server::getRTT(unsigned int clientID){ 167 167 assert(ClientInformation::findClient(clientID)); 168 168 return ClientInformation::findClient(clientID)->getRTT(); 169 } 170 171 void Server::printRTT() 172 { 173 for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() ) 174 COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl; 169 175 } 170 176 … … 299 305 { 300 306 //ServerConnection::disconnectClient( client ); 301 ClientConnectionListener::broadcastClientDisconnected( client->getID() );307 //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now 302 308 delete client; 303 309 } … … 311 317 } 312 318 COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl; 313 319 314 320 // synchronise class ids 315 321 syncClassid(temp->getID()); 316 322 317 323 // now synchronise functionIDs 318 324 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); … … 320 326 bool b = fIDs->send(); 321 327 assert(b); 322 328 323 329 temp->setSynched(true); 324 330 COUT(4) << "sending welcome" << std::endl; … … 338 344 return true; 339 345 } 340 346 341 347 void Server::disconnectClient( ClientInformation *client ){ 342 348 ServerConnection::disconnectClient( client ); 343 349 GamestateManager::removeClient(client); 344 350 // inform all the listeners 345 ClientConnectionListener::broadcastClientDisconnected(client->getID());351 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now 346 352 } 347 353 -
code/branches/pickup2/src/libraries/network/Server.h
r5929 r6412 57 57 bool queuePacket(ENetPacket *packet, int clientID); 58 58 void update(const Clock& time); 59 unsigned int getPing(unsigned int clientID); 59 unsigned int getRTT(unsigned int clientID); 60 virtual void printRTT(); 60 61 double getPacketLoss(unsigned int clientID); 61 62 protected: … … 65 66 unsigned int shipID(){return 0;} 66 67 unsigned int playerID(){return 0;} 67 68 68 69 void addPeer(ENetEvent *event); 69 70 void removePeer(ENetEvent *event); 70 71 71 72 bool createClient(int clientID); 72 73 void disconnectClient( ClientInformation *client); -
code/branches/pickup2/src/libraries/network/ServerConnection.cc
r5929 r6412 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/pickup2/src/libraries/network/ServerConnection.h
r5929 r6412 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/pickup2/src/libraries/network/TrafficControl.cc
r5781 r6412 64 64 *Initializing protected members 65 65 */ 66 67 68 69 70 71 72 66 TrafficControl *TrafficControl::instance_=0; 67 68 /** 69 * @brief Constructor: assures that only one reference will be created and sets the pointer 70 */ 71 TrafficControl::TrafficControl() 72 { 73 73 RegisterObject(TrafficControl); 74 75 74 assert(instance_==0); 75 instance_=this; 76 76 this->setConfigValues(); 77 78 79 80 81 82 83 84 85 77 } 78 79 /** 80 * @brief Destructor: resets the instance pointer to 0 81 */ 82 TrafficControl::~TrafficControl() 83 { 84 instance_=0; 85 } 86 86 87 87 /** … … 121 121 122 122 123 124 125 126 127 128 129 123 void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list) 124 { 125 currentClientID=clientID; 126 currentGamestateID=gamestateID; 127 evaluateList(clientID, list); 128 return; 129 } 130 130 131 131 TrafficControl *TrafficControl::getInstance() … … 135 135 } 136 136 137 138 137 void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID) 138 { 139 139 if ( !this->bActive_ ) 140 140 return; 141 141 std::list<obj>::iterator itvec; // iterator to iterate through the acked objects 142 142 143 143 //assertions to make sure the maps already exist … … 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]; … … 151 151 152 152 for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++) 153 154 if(objectListPerm.find( (*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists155 { 156 objectListPerm[ (*itvec).objID].objCurGS = gamestateID;157 objectListPerm[ (*itvec).objID].objValueSched = 0; //set scheduling value back153 { 154 if(objectListPerm.find(itvec->objID) != objectListPerm.end()) // check whether the obj already exists in our lists 155 { 156 objectListPerm[itvec->objID].objCurGS = gamestateID; 157 objectListPerm[itvec->objID].objValueSched = 0; //set scheduling value back 158 158 } 159 159 else 160 160 { 161 161 assert(0); 162 objectListPerm[ (*itvec).objID].objCurGS = gamestateID;163 objectListPerm[ (*itvec).objID].objID = (*itvec).objID;164 objectListPerm[ (*itvec).objID].objCreatorID = (*itvec).objCreatorID;165 objectListPerm[ (*itvec).objID].objSize = (*itvec).objSize;166 } 167 168 162 objectListPerm[itvec->objID].objCurGS = gamestateID; 163 objectListPerm[itvec->objID].objID = itvec->objID; 164 objectListPerm[itvec->objID].objCreatorID = itvec->objCreatorID; 165 objectListPerm[itvec->objID].objSize = itvec->objSize; 166 } 167 } 168 // remove temporary list (with acked objects) from the map 169 169 objectListTemp.erase( objectListTemp.find(gamestateID) ); 170 170 } 171 171 172 172 /** … … 174 174 */ 175 175 176 177 178 179 180 181 182 176 /** 177 *updateClientListPerm 178 *returns void 179 */ 180 void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf) 181 { 182 std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs 183 183 unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0; 184 184 clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom); 185 185 } 186 186 187 187 /** … … 205 205 for(itvec = list.begin(); itvec != list.end();) 206 206 { 207 assert( (*itvec).objSize < 1000);208 if ( ( size + (*itvec).objSize ) < targetsize )209 { 210 size += (*itvec).objSize;//objSize is given in bytes207 assert( itvec->objSize < 1000); 208 if ( ( size + itvec->objSize ) < targetsize ) 209 { 210 size += itvec->objSize;//objSize is given in bytes 211 211 ++itvec; 212 212 } 213 213 else 214 214 { 215 clientListPerm_[currentClientID][ (*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative215 clientListPerm_[currentClientID][itvec->objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative 216 216 list.erase(itvec, list.end()); 217 217 break; … … 223 223 224 224 225 226 227 228 229 225 /** 226 *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this. 227 */ 228 void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list) 229 { 230 230 231 231 if( bActive_ ) … … 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 { 243 if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )243 if ( objectListPerm.find( itvec->objID) != objectListPerm.end() ) 244 244 { 245 245 // we already have the object in our map 246 246 //obj bleibt in liste und permanente prio wird berechnet 247 objectListPerm[ (*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;247 objectListPerm[itvec->objID].objDiffGS = currentGamestateID - objectListPerm[itvec->objID].objCurGS; 248 248 continue;//check next objId 249 249 } … … 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); … … 289 289 COUT(0) << "=========== Objectlist ===========" << endl; 290 290 for( it=list.begin(); it!=list.end(); it++) 291 COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;291 COUT(0) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl; 292 292 } 293 293 294 294 void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID) 295 295 { 296 if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )297 return; 298 if( clientListPerm_[clientID][ (*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )296 if ( it1->objCreatorID == OBJECTID_UNKNOWN ) 297 return; 298 if( clientListPerm_[clientID][it1->objCreatorID].objCurGS != GAMESTATEID_INITIAL ) 299 299 return; 300 300 std::list<obj>::iterator it2, it3=it1; 301 301 for( it2 = ++it3; it2 != list.end(); it2++ ) 302 302 { 303 if( (*it2).objID == (*it1).objCreatorID )303 if( it2->objID == it1->objCreatorID ) 304 304 { 305 305 it3 = list.insert(it1, *it2); //insert creator before it1 -
code/branches/pickup2/src/libraries/network/TrafficControl.h
r5781 r6412 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 … … 105 105 *evaluates Data given (list) and produces result(->Data to be updated) 106 106 */ 107 void evaluateList(unsigned int clientID, std::list<obj>& list);//done 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_; … … 121 121 /** 122 122 *is being used by GSManager from Server: 123 *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY 123 *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY 124 124 *Elements of list are accessed by *list[i] 125 125 *Elements of struct i are therefore: *list[i].objID … … 130 130 static void processAck(unsigned int clientID, unsigned int gamestateID) 131 131 { return instance_->ack(clientID, gamestateID); } 132 void deleteObject(unsigned int objectID); 133 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 134 134 bool prioritySort(uint32_t clientID, obj i, obj j); 135 135 bool dataSort(obj i, obj j); -
code/branches/pickup2/src/libraries/network/packet/Acknowledgement.cc
r5781 r6412 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/pickup2/src/libraries/network/packet/Acknowledgement.h
r5781 r6412 37 37 namespace packet { 38 38 /** 39 39 @author 40 40 */ 41 41 class _NetworkExport Acknowledgement : public Packet -
code/branches/pickup2/src/libraries/network/packet/Chat.cc
r5781 r6412 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/pickup2/src/libraries/network/packet/Chat.h
r5781 r6412 36 36 namespace packet { 37 37 /** 38 38 @author 39 39 */ 40 40 class _NetworkExport Chat : public Packet -
code/branches/pickup2/src/libraries/network/packet/ClassID.cc
r5929 r6412 48 48 ClassID::ClassID( ) : Packet(){ 49 49 Identifier *id; 50 std::string classname;51 50 unsigned int nrOfClasses=0; 52 51 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses … … 58 57 std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); 59 58 for(;it != Identifier::getStringIdentifierMapEnd();++it){ 60 id = (*it).second;59 id = it->second; 61 60 if(id == NULL || !id->hasFactory()) 62 61 continue; 63 c lassname = id->getName();62 const std::string& classname = id->getName(); 64 63 network_id = id->getNetworkID(); 65 64 // now push the network id and the classname to the stack -
code/branches/pickup2/src/libraries/network/packet/ClassID.h
r5781 r6412 36 36 namespace packet { 37 37 38 38 39 39 /** 40 40 @author 41 41 */ 42 42 class _NetworkExport ClassID : public Packet -
code/branches/pickup2/src/libraries/network/packet/DeleteObjects.cc
r5781 r6412 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() … … 71 71 for(unsigned int i=0; i<number; i++){ 72 72 unsigned int temp = Synchronisable::popDeletedObject(); 73 // assert(temp<10000); //ugly hack74 73 *reinterpret_cast<uint32_t*>(tdata) = temp; 75 COUT(4) << temp << " ";74 COUT(4) << temp << ' '; 76 75 tdata += sizeof(uint32_t); 77 76 } -
code/branches/pickup2/src/libraries/network/packet/DeleteObjects.h
r5781 r6412 35 35 namespace packet { 36 36 /** 37 37 @author 38 38 */ 39 39 class _NetworkExport DeleteObjects : public Packet -
code/branches/pickup2/src/libraries/network/packet/FunctionCalls.cc
r5781 r6412 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/pickup2/src/libraries/network/packet/FunctionCalls.h
r5781 r6412 40 40 namespace packet { 41 41 /** 42 42 @author 43 43 */ 44 44 -
code/branches/pickup2/src/libraries/network/packet/FunctionIDs.cc
r5781 r6412 47 47 48 48 FunctionIDs::FunctionIDs( ) : Packet(){ 49 std::string functionname; 50 unsigned int nrOfFunctions=0; 49 unsigned int nrOfFunctions=0; 51 50 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions 52 51 uint32_t networkID; 53 52 flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS; 54 53 std::queue<std::pair<uint32_t, std::string> > tempQueue; 55 54 56 55 //calculate total needed size (for all strings and integers) 57 56 ObjectList<NetworkFunctionBase>::iterator it; 58 57 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){ 59 functionname = it->getName();58 const std::string& functionname = it->getName(); 60 59 networkID = it->getNetworkID(); 61 60 // now push the network id and the classname to the stack … … 64 63 packetSize += (functionname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t); // reserver size for the functionname string, the functionname length and the networkID 65 64 } 66 65 67 66 this->data_=new uint8_t[ packetSize ]; 68 67 //set the appropriate packet id 69 68 assert(this->data_); 70 69 *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs; 71 70 72 71 uint8_t *temp=data_+sizeof(uint32_t); 73 72 // save the number of all classes 74 73 *(uint32_t*)temp = nrOfFunctions; 75 74 temp += sizeof(uint32_t); 76 75 77 76 // now save all classids and classnames 78 77 std::pair<uint32_t, std::string> tempPair; … … 85 84 temp+=2*sizeof(uint32_t)+tempPair.second.size()+1; 86 85 } 87 86 88 87 COUT(5) << "FunctionIDs packetSize is " << packetSize << endl; 89 88 90 89 } 91 90 … … 106 105 temp += sizeof(uint32_t); 107 106 totalsize += sizeof(uint32_t); // storage size for nr of all classes 108 107 109 108 for(unsigned int i=0; i<nrOfFunctions; i++){ 110 109 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 120 uint32_t stringsize; 122 121 unsigned char *functionname; 123 122 124 123 COUT(4) << "=== processing functionids: " << endl; 125 124 std::pair<uint32_t, std::string> tempPair; … … 127 126 nrOfFunctions = *(uint32_t*)temp; 128 127 temp += sizeof(uint32_t); 129 128 130 129 for( int i=0; i<nrOfFunctions; i++){ 131 130 networkID = *(uint32_t*)temp; -
code/branches/pickup2/src/libraries/network/packet/FunctionIDs.h
r5781 r6412 36 36 namespace packet { 37 37 38 38 39 39 /** 40 40 @author 41 41 */ 42 42 class _NetworkExport FunctionIDs : public Packet -
code/branches/pickup2/src/libraries/network/packet/Gamestate.cc
r5929 r6412 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_); … … 437 437 // uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 438 438 // uint8_t *dest = ndata + GamestateHeader::getSize(); 439 // 440 // 439 // 440 // 441 441 // // LOOP-UNROLLED DIFFING 442 442 // uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs; … … 465 465 // } 466 466 // } 467 // 467 // 468 468 // Gamestate *g = new Gamestate(ndata, getClientID()); 469 469 // *(g->header_) = *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++ ) … … 529 529 // COUT(0) << "myvector contains:"; 530 530 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ ) 531 // COUT(0) << " "<< (*itt).objID;531 // COUT(0) << ' ' << (*itt).objID; 532 532 // COUT(0) << endl; 533 533 for(it=dataVector_.begin(); it!=dataVector_.end();){ 534 534 SynchronisableHeader oldobjectheader(origdata); 535 535 SynchronisableHeader newobjectheader(newdata); 536 if ( (*it).objSize == 0 )536 if ( it->objSize == 0 ) 537 537 { 538 538 ++it; … … 541 541 objectsize = oldobjectheader.getDataSize(); 542 542 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader 543 if ( (*it).objID == oldobjectheader.getObjectID() ){543 if ( it->objID == oldobjectheader.getObjectID() ){ 544 544 memcpy(newdata, origdata, objectsize); 545 545 assert(newobjectheader.isDataAvailable()==true); -
code/branches/pickup2/src/libraries/network/packet/Gamestate.h
r5781 r6412 96 96 97 97 /** 98 98 @author Oliver Scheuss 99 99 */ 100 100 class _NetworkExport Gamestate: public Packet{ -
code/branches/pickup2/src/libraries/network/packet/Packet.cc
r5781 r6412 101 101 @brief 102 102 Destroys a packet completely. 103 104 That also means destroying the ENetPacket if one exists. There 103 104 That also means destroying the ENetPacket if one exists. There 105 105 */ 106 106 Packet::~Packet(){ … … 230 230 */ 231 231 void Packet::deletePacket(ENetPacket *enetPacket){ 232 // Get our Packet from a glo abal map with all Packets created in the send() method of Packet.232 // Get our Packet from a global map with all Packets created in the send() method of Packet. 233 233 std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 234 234 assert(it != packetMap_.end()); -
code/branches/pickup2/src/libraries/network/packet/Packet.h
r5781 r6412 57 57 58 58 /** 59 59 @author Oliver Scheuss <scheusso [at] ee.ethz.ch> 60 60 */ 61 61 class _NetworkExport Packet{ -
code/branches/pickup2/src/libraries/network/packet/Welcome.h
r5781 r6412 36 36 37 37 /** 38 38 @author 39 39 */ 40 40 class _NetworkExport Welcome : public Packet -
code/branches/pickup2/src/libraries/network/synchronisable/CMakeLists.txt
r5781 r6412 2 2 NetworkCallbackManager.cc 3 3 Synchronisable.cc 4 SynchronisableSpecialisations.cc5 4 SynchronisableVariable.cc 6 5 ) -
code/branches/pickup2/src/libraries/network/synchronisable/NetworkCallback.h
r5781 r6412 33 33 #include "network/NetworkPrereqs.h" 34 34 #include "NetworkCallbackManager.h" 35 // #include "util/MultiType.h" 35 36 36 37 namespace orxonox{ 37 38 39 struct EmptyType{}; 40 38 41 class _NetworkExport NetworkCallbackBase 39 42 { … … 49 52 public: 50 53 NetworkCallback(T* object, void (T::*function) (void)) : object_(object), function_(function) {} 51 54 virtual ~NetworkCallback() {} 52 55 virtual void call() 53 56 { (this->object_->*function_)(); } … … 58 61 }; 59 62 63 template <class T, class U> 64 class NetworkCallbackNotify: public NetworkCallbackBase 65 { 66 public: 67 NetworkCallbackNotify(T* object, void (T::*function) (const U&)) : object_(object), function_(function) {} 68 NetworkCallbackNotify() {} 69 virtual ~NetworkCallbackNotify() {} 70 virtual void call() 71 { (this->object_->*function_)( this->oldValue_ ); } 72 void setOldValue(const U& value){ this->oldValue_ = value; } 73 private: 74 T* object_; 75 U oldValue_; 76 void (T::*function_) (const U&); 77 }; 78 60 79 } 61 80 -
code/branches/pickup2/src/libraries/network/synchronisable/NetworkCallbackManager.cc
r5781 r6412 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 { 39 callbackSet_.insert(cb); 38 { 39 callbackSet_.insert(cb); 40 40 } 41 41 void NetworkCallbackManager::deleteCallback(NetworkCallbackBase *cb) … … 48 48 } 49 49 } 50 50 51 51 void NetworkCallbackManager::triggerCallback(NetworkCallbackBase *cb) 52 52 { -
code/branches/pickup2/src/libraries/network/synchronisable/NetworkCallbackManager.h
r5781 r6412 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/pickup2/src/libraries/network/synchronisable/Synchronisable.cc
r5929 r6412 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; … … 390 390 } 391 391 392 template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 393 { 394 SynchronisableVariableBase* sv; 395 if (bidirectional) 396 sv = new SynchronisableVariableBidirectional<std::string>(variable, mode, cb); 397 else 398 sv = new SynchronisableVariable<std::string>(variable, mode, cb); 399 syncList.push_back(sv); 400 stringList.push_back(sv); 401 } 402 392 403 393 404 } -
code/branches/pickup2/src/libraries/network/synchronisable/Synchronisable.h
r5929 r6412 66 66 67 67 /** 68 * @brief: stores information about a Synchronisable 69 * 68 * @brief: stores information about a Synchronisable 69 * 70 70 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 71 71 * in an emulated bitset. … … 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 //template <class T> void unregisterVariable(T& var); 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; } … … 167 167 }; 168 168 169 // ================= Specialisation declarations170 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);173 template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);174 template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);175 template <> _NetworkExport void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);176 template <> _NetworkExport void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);177 template <> _NetworkExport void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);178 template <> _NetworkExport void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);179 template <> _NetworkExport void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);180 template <> _NetworkExport void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);181 template <> _NetworkExport void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);182 template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);183 template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);184 185 169 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 186 170 { 187 171 if (bidirectional) 188 172 { 189 syncList.push_back(new SynchronisableVariableBidirectional< constT>(variable, mode, cb));173 syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb)); 190 174 this->dataSize_ += syncList.back()->getSize(state_); 191 175 } 192 176 else 193 177 { 194 syncList.push_back(new SynchronisableVariable< constT>(variable, mode, cb));178 syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb)); 195 179 if ( this->state_ == mode ) 196 180 this->dataSize_ += syncList.back()->getSize(state_); 197 181 } 198 182 } 199 183 184 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 200 185 201 186 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 // else211 // 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 before216 // }217 218 219 187 } 220 188 -
code/branches/pickup2/src/libraries/network/synchronisable/SynchronisableVariable.h
r5781 r6412 35 35 #include <cassert> 36 36 #include <cstring> 37 #include " util/Serialise.h"37 #include "Serialise.h" 38 38 #include "util/TypeTraits.h" 39 39 #include "core/GameMode.h" … … 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 { … … 81 81 virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); } 82 82 protected: 83 84 T& variable_; 85 uint8_t mode_; 86 NetworkCallbackBase *callback_; 83 T& variable_; 84 uint8_t mode_; 85 NetworkCallbackBase *callback_; 87 86 }; 88 87 89 88 template <class T> 90 89 class SynchronisableVariableBidirectional: public SynchronisableVariable<T> … … 93 92 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=0); 94 93 virtual ~SynchronisableVariableBidirectional(); 95 94 96 95 virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^ 97 96 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); … … 113 112 } 114 113 } 115 114 116 115 template <class T> SynchronisableVariable<T>::~SynchronisableVariable() 117 116 { 118 if (this->callback_ != 0)117 if (this->callback_) 119 118 { 120 119 NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion … … 141 140 return; 142 141 // check whether we need to consider a callback 143 if ( this->callback_ != 0 ) 144 { 145 if( forceCallback || !checkEquality( this->variable_, mem ) ) 146 callback = true; 142 if ( this->callback_ ) 143 { 144 callback = forceCallback || !checkEquality( this->variable_, mem ); 145 } 146 // now do a callback if neccessary 147 if ( callback ) 148 { 149 NetworkCallbackManager::triggerCallback( this->callback_ ); 147 150 } 148 151 // write the data 149 152 loadAndIncrease( this->variable_, mem ); 150 // now do a callback if neccessary151 if ( callback )152 NetworkCallbackManager::triggerCallback( this->callback_ );153 153 } 154 154 … … 216 216 mem += sizeof(varReference_); 217 217 memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(T)); 218 if ( this->callback_ != 0)218 if ( this->callback_ ) 219 219 callback = true; 220 220 } … … 235 235 { 236 236 // value changed so remark for callback 237 if ( this->callback_ != 0)237 if ( this->callback_ ) 238 238 callback = true; 239 239 } 240 240 } 241 241 } 242 // now do a callback if neccessary 243 if ( callback ) 244 { 245 NetworkCallbackManager::triggerCallback( this->callback_ ); 246 } 242 247 // now write the data 243 248 loadAndIncrease(this->variable_, mem); 244 // now do a callback if neccessary245 if ( callback )246 NetworkCallbackManager::triggerCallback( this->callback_ );247 249 } 248 250 … … 251 253 return returnSize( this->variable_ ) + sizeof(varReference_); 252 254 } 253 255 254 256 255 257 }
Note: See TracChangeset
for help on using the changeset viewer.