Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 4, 2008, 5:12:31 PM (16 years ago)
Author:
scheusso
Message:

bidirectional synchronisation works now:
register variables with mode direction::serverMaster or direction::clientMaster
clientMaster: both sides may change the variable but the client is master
serverMaster: both sides may change the variable but the server is master

Location:
code/branches/objecthierarchy/src/network/packet
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/network/packet/Gamestate.cc

    r2112 r2132  
    7171}
    7272
    73 bool Gamestate::collectData(int id, int mode)
    74 {
    75   int tempsize=0, currentsize=0;
     73bool Gamestate::collectData(int id, uint8_t mode)
     74{
     75  unsigned int tempsize=0, currentsize=0;
    7676  assert(data_==0);
    77   int size = calcGamestateSize(id, mode);
     77  unsigned int size = calcGamestateSize(id, mode);
    7878
    7979  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    8686  }
    8787
    88 #ifndef NDEBUG
    89   std::list<Synchronisable*> slist;
    90   std::list<Synchronisable*>::iterator iit;
    91 #endif
    9288  //start collect data synchronisable by synchronisable
    9389  uint8_t *mem=data_;
     
    9894
    9995    if(currentsize+tempsize > size){
     96      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    10097      // start allocate additional memory
    10198      COUT(3) << "G.St.Man: need additional memory" << std::endl;
     
    110107    }// stop allocate additional memory
    111108
    112 #ifndef NDEBUG
    113     for(iit=slist.begin(); iit!=slist.end(); iit++)
    114       assert((*iit)!=*it);
    115     slist.push_back(*it);
    116 #endif
    117109
    118110    //if(it->doSelection(id))
     
    127119  //start write gamestate header
    128120  HEADER->packetType = ENUM::Gamestate;
    129   assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
    130121  HEADER->datasize = currentsize;
    131122  HEADER->id = id;
     
    140131}
    141132
    142 bool Gamestate::spreadData(int mode)
     133bool Gamestate::spreadData(uint8_t mode)
    143134{
    144135  assert(data_);
     
    163154      bool b = s->updateData(mem, mode);
    164155      assert(b);
    165       //if(!s->updateData(mem, mode))
    166         //return false;
    167156    }
    168157  }
     
    367356    assert(it->second->objectID==oldobjectheader->objectID);
    368357    *newobjectheader = *oldobjectheader;
    369     objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader
     358    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    370359    if(it->second->doSelection(HEADER->id)){
    371360      newobjectheader->dataAvailable=true; //TODO: probably not neccessary
     
    565554
    566555
    567 unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
    568 {
    569   int size=0;
     556unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
     557{
     558  unsigned int size=0;
    570559    // get the start of the Synchronisable list
    571560  ObjectList<Synchronisable>::iterator it;
  • code/branches/objecthierarchy/src/network/packet/Gamestate.h

    r2112 r2132  
    6969    ~Gamestate();
    7070
    71     bool collectData(int id, int mode=0x0);
    72     bool spreadData(int mode=0x0);
     71    bool collectData(int id, uint8_t mode=0x0);
     72    bool spreadData( uint8_t mode=0x0);
    7373    int getID();
    7474    bool isDiffed();
     
    9090    bool operator ==(packet::Gamestate gs);
    9191  private:
    92     unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
     92    unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
    9393    void removeObject(ObjectListIterator<Synchronisable> &it);
    9494    std::map<unsigned int, Synchronisable*> dataMap_;
  • code/branches/objecthierarchy/src/network/packet/Packet.cc

    r2112 r2132  
    5353#define _PACKETID           0
    5454
    55 std::map<ENetPacket *, Packet *> Packet::packetMap_;
     55std::map<size_t, Packet *> Packet::packetMap_;
    5656
    5757Packet::Packet(){
     
    134134    // Add the packet to a global list so we can access it again once enet calls our
    135135    // deletePacket method. We can of course only give a one argument function to the ENet C library.
    136     packetMap_[enetPacket_] = this;
     136    packetMap_[(size_t)(void*)enetPacket_] = this;
    137137  }
    138138#ifndef NDEBUG
     
    208208void Packet::deletePacket(ENetPacket *enetPacket){
    209209  // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
    210   std::map<ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket);
     210  std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
    211211  assert(it != packetMap_.end());
    212212  // Make sure we don't delete it again in the destructor
  • code/branches/objecthierarchy/src/network/packet/Packet.h

    r2112 r2132  
    9292    bool bDataENetAllocated_;
    9393  private:
    94     static std::map<ENetPacket *, Packet *> packetMap_;
     94    static std::map<size_t, Packet *> packetMap_;
    9595    ENetPacket *enetPacket_;
    9696};
Note: See TracChangeset for help on using the changeset viewer.