Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9909 in orxonox.OLD


Ignore:
Timestamp:
Oct 30, 2006, 10:35:23 PM (18 years ago)
Author:
rennerc
Message:

ClassID synchronization might work. at least it still works with it :D

Location:
branches/network/src/lib
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/lang/object_list.cc

    r9869 r9909  
    330330    return -1;
    331331}
     332
     333
     334/**
     335 * replace all ids. list must contain all (and no more) ids
     336 * @param str2id list: string -> newId
     337 */
     338void ObjectListBase::replaceIDMap( const std::map< std::string, int >& str2id )
     339{
     340  if ( str2id.size() != _classesByID->size() )
     341  {
     342    assert( false && "size of str2id does not match" );
     343  }
     344 
     345  IDMap * map = new IDMap();
     346 
     347  std::map< std::string, int >::const_iterator it;
     348  for ( it = str2id.begin(); it != str2id.end(); it++ )
     349  {
     350    assert( _classesByName->find( it->first ) != _classesByName->end() );
     351    (*map)[ it->second ] =  (*_classesByName)[it->first];
     352  }
     353 
     354  delete _classesByID;
     355  _classesByID = map;
     356}
     357
     358/**
     359 *
     360 * @return
     361 */
     362std::map< std::string, int > * ObjectListBase::createStrToId( )
     363{
     364  std::map< std::string, int > * res = new std::map< std::string, int >();
     365 
     366  NameMap::const_iterator it;
     367  for ( it = _classesByName->begin(); it != _classesByName->end(); it++ )
     368  {
     369    IDMap::const_iterator it2;
     370    int id = -1;
     371    for ( it2 = _classesByID->begin(); it2 != _classesByID->end(); it2++ )
     372    {
     373      if ( it->second == it2->second )
     374      {
     375        id = it2->first;
     376        break;
     377      }
     378    }
     379   
     380    assert( id != -1 );
     381    (*res)[ it->first ] = id;
     382  }
     383 
     384  return res;
     385}
  • branches/network/src/lib/lang/object_list.h

    r9869 r9909  
    133133  static NameMap*               _classesByName;     //!< A Map of all the classes in existance.
    134134  static std::list<std::string> _classNames;        //!< A list of all the registered ClassNames.
     135 
     136public:
     137  static void replaceIDMap( const std::map<std::string, int>& str2id );
     138  static std::map<std::string, int>* createStrToId();
    135139};
    136140
  • branches/network/src/lib/network/Makefile.am

    r9906 r9909  
    4444                      synchronizeable_var/synchronizeable_ip.cc \
    4545                      synchronizeable_var/synchronizeable_classid.cc \
     46                      synchronizeable_var/synchronizeable_classid_list.cc \
    4647                      \
    4748                      ip.cc
     
    9697                synchronizeable_var/synchronizeable_ip.h \
    9798                synchronizeable_var/synchronizeable_classid.h \
     99                synchronizeable_var/synchronizeable_classid_list.h \
    98100                \
    99101                ip.h
  • branches/network/src/lib/network/handshake.cc

    r9869 r9909  
    2222#include "debug.h"
    2323
     24#include "synchronizeable_var/synchronizeable_classid_list.h"
     25
     26std::map< std::string, int >* Handshake::classIdList = NULL;
    2427
    2528ObjectListDefinition(Handshake);
     
    3235  this->registerObject(this, Handshake::_objectList);
    3336
     37  if ( !Handshake::classIdList )
     38  {
     39    //TODO who else?
     40    if ( SharedNetworkData::getInstance()->isMasterServer() )
     41    {
     42      Handshake::classIdList = ObjectListBase::createStrToId();
     43    }
     44    else
     45    {
     46      Handshake::classIdList = new std::map< std::string, int >();
     47    }
     48  }
    3449
    3550  // register all variable handlers
     
    5267  registerVar( new SynchronizeableIP( &this->proxy2, &this->proxy2, "proxy server 2", PERMISSION_MASTER_SERVER ) );
    5368  registerVar( new SynchronizeableInt( &this->redirectProxy, &this->redirectProxy, "proxy server redirection flag", PERMISSION_MASTER_SERVER ) );
     69 
     70  registerVar( new SynchronizeableClassIDList( Handshake::classIdList, Handshake::classIdList, "classId List", PERMISSION_MASTER_SERVER ) );
    5471
    5572
  • branches/network/src/lib/network/handshake.h

    r9901 r9909  
    118118    IP                 proxy1;                               //!< ip address of the first proxy (0.0.0.0 of not available)
    119119    IP                 proxy2;                               //!< ip address of the second proxy (0.0.0.0 of not available)
     120   
     121    static std::map< std::string, int >* classIdList;
     122  public:
     123    std::map< std::string, int >* getClassIdList(){ return classIdList; }
    120124};
    121125
  • branches/network/src/lib/network/network_stream.cc

    r9908 r9909  
    716716              // init the new message manager
    717717              MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
     718              ObjectListBase::replaceIDMap( *(it->second.handshake->getClassIdList()) );
    718719            }
    719720
Note: See TracChangeset for help on using the changeset viewer.