Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 912 for code


Ignore:
Timestamp:
Mar 20, 2008, 4:04:52 PM (17 years ago)
Author:
scheusso
Message:

bugfix in packetdecoder, inserted some std::

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

Legend:

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

    r905 r912  
    4040
    4141  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
     42    GameState *gs;
    4243    if(compstate->diffed)
    43       return loadSnapshot(decode(reference, compstate));
     44      gs = decode(reference, compstate);
    4445    else
    45       return loadSnapshot(decode(compstate));
     46      gs = decode(compstate);
     47    if(gs)
     48      return loadSnapshot(gs);
     49    COUT(4) << "could not use gamestate sent by server" << std::endl;
     50    return false;
    4651  }
    4752
  • code/branches/network/src/network/PacketDecoder.cc

    r891 r912  
    4242namespace network
    4343{
    44   using namespace std;
    4544
    4645  PacketDecoder::PacketDecoder(){}
     
    5352  {
    5453    int client = clientId;
    55     cout << "clientId: " << client << endl; //control cout, not important, just debugging info
     54    COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info
    5655    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    5756    COUT(5) << "packet id: " << id << std::endl;
     
    145144  void PacketDecoder::gstate( ENetPacket* packet )
    146145  {
    147     GameStateCompressed* currentState = new GameStateCompressed;
     146    GameStateCompressed* currentState = NULL;
     147    currentState = new GameStateCompressed;
     148    if(currentState == NULL){
     149      COUT(3) << "could not generate new GameStateCompressed" << std::endl;
     150      return;
     151    }
    148152    //since it's not alowed to use void* for pointer arithmetic
    149     unsigned char* data = (unsigned char*)packet->data;
     153    unsigned char* data = (unsigned char *)(packet->data);
    150154    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    151155    //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
    152     currentState->id = (int)*(data+sizeof(int));
     156    currentState->id = (int)*(packet->data+sizeof(int));
    153157//     std::cout << "id: " << currentState->id << std::endl;
    154158    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
    155159    //position of the data stream, data+2*sizeof( int )
    156 //     memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
     160    memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) );
    157161    //currentState->compsize = (int)*(data+2*sizeof(int));
    158162//     std::cout << "compsize: " << currentState->compsize << std::endl;
    159163    //size of uncompressed data
    160     memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
     164    memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
    161165    //currentState->normsize = (int)*(data+3*sizeof(int));
    162166//     std::cout << "normsize. " << currentState->normsize << std::endl;
    163167    //since the packetgenerator was changed, due to a new parameter, change this function too
    164     memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
     168    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool));
    165169    //currentState->diffed = (bool)*(data+4*sizeof(int));
    166170//     std::cout << "diffed: " << currentState->diffed << std::endl;
    167171    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
     172    if(currentState->compsize==0)
     173      COUT(2) << "compsize is 0" << std::endl;
    168174    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
    169175    if(currentState->data==NULL)
     
    172178    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
    173179    //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
    174     memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
     180    memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
    175181
    176182    //clean memory
     
    222228  void PacketDecoder::printAck( ack* data )
    223229  {
    224     COUT(5) << "data id: " << data->id << endl;
    225     COUT(5) << "data:    " << data->a << endl;
     230    COUT(5) << "data id: " << data->id << std::endl;
     231    COUT(5) << "data:    " << data->a << std::endl;
    226232  }
    227233
    228234  void PacketDecoder::printMouse( mouse* data )
    229235  {
    230     COUT(5) << "data id: " << data->id << endl;
    231     COUT(5) << "data:    " << data->x << " " << data->y << endl;
     236    COUT(5) << "data id: " << data->id << std::endl;
     237    COUT(5) << "data:    " << data->x << " " << data->y << std::endl;
    232238  }
    233239
    234240  void PacketDecoder::printKey( keyboard* data )
    235241  {
    236     COUT(5) << "data id: " << data->id << endl;
    237     COUT(5) << "data:    " << (char)data->press << endl;
     242    COUT(5) << "data id: " << data->id << std::endl;
     243    COUT(5) << "data:    " << (char)data->press << std::endl;
    238244  }
    239245
     
    241247  {
    242248    if(clientId!=CLIENTID_CLIENT)
    243       COUT(5) << "client: " << clientId << endl;
    244     COUT(5) << "data id: " << data->id << endl;
    245     COUT(5) << "data:    " << data->message << endl;
     249      COUT(5) << "client: " << clientId << std::endl;
     250    COUT(5) << "data id: " << data->id << std::endl;
     251    COUT(5) << "data:    " << data->message << std::endl;
    246252  }
    247253
    248254  void PacketDecoder::printGamestate( GameStateCompressed* data )
    249255  {
    250     COUT(5) << "id of GameStateCompressed:   " << data->id << endl;
    251     COUT(5) << "size of GameStateCompressed: " << data->compsize << endl;
     256    COUT(5) << "id of GameStateCompressed:   " << data->id << std::endl;
     257    COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl;
    252258  }
    253259
    254260  void PacketDecoder::printClassid( classid *cid)
    255261  {
    256     COUT(5) << "id of classid:    " << cid->id << endl;
    257     COUT(5) << "size of classid:  " << cid->length << endl;
    258     COUT(5) << "ID of classid:    " << cid->clid <<endl;
    259     COUT(5) << "data of classid:  " << cid->message <<endl;
     262    COUT(5) << "id of classid:    " << cid->id << std::endl;
     263    COUT(5) << "size of classid:  " << cid->length << std::endl;
     264    COUT(5) << "ID of classid:    " << cid->clid << std::endl;
     265    COUT(5) << "data of classid:  " << cid->message << std::endl;
    260266  }
    261267
  • code/branches/network/src/network/Server.cc

    r907 r912  
    112112    processQueue();
    113113    updateGamestate();
     114    sleep(1); // TODO remove
    114115    return;
    115116  }
     
    178179
    179180  void Server::processAck( ack *data, int clientID) {
     181    COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
    180182    clients->findClient(clientID)->setGamestateID(data->a);
    181183  }
Note: See TracChangeset for help on using the changeset viewer.