Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 5:03:34 PM (16 years ago)
Author:
bknecht
Message:

merged back that script-branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/PacketDecoder.cc

    r790 r1021  
    3838#include "PacketTypes.h"
    3939#include "PacketManager.h"
     40#include "orxonox/core/Debug.h"
    4041
    4142namespace network
    4243{
    43   using namespace std;
    4444
    4545  PacketDecoder::PacketDecoder(){}
     
    5252  {
    5353    int client = clientId;
    54     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
    5555    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    56     std::cout << "packet id: " << id << std::endl;
    57     std::cout << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
     56    COUT(5) << "packet id: " << id << std::endl;
     57//     COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
    5858    switch( id ) {
    5959  case ACK:
     
    9393
    9494
    95     std::cout << "got ack id: " << a->id << std::endl;
     95    COUT(5) << "got ack id: " << a->id << std::endl;
    9696    processAck( a, clientId ); //debug info
    9797
     
    144144  void PacketDecoder::gstate( ENetPacket* packet )
    145145  {
    146     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    }
    147152    //since it's not alowed to use void* for pointer arithmetic
    148     unsigned char* data = (unsigned char*)packet->data;
     153    unsigned char* data = (unsigned char *)(packet->data);
    149154    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    150155    //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
    151     currentState->id = (int)*(data+sizeof(int));
    152     std::cout << "id: " << currentState->id << std::endl;
     156    //currentState->id = *((int *)packet->data+sizeof(int));
     157    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
     158    COUT(5) << "decoder: received gs id: " << currentState->id << std::endl;
     159//     std::cout << "id: " << currentState->id << std::endl;
    153160    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
    154161    //position of the data stream, data+2*sizeof( int )
    155     memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
     162    memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) );
    156163    //currentState->compsize = (int)*(data+2*sizeof(int));
    157     std::cout << "compsize: " << currentState->compsize << std::endl;
     164//     std::cout << "compsize: " << currentState->compsize << std::endl;
    158165    //size of uncompressed data
    159     memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
     166    memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
    160167    //currentState->normsize = (int)*(data+3*sizeof(int));
    161     std::cout << "normsize. " << currentState->normsize << std::endl;
     168//     std::cout << "normsize. " << currentState->normsize << std::endl;
    162169    //since the packetgenerator was changed, due to a new parameter, change this function too
    163     memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
     170    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool));
    164171    //currentState->diffed = (bool)*(data+4*sizeof(int));
    165     std::cout << "diffed: " << currentState->diffed << std::endl;
     172//     std::cout << "diffed: " << currentState->diffed << std::endl;
    166173    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
     174    if(currentState->compsize==0)
     175      COUT(2) << "compsize is 0" << std::endl;
    167176    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
    168177    if(currentState->data==NULL)
    169       std::cout << "memory leak" << std::endl;
     178      COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl;
    170179    //copy the GameStateCompressed data
    171180    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
    172181    //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
    173     memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
    174 
    175     //clean memory
    176     enet_packet_destroy( packet );
    177     //run processGameStateCompressed
    178     //TODO: not yet implemented!
     182    memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
     183
     184    //clean memory
     185    enet_packet_destroy( packet );
    179186    processGamestate(currentState);
    180187  }
     
    189196    void *data  = (void *)cid->message;
    190197    memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length);
    191     std::cout << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
     198    COUT(4) << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
    192199    enet_packet_destroy( packet );
    193200    processClassid(cid);
     
    223230  void PacketDecoder::printAck( ack* data )
    224231  {
    225     cout << "data id: " << data->id << endl;
    226     cout << "data:    " << data->a << endl;
     232    COUT(5) << "data id: " << data->id << std::endl;
     233    COUT(5) << "data:    " << data->a << std::endl;
    227234  }
    228235
    229236  void PacketDecoder::printMouse( mouse* data )
    230237  {
    231     cout << "data id: " << data->id << endl;
    232     cout << "data:    " << data->x << " " << data->y << endl;
     238    COUT(5) << "data id: " << data->id << std::endl;
     239    COUT(5) << "data:    " << data->x << " " << data->y << std::endl;
    233240  }
    234241
    235242  void PacketDecoder::printKey( keyboard* data )
    236243  {
    237     cout << "data id: " << data->id << endl;
    238     cout << "data:    " << (char)data->press << endl;
     244    COUT(5) << "data id: " << data->id << std::endl;
     245    COUT(5) << "data:    " << (char)data->press << std::endl;
    239246  }
    240247
     
    242249  {
    243250    if(clientId!=CLIENTID_CLIENT)
    244       cout << "client: " << clientId << endl;
    245     cout << "data id: " << data->id << endl;
    246     cout << "data:    " << data->message << endl;
     251      COUT(5) << "client: " << clientId << std::endl;
     252    COUT(5) << "data id: " << data->id << std::endl;
     253    COUT(5) << "data:    " << data->message << std::endl;
    247254  }
    248255
    249256  void PacketDecoder::printGamestate( GameStateCompressed* data )
    250257  {
    251     cout << "id of GameStateCompressed:   " << data->id << endl;
    252     cout << "size of GameStateCompressed: " << data->compsize << endl;
     258    COUT(5) << "id of GameStateCompressed:   " << data->id << std::endl;
     259    COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl;
    253260  }
    254261
    255262  void PacketDecoder::printClassid( classid *cid)
    256263  {
    257     cout << "id of classid:    " << cid->id << endl;
    258     cout << "size of classid:  " << cid->length << endl;
    259     cout << "ID of classid:    " << cid->clid <<endl;
    260     cout << "data of classid:  " << cid->message <<endl;
     264    COUT(5) << "id of classid:    " << cid->id << std::endl;
     265    COUT(5) << "size of classid:  " << cid->length << std::endl;
     266    COUT(5) << "ID of classid:    " << cid->clid << std::endl;
     267    COUT(5) << "data of classid:  " << cid->message << std::endl;
    261268  }
    262269
Note: See TracChangeset for help on using the changeset viewer.