Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 403 for code/branches/FICN/src


Ignore:
Timestamp:
Dec 5, 2007, 4:23:52 PM (17 years ago)
Author:
dumenim
Message:

compressed gamestates

Location:
code/branches/FICN/src/network
Files:
5 edited

Legend:

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

    r385 r403  
    168168
    169169GameState GameStateManager::compress(GameState a){
    170   // to be implemented !!!!!!!!!!!!!!
     170  a.
    171171  return a;
    172172}
  • code/branches/FICN/src/network/GameStateManager.h

    r385 r403  
    2929  unsigned char *data;
    3030};
     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  };
    3144
    3245/**
  • code/branches/FICN/src/network/PacketDecoder.cc

    r401 r403  
    110110void PacketDecoder::gstate( ENetPacket* packet )
    111111{
    112         GameState* currentState = new GameState;
     112        GameStateCompressed* currentState = new GameStateCompressed;
    113113        //since it's not alowed to use void* for pointer arithmetic
    114114        unsigned char* data = (unsigned char*)packet->data;
    115         //copy the gamestate id 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 )
    116116        memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
    117         //copy the size of the gamestate data into the new gamestate struct, located at 3th
     117        //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
    118118        //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 ) );
    120122        //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    121123        currentState->data = (unsigned char*)(malloc( currentState->size ));
    122         //copy the gamestate data
    123         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 );
    124126 
    125127        //clean memory
    126128        enet_packet_destroy( packet );
    127   //run processGamestate
     129  //run processGameStateCompressed
    128130  //TODO: not yet implemented!
    129131  //processGamestate(currentState);
     
    181183}
    182184
    183 void PacketDecoder::printGamestate( GameState* data )
     185void PacketDecoder::printGamestate( GameStateCompressed* data )
    184186{
    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;
    187189}
    188190
  • code/branches/FICN/src/network/PacketGenerator.cc

    r400 r403  
    7070
    7171/*### gamestate packet */
    72 ENetPacket* PacketGenerator::gstate( GameState* states, int reliable )
     72ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable )
    7373{
    7474        int* gid; *gid = GAMESTATE; //first assign the correct enet id
     
    7676        unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
    7777        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 );
    8385        //create an enet packet with the generated bytestream
    8486        ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
  • code/branches/FICN/src/network/PacketManager.h

    r401 r403  
    1515        CHAT,
    1616        GAMESTATE ,
    17         CLASSID
     17    CLASSID
    1818};
    1919
     
    102102        void chatMessage( ENetPacket* packet );
    103103        void gstate( ENetPacket* packet );
    104         void clid( ENetPacket *packet);
     104    void clid( ENetPacket *packet);
    105105       
    106106  //process data
     
    117117        void printChat( chat* data );
    118118        void printGamestate( GameState* data );
    119         void printClassid( classid *cid);
     119    void printClassid( classid *cid);
    120120};
    121121}
Note: See TracChangeset for help on using the changeset viewer.