Changeset 1581 for code/branches/gcc43/src/network
- Timestamp:
- Jun 9, 2008, 11:11:21 PM (16 years ago)
- Location:
- code/branches/gcc43/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gcc43/src/network/GameStateManager.cc
r1534 r1581 45 45 #include <zlib.h> 46 46 #include <assert.h> 47 #include <string.h> 47 48 48 49 #include "core/CoreIncludes.h" … … 70 71 return; 71 72 } 72 73 73 74 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 74 75 if(!gs) … … 83 84 return; 84 85 } 85 86 86 87 void GameStateManager::processGameStates(){ 87 88 std::map<int, GameStateCompressed*>::iterator it; … … 93 94 gameStateQueue.clear(); 94 95 } 95 96 96 97 97 98 /** 98 99 * this function is used to keep the memory usage low 99 100 * it tries to delete all the unused gamestates 100 * 101 * 101 * 102 * 102 103 */ 103 104 void GameStateManager::cleanup(){ … … 142 143 GameState *server = reference; 143 144 //COUT(4) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl; 144 COUT(4) << "client: " << (client!=0 ? client->id : (int)client) << " server: " << server->id << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl; 145 //FIXME complains about precision loss on int conversion 146 // COUT(4) << "client: " << (client!=0 ? client->id : (int)client) << " server: " << server->id << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl; 145 147 if(client) 146 148 return encode(client, server); … … 155 157 } 156 158 } 157 159 158 160 bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){ 159 161 GameState *ugs = decompress(gs); … … 308 310 return true; 309 311 } 310 311 312 313 312 314 //##### ADDED FOR TESTING PURPOSE ##### 313 315 GameStateCompressed* GameStateManager::testCompress( GameState* g ) { … … 405 407 switch ( retval ) { 406 408 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 407 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 409 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 408 410 return NULL; 409 411 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 426 428 return compressedGamestate; 427 429 } 428 430 429 431 GameState *GameStateManager::decompress(GameStateCompressed *a) { 430 432 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; … … 464 466 return gamestate; 465 467 } 466 468 467 469 468 470 void GameStateManager::ackGameState(int clientID, int gamestateID) { … … 471 473 return; 472 474 int curid = temp->getGamestateID(); 473 475 474 476 if(gamestateID == GAMESTATEID_INITIAL){ 475 477 temp->setGameStateID(GAMESTATEID_INITIAL); … … 481 483 } 482 484 if(curid > gamestateID) 483 // the network packets got messed up 485 // the network packets got messed up 484 486 return; 485 487 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; … … 512 514 return true; 513 515 } 514 516 515 517 bool GameStateManager::checkAccess(int clientID, int objectID){ 516 518 // currently we only check, wheter the object is the clients spaceship … … 518 520 return true; // TODO: change this 519 521 } 520 522 521 523 void GameStateManager::removeClient(ClientInformation* client){ 522 524 if(!client) -
code/branches/gcc43/src/network/PacketDecoder.cc
r1534 r1581 39 39 40 40 #include <iostream> 41 #include <string.h> 41 42 42 43 #include "core/Debug.h" -
code/branches/gcc43/src/network/Synchronisable.cc
r1534 r1581 43 43 #include <string> 44 44 #include <iostream> 45 #include <string.h> 45 46 46 47 #include "core/CoreIncludes.h" … … 49 50 namespace network 50 51 { 51 52 52 53 53 54 int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client 54 55 55 56 /** 56 57 * Constructor: … … 72 73 delete (*it)->callback; 73 74 } 74 75 75 76 bool Synchronisable::create(){ 76 77 this->classID = this->getIdentifier()->getNetworkID(); … … 78 79 return true; 79 80 } 80 81 81 82 void Synchronisable::setClient(bool b){ 82 83 if(b) // client … … 97 98 temp->size = size; 98 99 temp->var = var; 99 temp->mode = mode; 100 temp->mode = mode; 100 101 temp->type = t; 101 102 temp->callback = cb; 102 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 103 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 103 104 // increase datasize 104 105 datasize+=sizeof(int)+size; … … 187 188 switch((*i)->type){ 188 189 case DATA: 189 std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);190 memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size); 190 191 n+=(*i)->size; 191 192 break; … … 194 195 n+=sizeof(int); 195 196 const char *data = ( ( *(std::string *) (*i)->var).c_str()); 196 std::memcpy( retVal.data+n, (void*)data, (*i)->size);197 memcpy( retVal.data+n, (void*)data, (*i)->size); 197 198 COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl; 198 199 n+=(*i)->size; … … 278 279 return tsize; 279 280 } 280 281 281 282 void Synchronisable::setBacksync(bool sync){ 282 283 backsync_=sync; … … 286 287 return backsync_; 287 288 } 288 289 289 290 }
Note: See TracChangeset
for help on using the changeset viewer.