Changeset 7777 for code/branches/network5
- Timestamp:
- Dec 19, 2010, 2:27:06 PM (14 years ago)
- Location:
- code/branches/network5/src
- Files:
-
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/CMakeLists.txt
r7739 r7777 28 28 FunctionCallManager.cc 29 29 GamestateManager.cc 30 GamestateClient.cc30 #GamestateClient.cc 31 31 GamestateHandler.cc 32 32 LANDiscoverable.cc … … 53 53 FunctionCall.h 54 54 FunctionCallManager.h 55 GamestateClient.h55 #GamestateClient.h 56 56 GamestateHandler.h 57 57 GamestateManager.h -
code/branches/network5/src/libraries/network/Client.cc
r7772 r7777 64 64 */ 65 65 Client::Client(): 66 gamestate(0),67 66 isSynched_(false), 68 67 gameStateFailure_(false), … … 85 84 { 86 85 Synchronisable::setClient(true); 87 this->gamestate = new GamestateClient();88 86 if( ClientConnection::establishConnection() ) 89 87 { 90 88 Host::setActive(true); 89 GamestateManager::addPeer(NETWORK_PEER_ID_SERVER); 91 90 return true; 92 91 } … … 101 100 bool Client::closeConnection() 102 101 { 103 assert(this->gamestate);104 delete this->gamestate;105 this->gamestate = 0;106 102 Host::setActive(false); 103 GamestateManager::removePeer(NETWORK_PEER_ID_SERVER); 107 104 return ClientConnection::closeConnection(); 108 105 } … … 138 135 { 139 136 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 140 return m->send( );137 return m->send(static_cast<Host*>(this)); 141 138 } 142 139 … … 157 154 { 158 155 COUT(4) << "popping partial gamestate: " << std::endl; 159 packet::Gamestate *gs = gamestate->getGamestate(); 156 // packet::Gamestate *gs = GamestateClient::getGamestate(); 157 GamestateManager::update(); 158 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 159 std::vector<packet::Gamestate*>::iterator it; 160 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 161 { 162 (*it)->send( static_cast<Host*>(this) ); 163 } 160 164 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 161 if(gs){162 COUT(4) << "client tick: sending gs " << gs << std::endl;163 if( !gs->send() )164 COUT(2) << "Problem adding partial gamestate to queue" << std::endl;165 // gs gets automatically deleted by enet callback166 }167 FunctionCallManager::sendCalls( );165 // if(gs){ 166 // COUT(4) << "client tick: sending gs " << gs << std::endl; 167 // if( !gs->send() ) 168 // COUT(2) << "Problem adding partial gamestate to queue" << std::endl; 169 // // gs gets automatically deleted by enet callback 170 // } 171 FunctionCallManager::sendCalls(static_cast<Host*>(this)); 168 172 } 169 173 } … … 171 175 172 176 Connection::processQueue(); 173 if( gamestate->processGamestates())177 if(GamestateManager::processGamestates()) 174 178 { 175 179 FunctionCallManager::processBufferedFunctionCalls(); … … 177 181 isSynched_=true; 178 182 } 179 gamestate->cleanup();183 // GamestateManager::cleanup();; 180 184 // Connection::sendPackets(); 181 185 … … 198 202 Game::getInstance().popState(); 199 203 } 204 205 void Client::processPacket(packet::Packet* packet) 206 { 207 if( packet->isReliable() ) 208 { 209 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 210 packet->process(static_cast<Host*>(this)); 211 else 212 this->packetQueue_.push_back(packet); 213 } 214 else 215 packet->process(static_cast<Host*>(this)); 216 } 217 200 218 201 219 -
code/branches/network5/src/libraries/network/Client.h
r7772 r7777 45 45 46 46 #include <string> 47 #include <deque> 47 48 48 49 #include "util/UtilPrereqs.h" 49 50 #include "util/Singleton.h" 50 51 #include "ClientConnection.h" 51 #include "GamestateClient.h"52 // #include "GamestateClient.h" 52 53 #include "Host.h" 53 54 #include "LANDiscovery.h" … … 90 91 Client(const Client& copy); // not used 91 92 virtual bool isServer_(){return false;} 93 void processPacket(packet::Packet* packet); 92 94 93 95 static Client* singletonPtr_s; 94 GamestateClient* gamestate;95 96 bool isSynched_; 97 std::deque<packet::Packet*> packetQueue_; 96 98 97 99 bool gameStateFailure_; -
code/branches/network5/src/libraries/network/ClientConnection.h
r7772 r7777 44 44 void setPort( unsigned int port ); 45 45 46 ENetEvent *getEvent();46 // ENetEvent *getEvent(); 47 47 // check wheter the packet queue is empty 48 bool queueEmpty();48 // bool queueEmpty(); 49 49 // create a new listener thread 50 50 virtual bool establishConnection(); -
code/branches/network5/src/libraries/network/ClientInformation.cc
r7459 r7777 56 56 preve=0; 57 57 nexte=0; 58 partialGamestateID_=GAMESTATEID_INITIAL-1;59 58 synched_=false; 60 59 } … … 133 132 } 134 133 135 bool ClientInformation::setPartialGamestateID(int id){136 if(!this)137 return false;138 partialGamestateID_=id;139 return true;140 }141 142 134 unsigned int ClientInformation::getID() { 143 135 if(!this) … … 154 146 } 155 147 156 int ClientInformation::getFailures(){157 return failures_;158 }159 void ClientInformation::addFailure(){160 failures_++;161 }162 void ClientInformation::resetFailures(){163 failures_=0;164 }165 166 148 uint32_t ClientInformation::getRTT(){ 167 149 return this->peer_->roundTripTime; … … 175 157 if(this) 176 158 return gamestateID_; 177 else178 return static_cast<unsigned int>(-1);179 }180 181 unsigned int ClientInformation::getPartialGamestateID() {182 if(this)183 return partialGamestateID_;184 159 else 185 160 return static_cast<unsigned int>(-1); -
code/branches/network5/src/libraries/network/ClientInformation.h
r5781 r7777 66 66 bool setPeer(ENetPeer *peer); 67 67 bool setGamestateID(int id); 68 bool setPartialGamestateID(int id);69 68 inline void setShipID(unsigned int id){ShipID_=id;} 70 69 … … 73 72 unsigned int getID(); 74 73 unsigned int getGamestateID(); 75 unsigned int getPartialGamestateID();76 74 ENetPeer *getPeer(); 77 75 78 int getFailures();79 void addFailure();80 void resetFailures();81 76 uint32_t getRTT(); 82 77 double getPacketLoss(); … … 106 101 unsigned int clientID_; 107 102 unsigned int gamestateID_; 108 unsigned int partialGamestateID_;109 103 unsigned int ShipID_; // this is the unique objectID 110 104 bool synched_; 111 unsigned short failures_;112 105 113 106 }; -
code/branches/network5/src/libraries/network/Connection.cc
r7774 r7777 177 177 while( incomingEventsCount > 0 ) 178 178 { 179 packet::Packet* p; 179 180 this->incomingEventsMutex_->lock(); 180 181 event = this->incomingEvents_.front(); … … 193 194 case ENET_EVENT_TYPE_RECEIVE: 194 195 // COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl; 195 processPacket( &event ); 196 p = createPacket( &event ); 197 processPacket(p); 196 198 break; 197 199 case ENET_EVENT_TYPE_NONE: … … 205 207 } 206 208 207 bool Connection::processPacket(ENetEvent* event)209 packet::Packet* Connection::createPacket(ENetEvent* event) 208 210 { 209 211 packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); 210 return p->process(); 212 return p; 213 // return p->process(); 211 214 } 212 215 -
code/branches/network5/src/libraries/network/Connection.h
r7774 r7777 84 84 void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID); 85 85 void broadcastPacket(ENetPacket* packet, uint8_t channelID); 86 ENetHost* getHost(){ return this->host_; }86 // ENetHost* getHost(){ return this->host_; } 87 87 88 88 protected: … … 101 101 virtual void addPeer(ENetEvent* event)=0; 102 102 virtual void removePeer(ENetEvent* event)=0; 103 virtual bool processPacket(ENetEvent* event); 103 virtual void processPacket( packet::Packet* packet)=0; 104 virtual packet::Packet* createPacket(ENetEvent* event); 104 105 105 106 ENetHost* host_; 106 boost::mutex* incomingEventsMutex_;107 boost::mutex* outgoingEventsMutex_;108 107 private: 109 108 boost::thread* communicationThread_; … … 112 111 std::deque<ENetEvent> incomingEvents_; 113 112 std::deque<outgoingEvent> outgoingEvents_; 113 boost::mutex* incomingEventsMutex_; 114 boost::mutex* outgoingEventsMutex_; 114 115 115 116 // static Connection *instance_; -
code/branches/network5/src/libraries/network/FunctionCallManager.cc
r7759 r7777 34 34 namespace orxonox { 35 35 36 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::s ClientMap_;36 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_; 37 37 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_; 38 38 39 39 // Static calls 40 40 41 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)41 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID) 42 42 { 43 if(s ClientMap_.find(clientID)==sClientMap_.end())43 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 44 44 { 45 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;46 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);45 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 46 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 47 47 } 48 FunctionCallManager::s ClientMap_[clientID]->addCallStatic(functionID);48 FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID); 49 49 } 50 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)50 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1) 51 51 { 52 if(s ClientMap_.find(clientID)==sClientMap_.end())52 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 53 53 { 54 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;55 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);54 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 55 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 56 56 } 57 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1);57 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1); 58 58 } 59 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)59 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2) 60 60 { 61 if(s ClientMap_.find(clientID)==sClientMap_.end())61 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 62 62 { 63 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;64 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);63 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 64 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 65 65 } 66 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);66 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2); 67 67 } 68 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)68 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 69 69 { 70 if(s ClientMap_.find(clientID)==sClientMap_.end())70 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 71 71 { 72 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;73 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);72 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 73 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 74 74 } 75 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);75 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3); 76 76 } 77 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)77 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 78 78 { 79 if(s ClientMap_.find(clientID)==sClientMap_.end())79 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 80 80 { 81 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;82 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);81 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 82 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 83 83 } 84 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);84 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4); 85 85 } 86 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)86 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 87 87 { 88 if(s ClientMap_.find(clientID)==sClientMap_.end())88 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 89 89 { 90 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;91 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);90 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 91 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 92 92 } 93 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);93 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5); 94 94 } 95 95 … … 97 97 // MemberCalls 98 98 99 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)99 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID) 100 100 { 101 if(s ClientMap_.find(clientID)==sClientMap_.end())101 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 102 102 { 103 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;104 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);103 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 104 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 105 105 } 106 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID);106 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID); 107 107 } 108 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)108 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1) 109 109 { 110 if(s ClientMap_.find(clientID)==sClientMap_.end())110 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 111 111 { 112 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;113 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);112 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 113 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 114 114 } 115 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);115 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1); 116 116 } 117 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)117 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2) 118 118 { 119 if(s ClientMap_.find(clientID)==sClientMap_.end())119 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 120 120 { 121 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;122 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);121 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 122 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 123 123 } 124 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);124 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2); 125 125 } 126 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)126 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 127 127 { 128 if(s ClientMap_.find(clientID)==sClientMap_.end())128 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 129 129 { 130 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;131 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);130 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 131 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 132 132 } 133 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);133 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3); 134 134 } 135 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)135 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 136 136 { 137 if(s ClientMap_.find(clientID)==sClientMap_.end())137 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 138 138 { 139 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;140 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);139 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 140 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 141 141 } 142 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);142 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4); 143 143 } 144 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)144 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 145 145 { 146 if(s ClientMap_.find(clientID)==sClientMap_.end())146 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 147 147 { 148 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;149 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);148 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 149 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 150 150 } 151 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);151 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5); 152 152 } 153 153 154 154 // Send calls 155 155 156 void FunctionCallManager::sendCalls( )156 void FunctionCallManager::sendCalls(orxonox::Host* host) 157 157 { 158 158 std::map<uint32_t, packet::FunctionCalls*>::iterator it; 159 for (it = FunctionCallManager::s ClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )159 for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it ) 160 160 { 161 assert(!FunctionCallManager::s ClientMap_.empty());162 it->second->send( );161 assert(!FunctionCallManager::sPeerMap_.empty()); 162 it->second->send(host); 163 163 } 164 FunctionCallManager::s ClientMap_.clear();164 FunctionCallManager::sPeerMap_.clear(); 165 165 } 166 166 167 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID)167 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) 168 168 { 169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, clientID)));169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID))); 170 170 } 171 171 … … 175 175 while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) 176 176 { 177 uint32_t minGamestateID = it->second.first; 178 uint32_t clientID = it->second.second; 179 if( minGamestateID <= GamestateHandler::getInstance()->getLastProcessedGamestateID(clientID) && it->first.execute() ) 177 if( it->first.execute() ) 180 178 FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it); 181 179 else -
code/branches/network5/src/libraries/network/FunctionCallManager.h
r7759 r7777 46 46 { 47 47 public: 48 static void addCallStatic(uint32_t functionID, uint32_t clientID);49 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);50 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);51 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);52 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);53 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);48 static void addCallStatic(uint32_t functionID, uint32_t peerID); 49 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1); 50 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2); 51 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3); 52 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 53 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 54 54 55 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);56 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);57 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);58 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);59 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);60 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);55 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID); 56 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1); 57 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2); 58 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3); 59 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 60 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 61 61 62 static void sendCalls( );62 static void sendCalls(orxonox::Host* host); 63 63 64 static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID );64 static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID ); 65 65 static void processBufferedFunctionCalls(); 66 66 67 static std::map<uint32_t, packet::FunctionCalls*> s ClientMap_;67 static std::map<uint32_t, packet::FunctionCalls*> sPeerMap_; 68 68 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_; 69 69 protected: -
code/branches/network5/src/libraries/network/GamestateClient.cc
r7759 r7777 62 62 } 63 63 64 bool GamestateClient::ack (unsigned int gamestateID, unsigned int clientID)64 bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID) 65 65 { 66 66 return true; 67 67 } 68 68 69 bool GamestateClient::add (packet::Gamestate *gs, unsigned int clientID)69 bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID) 70 70 { 71 71 if(tempGamestate_!=NULL) -
code/branches/network5/src/libraries/network/GamestateClient.h
r7759 r7777 57 57 ~GamestateClient(); 58 58 59 virtual bool add (packet::Gamestate *gs, unsigned int clientID);60 virtual bool ack (unsigned int gamestateID, unsigned int clientID);61 virtual uint32_t getLastProcessedGamestateID(unsigned int clientID ) { return this->lastProcessedGamestateID_; }59 virtual bool addGamestate(packet::Gamestate *gs, unsigned int clientID); 60 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID); 61 virtual uint32_t getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; } 62 62 virtual uint32_t getCurrentGamestateID(){ return this->lastProcessedGamestateID_; } 63 63 -
code/branches/network5/src/libraries/network/GamestateHandler.cc
r6417 r7777 32 32 namespace orxonox { 33 33 34 GamestateHandler *GamestateHandler::instance_=0;34 // GamestateHandler *GamestateHandler::instance_=0; 35 35 36 36 GamestateHandler::GamestateHandler() 37 37 { 38 assert(instance_==0);39 instance_=this;40 38 } 41 39 … … 43 41 GamestateHandler::~GamestateHandler() 44 42 { 45 instance_=0;46 43 } 47 44 -
code/branches/network5/src/libraries/network/GamestateHandler.h
r7759 r7777 39 39 @author Oliver Scheuss 40 40 */ 41 class _NetworkExport GamestateHandler{ 41 class _NetworkExport GamestateHandler 42 { 42 43 private: 43 virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;44 virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;45 46 static GamestateHandler* instance_;47 44 48 45 … … 52 49 53 50 public: 54 static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); } 55 static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); } 56 static GamestateHandler* getInstance(){ assert(instance_); return instance_; } 57 51 virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0; 52 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0; 58 53 virtual uint32_t getLastProcessedGamestateID( unsigned int clientID )=0; 59 54 virtual uint32_t getCurrentGamestateID()=0; -
code/branches/network5/src/libraries/network/GamestateManager.cc
r7773 r7777 43 43 #include <cassert> 44 44 #include <queue> 45 #include "util/Clock.h"46 45 // #include <boost/thread/mutex.hpp> 47 46 48 #include "util/Debug.h"49 #include "core/ThreadPool.h"50 #include "core/command/Executor.h"51 #include "ClientInformation.h"52 47 #include "packet/Acknowledgement.h" 53 48 #include "packet/Gamestate.h" 54 49 #include "synchronisable/NetworkCallbackManager.h" 55 #include "TrafficControl.h" 50 51 #include "core/ThreadPool.h" 52 #include "core/command/Executor.h" 53 #include "core/GameMode.h" 54 #include "util/Debug.h" 55 #include "util/Clock.h" 56 // #include "TrafficControl.h" 56 57 57 58 namespace orxonox 58 59 { 59 60 GamestateManager::GamestateManager() : 60 reference(0), id_(0)61 { 62 trafficControl_ = new TrafficControl();61 currentGamestate_(0), id_(0) 62 { 63 // trafficControl_ = new TrafficControl(); 63 64 // threadMutex_ = new boost::mutex(); 64 65 // threadPool_ = new ThreadPool(); … … 67 68 GamestateManager::~GamestateManager() 68 69 { 69 if( this-> reference)70 delete this-> reference;std::map<unsigned int, packet::Gamestate*>::iterator it;70 if( this->currentGamestate_ ) 71 delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it; 71 72 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 72 73 delete it->second; 73 std::map<u nsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;74 std::map<u nsigned int, packet::Gamestate*>::iterator it2;75 for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1)76 { 77 for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)78 delete it2->second;79 } 80 this->trafficControl_->destroy();74 std::map<uint32_t, peerInfo>::iterator peerIt; 75 std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt; 76 for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt ) 77 { 78 for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt ) 79 delete gamestateIt->second; 80 } 81 // this->trafficControl_->destroy(); 81 82 // delete this->threadMutex_; 82 83 // delete this->threadPool_; … … 88 89 } 89 90 90 bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){ 91 bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID) 92 { 91 93 assert(gs); 92 94 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID); … … 99 101 } 100 102 101 bool GamestateManager::processGamestates(){ 103 bool GamestateManager::processGamestates() 104 { 102 105 if( this->gamestateQueue.empty() ) 103 106 return true; … … 118 121 119 122 bool GamestateManager::getSnapshot(){ 120 if ( reference != 0 ) 121 delete reference; 122 reference = new packet::Gamestate(); 123 if(!reference->collectData(++id_, 0x1)){ //we have no data to send 124 delete reference; 125 reference=0; 123 if ( currentGamestate_ != 0 ) 124 delete currentGamestate_; 125 currentGamestate_ = new packet::Gamestate(); 126 uint8_t gsMode; 127 if( GameMode::isMaster() ) 128 gsMode = packet::GAMESTATE_MODE_SERVER; 129 else 130 gsMode = packet::GAMESTATE_MODE_CLIENT; 131 uint32_t newID; 132 if( GameMode::isMaster() ) 133 newID = ++id_; 134 else 135 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID; 136 137 if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send 138 delete currentGamestate_; 139 currentGamestate_=0; 126 140 } 127 141 return true; 128 142 } 129 143 130 void GamestateManager::sendGamestates() 131 { 132 ClientInformation *temp = ClientInformation::getBegin(); 133 std::queue<packet::Gamestate*> clientGamestates; 134 while(temp != NULL){ 135 if( !(temp->getSynched()) ){ 144 std::vector<packet::Gamestate*> GamestateManager::getGamestates() 145 { 146 if(!currentGamestate_) 147 return std::vector<packet::Gamestate*>(); 148 std::vector<packet::Gamestate*> peerGamestates; 149 150 std::map<uint32_t, peerInfo>::iterator peerIt; 151 for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt ) 152 { 153 if( !peerIt->second.isSynched ) 154 { 136 155 COUT(5) << "Server: not sending gamestate" << std::endl; 137 temp=temp->next();138 if(!temp)139 break;140 156 continue; 141 157 } 142 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss()<< std::endl;158 COUT(4) << "client id: " << peerIt->first << std::endl; 143 159 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 144 int cid = temp->getID(); //get client id 145 146 unsigned int gID = temp->getGamestateID(); 147 if(!reference) 148 return; 149 150 packet::Gamestate *client=0; 151 if(gID != GAMESTATEID_INITIAL){ 152 assert(gamestateMap_.find(cid)!=gamestateMap_.end()); 153 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID); 154 if(it!=gamestateMap_[cid].end()) 155 { 156 client = it->second; 157 } 158 } 159 160 clientGamestates.push(0); 161 finishGamestate( cid, clientGamestates.back(), client, reference ); 160 int peerID = peerIt->first; //get client id 161 162 unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID; 163 164 packet::Gamestate* baseGamestate=0; 165 if(lastAckedGamestateID != GAMESTATEID_INITIAL) 166 { 167 assert(peerMap_.find(peerID)!=peerMap_.end()); 168 std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID); 169 assert(it!=peerMap_[peerID].gamestates.end()); 170 baseGamestate = it->second; 171 } 172 173 peerGamestates.push_back(0); // insert an empty gamestate* to change 174 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 162 175 //FunctorMember<GamestateManager>* functor = 163 176 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) ); 164 // executor->setDefaultValues( cid, &clientGamestates.back(), client, reference);177 // executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ ); 165 178 // (*static_cast<Executor*>(executor))(); 166 179 // this->threadPool_->passFunction( executor, true ); 167 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 168 169 temp = temp->next(); 180 // (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ ); 170 181 } 171 182 172 183 // threadPool_->synchronise(); 173 184 174 while( !clientGamestates.empty() ) 175 { 176 if(clientGamestates.front()) 177 clientGamestates.front()->send(); 178 clientGamestates.pop(); 179 } 180 } 181 182 183 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 185 return peerGamestates; 186 } 187 188 189 void GamestateManager::finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 184 190 //why are we searching the same client's gamestate id as we searched in 185 191 //Server::sendGameState? … … 194 200 // gs->collectData( id_, 0x1 ); 195 201 // this->threadMutex_->lock(); 196 gamestateMap_[clientID][gamestate->getID()]=gs;202 peerMap_[peerID].gamestates[gamestate->getID()]=gs; 197 203 // this->threadMutex_->unlock(); 198 199 204 Clock clock; 205 clock.capture(); 200 206 201 207 if(base) … … 218 224 // bool b = gs->compressData(); 219 225 // assert(b); 220 221 226 clock.capture(); 227 COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl; 222 228 // COUT(5) << "sending gamestate with id " << gs->getID(); 223 229 // if(gamestate->isDiffed()) … … 225 231 // else 226 232 // COUT(5) << endl; 227 gs->set ClientID(clientID);233 gs->setPeerID(peerID); 228 234 destgamestate = gs; 229 235 } 230 236 231 237 232 bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) { 233 ClientInformation *temp = ClientInformation::findClient(clientID); 234 assert(temp); 235 unsigned int curid = temp->getGamestateID(); 238 bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID) { 239 // ClientInformation *temp = ClientInformation::findClient(peerID); 240 // assert(temp); 241 std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID); 242 assert(it!=this->peerMap_.end()); 243 unsigned int curid = it->second.lastAckedGamestateID; 236 244 237 245 if(gamestateID == ACKID_NACK){ 238 temp->setGamestateID(GAMESTATEID_INITIAL); 246 it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 247 // temp->setGamestateID(GAMESTATEID_INITIAL); 239 248 // now delete all saved gamestates for this client 240 std::map<unsigned int, packet::Gamestate*>::iterator it; 241 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){ 242 delete it->second; 243 244 gamestateMap_[clientID].erase(it++); 245 } 249 std::map<uint32_t, packet::Gamestate*>::iterator it2; 250 for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 251 delete it2->second; 252 } 253 it->second.gamestates.clear(); 246 254 return true; 247 255 } 248 256 249 257 assert(curid==GAMESTATEID_INITIAL || curid<gamestateID); 250 COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 251 std::map<unsigned int, packet::Gamestate*>::iterator it; 252 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){ 253 delete it->second; 254 gamestateMap_[clientID].erase(it++); 255 } 256 temp->setGamestateID(gamestateID); 257 TrafficControl::processAck(clientID, gamestateID); 258 COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 259 std::map<uint32_t, packet::Gamestate*>::iterator it2; 260 for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ) 261 { 262 if( it2->second->getID() < gamestateID ) 263 { 264 delete it2->second; 265 it->second.gamestates.erase(it2++); 266 } 267 else 268 ++it2; 269 } 270 271 // std::map<unsigned int, packet::Gamestate*>::iterator it; 272 // for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){ 273 // delete it->second; 274 // gamestateMap_[peerID].erase(it++); 275 // } 276 it->second.lastAckedGamestateID = gamestateID; 277 // temp->setGamestateID(gamestateID); 278 // TrafficControl::processAck(peerID, gamestateID); 258 279 return true; 259 280 } 260 281 261 uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int clientID)262 { 263 assert( this-> lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() );264 if( this-> lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() )265 return this-> lastProcessedGamestateID_[clientID];282 uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID) 283 { 284 assert( this->peerMap_.find(peerID)!=this->peerMap_.end() ); 285 if( this->peerMap_.find(peerID) != this->peerMap_.end() ) 286 return this->peerMap_[peerID].lastProcessedGamestateID; 266 287 else 267 288 return GAMESTATEID_INITIAL; 268 289 } 269 270 void GamestateManager::removeClient(ClientInformation* client){ 271 assert(client); 272 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 273 // first delete all remained gamestates 274 std::map<unsigned int, packet::Gamestate*>::iterator it; 275 for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 276 delete it->second; 277 // now delete the clients gamestatemap 278 gamestateMap_.erase(clientMap); 279 } 280 281 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 290 291 292 void GamestateManager::addPeer(uint32_t peerID) 293 { 294 assert(peerMap_.find(peerID)==peerMap_.end()); 295 peerMap_[peerID].peerID = peerID; 296 peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL; 297 peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL; 298 if( GameMode::isMaster() ) 299 peerMap_[peerID].isSynched = false; 300 else 301 peerMap_[peerID].isSynched = true; 302 } 303 304 void GamestateManager::removePeer(uint32_t peerID) 305 { 306 assert(peerMap_.find(peerID)!=peerMap_.end()); 307 std::map<uint32_t, packet::Gamestate*>::iterator peerIt; 308 for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt ) 309 { 310 delete peerIt->second; 311 } 312 peerMap_.erase(peerMap_.find(peerID)); 313 } 314 315 316 // void GamestateManager::removeClient(ClientInformation* client){ 317 // assert(client); 318 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 319 // // first delete all remained gamestates 320 // std::map<unsigned int, packet::Gamestate*>::iterator it; 321 // for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 322 // delete it->second; 323 // // now delete the clients gamestatemap 324 // gamestateMap_.erase(clientMap); 325 // } 326 327 bool GamestateManager::processGamestate(packet::Gamestate *gs) 328 { 282 329 if(gs->isCompressed()) 283 330 { … … 286 333 } 287 334 assert(!gs->isDiffed()); 288 if( gs->spreadData(0x1) ) 289 { 290 this->lastProcessedGamestateID_[gs->getClientID()] = gs->getID(); 335 uint8_t gsMode; 336 if( GameMode::isMaster() ) 337 gsMode = packet::GAMESTATE_MODE_SERVER; 338 else 339 gsMode = packet::GAMESTATE_MODE_CLIENT; 340 if( gs->spreadData(gsMode) ) 341 { 342 this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID(); 291 343 return true; 292 344 } -
code/branches/network5/src/libraries/network/GamestateManager.h
r7759 r7777 47 47 #include "core/CorePrereqs.h" 48 48 #include "packet/Gamestate.h" 49 #include <boost/concept_check.hpp> 49 50 50 51 namespace orxonox … … 67 68 * @author Oliver Scheuss 68 69 */ 69 class _NetworkExport GamestateManager: public GamestateHandler{ 70 class _NetworkExport GamestateManager: public GamestateHandler 71 { 72 struct peerInfo 73 { 74 uint32_t peerID; 75 uint32_t lastProcessedGamestateID; 76 uint32_t lastAckedGamestateID; 77 bool isSynched; 78 std::map< uint32_t, packet::Gamestate* > gamestates; 79 }; 80 70 81 public: 82 71 83 GamestateManager(); 72 84 ~GamestateManager(); 73 85 74 virtual bool add (packet::Gamestate *gs, unsigned int clientID);75 virtual bool ack (unsigned int gamestateID, unsigned int clientID);76 virtual uint32_t getLastProcessedGamestateID( unsigned int clientID );77 virtual uint32_t getCurrentGamestateID(){ return reference->getID(); }86 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID); 87 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID); 88 virtual uint32_t getLastProcessedGamestateID( unsigned int peerID ); 89 virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); } 78 90 79 91 bool processGamestates(); 80 92 bool update(); 81 void sendGamestates(); 82 // packet::Gamestate *popGameState(unsigned int clientID); 83 void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 93 std::vector<packet::Gamestate*> getGamestates(); 94 void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 84 95 85 96 bool getSnapshot(); 86 97 87 void removeClient(ClientInformation *client); 98 void addPeer( uint32_t peerID ); 99 void setSynched( uint32_t peerID ) 100 { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; } 101 void removePeer( uint32_t peerID ); 102 // void removeClient(ClientInformation *client); 88 103 private: 89 104 bool processGamestate(packet::Gamestate *gs); 90 105 91 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;106 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 92 107 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 93 std::map<unsigned int, uint32_t> lastProcessedGamestateID_; 94 packet::Gamestate *reference; 95 TrafficControl *trafficControl_; 108 // std::map<unsigned int, uint32_t> lastProcessedGamestateID_; 109 std::map<uint32_t, peerInfo> peerMap_; 110 packet::Gamestate* currentGamestate_; 111 // TrafficControl *trafficControl_; 96 112 unsigned int id_; 97 113 // boost::mutex* threadMutex_; -
code/branches/network5/src/libraries/network/Host.cc
r7772 r7777 45 45 // Host* Host::instance_=0; 46 46 uint32_t Host::clientID_s=0; 47 uint32_t Host::shipID_s=-1;47 // uint32_t Host::shipID_s=-1; 48 48 std::vector<Host*> Host::instances_s; 49 49 -
code/branches/network5/src/libraries/network/Host.h
r7772 r7777 31 31 32 32 #include "NetworkPrereqs.h" 33 #include "GamestateManager.h" 33 34 #include "core/CorePrereqs.h" 34 35 … … 49 50 * @author Oliver Scheuss 50 51 */ 51 class _NetworkExport Host{ 52 class _NetworkExport Host: public GamestateManager 53 { 52 54 private: 53 55 //TODO add these functions or adequate … … 75 77 // static bool receiveChat(packet::Chat *message, unsigned int clientID); 76 78 static unsigned int getPlayerID(){ return clientID_s; } 77 static unsigned int getShipID(){return shipID_s;}78 79 static void setClientID(unsigned int id){ clientID_s = id; } 79 static void setShipID(unsigned int id){ shipID_s = id; }80 80 static bool isServer(); 81 81 static void Chat(const std::string& message); … … 86 86 private: 87 87 static uint32_t clientID_s; 88 static uint32_t shipID_s;89 88 static std::vector<Host*> instances_s; 90 89 bool bIsActive_; -
code/branches/network5/src/libraries/network/Server.cc
r7773 r7777 162 162 while(temp){ 163 163 chat = new packet::Chat(message, playerID); 164 chat->set ClientID(temp->getID());165 if(!chat->send( ))164 chat->setPeerID(temp->getID()); 165 if(!chat->send( static_cast<Host*>(this) )) 166 166 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 167 167 temp = temp->next(); … … 220 220 221 221 // send function calls to clients 222 FunctionCallManager::sendCalls( );222 FunctionCallManager::sendCalls( static_cast<Host*>(this) ); 223 223 224 224 //this steers our network frequency … … 271 271 return; 272 272 GamestateManager::update(); 273 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;273 // COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 274 274 //std::cout << "updated gamestate, sending it" << std::endl; 275 275 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 276 sendGameState ();276 sendGameStates(); 277 277 sendObjectDeletes(); 278 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;278 // COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 279 279 //std::cout << "sent gamestate" << std::endl; 280 280 } 281 281 282 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 283 packet::Packet *p = packet::Packet::createPacket(packet, peer); 284 return p->process(); 285 } 286 287 /** 288 * sends the gamestate 289 */ 290 bool Server::sendGameState() 291 { 292 // COUT(5) << "Server: starting function sendGameState" << std::endl; 293 // ClientInformation *temp = ClientInformation::getBegin(); 294 // bool added=false; 295 // while(temp != NULL){ 296 // if( !(temp->getSynched()) ){ 297 // COUT(5) << "Server: not sending gamestate" << std::endl; 298 // temp=temp->next(); 299 // if(!temp) 300 // break; 301 // continue; 302 // } 303 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 304 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 305 // int cid = temp->getID(); //get client id 306 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 307 // if(gs==NULL){ 308 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 309 // temp = temp->next(); 310 // continue; 311 // } 312 // //std::cout << "adding gamestate" << std::endl; 313 // gs->setClientID(cid); 314 // if ( !gs->send() ){ 315 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 316 // temp->addFailure(); 317 // }else 318 // temp->resetFailures(); 319 // added=true; 320 // temp=temp->next(); 321 // // gs gets automatically deleted by enet callback 322 // } 323 GamestateManager::sendGamestates(); 282 /** 283 * sends the current gamestate to all peers 284 */ 285 bool Server::sendGameStates() 286 { 287 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 288 std::vector<packet::Gamestate*>::iterator it; 289 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 290 { 291 (*it)->send(static_cast<Host*>(this)); 292 } 324 293 return true; 325 294 } 295 326 296 327 297 bool Server::sendObjectDeletes() … … 348 318 packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 349 319 assert(cd); 350 cd->set ClientID(cid);351 if ( !cd->send( ) )352 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended : " << temp->getFailures()<< std::endl;320 cd->setPeerID(cid); 321 if ( !cd->send( static_cast<Host*>(this) ) ) 322 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 353 323 temp=temp->next(); 354 324 // gs gets automatically deleted by enet callback … … 374 344 // inform all the listeners 375 345 ClientConnectionListener::broadcastClientConnected(newid); 346 GamestateManager::addPeer(newid); 376 347 377 348 ++newid; … … 394 365 } 395 366 } 367 368 void Server::processPacket(packet::Packet* packet) 369 { 370 if( packet->isReliable() ) 371 { 372 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 373 packet->process(static_cast<Host*>(this)); 374 else 375 this->packetQueue_.push_back(packet); 376 } 377 else 378 packet->process(static_cast<Host*>(this)); 379 } 380 396 381 397 382 bool Server::createClient(int clientID) … … 403 388 return false; 404 389 } 405 COUT( 5) << "Con.Man: creating client id: " << temp->getID() << std::endl;390 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 406 391 407 392 // synchronise class ids … … 410 395 // now synchronise functionIDs 411 396 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); 412 fIDs->set ClientID(clientID);413 bool b = fIDs->send( );397 fIDs->setPeerID(clientID); 398 bool b = fIDs->send( static_cast<Host*>(this) ); 414 399 assert(b); 415 400 416 401 temp->setSynched(true); 402 GamestateManager::setSynched(clientID); 403 417 404 COUT(4) << "sending welcome" << std::endl; 418 405 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 419 w->set ClientID(temp->getID());420 b = w->send( );406 w->setPeerID(temp->getID()); 407 b = w->send( static_cast<Host*>(this) ); 421 408 assert(b); 422 409 packet::Gamestate *g = new packet::Gamestate(); 423 g->setClientID(temp->getID()); 424 b = g->collectData(0,0x1); 410 g->setPeerID(temp->getID()); 411 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 412 assert(b); 425 413 if(!b) 426 414 return false; //no data for the client 427 415 // b = g->compressData(); 428 416 // assert(b); 429 b = g->send( );417 b = g->send( static_cast<Host*>(this) ); 430 418 assert(b); 431 419 return true; … … 435 423 { 436 424 ServerConnection::disconnectClient( client ); 437 GamestateManager::remove Client(client);425 GamestateManager::removePeer(client->getID()); 438 426 // inform all the listeners 439 427 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 457 445 { 458 446 chat = new packet::Chat(message, clientID); 459 chat->set ClientID(temp->getID());460 if(!chat->send( ))447 chat->setPeerID(temp->getID()); 448 if(!chat->send( static_cast<Host*>(this) )) 461 449 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 462 450 temp = temp->next(); … … 473 461 int failures=0; 474 462 packet::ClassID *classid = new packet::ClassID(); 475 classid->set ClientID(clientID);476 while(!classid->send( ) && failures < 10){463 classid->setPeerID(clientID); 464 while(!classid->send( static_cast<Host*>(this) ) && failures < 10){ 477 465 failures++; 478 466 } -
code/branches/network5/src/libraries/network/Server.h
r7772 r7777 32 32 #include "NetworkPrereqs.h" 33 33 34 #include <deque> 35 34 36 #include "util/UtilPrereqs.h" 35 37 #include "core/CorePrereqs.h" 36 38 #include "Host.h" 37 #include "GamestateManager.h"39 // #include "GamestateManager.h" 38 40 #include "ServerConnection.h" 39 41 #include "LANDiscoverable.h" … … 49 51 * It implements all functions necessary for a Server 50 52 */ 51 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, publicLANDiscoverable{53 class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{ 52 54 public: 53 55 Server(); … … 73 75 private: 74 76 virtual bool isServer_(){return true;} 75 unsigned int shipID(){return 0;}76 77 unsigned int playerID(){return 0;} 77 78 78 79 void addPeer(ENetEvent *event); 79 80 void removePeer(ENetEvent *event); 81 void processPacket(packet::Packet* packet); 80 82 81 83 bool createClient(int clientID); 82 84 void disconnectClient( ClientInformation *client); 83 bool processPacket( ENetPacket *packet, ENetPeer *peer ); 84 bool sendGameState(); 85 bool sendGameStates(); 85 86 bool sendObjectDeletes(); 86 87 virtual bool chat(const std::string& message); … … 91 92 float timeSinceLastUpdate_; 92 93 MasterServerComm msc; 94 std::deque<packet::Packet*> packetQueue_; 93 95 }; 94 96 -
code/branches/network5/src/libraries/network/packet/Acknowledgement.cc
r6417 r7777 31 31 #include "util/Debug.h" 32 32 #include "network/GamestateHandler.h" 33 #include "network/Host.h" 33 34 34 35 namespace orxonox { … … 39 40 #define _ACKID _PACKETID + sizeof(packet::Type::Value) 40 41 41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) 42 43 : Packet() 43 44 { … … 46 47 *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement; 47 48 *(uint32_t *)(data_ + _ACKID ) = id; 48 clientID_=clientID;49 peerID_=peerID; 49 50 } 50 51 51 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )52 : Packet(data, clientID)52 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID ) 53 : Packet(data, peerID) 53 54 { 54 55 } … … 62 63 } 63 64 64 bool Acknowledgement::process( ){65 bool Acknowledgement::process(orxonox::Host* host){ 65 66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 66 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);67 bool b = host->ackGamestate(getAckID(), peerID_); 67 68 delete this; 68 69 return b; -
code/branches/network5/src/libraries/network/packet/Acknowledgement.h
r6073 r7777 42 42 { 43 43 public: 44 Acknowledgement( unsigned int id, unsigned int clientID );45 Acknowledgement( uint8_t* data, unsigned int clientID );44 Acknowledgement( unsigned int id, unsigned int peerID ); 45 Acknowledgement( uint8_t* data, unsigned int peerID ); 46 46 ~Acknowledgement(); 47 47 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 unsigned int getAckID(); -
code/branches/network5/src/libraries/network/packet/Chat.cc
r7163 r7777 80 80 } 81 81 82 bool Chat::process( ){83 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));82 bool Chat::process(orxonox::Host* host){ 83 bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 84 84 delete this; 85 85 return b; -
code/branches/network5/src/libraries/network/packet/Chat.h
r7163 r7777 52 52 53 53 /* process chat message packet and remove it afterwards */ 54 bool process();54 virtual bool process(orxonox::Host* host); 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ -
code/branches/network5/src/libraries/network/packet/ClassID.cc
r7163 r7777 120 120 121 121 122 bool ClassID::process( ){122 bool ClassID::process(orxonox::Host* host){ 123 123 int nrOfClasses; 124 124 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid -
code/branches/network5/src/libraries/network/packet/ClassID.h
r6417 r7777 48 48 49 49 uint32_t getSize() const; 50 bool process();50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/branches/network5/src/libraries/network/packet/DeleteObjects.cc
r6417 r7777 57 57 } 58 58 59 bool DeleteObjects::fetchIDs(){ 59 bool DeleteObjects::fetchIDs() 60 { 60 61 unsigned int number = Synchronisable::getNumberOfDeletedObject(); 61 62 if(number==0) … … 79 80 } 80 81 81 unsigned int DeleteObjects::getSize() const{ 82 unsigned int DeleteObjects::getSize() const 83 { 82 84 assert(data_); 83 85 return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); 84 86 } 85 87 86 bool DeleteObjects::process(){ 87 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ 88 bool DeleteObjects::process(orxonox::Host* host) 89 { 90 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++) 91 { 88 92 COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl; 89 93 Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) ); -
code/branches/network5/src/libraries/network/packet/DeleteObjects.h
r6073 r7777 32 32 #include "Packet.h" 33 33 34 namespace orxonox { 35 namespace packet { 34 namespace orxonox 35 { 36 namespace packet 37 { 36 38 /** 37 39 @author … … 47 49 48 50 inline unsigned int getSize() const; 49 bool process();51 virtual bool process(orxonox::Host* host); 50 52 51 53 private: -
code/branches/network5/src/libraries/network/packet/FunctionCalls.cc
r7759 r7777 58 58 59 59 60 bool FunctionCalls::process(){ 60 bool FunctionCalls::process(orxonox::Host* host) 61 { 61 62 assert(isDataENetAllocated()); 62 63 … … 70 71 FunctionCall fctCall; 71 72 fctCall.loadData(temp); 72 if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )73 if( this->minGamestateID_ > host->getLastProcessedGamestateID(this->getPeerID()) || !fctCall.execute() ) 73 74 { 74 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->get ClientID() );75 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() ); 75 76 } 76 77 } … … 80 81 } 81 82 82 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 83 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 84 { 83 85 assert(!isDataENetAllocated()); 84 86 … … 88 90 } 89 91 90 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 92 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 93 { 91 94 assert(!isDataENetAllocated()); 92 95 … … 96 99 } 97 100 98 bool FunctionCalls::send( )101 bool FunctionCalls::send(orxonox::Host* host) 99 102 { 100 this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();103 this->minGamestateID_ = host->getCurrentGamestateID(); 101 104 assert(this->functionCalls_.size()); 102 105 data_=new uint8_t[ currentSize_ ]; … … 114 117 assert( temp==data_+currentSize_ ); 115 118 116 Packet::send( );119 Packet::send(host); 117 120 return true; 118 121 } -
code/branches/network5/src/libraries/network/packet/FunctionCalls.h
r7759 r7777 54 54 inline unsigned int getSize() const 55 55 { assert(!this->isDataENetAllocated()); return currentSize_; } 56 bool process();56 virtual bool process(orxonox::Host* host); 57 57 58 58 void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 59 59 void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 60 virtual bool send( );60 virtual bool send(orxonox::Host* host); 61 61 private: 62 62 std::queue<orxonox::FunctionCall> functionCalls_; -
code/branches/network5/src/libraries/network/packet/FunctionIDs.cc
r6417 r7777 46 46 47 47 48 FunctionIDs::FunctionIDs( ) : Packet(){ 48 FunctionIDs::FunctionIDs( ) : Packet() 49 { 49 50 unsigned int nrOfFunctions=0; 50 51 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions … … 55 56 //calculate total needed size (for all strings and integers) 56 57 ObjectList<NetworkFunctionBase>::iterator it; 57 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){ 58 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it) 59 { 58 60 const std::string& functionname = it->getName(); 59 61 networkID = it->getNetworkID(); … … 76 78 // now save all classids and classnames 77 79 std::pair<uint32_t, std::string> tempPair; 78 while( !tempQueue.empty() ){ 80 while( !tempQueue.empty() ) 81 { 79 82 tempPair = tempQueue.front(); 80 83 tempQueue.pop(); … … 98 101 } 99 102 100 uint32_t FunctionIDs::getSize() const{ 103 uint32_t FunctionIDs::getSize() const 104 { 101 105 assert(this->data_); 102 106 uint8_t *temp = data_+sizeof(uint32_t); // packet identification … … 114 118 115 119 116 bool FunctionIDs::process(){ 120 bool FunctionIDs::process(orxonox::Host* host) 121 { 117 122 int nrOfFunctions; 118 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid … … 127 132 temp += sizeof(uint32_t); 128 133 129 for( int i=0; i<nrOfFunctions; i++){ 134 for( int i=0; i<nrOfFunctions; i++) 135 { 130 136 networkID = *(uint32_t*)temp; 131 137 stringsize = *(uint32_t*)(temp+sizeof(uint32_t)); -
code/branches/network5/src/libraries/network/packet/FunctionIDs.h
r6417 r7777 47 47 ~FunctionIDs(); 48 48 49 uint32_t getSize() const;50 bool process();49 virtual uint32_t getSize() const; 50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/branches/network5/src/libraries/network/packet/Gamestate.cc
r7759 r7777 36 36 #include "network/synchronisable/Synchronisable.h" 37 37 #include "network/GamestateHandler.h" 38 #include "network/Host.h" 38 39 39 40 namespace orxonox { … … 44 45 45 46 // #define PACKET_FLAG_GAMESTATE PacketFlag::Unsequenced 46 //#define PACKET_FLAG_GAMESTATE 047 #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable47 #define PACKET_FLAG_GAMESTATE 0 48 // #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 48 49 49 50 inline bool memzero( uint8_t* data, uint32_t datalength) … … 138 139 assert(0); // if we don't use multithreading this part shouldn't be neccessary 139 140 // start allocate additional memory 140 COUT(3) << "G .St.Man: need additional memory" << std::endl;141 COUT(3) << "Gamestate: need additional memory" << std::endl; 141 142 ObjectList<Synchronisable>::iterator temp = it; 142 143 uint32_t addsize=tempsize; … … 165 166 //stop write gamestate header 166 167 167 COUT(5) << "G .ST.Man: Gamestate size: " << currentsize << std::endl;168 COUT(5) << "G .ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;168 COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl; 169 COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl; 169 170 return true; 170 171 } … … 173 174 bool Gamestate::spreadData(uint8_t mode) 174 175 { 175 COUT( 4) << "processing gamestate with id " << header_.getID() << endl;176 COUT(5) << "processing gamestate with id " << header_.getID() << endl; 176 177 assert(data_); 177 178 assert(!header_.isCompressed()); … … 204 205 } 205 206 } 207 assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize()); 208 206 209 // In debug mode, check first, whether there are no duplicate objectIDs 207 210 #ifndef NDEBUG … … 269 272 270 273 271 bool Gamestate::process( )272 { 273 return GamestateHandler::addGamestate(this, getClientID());274 bool Gamestate::process(orxonox::Host* host) 275 { 276 return host->addGamestate(this, getPeerID()); 274 277 } 275 278 … … 585 588 586 589 587 Gamestate *g = new Gamestate(newData, get ClientID());590 Gamestate *g = new Gamestate(newData, getPeerID()); 588 591 (g->header_) = header_; 589 592 g->header_.setBaseID( base->getID() ); … … 757 760 758 761 759 uint32_t Gamestate::calcGamestateSize( int32_t id, uint8_t mode)762 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 760 763 { 761 764 uint32_t size = 0; -
code/branches/network5/src/libraries/network/packet/Gamestate.h
r7758 r7777 42 42 #include "Packet.h" 43 43 44 namespace orxonox { 44 namespace orxonox 45 { 45 46 46 namespace packet { 47 namespace packet 48 { 49 50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1; 51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2; 47 52 48 class _NetworkExport GamestateHeader{ 53 class _NetworkExport GamestateHeader 54 { 49 55 public: 50 56 GamestateHeader(){ data_=0; } … … 58 64 { return 21; } 59 65 60 inline int32_t getID() const61 { assert(data_); return *( int32_t*)(data_+4); }62 inline void setID( int32_t id)63 { assert(data_); *( int32_t*)(data_+4) = id; }66 inline uint32_t getID() const 67 { assert(data_); return *(uint32_t*)(data_+4); } 68 inline void setID(uint32_t id) 69 { assert(data_); *(uint32_t*)(data_+4) = id; } 64 70 65 inline int32_t getBaseID() const66 { assert(data_); return *( int32_t*)(data_+8); }67 inline void setBaseID( int32_t id)68 { assert(data_); *( int32_t*)(data_+8) = id; }71 inline uint32_t getBaseID() const 72 { assert(data_); return *(uint32_t*)(data_+8); } 73 inline void setBaseID(uint32_t id) 74 { assert(data_); *(uint32_t*)(data_+8) = id; } 69 75 70 76 inline uint32_t getDataSize() const … … 103 109 @author Oliver Scheuss 104 110 */ 105 class _NetworkExport Gamestate: public Packet{ 111 class _NetworkExport Gamestate: public Packet 112 { 106 113 public: 107 114 Gamestate(); … … 114 121 bool collectData(int id, uint8_t mode=0x0); 115 122 bool spreadData( uint8_t mode=0x0); 116 inline int32_t getID() const { return header_.getID(); }123 inline uint32_t getID() const { return header_.getID(); } 117 124 inline bool isDiffed() const { return header_.isDiffed(); } 118 125 inline bool isCompressed() const { return header_.isCompressed(); } … … 132 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 133 140 virtual uint32_t getSize() const; 134 virtual inline bool process();135 uint32_t calcGamestateSize( int32_t id, uint8_t mode=0x0);141 virtual bool process(orxonox::Host* host); 142 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 136 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 137 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); -
code/branches/network5/src/libraries/network/packet/Packet.cc
r7773 r7777 68 68 flags_ = PACKET_FLAG_DEFAULT; 69 69 packetDirection_ = Direction::Outgoing; 70 clientID_=0;70 peerID_=0; 71 71 data_=0; 72 72 enetPacket_=0; … … 74 74 } 75 75 76 Packet::Packet(uint8_t *data, unsigned int clientID)76 Packet::Packet(uint8_t *data, unsigned int peerID) 77 77 { 78 78 flags_ = PACKET_FLAG_DEFAULT; 79 79 packetDirection_ = Direction::Incoming; 80 clientID_=clientID;80 peerID_=peerID; 81 81 data_=data; 82 82 enetPacket_=0; … … 89 89 flags_=p.flags_; 90 90 packetDirection_ = p.packetDirection_; 91 clientID_ = p.clientID_;91 peerID_ = p.peerID_; 92 92 if(p.data_){ 93 93 data_ = new uint8_t[p.getSize()]; … … 125 125 } 126 126 127 bool Packet::send( ){127 bool Packet::send(orxonox::Host* host){ 128 128 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){ 129 129 assert(0); … … 169 169 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 170 170 if( this->flags_ & PacketFlag::Reliable ) 171 Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_DEFAULT);171 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); 172 172 else 173 Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_UNRELIABLE);173 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE); 174 174 return true; 175 175 } … … 178 178 uint8_t *data = packet->data; 179 179 assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer()); 180 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();180 unsigned int peerID = ClientInformation::findClient(&peer->address)->getID(); 181 181 Packet *p = 0; 182 182 // COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; … … 185 185 case Type::Acknowledgement: 186 186 // COUT(5) << "ack" << std::endl; 187 p = new Acknowledgement( data, clientID );187 p = new Acknowledgement( data, peerID ); 188 188 break; 189 189 case Type::Chat: 190 190 // COUT(5) << "chat" << std::endl; 191 p = new Chat( data, clientID );191 p = new Chat( data, peerID ); 192 192 break; 193 193 case Type::ClassID: 194 194 // COUT(5) << "classid" << std::endl; 195 p = new ClassID( data, clientID );195 p = new ClassID( data, peerID ); 196 196 break; 197 197 case Type::Gamestate: 198 198 // COUT(5) << "gamestate" << std::endl; 199 p = new Gamestate( data, clientID );199 p = new Gamestate( data, peerID ); 200 200 break; 201 201 case Type::Welcome: 202 202 // COUT(5) << "welcome" << std::endl; 203 p = new Welcome( data, clientID );203 p = new Welcome( data, peerID ); 204 204 break; 205 205 case Type::DeleteObjects: 206 206 // COUT(5) << "deleteobjects" << std::endl; 207 p = new DeleteObjects( data, clientID );207 p = new DeleteObjects( data, peerID ); 208 208 break; 209 209 case Type::FunctionCalls: 210 210 // COUT(5) << "functionCalls" << std::endl; 211 p = new FunctionCalls( data, clientID );211 p = new FunctionCalls( data, peerID ); 212 212 break; 213 213 case Type::FunctionIDs: 214 214 // COUT(5) << "functionIDs" << std::endl; 215 p = new FunctionIDs( data, clientID );215 p = new FunctionIDs( data, peerID ); 216 216 break; 217 217 default: -
code/branches/network5/src/libraries/network/packet/Packet.h
r7772 r7777 68 68 virtual unsigned char *getData(){ return data_; }; 69 69 virtual unsigned int getSize() const =0; 70 virtual bool process( )=0;70 virtual bool process(orxonox::Host* host)=0; 71 71 inline uint32_t getFlags() 72 72 { return flags_; } 73 inline int getClientID() 74 { return clientID_; } 75 inline void setClientID( int id ) 76 { clientID_ = id; } 73 inline int getPeerID() 74 { return peerID_; } 75 inline void setPeerID( int id ) 76 { peerID_ = id; } 77 inline bool isReliable() 78 { return this->flags_ & PacketFlag::Reliable; } 79 inline uint32_t getRequiredGamestateID() 80 { return this->requiredGamestateID_; } 77 81 78 virtual bool send( );82 virtual bool send(orxonox::Host* host); 79 83 protected: 80 84 Packet(); 81 Packet(uint8_t *data, unsigned int clientID);85 Packet(uint8_t *data, unsigned int peerID); 82 86 // Packet(ENetPacket *packet, ENetPeer *peer); 83 87 inline bool isDataENetAllocated() const … … 85 89 86 90 uint32_t flags_; 87 unsigned int clientID_; 91 unsigned int peerID_; 92 uint32_t requiredGamestateID_; 88 93 Direction::Value packetDirection_; 89 94 /** Pointer to the data. Be careful when deleting it because it might -
code/branches/network5/src/libraries/network/packet/Welcome.cc
r5781 r7777 73 73 } 74 74 75 bool Welcome::process( ){75 bool Welcome::process(orxonox::Host* host){ 76 76 uint32_t clientID; 77 77 clientID = *(uint32_t *)(data_ + _CLIENTID ); 78 78 assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); 79 Host::setClientID(clientID);79 host->setClientID(clientID); 80 80 COUT(3) << "Welcome set clientId: " << clientID << endl; 81 81 Synchronisable::setClient(true); -
code/branches/network5/src/libraries/network/packet/Welcome.h
r6073 r7777 47 47 uint8_t *getData(); 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 private: -
code/branches/network5/src/orxonox/PlayerManager.cc
r7474 r7777 54 54 void PlayerManager::clientConnected(unsigned int clientID) 55 55 { 56 COUT(0) << "PlayerManager: client connected with id: " << clientID << endl; 56 57 if (GameMode::isMaster()) 57 58 { -
code/branches/network5/src/orxonox/gametypes/Gametype.cc
r7758 r7777 171 171 void Gametype::playerEntered(PlayerInfo* player) 172 172 { 173 COUT(0) << "Gametype: playerentered" << endl; 173 174 this->players_[player].state_ = PlayerState::Joined; 174 175 } … … 411 412 void Gametype::spawnPlayer(PlayerInfo* player) 412 413 { 414 COUT(0) << "Gametype: spawnPlayer" << endl; 413 415 SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); 414 416 if (spawnpoint) -
code/branches/network5/src/orxonox/infos/HumanPlayer.cc
r6417 r7777 45 45 HumanPlayer::HumanPlayer(BaseObject* creator) : PlayerInfo(creator) 46 46 { 47 COUT(0) << "new HumanPlayer" << endl; 47 48 RegisterObject(HumanPlayer); 48 49 … … 133 134 void HumanPlayer::networkcallback_client_initialized() 134 135 { 136 COUT(0) << "networkcallback_client_initialized" << endl; 135 137 if (this->getGametype()) 136 138 this->getGametype()->playerEntered(this); -
code/branches/network5/src/orxonox/worldentities/pawns/Spectator.cc
r6417 r7777 43 43 Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator) 44 44 { 45 COUT(0) << "creating specator" << endl; 45 46 RegisterObject(Spectator); 46 47
Note: See TracChangeset
for help on using the changeset viewer.