Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:06:55 PM (6 years ago)
Author:
merholzl
Message:

Merged Masterserver, refresh button had to be removed

Location:
code/branches/mergeFS18
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/network/packet/ClassID.cc

    r11071 r12027  
    4646
    4747
    48 ClassID::ClassID( ) : Packet(){
     48ClassID::ClassID() : Packet() {
    4949  Identifier *id;
    50   unsigned int nrOfClasses=0;
    51   unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
     50  unsigned int nrOfClasses = 0;
     51  unsigned int packetSize = 2 * sizeof(uint32_t); //space for the packetID and for the nrofclasses
    5252  uint32_t network_id;
    53   flags_ = flags_ | PACKET_FLAGS_CLASSID;
     53  this->flags_ |= PACKET_FLAGS_CLASSID;
    5454  std::queue<std::pair<uint32_t, std::string>> tempQueue;
    5555
    56   //calculate total needed size (for all strings and integers)
    57   for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()){
     56  // calculate total needed size (for all strings and integers)
     57  for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) {
    5858    id = mapEntry.second;
    5959    if(id == nullptr || !id->hasFactory())
     
    6464    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
    6565    ++nrOfClasses;
    66     packetSize += (classname.size()+1)+sizeof(network_id)+sizeof(uint32_t);
     66    packetSize += (classname.size() + 1) + sizeof(network_id) + sizeof(uint32_t);
    6767  }
    6868
    69   this->data_=new uint8_t[ packetSize ];
     69  this->data_ = new uint8_t[ packetSize ];
    7070  //set the appropriate packet id
    7171  assert(this->data_);
    7272  *(Type *)(this->data_ + _PACKETID ) = Type::ClassID;
    7373
    74   uint8_t *temp=data_+sizeof(uint32_t);
     74  uint8_t *temp = this->data_ + sizeof(uint32_t);
    7575  // save the number of all classes
    76   *(uint32_t*)temp = nrOfClasses;
     76  *(uint32_t*) temp = nrOfClasses;
    7777  temp += sizeof(uint32_t);
    7878
    7979  // now save all classids and classnames
    8080  std::pair<uint32_t, std::string> tempPair;
    81   uint32_t tempsize = 2*sizeof(uint32_t); // packetid and nrOfClasses
     81  uint32_t tempsize = 2 * sizeof(uint32_t); // packetid and nrOfClasses
    8282  while( !tempQueue.empty() ){
    8383    tempPair = tempQueue.front();
    8484    tempQueue.pop();
    85     *(uint32_t*)temp = tempPair.first;
    86     *(uint32_t*)(temp+sizeof(uint32_t)) = tempPair.second.size()+1;
    87     memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
    88     temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
    89     tempsize+=2*sizeof(uint32_t)+tempPair.second.size()+1;
     85    *(uint32_t*) temp = tempPair.first;
     86    *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size() + 1;
     87    memcpy(temp + 2 * sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size() + 1);
     88    temp += 2 * sizeof(uint32_t) + tempPair.second.size() + 1;
     89    tempsize += 2 * sizeof(uint32_t) + tempPair.second.size() + 1;
    9090  }
    91   assert(tempsize==packetSize);
     91  assert(tempsize == packetSize);
    9292
    9393  orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl;
     
    104104}
    105105
    106 uint32_t ClassID::getSize() const{
    107   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
     106uint32_t ClassID::getSize() const {
     107  uint8_t *temp = this->data_ + sizeof(uint32_t); // packet identification
    108108  uint32_t totalsize = sizeof(uint32_t); // packet identification
    109   uint32_t nrOfClasses = *(uint32_t*)temp;
     109  uint32_t nrOfClasses = *(uint32_t*) temp;
    110110  temp += sizeof(uint32_t);
    111111  totalsize += sizeof(uint32_t); // storage size for nr of all classes
    112112
    113   for(unsigned int i=0; i<nrOfClasses; i++){
    114     totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
    115     temp += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
     113  for(unsigned int i=0; i < nrOfClasses; i++) {
     114    totalsize += 2 * sizeof(uint32_t) + *(uint32_t*) (temp + sizeof(uint32_t));
     115    temp += 2 * sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
    116116  }
    117117  return totalsize;
    118118}
    119119
    120 
    121 bool ClassID::process(orxonox::Host* host){
     120bool ClassID::process(orxonox::Host* host) {
    122121  int nrOfClasses;
    123   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
     122  uint8_t *temp = this->data_ + sizeof(uint32_t); //skip the packetid
    124123  uint32_t networkID;
    125124  uint32_t stringsize;
    126125  unsigned char *classname;
    127 
    128126
    129127  //clear the map of network ids
     
    134132  Identifier *id;
    135133  // read the total number of classes
    136   nrOfClasses = *(uint32_t*)temp;
     134  nrOfClasses = *(uint32_t*) temp;
    137135  temp += sizeof(uint32_t);
    138136
    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) );
     137  for( int i = 0; i < nrOfClasses; i++) {
     138    networkID = *(uint32_t*) temp;
     139    stringsize = *(uint32_t*) (temp + sizeof(uint32_t));
     140    classname = temp + 2 * sizeof(uint32_t);
     141    id = ClassByString( std::string((const char*) classname) );
    144142    orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl;
    145     if(id==nullptr){
     143    if(id == nullptr) {
    146144      orxout(user_error, context::packets) << "Received a bad classname" << endl;
    147145      abort();
    148146    }
    149147    id->setNetworkID( networkID );
    150     temp += 2*sizeof(uint32_t) + stringsize;
     148    temp += 2 * sizeof(uint32_t) + stringsize;
    151149  }
    152150  delete this;
Note: See TracChangeset for help on using the changeset viewer.