Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2153


Ignore:
Timestamp:
Nov 7, 2008, 10:50:51 PM (16 years ago)
Author:
scheusso
Message:

Synchronisable::getSynchronisable function uses now a map to efficently work

File:
1 edited

Legend:

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

    r2144 r2153  
    7070    objectMode_=0x1; // by default do not send data to server
    7171    if(Host::running() && Host::isServer())
    72       objectID=idCounter++; //this is only needed when running a server
     72    {
     73      this->objectID = idCounter++; //this is only needed when running a server
     74    //add synchronisable to the objectMap
     75      objectMap_[this->objectID] = this;
     76    }
    7377    else
    7478      objectID=OBJECTID_UNKNOWN;
    7579    classID = (unsigned int)-1;
    7680    syncList = new std::list<synchronisableVariable *>;
     81   
    7782   
    7883#ifndef NDEBUG
     
    118123//       objectMap_.erase(objectID);
    119124    }
     125    std::map<unsigned int, Synchronisable*>::iterator it;
     126    it = objectMap_.find(objectID);
     127    if (it != objectMap_.end())
     128      objectMap_.erase(it);
    120129  }
    121130
     
    227236   */
    228237  Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
     238    std::map<unsigned int, Synchronisable*>::iterator it1;
     239    it1 = objectMap_.find(objectID);
     240    if (it1 != objectMap_.end())
     241      return it1->second;
     242   
    229243    ObjectList<Synchronisable>::iterator it;
    230244    for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    231       if( it->getObjectID()==objectID )
    232            return *it;
     245      if( it->getObjectID()==objectID ){
     246        objectMap_[objectID] = *it;
     247        return *it;
     248      }
    233249    }
    234250    return NULL;
    235 
    236 //     std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
    237 //     if(i==objectMap_.end())
    238 //       return NULL;
    239 //     assert(i->second->objectID==objectID);
    240 //     return (*i).second;
    241251  }
    242252
Note: See TracChangeset for help on using the changeset viewer.