Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 12:50:05 PM (16 years ago)
Author:
scheusso
Message:

merged network branch to presentation branch

Location:
code/branches/presentation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/network/packet/DeleteObjects.cc

    r2171 r2371  
    3030#include "DeleteObjects.h"
    3131#include <enet/enet.h>
    32 #include "network/Synchronisable.h"
     32#include "network/synchronisable/Synchronisable.h"
    3333#include "core/CoreIncludes.h"
    3434#include <assert.h>
  • code/branches/presentation/src/network/packet/Gamestate.cc

    r2171 r2371  
    2828
    2929#include "Gamestate.h"
    30 #include "network/ClientInformation.h"
    31 #include "network/GamestateHandler.h"
     30#include "../GamestateHandler.h"
     31#include "../synchronisable/Synchronisable.h"
     32#include "../TrafficControl.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/Iterator.h"
     
    4849
    4950#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
     51 
     52TrafficControl Gamestate::trafficControl_;
    5053
    5154Gamestate::Gamestate()
     
    7376bool Gamestate::collectData(int id, uint8_t mode)
    7477{
    75   unsigned int tempsize=0, currentsize=0;
     78  uint32_t tempsize=0, currentsize=0;
    7679  assert(data_==0);
    77   unsigned int size = calcGamestateSize(id, mode);
     80  uint32_t size = calcGamestateSize(id, mode);
    7881
    7982  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    109112
    110113    //if(it->doSelection(id))
    111     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     114    if(tempsize!=0)
     115      dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     116//     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
    112117    if(!it->getData(mem, id, mode))
    113118      return false; // mem pointer gets automatically increased because of call by reference
     
    148153    if(!s)
    149154    {
    150       Synchronisable::fabricate(mem, mode);
     155      s = Synchronisable::fabricate(mem, mode);
     156      if(s==0)
     157        assert(0);
     158//         COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl;
     159//       else
     160//         COUT(0) << "fabricated: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: "  << objectheader->creatorID << endl;
    151161    }
    152162    else
     
    166176}
    167177
    168 unsigned int Gamestate::getSize() const
     178uint32_t Gamestate::getSize() const
    169179{
    170180  assert(data_);
     
    251261  assert(HEADER->compressed);
    252262  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;
    253   unsigned int datasize = HEADER->datasize;
    254   unsigned int compsize = HEADER->compsize;
    255   unsigned int bufsize;
     263  uint32_t datasize = HEADER->datasize;
     264  uint32_t compsize = HEADER->compsize;
     265  uint32_t bufsize;
    256266//  assert(compsize<=datasize);
    257267  bufsize = datasize;
     
    302312  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    303313  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    304   unsigned int of=0; // pointers offset
    305   unsigned int dest_length=0;
     314  uint32_t of=0; // pointers offset
     315  uint32_t dest_length=0;
    306316  dest_length=HEADER->datasize;
    307317  if(dest_length==0)
     
    332342}
    333343
    334 Gamestate* Gamestate::doSelection(unsigned int clientID){
     344Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    335345  assert(data_);
    336   std::map<unsigned int, Synchronisable *>::iterator it;
     346  std::list<obj>::iterator it;
    337347
    338348  // allocate memory for new data
     
    341351  Gamestate *gs = new Gamestate(gdata);
    342352  uint8_t *newdata = gdata + sizeof(GamestateHeader);
    343   uint8_t *origdata = GAMESTATE_START(data_);
     353//   uint8_t *origdata = GAMESTATE_START(data_);
    344354
    345355  //copy the GamestateHeader
     
    347357
    348358  synchronisableHeader *oldobjectheader, *newobjectheader;
    349   unsigned int objectOffset;
    350 
     359  uint32_t objectOffset;
     360  unsigned int objectsize, destsize=0;
     361  Synchronisable *object;
     362
     363  //call TrafficControl
     364  trafficControl_.processObjectList( clientID, HEADER->id, &dataMap_ );
     365 
    351366  //copy in the zeros
    352367  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    353     oldobjectheader = (synchronisableHeader*)origdata;
     368    oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
    354369    newobjectheader = (synchronisableHeader*)newdata;
    355     unsigned int objectsize = oldobjectheader->size;
    356     assert(it->second->objectID==oldobjectheader->objectID);
     370    object = Synchronisable::getSynchronisable( (*it).objID );
     371    assert(object->objectID == oldobjectheader->objectID);
     372    objectsize = oldobjectheader->size;
    357373    *newobjectheader = *oldobjectheader;
    358374    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    359     if(it->second->doSelection(HEADER->id)){
     375    if ( /*object->doSelection(HEADER->id)*/true ){
    360376      assert(newobjectheader->dataAvailable==true);
    361       memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
     377      memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset);
    362378    }else{
    363379      newobjectheader->dataAvailable=false;
     
    366382    }
    367383    newdata += objectsize;
    368     origdata += objectsize;
    369   }
     384    destsize += objectsize;
     385//     origdata += objectsize;
     386  }
     387  ((GamestateHeader*)gdata)->datasize = destsize;
     388  assert(destsize!=0);
    370389  return gs;
    371390}
     
    382401
    383402  //preparations
    384   std::map<unsigned int, Synchronisable *>::iterator it;
     403  std::list<obj>::iterator it;
    385404  uint8_t *origdata, *basedata, *destdata, *ndata;
    386   unsigned int objectOffset, streamOffset=0;    //data offset
    387   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     405  uint32_t objectOffset, streamOffset=0;    //data offset
     406  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    388407  synchronisableHeader *origheader;
    389408  synchronisableHeader *destheader;
     409  Synchronisable *object;
    390410
    391411  origdata = GAMESTATE_START(this->data_);
     
    397417  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    398418    assert(streamOffset<HEADER->datasize);
    399     bool sendData = it->second->doSelection(HEADER->id);
    400419    origheader = (synchronisableHeader *)(origdata+streamOffset);
    401420    destheader = (synchronisableHeader *)(destdata+streamOffset);
     421    object = Synchronisable::getSynchronisable(origheader->objectID);
     422    bool sendData = object->doSelection(HEADER->id);
    402423
    403424    //copy and partially diff the object header
    404     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
     425    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
    405426    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
    406427    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
     
    450471
    451472  //preparations
    452   std::map<unsigned int, Synchronisable *>::iterator it;
     473  std::list<obj>::iterator it;
    453474  uint8_t *origdata, *basedata, *destdata, *ndata;
    454   unsigned int objectOffset, streamOffset=0;    //data offset
    455   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     475  uint32_t objectOffset, streamOffset=0;    //data offset
     476  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    456477  synchronisableHeader *origheader;
    457478  synchronisableHeader *destheader;
     479  Synchronisable *object;
    458480
    459481  origdata = GAMESTATE_START(this->data_);
     
    467489    origheader = (synchronisableHeader *)(origdata+streamOffset);
    468490    destheader = (synchronisableHeader *)(destdata+streamOffset);
     491    object = Synchronisable::getSynchronisable( origheader->objectID );
    469492    bool sendData;
    470493
    471494    //copy and partially diff the object header
    472     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
    473     *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)
    474     *(bool*)(destdata+sizeof(unsigned int)) = *(bool*)(origdata+sizeof(unsigned int));
    475     sendData = *(bool*)(origdata+sizeof(unsigned int));
     495    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
     496    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
     497    *(bool*)(destdata+sizeof(uint32_t)) = *(bool*)(origdata+sizeof(uint32_t));
     498    sendData = *(bool*)(origdata+sizeof(uint32_t));
    476499    if(sendData){
    477       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)
    478       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)
     500      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it)
     501      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it)
    479502    }else{
    480       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
    481       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;
     503      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
     504      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;
    482505    }
    483506    objectOffset=sizeof(synchronisableHeader);
     
    517540  uint8_t *basep = GAMESTATE_START(base->data_);
    518541  uint8_t *gs = GAMESTATE_START(this->data_);
    519   unsigned int of=0; // pointers offset
    520   unsigned int dest_length=0;
     542  uint32_t of=0; // pointers offset
     543  uint32_t dest_length=0;
    521544  dest_length=HEADER->datasize;
    522545  if(dest_length==0)
     
    548571
    549572
    550 unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
    551 {
    552   unsigned int size=0;
     573uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
     574{
     575  uint32_t size=0;
    553576    // get the start of the Synchronisable list
    554577  ObjectList<Synchronisable>::iterator it;
  • code/branches/presentation/src/network/packet/Gamestate.h

    r2171 r2371  
    3131#define NETWORK_PACKETGAMESTATE_H
    3232
    33 #include "../NetworkPrereqs.h"
     33#include "network/NetworkPrereqs.h"
    3434
    3535#include "Packet.h"
    36 #include "network/Synchronisable.h"
     36#include "network/TrafficControl.h"
     37#include "core/CoreIncludes.h"
    3738#include <map>
     39#include <list>
    3840#ifndef NDEBUG
    3941#include "util/CRC32.h"
     
    7981    Gamestate *undiff(Gamestate *base);
    8082    Gamestate* intelligentUnDiff(Gamestate *base);
    81     Gamestate* doSelection(unsigned int clientID);
     83    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
    8284    bool compressData();
    8385    bool decompressData();
     
    8587    // Packet functions
    8688  private:
    87     virtual unsigned int getSize() const;
     89    virtual uint32_t getSize() const;
    8890    virtual bool process();
    8991
    9092    bool operator ==(packet::Gamestate gs);
    9193  private:
    92     unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
     94    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    9395    void removeObject(ObjectListIterator<Synchronisable> &it);
    94     std::map<unsigned int, Synchronisable*> dataMap_;
     96    std::list<obj> dataMap_;
     97    static TrafficControl trafficControl_;
    9598};
    9699
  • code/branches/presentation/src/network/packet/Welcome.cc

    r2171 r2371  
    3232#include "Welcome.h"
    3333#include "network/Host.h"
    34 #include "network/Synchronisable.h"
     34#include "network/synchronisable/Synchronisable.h"
    3535#include "core/CoreIncludes.h"
    3636#include <assert.h>
     
    4343#define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
    4444#define _SHIPID               _CLIENTID + sizeof(uint32_t)
     45#define _ENDIANTEST           _SHIPID + sizeof(uint32_t)
    4546 
    4647  Welcome::Welcome( unsigned int clientID, unsigned int shipID )
     
    5253  assert(data_);
    5354  *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;
    54   *(uint32_t *)&data_[ _CLIENTID ] = clientID;
    55   *(uint32_t *)&data_[ _SHIPID ] = shipID;
     55  *(uint32_t *)(data_ + _CLIENTID ) = clientID;
     56  *(uint32_t *)(data_ + _SHIPID ) = shipID;
     57  *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321;
    5658}
    5759
     
    7072
    7173unsigned int Welcome::getSize() const{
    72   return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t);
     74  return sizeof(packet::ENUM::Type) + 3*sizeof(uint32_t);
    7375}
    7476
     
    7779  clientID = *(uint32_t *)&data_[ _CLIENTID ];
    7880  shipID = *(uint32_t *)&data_[ _SHIPID ];
     81  assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
    7982  Host::setClientID(clientID);
    8083  Host::setShipID(shipID);
Note: See TracChangeset for help on using the changeset viewer.