Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2008, 11:08:19 PM (16 years ago)
Author:
scheusso
Message:

implemented some sort of buffer for the spaceship movements (makes the movements on the client smoother)

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

Legend:

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

    r1409 r1425  
    246246      elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    247247    }
     248    int gameStateID = gamestate.processGameState();
     249    if(gameStateID!=GAMESTATEID_INITIAL){
     250      // ack gamestate and set synched
     251      if(!isSynched_)
     252        isSynched_=true;
     253      if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID)))
     254        COUT(3) << "could not ack gamestate" << std::endl;
     255    }
     256    gamestate.cleanup();
    248257    if(!client_connection.sendPackets())
    249258      COUT(3) << "Problem sending packets to server" << std::endl;
     
    252261
    253262  void Client::processGamestate( GameStateCompressed *data, int clientID){
    254     int id = data->id;
    255263    COUT(5) << "received gamestate id: " << data->id << std::endl;
    256     if(gamestate.pushGameState(data)){
    257       if(!isSynched_)
    258         isSynched_=true;
    259       if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
    260         return;
    261         // we do this at the end of a tick
    262       if(!client_connection.sendPackets())
    263         COUT(2) << "Could not send acknowledgment" << std::endl;
    264     }
     264    gamestate.addGameState(data);
    265265  }
    266266
  • code/branches/network/src/network/GameStateClient.cc

    r1360 r1425  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    25  *      ...
     25 *      Dumeni Manatschal
    2626 *
    2727 */
     
    3535#include "Synchronisable.h"
    3636
    37 #define GAMESTATEID_INITIAL -1
    3837
    3938namespace network
     
    4847    last_diff_=0;
    4948    last_gamestate_=GAMESTATEID_INITIAL-1;
     49    tempGameState_=NULL;
     50    myShip_=NULL;
    5051  }
    5152
     
    102103    delete gs;
    103104    return cgs;
     105  }
     106 
     107  void GameStateClient::addGameState(GameStateCompressed *gs){
     108    if(tempGameState_!=NULL){
     109      //delete the obsolete gamestate
     110      if(tempGameState_->id>gs->id)
     111        return;
     112      delete[] tempGameState_->data;
     113      delete tempGameState_;
     114    }
     115    tempGameState_=gs;
     116  }
     117  int GameStateClient::processGameState(){
     118    if(tempGameState_==NULL)
     119      return GAMESTATEID_INITIAL;
     120    int id=tempGameState_->id;
     121    bool b = saveShipCache();
     122    if(pushGameState(tempGameState_)){
     123      if(b)
     124        loadShipCache();
     125      return id;
     126    }
     127    else
     128      return GAMESTATEID_INITIAL;
    104129  }
    105130 
     
    388413      gameStateMap.erase(temp);
    389414    }
     415    tempGameState_=NULL;
    390416  }
    391417
     
    400426  }
    401427 
     428  bool GameStateClient::saveShipCache(){
     429    if(myShip_==NULL)
     430      myShip_ = orxonox::SpaceShip::getLocalShip();
     431    if(myShip_){
     432      //      unsigned char *data = new unsigned char[myShip_->getSize()];
     433      int size=myShip_->getSize(0x3);
     434      if(size==0)
     435        return false;
     436      unsigned char *data = new unsigned char [size];
     437      shipCache_ = myShip_->getData(data, 0x1);
     438      return true;
     439    }else
     440      return false;
     441  }
     442 
     443  bool GameStateClient::loadShipCache(){
     444    if(myShip_){
     445      myShip_->updateData(shipCache_, 0x2);
     446      if(shipCache_.data){
     447        delete[] shipCache_.data;
     448      }
     449      return true;
     450    }else
     451      return false;
     452  }
    402453 
    403454    //##### ADDED FOR TESTING PURPOSE #####
  • code/branches/network/src/network/GameStateClient.h

    r1360 r1425  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    25  *      ...
     25 *      Dumeni Manatschal
    2626 *
    2727 */
     
    3333//
    3434//
    35 // Author:  <>, (C) 2007
     35// Author:  Oliver Scheuss, (C) 2007
    3636//
    3737// Copyright: See COPYING file that comes with this distribution
     
    4646#include "core/CorePrereqs.h"
    4747#include "PacketTypes.h"
     48#include "objects/SpaceShip.h"
    4849
     50
     51#define GAMESTATEID_INITIAL -1
    4952
    5053namespace network
     
    5659    ~GameStateClient();
    5760   
     61    void addGameState(GameStateCompressed *gs);
     62    int processGameState();
     63    GameStateCompressed *popPartialGameState();
     64    void cleanup();
     65  private:
    5866    bool pushGameState(GameStateCompressed *compstate);
    59     GameStateCompressed *popPartialGameState();
    60   private:
    6167    bool loadSnapshot(GameState *state);
    6268    GameState *getPartialSnapshot();
    63     void cleanup();
    6469    GameState *undiff(GameState *old, GameState *diff);
    6570    GameStateCompressed *compress_(GameState *a);
     
    6974    void removeObject(orxonox::Iterator<Synchronisable> &it);
    7075    void printGameStateMap();
     76    bool saveShipCache();
     77    bool loadShipCache();
    7178
    7279    int           last_diff_;
    7380    int           last_gamestate_;
    7481    std::map<int, GameState *> gameStateMap;
     82    GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue
     83    orxonox::SpaceShip *myShip_;
     84    syncData shipCache_;
    7585   
    7686   
  • code/branches/network/src/network/GameStateManager.cc

    r1360 r1425  
    6868    printGameStates();
    6969    return;
     70  }
     71 
     72  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
     73    if(!gs)
     74      return;
     75    std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID);
     76    if(it!=gameStateQueue.end()){
     77      // delete obsolete gamestate
     78      delete[] it->second->data;
     79      delete it->second;
     80    }
     81    gameStateQueue[clientID] = gs;
     82    return;
     83  }
     84 
     85  void GameStateManager::processGameStates(){
     86    std::map<int, GameStateCompressed*>::iterator it;
     87    // now push only the most recent gamestates we received (ignore obsolete ones)
     88    for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){
     89      pushGameState(it->second, it->first);
     90    }
     91    // now clear the queue
     92    gameStateQueue.clear();
    7093  }
    7194 
  • code/branches/network/src/network/GameStateManager.h

    r1293 r1425  
    7272    ~GameStateManager();
    7373   
     74    void addGameState(GameStateCompressed *gs, int clientID);
     75    void processGameStates();
     76   
    7477    void update();
    7578    GameStateCompressed *popGameState(int clientID);
    76     bool pushGameState(GameStateCompressed *gs, int clientID);
    7779    void ackGameState(int clientID, int gamestateID);
    7880    void removeClient(ClientInformation *client);
    79   private:
     81    private:
     82    bool pushGameState(GameStateCompressed *gs, int clientID);
    8083    void cleanup(); // "garbage handler"
    8184    GameState *getSnapshot();
     
    9194    std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
    9295    std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate
     96    std::map<int, GameStateCompressed*> gameStateQueue;
    9397    GameState *reference;
    9498    ClientInformation *head_;
  • code/branches/network/src/network/Server.cc

    r1409 r1425  
    157157  void Server::tick(float time) {
    158158    processQueue();
     159    gamestates->processGameStates();
    159160    updateGamestate();
    160161//     usleep(500000); // TODO remove
     
    245246          disconnectClient(temp);
    246247      //std::cout << "added gamestate" << std::endl;
    247       }
     248      }else
     249        temp->resetFailures();
    248250      added=true;
    249251      temp=temp->next();
     
    276278  void Server::processGamestate( GameStateCompressed *data, int clientID){
    277279    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
    278     if(!gamestates->pushGameState(data, clientID))
    279         COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
     280    gamestates->addGameState(data, clientID);
     281        /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
    280282    else
    281283      if(clients->findClient(clientID))
    282         clients->findClient(clientID)->resetFailures();
     284        clients->findClient(clientID)->resetFailures();*/
    283285  }
    284286 
  • code/branches/network/src/network/Synchronisable.cc

    r1418 r1425  
    7070  bool Synchronisable::create(){
    7171    this->classID = this->getIdentifier()->getNetworkID();
     72    COUT(4) << "setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
    7273    return true;
    7374  }
     
    156157  * @return data containing all variables and their sizes
    157158  */
    158   syncData Synchronisable::getData(unsigned char *mem){
     159  syncData Synchronisable::getData(unsigned char *mem, int mode){
    159160    //std::cout << "inside getData" << std::endl;
     161    if(mode==0x0)
     162      mode=state_;
    160163    if(classID==0)
    161164      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     
    172175    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    173176      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    174       if( ((*i)->mode & state_) == 0 ){
     177      if( ((*i)->mode & mode) == 0 ){
    175178        COUT(5) << "not getting data: " << std::endl;
    176179        continue;  // this variable should only be received
     
    199202  * @return true/false
    200203  */
    201   bool Synchronisable::updateData(syncData vars){
     204  bool Synchronisable::updateData(syncData vars, int mode){
     205    if(mode==0x0)
     206      mode=state_;
    202207    unsigned char *data=vars.data;
    203208    std::list<synchronisableVariable *>::iterator i;
     
    208213    COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
    209214    for(i=syncList->begin(); i!=syncList->end(); i++){
    210       if( ((*i)->mode ^ state_) == 0 ){
     215      if( ((*i)->mode ^ mode) == 0 ){
    211216        COUT(5) << "synchronisable: not updating variable " << std::endl;
    212         continue;  // this variable should only be updated
     217        continue;  // this variable should only be set
    213218      }
    214219      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     
    235240  * @return amount of bytes
    236241  */
    237   int Synchronisable::getSize(){
     242  int Synchronisable::getSize(int mode){
    238243    int tsize=0;
     244    if(mode==0x0)
     245      mode=state_;
    239246    std::list<synchronisableVariable *>::iterator i;
    240247    for(i=syncList->begin(); i!=syncList->end(); i++){
    241       if( ((*i)->mode & state_) == 0 )
     248      if( ((*i)->mode & mode) == 0 )
    242249        continue;  // this variable should only be received, so dont add its size to the send-size
    243250      switch((*i)->type){
  • code/branches/network/src/network/Synchronisable.h

    r1418 r1425  
    8383    void registerVar(void *var, int size, variableType t, int mode=1);
    8484    //  syncData getData();
    85     syncData getData(unsigned char *mem);
    86     int getSize();
    87     bool updateData(syncData vars);
     85    syncData getData(unsigned char *mem, int mode=0x0);
     86    int getSize(int mode=0x0);
     87    bool updateData(syncData vars, int mode=0x0);
    8888    void setBacksync(bool sync);
    8989    bool getBacksync();
Note: See TracChangeset for help on using the changeset viewer.