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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 #####
Note: See TracChangeset for help on using the changeset viewer.