Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2749


Ignore:
Timestamp:
Mar 5, 2009, 1:54:27 PM (16 years ago)
Author:
scheusso
Message:

changed the process of classid (or networkid in the factory) synchronisation:
the packet classid synchronises all classid at once now

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

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/Factory.cc

    r2662 r2749  
    8787    void Factory::changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID)
    8888    {
    89         getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
     89//        getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
    9090        getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier;
    9191//std::cout << identifier->getName() << ": " << oldID << " -> " << newID << std::endl;
     92    }
     93
     94    /**
     95        @brief Cleans the NetworkID map (needed on clients for correct initialization)
     96    */
     97    void Factory::cleanNetworkIDs()
     98    {
     99        getFactoryPointer()->identifierNetworkIDMap_.clear();
    92100    }
    93101
  • code/branches/network/src/core/Factory.h

    r2710 r2749  
    6363            static void add(const std::string& name, Identifier* identifier);
    6464            static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
     65            static void cleanNetworkIDs();
    6566            static void createClassHierarchy();
    6667
  • code/branches/network/src/network/ConnectionManager.cc

    r2662 r2749  
    4646#include <boost/bind.hpp>
    4747
    48 #include "core/CoreIncludes.h"
    49 #include "core/BaseObject.h"
    50 #include "core/Iterator.h"
     48// #include "core/CoreIncludes.h"
     49// #include "core/BaseObject.h"
     50// #include "core/Iterator.h"
    5151#include "util/Math.h"
    5252#include "util/Sleep.h"
     
    303303   * @param clientID
    304304   */
     305//   void ConnectionManager::syncClassid(unsigned int clientID) {
     306//     unsigned int network_id=0, failures=0;
     307//     std::string classname;
     308//     Identifier *id;
     309//     std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
     310//     while(it != Factory::getFactoryMapEnd()){
     311//       id = (*it).second;
     312//       if(id == NULL)
     313//         continue;
     314//       classname = id->getName();
     315//       network_id = id->getNetworkID();
     316//       if(network_id==0)
     317//         COUT(3) << "we got a null class id: " << id->getName() << std::endl;
     318//       COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
     319//
     320//       packet::ClassID *classid = new packet::ClassID( network_id, classname );
     321//       classid->setClientID(clientID);
     322//       while(!classid->send() && failures < 10){
     323//         failures++;
     324//       }
     325//       ++it;
     326//     }
     327//     //sendPackets();
     328//     COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
     329//   }
     330
    305331  void ConnectionManager::syncClassid(unsigned int clientID) {
    306     unsigned int network_id=0, failures=0;
    307     std::string classname;
    308     Identifier *id;
    309     std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
    310     while(it != Factory::getFactoryMapEnd()){
    311       id = (*it).second;
    312       if(id == NULL)
    313         continue;
    314       classname = id->getName();
    315       network_id = id->getNetworkID();
    316       if(network_id==0)
    317         COUT(3) << "we got a null class id: " << id->getName() << std::endl;
    318       COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    319 
    320       packet::ClassID *classid = new packet::ClassID( network_id, classname );
    321       classid->setClientID(clientID);
    322       while(!classid->send() && failures < 10){
    323         failures++;
    324       }
    325       ++it;
    326     }
    327     //sendPackets();
     332    int failures=0;
     333    packet::ClassID *classid = new packet::ClassID();
     334    classid->setClientID(clientID);
     335    while(!classid->send() && failures < 10){
     336      failures++;
     337    }
     338    assert(failures<10);
    328339    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
    329340  }
    330 
     341 
    331342
    332343  void ConnectionManager::disconnectClient(ClientInformation *client){
  • code/branches/network/src/network/packet/ClassID.cc

    r2737 r2749  
    3131#include "ClassID.h"
    3232#include "core/CoreIncludes.h"
     33#include "core/Factory.h"
    3334#include <cstring>
     35#include <string>
    3436#include <assert.h>
     37#include <map>
     38#include <queue>
    3539
    3640namespace orxonox {
     
    3842
    3943
     44#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
     45#define _PACKETID             0
    4046
    41   ClassID::ClassID( uint32_t classID, std::string className )
    42  : Packet()
    43 {
     47
     48ClassID::ClassID( ) : Packet(){
     49  Identifier *id;
     50  std::string classname;
     51  unsigned int nrOfClasses=0;
     52  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
     53  uint32_t network_id;
    4454  flags_ = flags_ | PACKET_FLAGS_CLASSID;
    45   classNameLength_=className.length()+1;
    46   assert(getSize());
    47   data_=new unsigned char[ getSize() ];
    48   assert(data_);
    49   *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::ClassID;
    50   *(uint32_t *)(data_ + _CLASSID ) = classID;
    51   *(uint32_t *)(data_ + _CLASSNAMELENGTH ) = classNameLength_;
    52   memcpy( data_+_CLASSNAME, (void *)className.c_str(), classNameLength_ );
     55  std::queue<std::pair<uint32_t, std::string> > tempQueue;
     56 
     57  //calculate total needed size (for all strings and integers)
     58  std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
     59  for(;it != Factory::getFactoryMapEnd();++it){
     60    id = (*it).second;
     61    if(id == NULL)
     62      continue;
     63    classname = id->getName();
     64    network_id = id->getNetworkID();
     65    if(network_id==0)
     66      COUT(3) << "we got a null class id: " << id->getName() << std::endl;
     67    // now push the network id and the classname to the stack
     68    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
     69    ++nrOfClasses;
     70    packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t);
     71  }
     72 
     73  this->data_=new uint8_t[ packetSize ];
     74  //set the appropriate packet id
     75  assert(this->data_);
     76  *(ENUM::Type *)(this->data_ + _PACKETID ) = ENUM::ClassID;
     77 
     78  uint8_t *temp=data_+sizeof(uint32_t);
     79  // save the number of all classes
     80  *(uint32_t*)temp = nrOfClasses;
     81  temp += sizeof(uint32_t);
     82 
     83  // now save all classids and classnames
     84  std::pair<uint32_t, std::string> tempPair;
     85  while( !tempQueue.empty() ){
     86    tempPair = tempQueue.front();
     87    tempQueue.pop();
     88    *(uint32_t*)temp = tempPair.first;
     89    *(uint32_t*)(temp+sizeof(uint32_t)) = tempPair.second.size()+1;
     90    memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
     91    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
     92  }
     93 
     94  COUT(0) << "classid packetSize is " << packetSize << endl;
     95 
    5396}
    5497
     
    5699  : Packet(data, clientID)
    57100{
    58   memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) );
    59101}
    60102
     
    63105}
    64106
     107uint32_t ClassID::getSize() const{
     108  uint8_t *temp = data_+sizeof(uint32_t); // packet identification
     109  uint32_t totalsize = sizeof(uint32_t); // packet identification
     110  uint32_t nrOfClasses = *(uint32_t*)temp;
     111  temp += sizeof(uint32_t);
     112  totalsize += sizeof(uint32_t); // storage size for nr of all classes
     113 
     114  for(unsigned int i=0; i<nrOfClasses; i++){
     115    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
     116  }
     117  return totalsize;
     118}
     119
    65120
    66121bool ClassID::process(){
    67   COUT(3) << "processing classid: " << getClassID() << " name: " << getClassName() << std::endl;
    68   Identifier *id=ClassByString( std::string(getClassName()) );
    69   if(id==NULL){
    70     COUT(0) << "Recieved a bad classname" << endl;
    71     abort();
     122  int nrOfClasses;
     123  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
     124  uint32_t networkID;
     125  uint32_t stringsize;
     126  unsigned char *classname;
     127 
     128 
     129  //clean the map of network ids
     130  Factory::cleanNetworkIDs();
     131 
     132  COUT(4) << "=== processing classids: " << endl;
     133  std::pair<uint32_t, std::string> tempPair;
     134  Identifier *id;
     135  // read the total number of classes
     136  nrOfClasses = *(uint32_t*)temp;
     137  temp += sizeof(uint32_t);
     138 
     139  for( int i=0; i<nrOfClasses; i++){
     140    networkID = *(uint32_t*)temp;
     141    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     142    classname = temp+2*sizeof(uint32_t);
     143    id=ClassByString( std::string((const char*)classname) );
     144    COUT(0) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
     145    if(id==NULL){
     146      COUT(0) << "Recieved a bad classname" << endl;
     147      abort();
     148    }
     149    id->setNetworkID( networkID );
     150    temp += 2*sizeof(uint32_t) + stringsize;
    72151  }
    73   id->setNetworkID( getClassID() );
    74152  delete this;
    75153  return true;
     
    77155
    78156
    79 uint32_t ClassID::getClassID(){
    80   return *(uint32_t *)(data_ + _CLASSID);
    81 }
     157// uint32_t ClassID::getClassID(){
     158//   return *(uint32_t *)(data_ + _CLASSID);
     159// }
    82160
    83161} //namespace packet
  • code/branches/network/src/network/packet/ClassID.h

    r2737 r2749  
    3838namespace packet {
    3939
    40 #define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
    41 #define _PACKETID             0
    42 #define _CLASSID              _PACKETID + sizeof(ENUM::Type)
    43 #define _CLASSNAMELENGTH      _CLASSID + sizeof(uint32_t)
    44 #define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
    4540 
    4641/**
     
    5045{
    5146public:
    52   ClassID( uint32_t classID, std::string className );
     47  ClassID( );
    5348  ClassID( uint8_t* data, unsigned int clientID );
    5449  ~ClassID();
    5550
    56   inline uint32_t getSize() const{ return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_; }
     51  uint32_t getSize() const;
    5752  bool process();
    5853
    59   uint32_t getClassID();
    60   uint32_t getClassNameLength(){ return classNameLength_; }
    61   const char *getClassName(){ return (const char*)(data_+_CLASSNAME); }
     54//   uint32_t getClassID();
     55//   uint32_t getClassNameLength(){ return classNameLength_; }
     56//   const char *getClassName(){ return (const char*)(data_+_CLASSNAME); }
    6257private:
    63   uint32_t classNameLength_;
     58//   uint32_t classNameLength_;
     59//   static bool alreadySetOneClassID_;
    6460};
    6561
  • code/branches/network/src/network/synchronisable/Synchronisable.cc

    r2710 r2749  
    158158    if (!id)
    159159    {
     160        for(int i = 0; i<100; i++)
     161            COUT(0) << "classid: " << i << " identifier: " << ClassByID(i) << endl;
    160162        COUT(0) << "Assertion failed: id" << std::endl;
    161163        COUT(0) << "Possible reason for this error: Client received a synchronizable object whose class has no factory." << std::endl;
Note: See TracChangeset for help on using the changeset viewer.