Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 290


Ignore:
Timestamp:
Nov 28, 2007, 12:08:09 AM (17 years ago)
Author:
dumenim
Message:

added gamestates to packetCode/Decode classes

Location:
code/branches/network/src/network
Files:
4 edited

Legend:

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

    r247 r290  
    2222}
    2323
    24 GameState GameStateManager::getSnapshot(){
     24GameState GameStateManager::getSnapshot()
     25{
    2526 
    2627}
    2728
    28 bool GameStateManager::loadSnapshot(GameState state){
     29bool GameStateManager::loadSnapshot(GameState state)
     30{
    2931 
    3032}
  • code/branches/network/src/network/PacketDecoder.cc

    r237 r290  
    4040                return true;
    4141                break;
     42        case GAMESTATE:
     43                gstate( packet );
     44                return true;
     45                break;
    4246        }
    4347        return false;
     
    7781}
    7882
     83void PacketDecoder::gstate( ENetPacket* packet )
     84{
     85        GameState* currentState = new GameState;
     86        unsigned char* data = (unsigned char*)packet->data;
     87        memcpy( (void*)&(currentState->size), (const void*)(data+sizeof( int )), sizeof(int) );
     88        memcpy( (void*)(currentState->data), (const void*)(data+2*sizeof( int )), currentState->size );
     89}
     90
    7991//these are some print functions for test stuff
    8092
     
    100112{
    101113        cout << "data id: " << data->id << endl;
    102         cout << "blablabla" << endl;
    103114        cout << "data:    " << data->message << endl;
    104115}
     116
     117void PacketDecoder::printGamestate( GameState* data )
     118{
     119        cout << "size of gamestate: " << data->size << endl;
     120}
  • code/branches/network/src/network/PacketGenerator.cc

    r223 r290  
    6868}
    6969
     70/*### gamestate packet */
     71ENetPacket* PacketGenerator::gstate( GameState* states, int reliable )
     72{
     73        int* gid; *gid = GAMESTATE;
     74        int totalLen = sizeof( int ) + states->size;
     75        unsigned char* data = (unsigned char*)malloc( totalLen );
     76        memcpy( (void*)(data), (const void*)gid, sizeof( int ) );
     77        memcpy( (void*)(data+sizeof( int )), (const void*)states->data, states->size );
     78        ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
     79       
     80        return packet;
     81}
  • code/branches/network/src/network/PacketManager.h

    r223 r290  
    33
    44#include <enet/enet.h>
     5#include <network/GameStateManager.h>
    56
    67//enum netowk generaly used to set the type ID of a packet
     
    1112        MOUSE,
    1213        KEYBOARD,
    13         CHAT
     14        CHAT,
     15        GAMESTATE
    1416};
    1517
     
    2931        ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3032        ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
     33        ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3134private:
    3235        //used to set the bytes in the right order
     
    8790        void keystrike( ENetPacket* packet );
    8891        void chatMessage( ENetPacket* packet );
     92        void gstate( ENetPacket* packet );
    8993       
    9094        //print functions
     
    9397        void printKey( keyboard* data );
    9498        void printChat( chat* data );
    95         void printPeer( ENetPeer* peer );
     99        void printGamestate( GameState* data );
    96100};
    97101}
Note: See TracChangeset for help on using the changeset viewer.