Changeset 1425 for code/branches/network/src
- Timestamp:
- May 25, 2008, 11:08:19 PM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1409 r1425 246 246 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 247 247 } 248 int gameStateID = gamestate.processGameState(); 249 if(gameStateID!=GAMESTATEID_INITIAL){ 250 // ack gamestate and set synched 251 if(!isSynched_) 252 isSynched_=true; 253 if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID))) 254 COUT(3) << "could not ack gamestate" << std::endl; 255 } 256 gamestate.cleanup(); 248 257 if(!client_connection.sendPackets()) 249 258 COUT(3) << "Problem sending packets to server" << std::endl; … … 252 261 253 262 void Client::processGamestate( GameStateCompressed *data, int clientID){ 254 int id = data->id;255 263 COUT(5) << "received gamestate id: " << data->id << std::endl; 256 if(gamestate.pushGameState(data)){ 257 if(!isSynched_) 258 isSynched_=true; 259 if(!client_connection.addPacket(pck_gen.acknowledgement(id))) 260 return; 261 // we do this at the end of a tick 262 if(!client_connection.sendPackets()) 263 COUT(2) << "Could not send acknowledgment" << std::endl; 264 } 264 gamestate.addGameState(data); 265 265 } 266 266 -
code/branches/network/src/network/GameStateClient.cc
r1360 r1425 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 35 35 #include "Synchronisable.h" 36 36 37 #define GAMESTATEID_INITIAL -138 37 39 38 namespace network … … 48 47 last_diff_=0; 49 48 last_gamestate_=GAMESTATEID_INITIAL-1; 49 tempGameState_=NULL; 50 myShip_=NULL; 50 51 } 51 52 … … 102 103 delete gs; 103 104 return cgs; 105 } 106 107 void GameStateClient::addGameState(GameStateCompressed *gs){ 108 if(tempGameState_!=NULL){ 109 //delete the obsolete gamestate 110 if(tempGameState_->id>gs->id) 111 return; 112 delete[] tempGameState_->data; 113 delete tempGameState_; 114 } 115 tempGameState_=gs; 116 } 117 int GameStateClient::processGameState(){ 118 if(tempGameState_==NULL) 119 return GAMESTATEID_INITIAL; 120 int id=tempGameState_->id; 121 bool b = saveShipCache(); 122 if(pushGameState(tempGameState_)){ 123 if(b) 124 loadShipCache(); 125 return id; 126 } 127 else 128 return GAMESTATEID_INITIAL; 104 129 } 105 130 … … 388 413 gameStateMap.erase(temp); 389 414 } 415 tempGameState_=NULL; 390 416 } 391 417 … … 400 426 } 401 427 428 bool GameStateClient::saveShipCache(){ 429 if(myShip_==NULL) 430 myShip_ = orxonox::SpaceShip::getLocalShip(); 431 if(myShip_){ 432 // unsigned char *data = new unsigned char[myShip_->getSize()]; 433 int size=myShip_->getSize(0x3); 434 if(size==0) 435 return false; 436 unsigned char *data = new unsigned char [size]; 437 shipCache_ = myShip_->getData(data, 0x1); 438 return true; 439 }else 440 return false; 441 } 442 443 bool GameStateClient::loadShipCache(){ 444 if(myShip_){ 445 myShip_->updateData(shipCache_, 0x2); 446 if(shipCache_.data){ 447 delete[] shipCache_.data; 448 } 449 return true; 450 }else 451 return false; 452 } 402 453 403 454 //##### ADDED FOR TESTING PURPOSE ##### -
code/branches/network/src/network/GameStateClient.h
r1360 r1425 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 33 33 // 34 34 // 35 // Author: <>, (C) 200735 // Author: Oliver Scheuss, (C) 2007 36 36 // 37 37 // Copyright: See COPYING file that comes with this distribution … … 46 46 #include "core/CorePrereqs.h" 47 47 #include "PacketTypes.h" 48 #include "objects/SpaceShip.h" 48 49 50 51 #define GAMESTATEID_INITIAL -1 49 52 50 53 namespace network … … 56 59 ~GameStateClient(); 57 60 61 void addGameState(GameStateCompressed *gs); 62 int processGameState(); 63 GameStateCompressed *popPartialGameState(); 64 void cleanup(); 65 private: 58 66 bool pushGameState(GameStateCompressed *compstate); 59 GameStateCompressed *popPartialGameState();60 private:61 67 bool loadSnapshot(GameState *state); 62 68 GameState *getPartialSnapshot(); 63 void cleanup();64 69 GameState *undiff(GameState *old, GameState *diff); 65 70 GameStateCompressed *compress_(GameState *a); … … 69 74 void removeObject(orxonox::Iterator<Synchronisable> &it); 70 75 void printGameStateMap(); 76 bool saveShipCache(); 77 bool loadShipCache(); 71 78 72 79 int last_diff_; 73 80 int last_gamestate_; 74 81 std::map<int, GameState *> gameStateMap; 82 GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue 83 orxonox::SpaceShip *myShip_; 84 syncData shipCache_; 75 85 76 86 -
code/branches/network/src/network/GameStateManager.cc
r1360 r1425 68 68 printGameStates(); 69 69 return; 70 } 71 72 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 73 if(!gs) 74 return; 75 std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID); 76 if(it!=gameStateQueue.end()){ 77 // delete obsolete gamestate 78 delete[] it->second->data; 79 delete it->second; 80 } 81 gameStateQueue[clientID] = gs; 82 return; 83 } 84 85 void GameStateManager::processGameStates(){ 86 std::map<int, GameStateCompressed*>::iterator it; 87 // now push only the most recent gamestates we received (ignore obsolete ones) 88 for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){ 89 pushGameState(it->second, it->first); 90 } 91 // now clear the queue 92 gameStateQueue.clear(); 70 93 } 71 94 -
code/branches/network/src/network/GameStateManager.h
r1293 r1425 72 72 ~GameStateManager(); 73 73 74 void addGameState(GameStateCompressed *gs, int clientID); 75 void processGameStates(); 76 74 77 void update(); 75 78 GameStateCompressed *popGameState(int clientID); 76 bool pushGameState(GameStateCompressed *gs, int clientID);77 79 void ackGameState(int clientID, int gamestateID); 78 80 void removeClient(ClientInformation *client); 79 private: 81 private: 82 bool pushGameState(GameStateCompressed *gs, int clientID); 80 83 void cleanup(); // "garbage handler" 81 84 GameState *getSnapshot(); … … 91 94 std::map<int, GameState*> gameStateMap; //map gsID to gamestate* 92 95 std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate 96 std::map<int, GameStateCompressed*> gameStateQueue; 93 97 GameState *reference; 94 98 ClientInformation *head_; -
code/branches/network/src/network/Server.cc
r1409 r1425 157 157 void Server::tick(float time) { 158 158 processQueue(); 159 gamestates->processGameStates(); 159 160 updateGamestate(); 160 161 // usleep(500000); // TODO remove … … 245 246 disconnectClient(temp); 246 247 //std::cout << "added gamestate" << std::endl; 247 } 248 }else 249 temp->resetFailures(); 248 250 added=true; 249 251 temp=temp->next(); … … 276 278 void Server::processGamestate( GameStateCompressed *data, int clientID){ 277 279 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; 278 if(!gamestates->pushGameState(data, clientID))279 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;280 gamestates->addGameState(data, clientID); 281 /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 280 282 else 281 283 if(clients->findClient(clientID)) 282 clients->findClient(clientID)->resetFailures(); 284 clients->findClient(clientID)->resetFailures();*/ 283 285 } 284 286 -
code/branches/network/src/network/Synchronisable.cc
r1418 r1425 70 70 bool Synchronisable::create(){ 71 71 this->classID = this->getIdentifier()->getNetworkID(); 72 COUT(4) << "setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 72 73 return true; 73 74 } … … 156 157 * @return data containing all variables and their sizes 157 158 */ 158 syncData Synchronisable::getData(unsigned char *mem ){159 syncData Synchronisable::getData(unsigned char *mem, int mode){ 159 160 //std::cout << "inside getData" << std::endl; 161 if(mode==0x0) 162 mode=state_; 160 163 if(classID==0) 161 164 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; … … 172 175 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 173 176 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 174 if( ((*i)->mode & state_) == 0 ){177 if( ((*i)->mode & mode) == 0 ){ 175 178 COUT(5) << "not getting data: " << std::endl; 176 179 continue; // this variable should only be received … … 199 202 * @return true/false 200 203 */ 201 bool Synchronisable::updateData(syncData vars){ 204 bool Synchronisable::updateData(syncData vars, int mode){ 205 if(mode==0x0) 206 mode=state_; 202 207 unsigned char *data=vars.data; 203 208 std::list<synchronisableVariable *>::iterator i; … … 208 213 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl; 209 214 for(i=syncList->begin(); i!=syncList->end(); i++){ 210 if( ((*i)->mode ^ state_) == 0 ){215 if( ((*i)->mode ^ mode) == 0 ){ 211 216 COUT(5) << "synchronisable: not updating variable " << std::endl; 212 continue; // this variable should only be updated217 continue; // this variable should only be set 213 218 } 214 219 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; … … 235 240 * @return amount of bytes 236 241 */ 237 int Synchronisable::getSize( ){242 int Synchronisable::getSize(int mode){ 238 243 int tsize=0; 244 if(mode==0x0) 245 mode=state_; 239 246 std::list<synchronisableVariable *>::iterator i; 240 247 for(i=syncList->begin(); i!=syncList->end(); i++){ 241 if( ((*i)->mode & state_) == 0 )248 if( ((*i)->mode & mode) == 0 ) 242 249 continue; // this variable should only be received, so dont add its size to the send-size 243 250 switch((*i)->type){ -
code/branches/network/src/network/Synchronisable.h
r1418 r1425 83 83 void registerVar(void *var, int size, variableType t, int mode=1); 84 84 // syncData getData(); 85 syncData getData(unsigned char *mem );86 int getSize( );87 bool updateData(syncData vars );85 syncData getData(unsigned char *mem, int mode=0x0); 86 int getSize(int mode=0x0); 87 bool updateData(syncData vars, int mode=0x0); 88 88 void setBacksync(bool sync); 89 89 bool getBacksync(); -
code/branches/network/src/orxonox/objects/Ambient.h
r1293 r1425 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 void setAmbientLight(const ColourValue& colour); 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 -
code/branches/network/src/orxonox/objects/Explosion.cc
r1421 r1425 80 80 }; 81 81 82 bool Explosion::create(){ 83 return WorldEntity::create(); 84 } 82 /*bool Explosion::create(){ 83 if(!WorldEntity::create()) 84 return false; 85 classID=this->getIdentifier()->getNetworkID(); 86 }*/ 85 87 86 88 void Explosion::destroyObject() -
code/branches/network/src/orxonox/objects/Explosion.h
r1421 r1425 43 43 virtual ~Explosion(); 44 44 void destroyObject(); 45 bool create();45 virtual bool create(){return WorldEntity::create();} 46 46 47 47 private: -
code/branches/network/src/orxonox/objects/Model.h
r1293 r1425 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 void setMesh(const std::string& meshname); 47 bool create();47 virtual bool create(); 48 48 49 49 protected: -
code/branches/network/src/orxonox/objects/NPC.cc
r1293 r1425 67 67 } 68 68 69 bool NPC::create(){70 Model::create();71 return true;72 }73 69 74 70 /** -
code/branches/network/src/orxonox/objects/NPC.h
r1293 r1425 53 53 void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable); 54 54 void registerAllVariables(); 55 bool create();55 virtual bool create(){return Model::create();} 56 56 57 57 private: -
code/branches/network/src/orxonox/objects/Projectile.cc
r1418 r1425 91 91 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 92 92 { 93 new Explosion(this); 93 Explosion *exp = new Explosion(this); 94 exp->create(); 94 95 delete this; 95 96 return; -
code/branches/network/src/orxonox/objects/Projectile.h
r1056 r1425 46 46 void destroyObject(); 47 47 virtual void tick(float dt); 48 virtual bool create(){return WorldEntity::create();} 48 49 49 50 private: -
code/branches/network/src/orxonox/objects/Skybox.h
r1293 r1425 47 47 void setSkybox(const std::string& skyboxname); 48 48 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 void setSkyboxSrc(const std::string &src); -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1413 r1425 70 70 Iterator<SpaceShip> it; 71 71 for(it = ObjectList<SpaceShip>::start(); it; ++it){ 72 if( (it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ))72 if( (it)->myShip_ ) 73 73 return *it; 74 74 } … … 109 109 mouseY_(0.0f), 110 110 emitterRate_(0.0f), 111 server_(false)111 myShip_(false) 112 112 { 113 113 RegisterObject(SpaceShip); … … 140 140 141 141 bool SpaceShip::create(){ 142 if(!myShip_){ 143 if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) 144 myShip_=true; 145 } 142 146 if(Model::create()) 143 147 this->init(); … … 299 303 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 300 304 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 301 server_=true; // TODO: this is only a hack305 myShip_=true; // TODO: this is only a hack 302 306 SpaceShip::create(); 303 307 getFocus(); … … 354 358 355 359 Projectile *p = new Projectile(this); 360 p->create(); 356 361 357 362 p->setBacksync(true); … … 439 444 this->tt_->setRate(0); 440 445 441 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ )446 if( myShip_ ) 442 447 { 443 448 COUT(4) << "steering our ship: " << objectID << std::endl; -
code/branches/network/src/orxonox/objects/SpaceShip.h
r1406 r1425 49 49 SpaceShip(); 50 50 ~SpaceShip(); 51 bool create();51 virtual bool create(); 52 52 void registerAllVariables(); 53 53 void init(); … … 81 81 Vector3 getOrth(); 82 82 Camera* getCamera(); 83 84 bool getMyShip(){return myShip_;} 83 85 84 86 private: … … 135 137 136 138 float emitterRate_; 137 bool server_;139 bool myShip_; 138 140 139 141 static SpaceShip* instance_s; -
code/branches/network/src/orxonox/objects/WorldEntity.cc
r1360 r1425 153 153 registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3); 154 154 //register acceleration & momentum 155 registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);156 registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);157 registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);158 registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA); 155 // registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2); 156 // registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2); 157 // registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2); 158 // registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync 159 159 } 160 160 -
code/branches/network/src/orxonox/objects/WorldEntity.h
r1418 r1425 53 53 virtual void loadParams(TiXmlElement* xmlElem); 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 inline bool create(){ return Synchronisable::create(); }55 virtual inline bool create(){ return Synchronisable::create(); } 56 56 57 57 void attachWorldEntity(WorldEntity* entity);
Note: See TracChangeset
for help on using the changeset viewer.