Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1248


Ignore:
Timestamp:
May 8, 2008, 11:53:58 AM (17 years ago)
Author:
scheusso
Message:

some enhanced memory handling

Location:
code/branches/network3/src/network
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/src/network/Client.cc

    r1246 r1248  
    8484    // set server address to localhost
    8585    isConnected=false;
    86     test_once=false;
     86    isSynched_=false;
    8787  }
    8888
     
    9494  Client::Client(std::string address, int port) : client_connection(port, address){
    9595    isConnected=false;
    96     test_once=false;
     96    isSynched_=false;
    9797  }
    9898
     
    104104  Client::Client(const char *address, int port) : client_connection(port, address){
    105105    isConnected=false;
    106     test_once=false;
     106    isSynched_=false;
    107107  }
    108108
     
    229229  */
    230230  void Client::tick(float time){
    231     if(client_connection.isConnected()){
     231    if(client_connection.isConnected() && isSynched_){
    232232      COUT(4) << "popping partial gamestate: " << std::endl;
    233233      GameStateCompressed *gs = gamestate.popPartialGameState();
     
    246246      packet = client_connection.getPacket();
    247247      COUT(5) << "tick packet size " << packet->dataLength << std::endl;
    248       if(!test_once){
    249         elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    250       }
     248      elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    251249    }
    252250    if(!client_connection.sendPackets())
     
    256254
    257255  void Client::processGamestate( GameStateCompressed *data, int clientID){
    258     if(!test_once){
    259       int id = data->id;
    260       COUT(5) << "received gamestate id: " << data->id << std::endl;
    261       if(gamestate.pushGameState(data)){
    262         client_connection.addPacket(pck_gen.acknowledgement(id));
     256    int id = data->id;
     257    COUT(5) << "received gamestate id: " << data->id << std::endl;
     258    if(gamestate.pushGameState(data)){
     259      if(!isSynched_)
     260        isSynched_=true;
     261      client_connection.addPacket(pck_gen.acknowledgement(id));
    263262        // we do this at the end of a tick
    264 //        if(!client_connection.sendPackets())
    265 //          COUT(2) << "Could not send acknowledgment" << std::endl;
    266       }
    267 //       test_once=true;
     263       if(!client_connection.sendPackets())
     264         COUT(2) << "Could not send acknowledgment" << std::endl;
    268265    }
    269266  }
     
    275272      id->setNetworkID(clid->clid);
    276273    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
     274    delete clid;
    277275    return;
    278276  }
     
    280278  void Client::processChat( chat *data){
    281279    COUT(0) << "Server: " << data->message << std::endl;
     280    delete[] data->message;
     281    delete data;
    282282  }
    283283 
     
    286286    clientID_ = w->clientID;
    287287    shipID_ = w->shipID;
     288    delete w;
    288289    return true;
    289290  }
  • code/branches/network3/src/network/Client.h

    r1245 r1248  
    101101    GameStateClient gamestate;
    102102    bool isConnected;
     103    bool isSynched_;
    103104
    104105    // implement data processing functions of PacketDecoder
     
    109110    int clientID_;     // this is the id the server gave to us
    110111    int shipID_;
    111     bool test_once;
    112112  };
    113113
  • code/branches/network3/src/network/GameStateManager.cc

    r1246 r1248  
    261261    }
    262262   
    263     delete[] state->data;
    264     delete state;
    265263    return true;
    266264  }
  • code/branches/network3/src/network/PacketDecoder.cc

    r1245 r1248  
    9090    return false;
    9191  }
     92 
     93  // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function
    9294
    9395  //following are the decode functions for the data of the packets
     
    101103    COUT(4) << "PacketDecoder: got ack id: " << a->a << std::endl;
    102104    processAck( a, clientId ); //debug info
    103 
    104105    //clean memory
    105106    enet_packet_destroy( packet );
     
    121122    //clean memory
    122123    enet_packet_destroy( packet );
    123 
    124124    printMouse( mouseMove ); //debug info
    125125  }
     
    132132    //clean memory
    133133    enet_packet_destroy( packet );
    134 
    135134    printKey( key ); //debug info
    136135
     
    232231  {
    233232    printChat(data, clientId);
     233    delete[] data->message;
     234    delete data;
    234235  }
    235236
    236237  void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID )
    237238  {
    238     COUT(5) << "PacketDecoder: processing Gamestate" << std::endl;
     239    COUT(3) << "PacketDecoder-process: processing Gamestate" << std::endl;
    239240    //printGamestate( state );
     241    delete[] state->data;
     242    delete state;
    240243  }
    241244
     
    243246  {
    244247    printClassid(cid);
     248    delete cid;
    245249    return;
    246250  }
     
    249253  {
    250254    printAck(data);
     255    delete data;
    251256    return;
    252257  }
    253258 
    254259  bool PacketDecoder::processWelcome( welcome *w ){
     260    delete w;
    255261    return true;
    256262  }
     
    258264  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
    259265    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
     266    delete con;
    260267    return true;
    261268  }
  • code/branches/network3/src/network/PacketGenerator.cc

    r1232 r1248  
    5858
    5959    ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable );
    60 
     60    delete ackreq;
    6161    return packet;
    6262  }
     
    7171    memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int));
    7272    memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength);
    73     return enet_packet_create(stream, dataLength+2*sizeof(int), reliable);
     73    ENetPacket *packet = enet_packet_create(stream, dataLength+2*sizeof(int), reliable);
     74    delete[] stream; // TODO: we could also tell enet not to copy the data, but to use the exisiting memory
     75    return packet;
    7476  }
    7577
     
    8486
    8587    ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );
    86 
     88    delete mousemove;
    8789    return packet;
    8890  }
     
    9799
    98100    ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );
    99 
     101    delete key;
    100102    return packet;
    101103  }
     
    109111    memcpy( &trans[1], (const void*)message, strlen( message ) + 1);
    110112    ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable );
    111 
     113    delete[] trans;
    112114    return packet;
    113115  }
     
    136138    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
    137139    ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    138     //delete data;
     140    delete[] data;
    139141    return packet;
    140142  }
     
    150152    memcpy( (void *)(data+3*sizeof(int)), classname.c_str(), classname.length()+1);
    151153    ENetPacket *packet = enet_packet_create( data , 3*sizeof(int)+classname.length()+1, reliable );
     154    delete[] data;
    152155    return packet;
    153156  }
     
    160163    wc->allowed = true;
    161164    ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable);
     165    delete wc;
    162166    return packet;
    163167  }
     
    166170    connectRequest *con = new connectRequest;
    167171    con->id=CONNECT;
    168     return enet_packet_create( con, sizeof(connectRequest), reliable);
     172    ENetPacket *packet = enet_packet_create( con, sizeof(connectRequest), reliable);
     173    delete con;
     174    return packet;
    169175  }
    170176
  • code/branches/network3/src/network/Server.cc

    r1246 r1248  
    232232    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    233233    connection->createClient(clientID);
     234    delete con;
    234235    return true;
    235236  }
     
    239240    if(!gamestates->pushGameState(data, clientID))
    240241        COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
     242    delete[] data->data;
     243    delete data;
    241244  }
    242245
  • code/branches/network3/src/network/Synchronisable.cc

    r1245 r1248  
    166166      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    167167      if( ((*i)->mode & state_) == 0 ){
    168         COUT(4) << "not getting data: " << std::endl;
     168        COUT(5) << "not getting data: " << std::endl;
    169169        continue;  // this variable should only be received
    170170      }
Note: See TracChangeset for help on using the changeset viewer.