Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1739


Ignore:
Timestamp:
Sep 8, 2008, 1:36:32 AM (16 years ago)
Author:
scheusso
Message:

further fixes (diff/undiff not working yet)

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

Legend:

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

    r1735 r1739  
    6161    isSynched_=false;
    6262    gameStateFailure_=false;
     63    isServer_ = false;
    6364  }
    6465
     
    7273    isSynched_=false;
    7374    gameStateFailure_=false;
     75    isServer_ = false;
    7476  }
    7577
     
    8385    isSynched_=false;
    8486    gameStateFailure_=false;
     87    isServer_ = false;
    8588  }
    8689
     
    151154    if(client_connection.isConnected() && isSynched_){
    152155      COUT(4) << "popping partial gamestate: " << std::endl;
    153       /*packet::Gamestate *gs = gamestate.getGamestate();
     156      packet::Gamestate *gs = gamestate.getGamestate();
    154157      if(gs){
    155158        COUT(4) << "client tick: sending gs " << gs << std::endl;
     
    157160          COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
    158161        // gs gets automatically deleted by enet callback
    159       }*/
     162      }
    160163    }
    161164    ENetEvent *event;
     
    168171    }
    169172    int gameStateID = gamestate.processGamestates();
    170     /*if(gameStateID==GAMESTATEID_INITIAL)
     173    if(gameStateID==GAMESTATEID_INITIAL)
    171174      if(gameStateFailure_){
    172         packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0);
    173         if(!ack.send())
     175        packet::Acknowledgement *ack = new packet::Acknowledgement(GAMESTATEID_INITIAL, 0);
     176        if(!ack->send())
    174177          COUT(3) << "could not (negatively) ack gamestate" << std::endl;
    175178        else
     
    183186        isSynched_=true;
    184187      gameStateFailure_=false;
    185       packet::Acknowledgement ack(gameStateID, 0);
    186       if(!ack.send())
     188      packet::Acknowledgement *ack = new packet::Acknowledgement(gameStateID, 0);
     189      if(!ack->send())
    187190        COUT(3) << "could not ack gamestate" << std::endl;
    188     }*/// otherwise we had no gamestate to load
     191    }// otherwise we had no gamestate to load
    189192    gamestate.cleanup();
    190193    return;
  • code/branches/network/src/network/GamestateClient.cc

    r1735 r1739  
    7373      return 0;
    7474    int id = GAMESTATEID_INITIAL;
    75     bool b = saveShipCache();
    76     if(processGamestate(tempGamestate_)){
    77       if(b)
    78         loadShipCache();
    79       id = tempGamestate_->getID();
    80     }
     75    //bool b = saveShipCache();
     76    packet::Gamestate *processed = processGamestate(tempGamestate_);
     77    assert(processed);
     78    //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
     79    tempGamestate_=0;
     80    gamestateMap_[processed->getID()]=processed;
     81    last_diff_ = processed->getBaseID();
     82    last_gamestate_ = processed->getID();
     83    //if(b)
     84      //loadShipCache();
     85    id = processed->getID();
    8186    cleanup();
    8287    return id;
     
    151156  }
    152157
    153   bool GamestateClient::processGamestate(packet::Gamestate *gs){
    154     assert(gs->decompressData());
    155     if(gs->isDiffed())
    156       assert(gs->undiff(gamestateMap_[gs->getBaseID()]));
    157     return gs->spreadData();
     158  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
     159    if(gs->isCompressed())
     160      assert(gs->decompressData());
     161    if(gs->isDiffed()){
     162      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
     163      assert(base);
     164      packet::Gamestate *undiffed = gs->undiff(base);
     165      delete gs;
     166      gs=undiffed;
     167      COUT(3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
     168    }
     169    if(gs->spreadData())
     170      return gs;
     171    else
     172      return NULL;
    158173  }
    159174
  • code/branches/network/src/network/GamestateClient.h

    r1735 r1739  
    6666    void cleanup();
    6767  private:
    68     bool processGamestate(packet::Gamestate *gs);
     68    packet::Gamestate *processGamestate(packet::Gamestate *gs);
    6969    void removeObject(orxonox::Iterator<Synchronisable> &it);
    7070    void printGamestateMap();
  • code/branches/network/src/network/GamestateManager.cc

    r1735 r1739  
    194194    if(client->getGamestateID()>=0)
    195195      gamestateUsed[client->getGamestateID()]--;
    196     ClientInformation::removeClient(client->getID());
    197196  }
    198197 
    199198  bool GamestateManager::processGamestate(packet::Gamestate *gs){
    200     assert(gs->decompressData());
     199    if(gs->isCompressed())
     200       assert(gs->decompressData());
    201201    assert(!gs->isDiffed());
    202202    return gs->spreadData();
  • code/branches/network/src/network/Host.cc

    r1735 r1739  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
    129#include <assert.h>
    230
  • code/branches/network/src/network/Host.h

    r1735 r1739  
    5454    ~Host();
    5555    static Host *instance_;
     56    bool isServer_;     
    5657   
    5758  public:
     
    6465    static void setClientID(unsigned int id){ instance_->clientID_ = id; }
    6566    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
     67    static bool isServer(){ return instance_->isServer_; }             
    6668  private:
    6769    unsigned int clientID_;
  • code/branches/network/src/network/Server.cc

    r1735 r1739  
    5353#include "packet/Packet.h"
    5454#include "packet/Welcome.h"
     55#include <util/Convert.h>
    5556
    5657namespace network
     
    6768    connection = new ConnectionManager();
    6869    gamestates_ = new GamestateManager();
     70    isServer_ = true;
    6971  }
    7072 
     
    7375    connection = new ConnectionManager(port);
    7476    gamestates_ = new GamestateManager();
     77    isServer_ = true;
    7578  }
    7679
     
    8487    connection = new ConnectionManager(port, bindAddress);
    8588    gamestates_ = new GamestateManager();
     89    isServer_ = true;
    8690  }
    8791
     
    9599    connection = new ConnectionManager(port, bindAddress);
    96100    gamestates_ = new GamestateManager();
     101    isServer_ = true;
    97102  }
    98103
     
    348353    no->setTransDamp(75);
    349354    no->setRotDamp(1.0);
    350     no->setCamera("cam_"+client->getID());
     355    no->setCamera(std::string("cam_") + convertToString(client->getID()));
    351356    no->create();
    352357    no->setBacksync(true);
     
    364369    if(!client)
    365370      return false;
     371    gamestates_->removeClient(client);
    366372    while(it){
    367373      if(it->objectID!=client->getShipID()){
  • code/branches/network/src/network/packet/Acknowledgement.cc

    r1735 r1739  
    4545  data_=new unsigned char[ getSize() ];
    4646  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;
    47   *(unsigned int *)&data_[ _ACKID ] = id;
     47  *(unsigned int *)(data_ + _ACKID ) = id;
    4848  clientID_=clientID;
    4949}
  • code/branches/network/src/network/packet/Gamestate.cc

    r1735 r1739  
    120120bool Gamestate::spreadData(int mode)
    121121{
    122   assert(data_ && !HEADER->compressed && !HEADER->diffed);
     122  assert(data_);
     123  assert(!HEADER->compressed);
     124  assert(!HEADER->diffed);
    123125  unsigned int size, objectID, classID;
    124126  unsigned char *mem=data_+sizeof(GamestateHeader);
     
    141143        //fabricate the new synchronisable
    142144        if(!Synchronisable::fabricate(mem, mode))
    143           /*return false*/;
     145          return false;
    144146        it=orxonox::ObjectList<Synchronisable>::end();
    145147      }
     
    276278  *GAMESTATE_HEADER(ndata) = *HEADER;
    277279  GAMESTATE_HEADER(ndata)->diffed = true;
     280  GAMESTATE_HEADER(ndata)->base_id = base->getID();
    278281  Gamestate *g = new Gamestate(ndata, 0);
     282  g->flags_=flags_;
     283  g->packetDirection_ = packetDirection_;
     284  g->clientID_ = clientID_;
    279285  return g;
    280286}
     
    310316  GAMESTATE_HEADER(ndata)->diffed = false;
    311317  Gamestate *g = new Gamestate(ndata, 0);
     318  g->flags_=flags_;
     319  g->packetDirection_ = packetDirection_;
     320  g->clientID_ = clientID_;
     321  assert(!g->isDiffed());
     322  assert(!g->isCompressed());
    312323  return g;
    313324}
     
    341352  }
    342353 
     354  bool Gamestate::isCompressed(){
     355    return HEADER->compressed;
     356  }
     357 
    343358  int Gamestate::getBaseID(){
    344359    return HEADER->base_id;
  • code/branches/network/src/network/packet/Gamestate.h

    r1735 r1739  
    6464    int getID();
    6565    bool isDiffed();
     66    bool isCompressed();
    6667    int getBaseID();
    6768    Gamestate *diff(Gamestate *base);
  • code/branches/network/src/network/packet/Packet.cc

    r1735 r1739  
    113113    packetMap_[enetPacket_] = this;
    114114  }
    115   /*switch( *(ENUM::Type *)(data_ + _PACKETID) )
     115#ifndef NDEBUG
     116  switch( *(ENUM::Type *)(data_ + _PACKETID) )
    116117  {
    117118    case ENUM::Acknowledgement:
     
    120121    case ENUM::Gamestate:
    121122    case ENUM::Welcome:
    122       COUT(3) << "welcome" << std::endl;
    123       p = new Welcome( data, clientID );
     123      break;
    124124    default:
    125125      assert(0); //TODO: repair this
    126126      break;
    127   }*/
     127  }
     128#endif
    128129  network::Host::addPacket( enetPacket_, clientID_);
    129130  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
  • code/branches/network/src/network/packet/Packet.h

    r1735 r1739  
    7878    enet_uint32 flags_;
    7979    int clientID_;
     80    ENUM::Direction packetDirection_;
    8081    unsigned char *data_;
    8182  private:
    8283    static std::map<ENetPacket *, Packet *> packetMap_;
    8384    ENetPacket *enetPacket_;
    84     ENUM::Direction packetDirection_;
    8585};
    8686
Note: See TracChangeset for help on using the changeset viewer.