Changeset 2087 for code/trunk/src/network/GamestateClient.cc
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/GamestateClient.cc
r1907 r2087 29 29 #include "GamestateClient.h" 30 30 31 #include <cassert> 31 32 #include <zlib.h> 32 33 … … 40 41 namespace network 41 42 { 42 struct GameStateItem{43 struct _NetworkExport GameStateItem{ 43 44 packet::Gamestate *state; 44 int id;45 unsigned int id; 45 46 }; 46 47 … … 50 51 last_gamestate_=GAMESTATEID_INITIAL-1; 51 52 tempGamestate_=NULL; 52 myShip_=NULL;53 53 } 54 54 … … 56 56 } 57 57 58 bool GamestateClient::ack( int gamestateID,int clientID){58 bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){ 59 59 return true; 60 60 } 61 61 62 bool GamestateClient::add(packet::Gamestate *gs, int clientID){62 bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){ 63 63 if(tempGamestate_!=NULL){ 64 64 //delete the obsolete gamestate … … 75 75 return false; 76 76 int id = GAMESTATEID_INITIAL; 77 bool b = saveShipCache();78 77 packet::Gamestate *processed = processGamestate(tempGamestate_); 79 if(!processed){80 if(b)81 loadShipCache();82 return false;83 }84 78 // assert(processed); 79 if (!processed) 80 return false; 85 81 //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs 86 82 tempGamestate_=NULL; 87 83 gamestateMap_[processed->getID()]=processed; 88 84 last_diff_ = processed->getID(); 89 if(b)90 loadShipCache();91 85 id = processed->getID(); 92 86 sendAck(id); … … 108 102 packet::Gamestate *GamestateClient::getGamestate(){ 109 103 packet::Gamestate *gs = new packet::Gamestate(); 110 gs->collectData(0); 104 if(!gs->collectData(0)){ 105 delete gs; 106 return 0; 107 } 111 108 return gs; 112 109 } 113 110 114 111 void GamestateClient::cleanup(){ 115 std::map< int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();112 std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin(); 116 113 while(it!=gamestateMap_.end()){ 117 114 if(it->first>=last_diff_) … … 126 123 127 124 void GamestateClient::printGamestateMap(){ 128 std::map< int, packet::Gamestate*>::iterator it;125 std::map<unsigned int, packet::Gamestate*>::iterator it; 129 126 COUT(4) << "gamestates: "; 130 127 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){ … … 134 131 135 132 } 136 133 137 134 bool GamestateClient::sendAck(unsigned int gamestateID){ 138 135 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0); … … 142 139 } 143 140 else{ 144 COUT( 3) << "acked a gamestate: " << gamestateID << std::endl;141 COUT(5) << "acked a gamestate: " << gamestateID << std::endl; 145 142 return true; 146 143 } 147 }148 149 bool GamestateClient::saveShipCache(){150 if(myShip_==NULL){151 myShip_ = orxonox::SpaceShip::getLocalShip();152 // COUT(2) << "myShip_: " << myShip_ << " getLocalShip(): " << orxonox::SpaceShip::getLocalShip() << std::endl;153 if(!myShip_)154 return false;155 }156 if(myShip_){157 // unsigned char *data = new unsigned char[myShip_->getSize()];158 int size=myShip_->getSize(0, 0x1);159 if(size==0)160 return false;161 shipCache_ = new unsigned char [size];162 unsigned char *temp = shipCache_;163 if(!myShip_->getData(temp, 0, 0x1))164 COUT(3) << "could not save shipCache" << std::endl;165 return true;166 }else167 return false;168 }169 170 bool GamestateClient::loadShipCache(){171 myShip_=orxonox::SpaceShip::getLocalShip(); //TODO: remove this (only a hack)172 if(myShip_ && shipCache_){173 assert(myShip_->getIdentifier());174 unsigned char *temp = shipCache_;175 myShip_->updateData(temp, 0x2);176 delete shipCache_;177 return true;178 }else179 return false;180 144 } 181 145 … … 196 160 delete gs; 197 161 gs=undiffed; 198 COUT( 3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;162 COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl; 199 163 } 200 164 if(gs->spreadData())
Note: See TracChangeset
for help on using the changeset viewer.