Changeset 332 for code/branches/merger/src/network/PacketGenerator.cc
- Timestamp:
- Nov 28, 2007, 5:20:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merger/src/network/PacketGenerator.cc
r278 r332 1 1 /* 2 2 *Class generates packets that can be send by enet 3 * ->don't read this without the class PacketDecoder, since they belong together 3 4 * 4 5 * Autor: Dumeni Manatschal … … 68 69 } 69 70 71 /*### gamestate packet */ 72 ENetPacket* PacketGenerator::gstate( GameState* states, int reliable ) 73 { 74 int* gid; *gid = GAMESTATE; //first assign the correct enet id 75 int totalLen = 3*sizeof( int ) + states->size; //calculate the total size of the datastream memory 76 unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream 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 ); 83 //create an enet packet with the generated bytestream 84 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 85 86 return packet; 87 }
Note: See TracChangeset
for help on using the changeset viewer.