Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 18, 2007, 5:51:47 PM (16 years ago)
Author:
scheusso
Message:

gamestatehandling, error correction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/PacketGenerator.cc

    r514 r620  
    9898ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable )
    9999{
    100         int* gid = new int;
    101         *gid = GAMESTATE; //first assign the correct enet id
     100        int gid = GAMESTATE; //first assign the correct enet id
    102101        int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
    103         unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
    104         memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id
    105         memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
    106         //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
    107         memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
     102        unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     103  memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
     104  memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     105  memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
     106  memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
     107  memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
     108  /*(int)*(data) = gid;
     109        (int)*(data+sizeof(int)) = states->id;
     110  //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
     111  (int)*(data+2*sizeof(int)) = states->compsize;
    108112        //this is the uncompressed size of GameStateCompressed data
    109         memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
     113  (int)*(data+3*sizeof(int)) = states->normsize;
    110114        //since there is a new parameter inside GameStateCompressed, change this function to create packet
    111         memcpy( (void*)(data+4*sizeof(int)), (const void*)states->diffed, sizeof(bool));
     115  (bool)*(data+4*sizeof(int)) = states->diffed;*/
    112116        //place the GameStateCompressed data at the end of the enet datastream
    113117        memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
    114118        //create an enet packet with the generated bytestream
    115119        ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    116 
     120  //delete data;
    117121        return packet;
    118122}
Note: See TracChangeset for help on using the changeset viewer.