Changeset 403 for code/branches/FICN/src
- Timestamp:
- Dec 5, 2007, 4:23:52 PM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/GameStateManager.cc
r385 r403 168 168 169 169 GameState GameStateManager::compress(GameState a){ 170 // to be implemented !!!!!!!!!!!!!!170 a. 171 171 return a; 172 172 } -
code/branches/FICN/src/network/GameStateManager.h
r385 r403 29 29 unsigned char *data; 30 30 }; 31 32 /** 33 * this struct defines a gamestate: 34 * compsize is the size of the compressed data 35 * normsize is the size of the uncompressed data 36 * data are the gamestates 37 */ 38 struct GameStateCompressed{ 39 int id; 40 int compsize; 41 int normsize; 42 unsigned char *data; 43 }; 31 44 32 45 /** -
code/branches/FICN/src/network/PacketDecoder.cc
r401 r403 110 110 void PacketDecoder::gstate( ENetPacket* packet ) 111 111 { 112 GameState * currentState = new GameState;112 GameStateCompressed* currentState = new GameStateCompressed; 113 113 //since it's not alowed to use void* for pointer arithmetic 114 114 unsigned char* data = (unsigned char*)packet->data; 115 //copy the gamestateid into the struct, which is located at second place data+sizeof( int )115 //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int ) 116 116 memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) ); 117 //copy the size of the gamestate data into the new gamestatestruct, located at 3th117 //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th 118 118 //position of the data stream, data+2*sizeof( int ) 119 memcpy( (void*)&(currentState->size), (const void*)(data+2*sizeof( int )), sizeof( int) ); 119 memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) ); 120 //size of uncompressed data 121 memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) ); 120 122 //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream 121 123 currentState->data = (unsigned char*)(malloc( currentState->size )); 122 //copy the gamestatedata123 memcpy( (void*)(currentState->data), (const void*)(data+ 3*sizeof( int )), currentState->size );124 //copy the GameStateCompressed data 125 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int )), currentState->compsize ); 124 126 125 127 //clean memory 126 128 enet_packet_destroy( packet ); 127 //run processGame state129 //run processGameStateCompressed 128 130 //TODO: not yet implemented! 129 131 //processGamestate(currentState); … … 181 183 } 182 184 183 void PacketDecoder::printGamestate( GameState * data )185 void PacketDecoder::printGamestate( GameStateCompressed* data ) 184 186 { 185 cout << "id of gamestate: " << data->id << endl;186 cout << "size of gamestate: " << data->size << endl;187 cout << "id of GameStateCompressed: " << data->id << endl; 188 cout << "size of GameStateCompressed: " << data->size << endl; 187 189 } 188 190 -
code/branches/FICN/src/network/PacketGenerator.cc
r400 r403 70 70 71 71 /*### gamestate packet */ 72 ENetPacket* PacketGenerator::gstate( GameState * states, int reliable )72 ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable ) 73 73 { 74 74 int* gid; *gid = GAMESTATE; //first assign the correct enet id … … 76 76 unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 77 77 memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id 78 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the gamestate id 79 //this is the size of the gamestate data, place at 3th position of the enet datastream 80 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->size), sizeof(int)); 81 //place the gamestate data at the end of the enet datastream 82 memcpy( (void*)(data+3*sizeof( int )), (const void*)states->data, states->size ); 78 memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id 79 //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream 80 memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int)); 81 //this is the uncompressed size of GameStateCompressed data 82 memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int)); 83 //place the GameStateCompressed data at the end of the enet datastream 84 memcpy( (void*)(data+4*sizeof( int )), (const void*)states->data, states->compsize ); 83 85 //create an enet packet with the generated bytestream 84 86 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); -
code/branches/FICN/src/network/PacketManager.h
r401 r403 15 15 CHAT, 16 16 GAMESTATE , 17 17 CLASSID 18 18 }; 19 19 … … 102 102 void chatMessage( ENetPacket* packet ); 103 103 void gstate( ENetPacket* packet ); 104 104 void clid( ENetPacket *packet); 105 105 106 106 //process data … … 117 117 void printChat( chat* data ); 118 118 void printGamestate( GameState* data ); 119 119 void printClassid( classid *cid); 120 120 }; 121 121 }
Note: See TracChangeset
for help on using the changeset viewer.