Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1425 for code


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
Files:
21 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();
  • code/branches/network/src/orxonox/objects/Ambient.h

    r1293 r1425  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848            void setAmbientLight(const ColourValue& colour);
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151
  • code/branches/network/src/orxonox/objects/Explosion.cc

    r1421 r1425  
    8080    };
    8181   
    82     bool Explosion::create(){
    83       return WorldEntity::create();
    84     }
     82    /*bool Explosion::create(){
     83      if(!WorldEntity::create())
     84        return false;
     85      classID=this->getIdentifier()->getNetworkID();
     86    }*/
    8587
    8688    void Explosion::destroyObject()
  • code/branches/network/src/orxonox/objects/Explosion.h

    r1421 r1425  
    4343            virtual ~Explosion();
    4444            void destroyObject();
    45             bool create();
     45            virtual bool create(){return WorldEntity::create();}
    4646
    4747        private:
  • code/branches/network/src/orxonox/objects/Model.h

    r1293 r1425  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            void setMesh(const std::string& meshname);
    47             bool create();
     47            virtual bool create();
    4848
    4949        protected:
  • code/branches/network/src/orxonox/objects/NPC.cc

    r1293 r1425  
    6767  }
    6868 
    69   bool NPC::create(){
    70     Model::create();
    71     return true;
    72   }
    7369
    7470  /**
  • code/branches/network/src/orxonox/objects/NPC.h

    r1293 r1425  
    5353      void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
    5454      void registerAllVariables();
    55       bool create();
     55      virtual bool create(){return Model::create();}
    5656
    5757    private:
  • code/branches/network/src/orxonox/objects/Projectile.cc

    r1418 r1425  
    9191                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9292                {
    93                     new Explosion(this);
     93                    Explosion *exp = new Explosion(this);
     94                    exp->create();
    9495                    delete this;
    9596                    return;
  • code/branches/network/src/orxonox/objects/Projectile.h

    r1056 r1425  
    4646            void destroyObject();
    4747            virtual void tick(float dt);
     48            virtual bool create(){return WorldEntity::create();}
    4849
    4950        private:
  • code/branches/network/src/orxonox/objects/Skybox.h

    r1293 r1425  
    4747            void setSkybox(const std::string& skyboxname);
    4848           
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151            void setSkyboxSrc(const std::string &src);
  • code/branches/network/src/orxonox/objects/SpaceShip.cc

    r1413 r1425  
    7070      Iterator<SpaceShip> it;
    7171      for(it = ObjectList<SpaceShip>::start(); it; ++it){
    72         if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) )
     72        if( (it)->myShip_ )
    7373          return *it;
    7474      }
     
    109109      mouseY_(0.0f),
    110110      emitterRate_(0.0f),
    111       server_(false)
     111      myShip_(false)
    112112    {
    113113        RegisterObject(SpaceShip);
     
    140140
    141141    bool SpaceShip::create(){
     142      if(!myShip_){
     143        if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID())
     144          myShip_=true;
     145      }
    142146      if(Model::create())
    143147        this->init();
     
    299303        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    300304        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    301         server_=true; // TODO: this is only a hack
     305        myShip_=true; // TODO: this is only a hack
    302306        SpaceShip::create();
    303307        getFocus();
     
    354358
    355359            Projectile *p = new Projectile(this);
     360            p->create();
    356361
    357362            p->setBacksync(true);
     
    439444            this->tt_->setRate(0);
    440445
    441         if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
     446        if( myShip_ )
    442447        {
    443448          COUT(4) << "steering our ship: " << objectID << std::endl;
  • code/branches/network/src/orxonox/objects/SpaceShip.h

    r1406 r1425  
    4949            SpaceShip();
    5050            ~SpaceShip();
    51             bool create();
     51            virtual bool create();
    5252            void registerAllVariables();
    5353            void init();
     
    8181            Vector3 getOrth();
    8282            Camera* getCamera();
     83           
     84            bool getMyShip(){return myShip_;}
    8385
    8486        private:
     
    135137
    136138            float emitterRate_;
    137             bool server_;
     139            bool myShip_;
    138140
    139141            static SpaceShip* instance_s;
  • code/branches/network/src/orxonox/objects/WorldEntity.cc

    r1360 r1425  
    153153      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
    154154      //register acceleration & momentum
    155       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
    156       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
    157       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
    158       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA);
     155//       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2);
     156//       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2);
     157//       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2);
     158//       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync
    159159    }
    160160
  • code/branches/network/src/orxonox/objects/WorldEntity.h

    r1418 r1425  
    5353            virtual void loadParams(TiXmlElement* xmlElem);
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    55             inline bool create(){ return Synchronisable::create(); }
     55            virtual inline bool create(){ return Synchronisable::create(); }
    5656
    5757            void attachWorldEntity(WorldEntity* entity);
Note: See TracChangeset for help on using the changeset viewer.