Changeset 422 for code/branches/FICN
- Timestamp:
- Dec 5, 2007, 9:17:22 PM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/GameStateManager.cc
r413 r422 24 24 25 25 void GameStateManager::update(){ 26 reference = getSnapshot(id++); 26 reference = getSnapshot(id); 27 idGameState[id]=reference; 28 ++id; 27 29 return; 28 30 } … … 30 32 GameStateCompressed GameStateManager::popGameState(int clientID){ 31 33 GameState *client = clientGameState[clientID]; 32 GameState *server = &reference;34 GameState *server = reference; 33 35 return encode(client, server); 34 36 } … … 41 43 * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list 42 44 */ 43 GameState GameStateManager::getSnapshot(int id)45 GameState *GameStateManager::getSnapshot(int id) 44 46 { 45 47 //the size of the gamestate … … 52 54 syncData sync; 53 55 54 GameState retval; //return value55 retval .id=id;56 GameState *retval=new GameState; //return value 57 retval->id=id; 56 58 // reserve a little memory and increase it later on 57 retval .data = (unsigned char*)malloc(1);59 retval->data = (unsigned char*)malloc(1); 58 60 59 61 // offset of memory functions … … 66 68 totalsize+=tempsize+3*sizeof(int); 67 69 // allocate additional space 68 retval .data = (unsigned char *)realloc((void *)retval.data, totalsize);70 retval->data = (unsigned char *)realloc((void *)retval->data, totalsize); 69 71 70 72 // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length) 71 sync=it->getData(retval .data+offset+3*sizeof(int));72 *(retval .data+offset)=sync.length;73 *(retval .data+offset+sizeof(int))=sync.objectID;74 *(retval .data+offset+2*sizeof(int))=sync.classID;73 sync=it->getData(retval->data+offset+3*sizeof(int)); 74 *(retval->data+offset)=sync.length; 75 *(retval->data+offset+sizeof(int))=sync.objectID; 76 *(retval->data+offset+2*sizeof(int))=sync.classID; 75 77 // increase data pointer 76 78 offset+=tempsize+3*sizeof(int); 77 79 } 78 retval .size=totalsize;80 retval->size=totalsize; 79 81 return retval; 80 82 } … … 143 145 } 144 146 147 void GameStateManager::ackGameState(int clientID, int gamestateID){ 148 GameState *old = clientGameState[clientID]; 149 deleteUnusedGameState(old); 150 clientGameState[clientID]=idGameState[gamestateID]; 151 } 145 152 153 bool GameStateManager::deleteUnusedGameState(GameState *state){ 154 for(unsigned int i=0; i<clientGameState.size(); i++){ 155 if(clientGameState[i]==state) 156 return false; 157 } 158 delete state; 159 return true; 160 } 146 161 147 162 } -
code/branches/FICN/src/network/GameStateManager.h
r415 r422 47 47 void update(); 48 48 GameStateCompressed popGameState(int clientID); 49 void ackGameState(int clientID, int gamestateID); 49 50 private: 50 GameState getSnapshot(int id);51 GameState *getSnapshot(int id); 51 52 GameStateCompressed encode(GameState *a, GameState *b); 52 53 GameState diff(GameState *a, GameState *b); 53 54 GameStateCompressed compress_(GameState a); 55 bool deleteUnusedGameState(GameState *state); 54 56 55 57 std::vector<GameState *> clientGameState; 56 GameState reference; 58 std::vector<GameState *> idGameState; 59 GameState *reference; 57 60 int id; 58 61 }; -
code/branches/FICN/src/network/PacketManager.h
r415 r422 50 50 51 51 52 53 54 55 56 52 void acknowledgement( ENetPacket* packet ); 53 void mousem( ENetPacket* packet ); 54 void keystrike( ENetPacket* packet ); 55 void chatMessage( ENetPacket* packet ); 56 void gstate( ENetPacket* packet ); 57 57 void clid( ENetPacket *packet); 58 58 -
code/branches/FICN/src/network/Server.cc
r400 r422 103 103 while(!connection.queueEmpty()){ 104 104 packet = connection.getPacket(clientID); 105 elaborate(packet, clientID); 105 106 } 106 107 } … … 110 111 */ 111 112 void Server::updateGamestate(){ 113 gamestates.update(); 114 sendGameState(); 115 } 116 117 bool Server::sendGameState(){ 118 112 119 } 113 120 -
code/branches/FICN/src/network/Server.h
r413 r422 38 38 void tick(); 39 39 private: 40 bool sendGameState(); 40 41 ConnectionManager connection; 41 42 GameStateManager gamestates;
Note: See TracChangeset
for help on using the changeset viewer.