Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6695 in orxonox.OLD


Ignore:
Timestamp:
Jan 25, 2006, 2:39:53 PM (18 years ago)
Author:
patrick
Message:

merged the network branche to the trunk

Location:
trunk/src
Files:
36 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r6655 r6695  
    147147  CL_GLGUI_MAIN_WIDGET          =    0x00000f41,
    148148  CL_NETWORK_MANAGER            =    0x00000f50,
     149  CL_SHARED_NETWORK_DATA        =    0x00000f51,
    149150
    150151
  • trunk/src/lib/coord/p_node.cc

    r6634 r6695  
    4242 */
    4343PNode::PNode (PNode* parent, long nodeFlags)
     44  : Synchronizeable(), BaseObject()
    4445{
    4546  this->setClassID(CL_PARENT_NODE, "PNode");
     
    487488      this->children.push_back(child);
    488489    child->parentCoorChanged();
     490
     491//     if(this->getUniqueID() == NET_UID_UNASSIGNED)
     492//     {
     493//       PRINTF(1)("Adding to an UNASSIGNED PNode - looking for next assigned Node\n");
     494//       PNode* node = this->seekNextAssignedPNode(this);
     495//       if( node == NULL)
     496//         PRINTF(1)("    Got NULL - Is this the NULLParent - uid %i\n", this->getUniqueID());
     497//       else
     498//         PRINTF(1)("    Found next assigned node: %i\n", node->getUniqueID());
     499//     }
    489500  }
    490501  else
     
    495506    child->parentCoorChanged();
    496507  }
     508}
     509
     510
     511PNode* PNode::seekNextAssignedPNode(PNode* node) const
     512{
     513  PNode* tmpNode = node->parent;
     514  printf("entering seek PNode loop for name: %s, uid: %i\n", node->getName(), node->getUniqueID());
     515  if(tmpNode)
     516    printf("  @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID());
     517  while( tmpNode != NULL && tmpNode->getUniqueID() == NET_UID_UNASSIGNED)
     518  {
     519    printf("  @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID());
     520    tmpNode = tmpNode->parent;
     521  }
     522  printf("leaving PNode loop\n\n");
     523
     524  return tmpNode;
    497525}
    498526
     
    695723  {
    696724    PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL);
     725    PNode::nullParent->setClassID(CL_NULL_PARENT, "NullParent");
    697726    PNode::nullParent->setName("NullParent");
     727    PNode::nullParent->setSynchronized(true);
    698728  }
    699729  return PNode::nullParent;
     
    10491079  SYNCHELP_READ_FKT( BaseObject::writeState );
    10501080
    1051   char * parentName = NULL;
    1052   SYNCHELP_READ_STRINGM( parentName );
    1053 
    1054   if ( strcmp(parentName, "")==0 )
    1055   {
    1056     setParent( (char*)NULL );
    1057   }
    1058   else
    1059   {
    1060     setParent( parentName );
    1061   }
    1062 
    1063   delete[] parentName;
     1081//   char * parentName = NULL;
     1082//   SYNCHELP_READ_STRINGM( parentName );
     1083//
     1084//   if ( strcmp(parentName, "")==0 )
     1085//   {
     1086//     setParent( (char*)NULL );
     1087//   }
     1088//   else
     1089//   {
     1090//     setParent( parentName );
     1091//   }
     1092//
     1093//  delete[] parentName;
    10641094
    10651095  int parentMode;
     
    10811111  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    10821112
    1083   int n;
    1084   char * childName;
    1085 
    1086   PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]);
    1087   SYNCHELP_READ_INT( n );
    1088   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
    1089 
    1090   for (int i = 0; i<n; i++)
    1091   {
    1092     SYNCHELP_READ_STRINGM( childName );
    1093     PRINTF(0)("RCVD CHILD = %s\n", childName);
    1094     addChild( childName );
    1095     delete childName;
    1096     childName = NULL;
    1097   }
     1113//   int n;
     1114//   char * childName;
     1115//
     1116//   PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]);
     1117//   SYNCHELP_READ_INT( n );
     1118//   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
     1119//
     1120//   for (int i = 0; i<n; i++)
     1121//   {
     1122//     SYNCHELP_READ_STRINGM( childName );
     1123//     PRINTF(0)("RCVD CHILD = %s\n", childName);
     1124//     addChild( childName );
     1125//     delete childName;
     1126//     childName = NULL;
     1127//   }
    10981128
    10991129  return SYNCHELP_READ_N;
     
    11121142  SYNCHELP_WRITE_FKT( BaseObject::readState );
    11131143
    1114   if ( this->parent )
    1115   {
    1116     SYNCHELP_WRITE_STRING( parent->getName() );
    1117   }
    1118   else
    1119   {
    1120     SYNCHELP_WRITE_STRING( "" );
    1121   }
     1144//   if ( this->parent )
     1145//   {
     1146//     SYNCHELP_WRITE_STRING( parent->getName() );
     1147//   }
     1148//   else
     1149//   {
     1150//     SYNCHELP_WRITE_STRING( "" );
     1151//   }
    11221152
    11231153  SYNCHELP_WRITE_INT( this->parentMode );
     
    11321162  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
    11331163
    1134   int n = children.size();
    1135 
    1136   //check if camera is in children
    1137   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1138   {
    1139     if ( (*it)->isA(CL_CAMERA) )
    1140       n--;
    1141   }
    1142   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
    1143   SYNCHELP_WRITE_INT( n );
    1144   PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]);
    1145 
    1146   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1147   {
    1148     //dont add camera because there is only one camera attached to local player
    1149     if ( !(*it)->isA(CL_CAMERA) )
    1150     {
    1151       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
    1152       SYNCHELP_WRITE_STRING( (*it)->getName() );
    1153     }
    1154   }
     1164//   int n = children.size();
     1165//   //check if camera is in children
     1166//   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1167//   {
     1168//     if ( (*it)->isA(CL_CAMERA) )
     1169//       n--;
     1170//   }
     1171//   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
     1172//   SYNCHELP_WRITE_INT( n );
     1173//   PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]);
     1174//
     1175//
     1176//   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1177//   {
     1178//     //dont add camera because there is only one camera attached to local player
     1179//     if ( !(*it)->isA(CL_CAMERA) )
     1180//     {
     1181//       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
     1182//       SYNCHELP_WRITE_STRING( (*it)->getName() );
     1183//     }
     1184//   }
    11551185
    11561186  return SYNCHELP_WRITE_N;
  • trunk/src/lib/coord/p_node.h

    r6634 r6695  
    147147  void removeNode();
    148148
     149  PNode* seekNextAssignedPNode(PNode* node) const;
     150
    149151  /** @param parent the new parent of this node */
    150152  inline void setParent (PNode* parent) { parent->addChild(this); };
  • trunk/src/lib/graphics/importer/vertex_array_model.cc

    r6519 r6695  
    305305    this->addColor(.125,.436,.246); ///FIXME
    306306  }
     307
    307308  for (unsigned int loopNumber = 0; loopNumber <= loops; ++loopNumber)
    308309  {
     
    326327    }
    327328  }
     329
    328330  for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber)
    329331  {
     
    331333    this->addIndice(segmentsPerLoop + loopSegmentNumber);
    332334  }
     335
    333336  for (unsigned int loopNumber = 0; loopNumber < loops; ++loopNumber)
    334337  {
  • trunk/src/lib/network/Makefile.am

    r6139 r6695  
    66libORXnet_a_SOURCES = synchronizeable.cc \
    77                      network_manager.cc \
     8                      shared_network_data.cc \
    89                      network_socket.cc \
    910                      connection_monitor.cc \
     
    2122noinst_HEADERS = synchronizeable.h \
    2223                 network_manager.h \
     24                 shared_network_data.h \
    2325                 network_socket.h \
    2426                 connection_monitor.h \
  • trunk/src/lib/network/handshake.cc

    r6341 r6695  
    2323
    2424Handshake::Handshake( bool server, int clientId, int networkGameManagerId )
     25  : Synchronizeable()
    2526{
    2627  /* set the class id for the base object */
     
    3435  this->setOwner(0);
    3536
     37  this->setSynchronized(true);
    3638  PRINTF(5)("Handshake created clientId = %d\n", clientId);
    3739}
  • trunk/src/lib/network/netdefs.h

    r5822 r6695  
    1717
    1818
     19#define MAX_CONNECTIONS 1000
     20
     21
    1922typedef unsigned char byte;
    2023
     
    2528} NodeType;
    2629
     30
     31typedef enum {
     32  NET_UID_UNASSIGNED = -1,
     33
     34  NET_UID_NUMBER
     35} UidType;
     36
    2737#endif /* _NETWORK_MANAGER */
  • trunk/src/lib/network/network_game_manager.cc

    r6634 r6695  
    4646 */
    4747NetworkGameManager::NetworkGameManager()
     48  : Synchronizeable()
    4849{
    4950  PRINTF(0)("START\n");
     
    5253  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
    5354
    54   newUniqueID = MAX_CONNECTIONS + 2;
    55 
    5655  hasRequestedWorld = false;
     56  this->setSynchronized(true);
    5757}
    5858
     
    8080    b = data[i++];
    8181
     82    /**************** Commands only processed by servers ****************/
    8283    if ( isServer() )
    8384    {
    84       if ( b == REQUEST_CREATE )
     85      if ( b == NET_REQUEST_CREATE )
    8586      {
    8687        if ( !handleRequestCreate( i, data, length, sender ) )
     
    8889        continue;
    8990      }
    90       if ( b == REQUEST_REMOVE )
     91      else if ( b == NET_REQUEST_REMOVE )
    9192      {
    9293        if ( !handleRequestRemove( i, data, length, sender ) )
     
    9495        continue;
    9596      }
     97      else if ( b == NET_REQUEST_PNODE_PATH )
     98      {
     99        if ( !handleRequestPNodePath( i, data, length, sender ) )
     100          return i;
     101        continue;
     102      }
    96103    }
    97104    else
    98105    {
    99       if ( b == CREATE_ENTITY )
     106      /**************** Commands only processed by clients ****************/
     107      if ( b == NET_CREATE_ENTITY )
    100108      {
    101109        PRINTF(0)("CREATE_ENTITY\n");
     
    104112        continue;
    105113      }
    106       if ( b == REMOVE_ENTITY )
     114      else if ( b == NET_REMOVE_ENTITY )
    107115      {
    108116        if ( !handleRemoveEntity( i, data, length, sender ) )
     
    110118        continue;
    111119      }
    112       if ( b == CREATE_ENTITY_LIST )
     120      else if ( b == NET_CREATE_ENTITY_LIST )
    113121      {
    114122        if ( !handleCreateEntityList( i, data, length, sender ) )
     
    116124        continue;
    117125      }
    118       if ( b == REMOVE_ENTITY_LIST )
     126      else if ( b == NET_REMOVE_ENTITY_LIST )
    119127      {
    120128        if ( !handleRemoveEntityList( i, data, length, sender ) )
     
    122130        continue;
    123131      }
    124       if ( b == YOU_ARE_ENTITY )
     132      else if ( b == NET_YOU_ARE_ENTITY )
    125133      {
    126134        if ( !handleYouAreEntity( i, data, length, sender ) )
     
    130138    }
    131139
    132     if ( b == REQUEST_ENTITY_LIST )
     140    /**************** Commands processed by servers and clients ****************/
     141    if ( b == NET_REQUEST_ENTITY_LIST )
    133142    {
    134143      sendEntityList( sender );
    135144      continue;
    136145    }
    137 
    138     if ( b == REQUEST_SYNC )
     146    else if ( b == NET_REQUEST_SYNC )
    139147    {
    140148      if ( !handleRequestSync( i, data, length, sender ) )
     
    143151    }
    144152
    145     //if we get her something with data is wrong
     153
     154    PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender);
     155    PRINTF(1)("Probably this is because the network protocol has different \n");
     156    PRINTF(1)("versions or there occured an error in the sending algorithm\n");
    146157    PRINTF(1)("Data is not in the right format! i=%d\n", i);
    147158    return i;
     
    156167  {
    157168    SYNCHELP_WRITE_BEGIN();
    158     byte b = REQUEST_ENTITY_LIST;
     169    byte b = NET_REQUEST_ENTITY_LIST;
    159170    SYNCHELP_WRITE_BYTE( b );
    160171    hasRequestedWorld = true;
     
    200211int NetworkGameManager::createEntity( ClassID classID, int owner )
    201212{
    202   if ( this->isServer() )
    203   {
    204     if ( newUniqueID < 0 )
     213  if ( this->isServer())
     214  {
     215    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
    205216    {
    206217      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
    207218      return -1;
    208219    }
    209 
    210     return this->executeCreateEntity( classID, newUniqueID++, owner );
     220    return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
    211221  }
    212222  else
     
    227237  if ( this->isServer() )
    228238  {
    229     if ( newUniqueID < 0 )
     239    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
    230240    {
    231241      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
     
    245255    {
    246256      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
    247       s->setUniqueID( newUniqueID++ );
     257      s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    248258      s->setOwner( 0 );
    249       this->networkStream->connectSynchronizeable( *s );
     259      // all entities created via this function are added automaticaly to the synchronizeable list
     260      s->setSynchronized(true);
    250261      return b;
    251262    }
     
    258269  }
    259270  else
     271
    260272  {
    261273    PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value());
     
    295307      continue;
    296308
    297     if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) )
     309    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) )
    298310      return;
    299311    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     
    313325      continue;
    314326
    315     if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) )
     327    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) )
    316328      return;
    317329    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     
    332344      continue;
    333345
    334     if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) )
     346    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) )
    335347      return -1;
    336348    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     
    342354  }
    343355
     356  PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
    344357  doCreateEntity( classID, uniqueID, owner );
    345358
     
    359372      continue;
    360373
    361     if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) )
     374    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) )
    362375      return;
    363376    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     
    394407  e = this->networkStream->getSyncEnd();
    395408
    396   if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) )
     409  // send the packet header
     410  if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) )
    397411    return;
    398412
    399   // -2 because you must not send network_game_manager and handshake
     413  // send the number of entities: -2 because you must not send network_game_manager and handshake
    400414  if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) )
    401415    return;
     
    403417  //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
    404418
    405   int n = 0;
    406 
     419  // first send the NullParent
     420  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) )
     421    return;
     422  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) )
     423    return;
     424  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) )
     425    return;
     426
     427  // now send the rest of the entities
    407428  while ( it != e )
    408429  {
    409     PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() );
    410     if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
    411       return;
    412 
    413     if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
    414       return;
    415 
    416     if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
    417       return;
    418 
     430    if( (*it)->beSynchronized() && (*it) != PNode::getNullParent())
     431    {
     432      PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() );
     433      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
     434        return;
     435
     436      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
     437        return;
     438
     439      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
     440        return;
     441    }
    419442    it++;
    420443  }
     
    467490BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
    468491{
    469   BaseObject * b = Factory::fabricate( classID );
     492  PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
     493
     494  BaseObject * b;
     495  /* These are some small exeptions in creation: Not all objects can/should be created via Factory */
     496  /* Exception 1: NullParent */
     497  if( classID == CL_NULL_PARENT)
     498  {
     499    b = (BaseObject*)PNode::getNullParent();
     500  }
     501  else
     502    b = Factory::fabricate( classID );
    470503
    471504  if ( !b )
     
    480513    s->setUniqueID( uniqueID );
    481514    s->setOwner( owner );
    482     this->networkStream->connectSynchronizeable( *s );
     515    s->setSynchronized(true);
     516    //this->networkStream->connectSynchronizeable( *s );
    483517    if ( !isServer() )
    484518      s->setIsOutOfSync( true );
     
    646680  if ( userID != 0 )
    647681  {
    648     if ( !writeToClientBuffer( outBuffer[userID], (byte)YOU_ARE_ENTITY ) )
     682    if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) )
    649683      return;
    650684
     
    714748  i += Converter::byteArrayToInt( &data[i], &owner );
    715749
     750  PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
    716751  doCreateEntity( (ClassID)classID, uniqueID, owner );
    717752
     
    779814    {
    780815      BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner );
    781 
    782       /*if ( b != NULL )
    783       {
    784         if ( b->isA(CL_WORLD_ENTITY) )
    785         {
    786           int n = dynamic_cast<WorldEntity*>(b)->writeState( data, length, sender );
    787 
    788           i += n;
    789         }
    790     }*/
    791816    }
    792817
     
    854879  return true;
    855880}
     881
     882
     883/**
     884 *  handles the network signal NET_REQUEST_PNODE_PATH
     885 * @param i byte offset in the buffer
     886 * @param data data array
     887 * @param length length of the data arary
     888 * @param sender the sender id
     889 * @return true if process terminated sucessfully
     890 */
     891bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender)
     892{
     893  if( INTSIZE > length-i )
     894  {
     895    PRINTF(1)("Cannot read n from buffer! Not enough data left!\n");
     896    return false;
     897  }
     898  PRINTF(0)("HandleRequestPNodePath:  data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]);
     899
     900  int uniqueID1, uniqueID2;
     901  if( INTSIZE > length-i )
     902  {
     903    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
     904    return false;
     905  }
     906  i += Converter::byteArrayToInt( &data[i], &uniqueID1 );
     907
     908  if( INTSIZE > length-i )
     909  {
     910    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
     911    return false;
     912  }
     913  i += Converter::byteArrayToInt( &data[i], &uniqueID2 );
     914
     915
     916  PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2);
     917
     918  return true;
     919}
     920
    856921
    857922bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
     
    898963    resizeBufferVector( user );
    899964
    900   if ( !writeToClientBuffer( outBuffer[user], (byte)REQUEST_SYNC ) )
     965  if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) )
    901966    return;
    902967  if ( !writeToClientBuffer( outBuffer[user], uniqueID ) )
  • trunk/src/lib/network/network_game_manager.h

    r6634 r6695  
    1515
    1616class TiXmlElement;
     17class PNode;
    1718
    1819/**
    1920 * protocol definition
    2021 *
    21  *  CREATE_ENTITY:       CLASS_ID, UNIQUE_ID, OWNER
    22  *  REMOVE_ENTITY:       UNIQUE_ID
     22 *  CREATE_ENTITY:       >> CLASS_ID, UNIQUE_ID, OWNER
     23 *  REMOVE_ENTITY:       >> UNIQUE_ID
    2324 *
    24  *  CREATE_ENTITY_LIST:  NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
    25  *  REMOVE_ENTITY_LIST:  NUMBER, [UNIQUE_ID][0..NUMBER]
     25 *  CREATE_ENTITY_LIST:  >> NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
     26 *  REMOVE_ENTITY_LIST:  >> NUMBER, [UNIQUE_ID][0..NUMBER]
    2627 *
    27  *  REQUEST_CREATE:      CLASS_ID
    28  *  REQUEST_REMOVE:      UNIQUE_ID
     28 *  REQUEST_CREATE:      >> CLASS_ID
     29 *                       << [Sync Info]
     30 *  REQUEST_REMOVE:      >> UNIQUE_ID
     31 *                       << [Sync Info]
    2932 *
    3033 *  //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]
     
    3235 *
    3336 *  REQUEST_ENTITY_LIST: //request the whole world :D
    34  *  REQUEST_SYNC:        UNIQUE_ID
     37 *  REQUEST_SYNC:        >> UNIQUE_ID
     38 *                       << [Sync Info]
    3539 *  //REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
    3640 *
    37  *  YOU_ARE_ENTITY:      UNIQUE_ID
     41 *  YOU_ARE_ENTITY:      >> UNIQUE_ID
    3842 *
     43 *  REQUEST_PNODE_PATH   >> UNIQUE_ID_START   UNIQUE_ID_STOP
     44 *                       << UNIQUE_ID_1   UNIQUE_ID_2   UNIQUE_ID_3 ...   UNIQUE_ID_N
     45 *
     46 *  SEND_PNODE_PATH      >> UNIQUE_ID_START   UNIQUE_ID_STOP NUMBER [UNIQUE_ID][0..NUMBER]
    3947 */
    4048
    41 typedef enum NetworkGameManagerProtocol{
    42   CREATE_ENTITY = 0,
    43   REMOVE_ENTITY,
    44   CREATE_ENTITY_LIST,
    45   REMOVE_ENTITY_LIST,
    46   REQUEST_CREATE,
    47   REQUEST_REMOVE,
    48   REQUEST_SYNC,
    49   YOU_ARE_ENTITY,
    50   REQUEST_ENTITY_LIST
     49typedef enum NetworkGameManagerProtocol {
     50  NET_CREATE_ENTITY = 0,
     51  NET_REMOVE_ENTITY,
     52  NET_CREATE_ENTITY_LIST,
     53  NET_REMOVE_ENTITY_LIST,
     54  NET_REQUEST_CREATE,
     55  NET_REQUEST_REMOVE,
     56  NET_REQUEST_SYNC,
     57  NET_YOU_ARE_ENTITY,
     58  NET_REQUEST_ENTITY_LIST,
     59  NET_REQUEST_PNODE_PATH,
     60  NET_SEND_PNODE_PATH,
     61
     62  NET_NUMBER
    5163};
    5264
     
    8395    void sendEntityList(int userID);
    8496
     97
    8598  private:
    8699    NetworkGameManager();
    87100
     101
     102    /* some network signal handlers */
     103    bool handleRequestCreate( int& i, const byte* data, int length, int sender );
     104    bool handleRequestRemove( int& i, const byte* data, int length, int sender );
     105    bool handleCreateEntity( int& i, const byte* data, int length, int sender );
     106    bool handleRemoveEntity( int& i, const byte* data, int length, int sender );
     107    bool handleCreateEntityList( int& i, const byte* data, int length, int sender );
     108    bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
     109    bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
     110    bool handleRequestSync( int& i, const byte* data, int length, int sender );
     111    bool handleRequestPNodePath(int& i, const byte* data, int length, int sender);
     112    bool handleSendPNodePath(int& i, const byte* data, int length, int sender);
     113
     114
     115    /* some network handlers helper functions */
    88116    void requestCreateEntity(ClassID classID);
    89117    int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
     118    BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
    90119
    91120    void requestRemoveEntity(int uniqueID);
    92121    void executeRemoveEntity(int uniqueID);
     122    void doRemoveEntity(int uniqueID);
    93123
    94124    void executeRequestSync( int uniqueID, int user );
     125    void doRequestSync(int uniqueID, int userID);
    95126
    96     BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
    97     void doRemoveEntity(int uniqueID);
    98     void doRequestSync(int uniqueID, int userID);
    99127    void doYouAre( int uniqueID );
     128
     129    void requestPNodePath(const PNode* node1, const PNode* node2);
     130    void executeRequestPNodePath(const PNode* node2, const PNode* node2);
     131    void doRequestPNodePath(const PNode* node1, const PNode* node2);
    100132
    101133    bool canCreateEntity(ClassID classID);
     
    105137    void resizeBufferVector(int n);
    106138
    107     inline bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
    108     inline bool writeToClientBuffer( clientBuffer &cb, byte b );
    109     inline bool writeToClientBuffer( clientBuffer &cb, int i );
    110     inline bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
     139    bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
     140    bool writeToClientBuffer( clientBuffer &cb, byte b );
     141    bool writeToClientBuffer( clientBuffer &cb, int i );
     142    bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
    111143
    112     //helper functions for writeBytes
    113     inline bool handleRequestCreate( int& i, const byte* data, int length, int sender );
    114     inline bool handleRequestRemove( int& i, const byte* data, int length, int sender );
    115     inline bool handleCreateEntity( int& i, const byte* data, int length, int sender );
    116     inline bool handleRemoveEntity( int& i, const byte* data, int length, int sender );
    117     inline bool handleCreateEntityList( int& i, const byte* data, int length, int sender );
    118     inline bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
    119     inline bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
    120     inline bool handleRequestSync( int& i, const byte* data, int length, int sender );
    121144
    122145  private:
     
    124147    //clientBuffer                  allOutBuffer;
    125148    static NetworkGameManager*    singletonRef;
    126 
    127     int                           newUniqueID;
    128149    bool                          hasRequestedWorld;
    129150};
  • trunk/src/lib/network/network_manager.cc

    r6341 r6695  
    2020#define DEBUG_MODULE_NETWORK
    2121
    22 
    23 #include "network_stream.h"
    2422#include "class_list.h"
    25 
    2623#include "debug.h"
    27 
     24#include "shell_command.h"
    2825
    2926/* include your own header */
    3027#include "network_manager.h"
     28#include "shared_network_data.h"
     29#include "network_stream.h"
    3130
    3231
    3332/* using namespace std is default, this needs to be here */
    3433using namespace std;
     34
     35SHELL_COMMAND(debug, NetworkManager, debug);
    3536
    3637
     
    4950  this->netStreamList = NULL;
    5051  this->syncList = NULL;
    51   this->tmpStream = NULL;
    52 
    53   this->hostID = -1;
    54   this->bGameServer = false;
     52  this->defaultSyncStream = NULL;
     53  this->sharedNetworkData = SharedNetworkData::getInstance();
    5554
    5655  PRINTF(0)("NetworkManager created\n");
     
    9897  }
    9998
    100   this->tmpStream = new NetworkStream(ipAddress);
     99  this->defaultSyncStream = new NetworkStream(ipAddress);
     100  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
     101  this->defaultSyncStream->startHandshake();
    101102  return 1;
    102103}
     
    109110int NetworkManager::createServer(unsigned int port)
    110111{
    111   this->hostID = 0;
    112   this->bGameServer = true;
    113   this->tmpStream = new NetworkStream(port);
    114   this->bGameServer = true;
     112  this->sharedNetworkData->setHostID(0);
     113  this->sharedNetworkData->setGameServer(true);
     114  this->defaultSyncStream = new NetworkStream(port);
     115  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
     116  this->defaultSyncStream->createNetworkGameManager();
     117  PRINTF(0)("CREATE SERVER\n");
    115118  SDL_Delay(20);
    116119  return 1;
     
    118121
    119122
    120 /**
    121  *  creates a connection from one object to a host
    122  * @param address: the address of the destination host
    123  * @param synchronizeable: reference to the sync object
    124  */
    125 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
    126 {
    127   /* creating a new network stream, it will register itself automaticaly to the class list */
    128   this->tmpStream = new NetworkStream(address);
    129   this->tmpStream->connectSynchronizeable(sync);
    130 }
    131 
    132 
    133 /**
    134  *  teardown a connection
    135  */
    136 void NetworkManager::shutdownConnection()
    137 {
    138   PRINTF(0)("Shutdown connection\n");
    139 }
    140 
    141 
    142123void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
    143124{
    144   this->tmpStream->connectSynchronizeable(sync);
     125  if( this->defaultSyncStream)
     126    this->defaultSyncStream->connectSynchronizeable(sync);
    145127}
    146128
     
    157139      if( static_cast<NetworkStream*>(*stream)->isActive())
    158140        static_cast<NetworkStream*>(*stream)->processData();
    159 
    160141  }
    161 
    162142}
    163143
     144
     145
    164146/**
    165  * Sets the hostID to a specific number
    166  * @param id: The new ID
     147 * debug output
    167148 */
    168 void NetworkManager::setHostID(int id)
     149 void NetworkManager::debug()
    169150{
    170     this->hostID = id;
     151  PRINT(0)("=================Network::debug()=========\n");
     152  this->defaultSyncStream->debug();
     153  PRINT(0)("===========================================\n");
    171154}
  • trunk/src/lib/network/network_manager.h

    r6341 r6695  
    66/* you will want to add such a a line at your header file also, since it will
    77   prevent c++ from including your code twice*/
    8 #ifndef _NETWORK_MANGER
     8#ifndef _NETWORK_MANAGER
    99#define _NETWORK_MANAGER
    1010
    1111/* include this file, it contains some default definitions */
    1212#include "netdefs.h"
     13#include "shared_network_data.h"
    1314
    1415/* include base_object.h since all classes are derived from this one */
     
    3839    int createServer(unsigned int port);
    3940
    40     NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
    41     void shutdownConnection();
    42 
    43 
    44     void setHostID(int id);
    4541    /** Returns the hostID @return The hostID of the object */
    46     inline int getHostID() { return this->hostID; }
    47     inline bool isGameServer() { return this->bGameServer; }
     42    inline int getHostID() { return this->sharedNetworkData->getHostID(); }
     43    inline bool isGameServer() { return this->sharedNetworkData->isGameServer(); }
    4844
    4945
    5046    void connectSynchronizeable(Synchronizeable& sync);
    5147    void synchronize();
     48
     49    void debug();
     50
    5251
    5352  private:
     
    5958    const std::list<BaseObject*>*    syncList;                // list of synchronizeables
    6059    static NetworkManager*           singletonRef;            //!< Pointer to the only instance of this Class
    61     NetworkStream*                   tmpStream;               //!< FIXME: this is only for testing purposes
    62     int                              hostID;                  //!< The Host-ID of the Manager
    63     bool                             bGameServer;             //!< true if it is a server
     60    NetworkStream*                   defaultSyncStream;       //!< FIXME: this is only for testing purposes
    6461
     62    SharedNetworkData*               sharedNetworkData;       //!< reference to the shared data
    6563};
    6664
  • trunk/src/lib/network/network_socket.cc

    r6634 r6695  
    9797/**
    9898 * Default destructor
     99 * dont use this from outside: use destroy() instead!!
    99100 */
    100101NetworkSocket::~NetworkSocket( )
  • trunk/src/lib/network/network_socket.h

    r6139 r6695  
    8181  void init();
    8282
    83   //dont make this public use destroy() instead
    84   ~NetworkSocket();
    85 
    8683public:
    8784
    8885  NetworkSocket();
     86  ~NetworkSocket();
    8987  NetworkSocket(IPaddress ip);
    9088  NetworkSocket(TCPsocket sock);
  • trunk/src/lib/network/network_stream.cc

    r6634 r6695  
    5353}
    5454
     55
    5556NetworkStream::NetworkStream(IPaddress& address)
    5657{
     
    6061  this->networkProtocol = new NetworkProtocol();
    6162  this->connectionMonitor = new ConnectionMonitor();
    62 
    63   Handshake* hs = new Handshake(false);
    64   hs->setUniqueID( 0 );
    65   this->handshakes.push_back(hs);
    66   this->connectSynchronizeable(*hs);
    67   PRINTF(0)("NetworkStream: %s\n", hs->getName());
    6863  this->maxConnections = 1;
    6964}
     
    8176  this->handshakes.push_back( NULL );
    8277  this->bActive = true;
    83   this->networkGameManager = NetworkGameManager::getInstance();
    84   // setUniqueID( maxCon+2 ) because we need one id for every handshake
    85   // and one for handshake to reject client maxCon+1
    86   this->networkGameManager->setUniqueID( this->maxConnections+2 );
    87   this->connectSynchronizeable( *(this->networkGameManager) );
    88 
    89   this->setMaxConnections( 10 );
    9078}
    9179
     
    132120
    133121
     122void NetworkStream::createNetworkGameManager()
     123{
     124  this->networkGameManager = NetworkGameManager::getInstance();
     125  // setUniqueID( maxCon+2 ) because we need one id for every handshake
     126  // and one for handshake to reject client maxCon+1
     127  this->networkGameManager->setUniqueID( this->maxConnections + 2 );
     128  //this->connectSynchronizeable( *(this->networkGameManager) );
     129  this->setMaxConnections( 10 );
     130}
     131
     132
     133void NetworkStream::startHandshake()
     134{
     135  Handshake* hs = new Handshake(false);
     136  hs->setUniqueID( 0 );
     137  this->handshakes.push_back(hs);
     138  //this->connectSynchronizeable(*hs);
     139  PRINTF(0)("NetworkStream: %s\n", hs->getName());
     140}
     141
     142
    134143void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
    135144{
     
    140149    this->bActive = true;
    141150}
     151
    142152
    143153void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync)
     
    184194          if ( type != NET_SERVER )
    185195          {
    186             NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
     196            SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() );
    187197            myHostId = NetworkManager::getInstance()->getHostID();
    188198
    189199            this->networkGameManager = NetworkGameManager::getInstance();
    190200            this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
    191             this->connectSynchronizeable( *(this->networkGameManager) );
     201            //this->connectSynchronizeable( *(this->networkGameManager) );
    192202          }
    193203          else
     
    216226  /* DOWNSTREAM */
    217227
     228
     229
    218230  int dataLength;
    219231  int reciever;
     
    221233  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    222234  {
    223     if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )
     235    if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ )
    224236    {
    225237      do {
     
    357369    PRINTF(0)("New Client: %d\n", clientId);
    358370
    359     this->connectSynchronizeable(*handshakes[clientId]);
     371    //this->connectSynchronizeable(*handshakes[clientId]);
    360372  }
    361373
     
    416428
    417429
     430
     431void NetworkStream::debug()
     432{
     433  if( this->isServer())
     434    PRINT(0)(" Host ist Server with ID: %i\n", this->myHostId);
     435  else
     436    PRINT(0)(" Host ist Client with ID: %i\n", this->myHostId);
     437
     438  PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size());
     439  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
     440  {
     441    if( (*it)->beSynchronized() == true)
     442      PRINT(0)("  Synchronizeable of class: %s::%s, with unique ID: %i, Synchronize: %i\n", (*it)->getClassName(), (*it)->getName(),
     443               (*it)->getUniqueID(), (*it)->beSynchronized());
     444  }
     445  PRINT(0)(" Maximal Connections: %i\n", this->maxConnections);
     446
     447}
     448
     449
     450int NetworkStream::getSyncCount()
     451{
     452  int n = 0;
     453  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
     454    if( (*it)->beSynchronized() == true)
     455      ++n;
     456
     457  //return synchronizeables.size();
     458  return n;
     459}
     460
     461
     462
     463
     464
     465
  • trunk/src/lib/network/network_stream.h

    r6634 r6695  
    1414#include "server_socket.h"
    1515#include "handshake.h"
    16 
    17 #define MAX_CONNECTIONS 1000
    1816
    1917class Synchronizeable;
     
    4038    void init();
    4139
     40    void createNetworkGameManager();
     41    void startHandshake();
     42
    4243    void connectSynchronizeable(Synchronizeable& sync);
    4344    void disconnectSynchronizeable(Synchronizeable& sync);
     
    5354    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
    5455    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
    55     inline int getSyncCount(){ return synchronizeables.size(); }
     56    int getSyncCount();
    5657
    5758    inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; }
    5859
     60    void debug();
     61
     62
    5963  private:
    60     NetworkProtocol*       networkProtocol;
    61     ConnectionMonitor*     connectionMonitor;
    62     SynchronizeableList    synchronizeables;
    63     NetworkSocketVector    networkSockets;
    64     HandshakeVector        handshakes;
    65     ServerSocket*          serverSocket;
    66     int                    type;
    67     Header                 packetHeader;
    68     bool                   bActive;
    69     std::list<int>         freeSocketSlots;
     64    void updateConnectionList();
    7065
    71     int                    myHostId;
    72     int                    maxConnections;
    7366
    74     NetworkGameManager*   networkGameManager;
     67  private:
     68    NetworkProtocol*           networkProtocol;
     69    ConnectionMonitor*         connectionMonitor;
     70    SynchronizeableList        synchronizeables;
     71    NetworkSocketVector        networkSockets;
     72    HandshakeVector            handshakes;
     73    ServerSocket*              serverSocket;
     74    int                        type;
     75    Header                     packetHeader;
     76    bool                       bActive;
     77    std::list<int>             freeSocketSlots;
    7578
    76     void updateConnectionList();
     79    int                        myHostId;
     80    int                        maxConnections;
     81
     82    NetworkGameManager*        networkGameManager;
    7783};
    7884#endif /* _NETWORK_STREAM */
  • trunk/src/lib/network/synchronizeable.cc

    r6424 r6695  
    1717#define DEBUG_MODULE_NETWORK
    1818
     19#include "shared_network_data.h"
     20#include "network_stream.h"
     21#include "netdefs.h"
     22
     23#include "state.h"
     24
     25#include "assert.h"
     26
    1927#include "synchronizeable.h"
    20 #include "netdefs.h"
    21 #include "network_manager.h"
    22 #include "network_stream.h"
     28
    2329
    2430
     
    2935{
    3036  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
    31   owner = 0;
    32   state = 0;
    33   hostID = NetworkManager::getInstance()->getHostID();
     37  this->owner = 0;
     38  this->state = 0;
     39  this->hostID = SharedNetworkData::getInstance()->getHostID();
    3440  this->setIsServer(this->hostID == 0);
    35   uniqueID = -1;
     41  this->uniqueID = NET_UID_UNASSIGNED;
    3642  this->networkStream = NULL;
    3743  this->setRequestedSync( false );
    3844  this->setIsOutOfSync( !(this->isServer()) );
     45  this->bSynchronize = false;
     46
     47  if( State::isOnline())
     48  {
     49    NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream();
     50    assert(nd != NULL);
     51    nd->connectSynchronizeable(*this);
     52    this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
     53  }
    3954}
    4055
     
    5065}
    5166
     67
    5268/**
    5369 *  write data to NetworkStream
     
    5773  PRINTF(5)("Synchronizeable::writeBytes was called\n");
    5874}
     75
    5976
    6077/**
     
    87104}
    88105
     106
    89107/**
    90108 * Sets the outofsync flag to a given value
     
    100118}
    101119
     120
    102121/**
    103122 * Determines if the server flag is set
     
    108127  return (this->state & STATE_SERVER) >0;
    109128}
     129
    110130
    111131/**
     
    118138}
    119139
     140
    120141/**
    121142 * Determines if the requestedSync flag is set
     
    126147  return (this->state & STATE_REQUESTEDSYNC) >0;
    127148}
     149
    128150
    129151/**
  • trunk/src/lib/network/synchronizeable.h

    r6341 r6695  
    163163
    164164class Synchronizeable : virtual public BaseObject
    165   {
     165{
     166
    166167  public:
    167168    Synchronizeable();
    168     ~Synchronizeable();
     169    virtual ~Synchronizeable();
    169170
    170171    virtual int       writeBytes(const byte* data, int length, int sender);
     
    179180    bool isOutOfSync();
    180181    bool requestedSync();
     182
    181183    inline void setUniqueID( int id ){ uniqueID = id; }
    182     inline int  getUniqueID() const { return uniqueID; };
     184    inline int  getUniqueID() const { return uniqueID; }
     185    inline int getHostID() { return this->hostID; }
     186
     187    inline int getOwner(){ return owner; }
     188    inline void setOwner(int owner){ this->owner = owner; }
     189
     190    /** @returns true if this Synchronizeable has to be synchronized over network */
     191    inline bool beSynchronized() { return this->bSynchronize; }
     192    /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */
     193    inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; }
     194
    183195    inline void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); }
    184196    inline int getRequestSync( void ){ if ( this->synchronizeRequests.size()>0 ){ int n = *(synchronizeRequests.begin()); synchronizeRequests.pop_front(); return n; } else { return -1; } };
    185     inline int getHostID() { return this->hostID; }
    186 
    187     inline int getOwner(){ return owner; }
    188     inline void setOwner(int owner){ this->owner = owner; }
    189197
    190198    inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
     199    inline NetworkStream* getNetworkStream() { return this->networkStream; }
     200
     201
     202  protected:
     203    NetworkStream*    networkStream;
     204    int               state;
     205
    191206
    192207  private:
    193 
    194208    int               uniqueID;
    195 
    196 
    197 
    198     //static std::vector<Synchronizeable*> classList;
    199     int owner;
    200     int hostID;
    201 
    202     std::list<int> synchronizeRequests;
    203 
    204   protected:
    205     NetworkStream* networkStream;
    206     int state;
    207 
    208   };
     209    int               owner;
     210    int               hostID;
     211    bool              bSynchronize;
     212
     213    std::list<int>    synchronizeRequests;
     214
     215};
    209216#endif /* _SYNCHRONIZEABLE_H */
  • trunk/src/orxonox.cc

    r6426 r6695  
    5656
    5757#include "network_manager.h"
     58
     59#include "state.h"
    5860
    5961#include <string.h>
     
    276278
    277279  if( this->serverName != NULL) // we are a client
     280  {
     281    State::setOnline(true);
    278282    NetworkManager::getInstance()->establishConnection(this->serverName, port);
     283  }
    279284  else if( this->port > 0) {    // we are a server
     285    State::setOnline(true);
    280286    NetworkManager::getInstance()->createServer(port);
    281287  }
    282 
    283288  return 0;
    284289}
  • trunk/src/util/state.cc

    r6498 r6695  
    4141Player* State::player = NULL;
    4242
     43bool State::bOnline = false;
    4344
    4445/**
  • trunk/src/util/state.h

    r6498 r6695  
    7373
    7474
     75  ///////////////
     76  /// NETWORK ///
     77  ///////////////
     78  /** sets the online stat (multiplayer network) @param bOnline is true if node is online */
     79  static inline void setOnline(bool bOnline) { State::bOnline = bOnline; }
     80  /** @returns true if this node is online (multiplayer network game) */
     81  static bool isOnline() { return State::bOnline; }
     82
    7583
    7684 private:
     
    8795  static unsigned int           resX;              //!< The X Resolution of the screen.
    8896  static unsigned int           resY;              //!< The Y Resolution of the screen.
     97
     98  static bool                   bOnline;           //!< Is true if this node is in multiplayer mode (via network)
     99
    89100  };
    90101
  • trunk/src/world_entities/environments/water.cc

    r6684 r6695  
    2828#include "skybox.h"
    2929
     30#include "network_game_manager.h"
    3031
    3132using namespace std;
     
    238239  this->grid->rebuildNormals(this->height);
    239240}
     241
     242
     243/**
     244 * Writes data from network containing information about the state
     245 * @param data pointer to data
     246 * @param length length of data
     247 * @param sender hostID of sender
     248 */
     249int Water::writeBytes( const byte * data, int length, int sender )
     250{
     251  setRequestedSync( false );
     252  setIsOutOfSync( false );
     253
     254  SYNCHELP_READ_BEGIN();
     255
     256  SYNCHELP_READ_FKT( Water::writeState );
     257
     258  return SYNCHELP_READ_N;
     259}
     260
     261
     262/**
     263 * data copied in data will bee sent to another host
     264 * @param data pointer to data
     265 * @param maxLength max length of data
     266 * @return the number of bytes writen
     267 */
     268int Water::readBytes( byte * data, int maxLength, int * reciever )
     269{
     270  SYNCHELP_WRITE_BEGIN();
     271
     272  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     273  {
     274    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     275    setRequestedSync( true );
     276  }
     277
     278  int rec = this->getRequestSync();
     279  if ( rec > 0 )
     280  {
     281    *reciever = rec;
     282    SYNCHELP_WRITE_FKT( Water::readState );
     283  }
     284
     285  *reciever = 0;
     286  return SYNCHELP_WRITE_N;
     287}
     288
     289
     290
     291/**
     292 * data copied in data will bee sent to another host
     293 * @param data pointer to data
     294 * @param maxLength max length of data
     295 * @return the number of bytes writen
     296 */
     297int Water::readState( byte * data, int maxLength )
     298{
     299  SYNCHELP_WRITE_BEGIN();
     300
     301  SYNCHELP_WRITE_FKT( WorldEntity::readState );
     302
     303  // sync the size
     304  SYNCHELP_WRITE_FLOAT( this->sizeX );
     305  SYNCHELP_WRITE_FLOAT( this->sizeY );
     306
     307  //sync resolution
     308  SYNCHELP_WRITE_INT( this->resX );
     309  SYNCHELP_WRITE_INT( this->resY );
     310
     311  //sync the height
     312  SYNCHELP_WRITE_FLOAT( this->height );
     313
     314  return SYNCHELP_WRITE_N;
     315}
     316
     317
     318/**
     319 * Writes data from network containing information about the state
     320 * @param data pointer to data
     321 * @param length length of data
     322 * @param sender hostID of sender
     323 */
     324int Water::writeState( const byte * data, int length, int sender )
     325{
     326  SYNCHELP_READ_BEGIN();
     327
     328  SYNCHELP_READ_FKT( WorldEntity::writeState );
     329
     330  float f1, f2;
     331  int i1, i2;
     332
     333  //read the size
     334  SYNCHELP_READ_FLOAT( f1 );
     335  SYNCHELP_READ_FLOAT( f2 );
     336  this->sizeX = f1;
     337  this->sizeY = f2;
     338  PRINTF(0)("Setting Water to size: %f x %f\n", f1, f2);
     339
     340  //read the resolution
     341  SYNCHELP_READ_INT( i1 );
     342  SYNCHELP_READ_INT( i2 );
     343  this->resX = i1;
     344  this->resY = i2;
     345  PRINTF(0)("Setting Water to resolution: %i x %i\n", i1, i2);
     346
     347  //read the height
     348  SYNCHELP_READ_FLOAT( f1 );
     349  this->height = f1;
     350
     351  this->rebuildGrid();
     352
     353  return SYNCHELP_READ_N;
     354}
     355
     356
  • trunk/src/world_entities/environments/water.h

    r6518 r6695  
    3535   void tick(float dt);
    3636
     37   virtual int writeBytes(const byte* data, int length, int sender);
     38   virtual int readBytes(byte* data, int maxLength, int * reciever);
     39
     40   int writeState( const byte * data, int length, int sender );
     41   int readState( byte * data, int maxLength );
     42
     43
    3744  private:
    3845    Grid*           grid;            //!< The water-surface-model to render with
  • trunk/src/world_entities/movie_entity.cc

    r6676 r6695  
    4040  this->toList(OM_COMMON);
    4141
    42   this->loadParams(root);
     42  if( root != NULL)
     43    this->loadParams(root);
    4344
    4445  counter = 0;
     
    5253MovieEntity::~MovieEntity ()
    5354{
    54   delete this->media_container;
     55  if( this->media_container)
     56    delete this->media_container;
    5557}
    5658
  • trunk/src/world_entities/planet.cc

    r6634 r6695  
    2727#include "network_game_manager.h"
    2828#include "converter.h"
     29#include "vertex_array_model.h"
     30#include "primitive_model.h"
    2931
    3032using namespace std;
     
    4446
    4547  this->material = new Material();
    46   this->material->setIllum(10);
     48  //this->material->setIllum(20);
     49  //this->material->setAmbient(0.1, 0.1, 0.1);
     50
     51
     52
     53      //st float radius, const unsigned int loops, const unsigned int segmentsPerLoop
    4754
    4855  this->loadParams(root);
     56
     57//   VertexArrayModel* model = new VertexArrayModel();
     58//   model->spiralSphere(this->size, 10, 10);
     59//   this->setModel(model);
     60//   model->debug();
     61//
     62  PrimitiveModel* model = new PrimitiveModel(PRIM_SPHERE, this->size, 50);
     63  this->setModel(model);
    4964}
    5065
     
    98113{
    99114
     115
    100116  glMatrixMode(GL_MODELVIEW);
    101117  glPushMatrix();
     118
     119  glShadeModel(GL_SMOOTH);
    102120
    103121  /* translate */
     
    109127  this->material->select();
    110128
    111 
    112   Vector c;
    113   double r = this->size;
    114   int n = 200;
    115   int method = 1;
    116   double theta1 = 0;
    117   double theta2 = 2 * M_PI;
    118   double phi1 = -M_PI/2.0;
    119   double phi2 = M_PI/2.0;
    120 
    121 
    122   int i,j;
    123   double jdivn,j1divn,idivn,dosdivn,unodivn=1/(double)n,ndiv2=(double)n/2,t1,t2,t3,cost1,cost2,cte1,cte3;
    124   cte3 = (theta2-theta1)/n;
    125   cte1 = (phi2-phi1)/ndiv2;
    126   dosdivn = 2*unodivn;
    127   Vector e,p,e2,p2;
    128 
    129 
    130   t2=phi1;
    131   cost2=cos(phi1);
    132   j1divn=0;
    133   for (j=0;j<ndiv2;j++) {
    134     t1 = t2;//t1 = phi1 + j * cte1;
    135     t2 += cte1;//t2 = phi1 + (j + 1) * cte1;
    136     t3 = theta1 - cte3;
    137     cost1 = cost2;//cost1=cos(t1);
    138     cost2 = cos(t2);
    139     e.y = sin(t1);
    140     e2.y = sin(t2);
    141     p.y = c.y + r * e.y;
    142     p2.y = c.y + r * e2.y;
    143 
    144     if (method == 0)
    145       glBegin(GL_QUAD_STRIP);
    146     else
    147       glBegin(GL_TRIANGLE_STRIP);
    148 
    149     idivn=0;
    150     jdivn=j1divn;
    151     j1divn+=dosdivn;//=2*(j+1)/(double)n;
    152     for (i=0;i<=n;i++) {
    153        //t3 = theta1 + i * (theta2 - theta1) / n;
    154       t3 += cte3;
    155       e.x = cost1 * cos(t3);
    156        //e.y = sin(t1);
    157       e.z = cost1 * sin(t3);
    158       p.x = c.x + r * e.x;
    159        //p.y = c.y + r * e.y;
    160       p.z = c.z + r * e.z;
    161       glNormal3f(e.x,e.y,e.z);
    162       glTexCoord2f(idivn,jdivn);
    163       glVertex3f(p.x,p.y,p.z);
    164 
    165 
    166       e2.x = cost2 * cos(t3);
    167        //e.y = sin(t2);
    168       e2.z = cost2 * sin(t3);
    169       p2.x = c.x + r * e2.x;
    170        //p.y = c.y + r * e.y;
    171       p2.z = c.z + r * e2.z;
    172       glNormal3f(e2.x,e2.y,e2.z);
    173       glTexCoord2f(idivn,j1divn);
    174       glVertex3f(p2.x,p2.y,p2.z);
    175       idivn += unodivn;
    176     }
    177     glEnd();
    178   }
     129//   /WorldEntity::draw();
     130  this->getModel(0)->draw();
     131 // static_cast<VertexArrayModel*>(this->getModel(0))->debug();
    179132}
    180133
  • trunk/src/world_entities/playable.cc

    r6676 r6695  
    3636  // the reference to the Current Player is NULL, because we dont have one at the beginning.
    3737  this->currentPlayer = NULL;
    38 }
     38
     39  this->setSynchronized(true);
     40}
     41
     42
    3943
    4044Playable::~Playable()
     
    5761}
    5862
     63
    5964void Playable::removeWeapon(Weapon* weapon)
    6065{
     
    6368    this->weaponConfigChanged();
    6469}
     70
    6571
    6672void Playable::nextWeaponConfig()
     
    7076}
    7177
     78
    7279void Playable::previousWeaponConfig()
    7380{
     
    7683}
    7784
     85
    7886void Playable::weaponConfigChanged()
    7987{
     
    8189    this->currentPlayer->weaponConfigChanged();
    8290}
     91
    8392
    8493/**
  • trunk/src/world_entities/power_ups/param_power_up.cc

    r6547 r6695  
    4646{
    4747  this->init();
    48   this->loadParams(root);
     48  if( root != NULL)
     49    this->loadParams(root);
    4950}
    5051
  • trunk/src/world_entities/power_ups/turret_power_up.cc

    r6512 r6695  
    3636  this->init();
    3737
    38   this->loadParams(root);
     38  if( root != NULL)
     39    this->loadParams(root);
    3940}
    4041
  • trunk/src/world_entities/power_ups/weapon_power_up.cc

    r6589 r6695  
    3939{
    4040  this->init();
    41   this->loadParams(root);
     41  if( root != NULL)
     42    this->loadParams(root);
    4243}
    4344
  • trunk/src/world_entities/projectiles/laser.cc

    r6692 r6695  
    3030#include <cassert>
    3131
     32#include "assert.h"
    3233
    3334
  • trunk/src/world_entities/skybox.cc

    r6634 r6695  
    5151  this->preInit();
    5252
    53   this->loadParams(root);
     53  if( root != NULL)
     54    this->loadParams(root);
    5455
    5556  this->postInit();
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6692 r6695  
    9797  if (root != NULL)
    9898    this->loadParams(root);
     99  else
     100  {
     101    this->loadModel("models/ships/reap_#.obj");
     102  }
     103
     104}
     105
     106
     107/**
     108 * initializes a Spaceship
     109 */
     110void SpaceShip::init()
     111{
     112//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
     113  this->setClassID(CL_SPACE_SHIP, "SpaceShip");
     114
     115  PRINTF(4)("SPACESHIP INIT\n");
    99116
    100117  //weapons:
     
    112129
    113130  this->getWeaponManager()->changeWeaponConfig(1);
    114 }
    115 
    116 
    117 /**
    118  * initializes a Spaceship
    119  */
    120 void SpaceShip::init()
    121 {
    122 //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    123   this->setClassID(CL_SPACE_SHIP, "SpaceShip");
    124 
    125   PRINTF(4)("SPACESHIP INIT\n");
    126131
    127132  EventHandler::getInstance()->grabEvents(true);
     
    206211  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
    207212}
     213
    208214
    209215/**
  • trunk/src/world_entities/terrain.cc

    r6512 r6695  
    3939{
    4040  this->init();
    41   this->loadParams(root);
     41  if( root != NULL)
     42    this->loadParams(root);
    4243
    4344//  if (this->model != NULL)
  • trunk/src/world_entities/weapons/targeting_turret.cc

    r6671 r6695  
    4848{
    4949  this->init();
    50   this->loadParams(root);
     50  if( root != NULL)
     51    this->loadParams(root);
    5152}
    5253
  • trunk/src/world_entities/weapons/weapon.cc

    r6671 r6695  
    100100
    101101  this->energyWidget = NULL;
     102
     103  // set this object to be synchronized over network
     104  //this->setSynchronized(true);
    102105}
    103106
  • trunk/src/world_entities/world_entity.cc

    r6634 r6695  
    5454  this->energyMax = 1.0f;
    5555  this->energy = 1.0f;
     56  this->scaling = 1.0f;
     57
     58  /* OSOLETE */
     59  this->bVisible = true;
     60  this->bCollide = true;
    5661
    5762  this->md2TextureFileName = NULL;
    58 
    59 
    60   this->setVisibiliy(true);
    6163
    6264  this->objectListNumber = OM_INIT;
     
    122124void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber)
    123125{
     126  this->modelLODName = fileName;
    124127  this->scaling = scaling;
    125128  if ( fileName != NULL && strcmp(fileName, "") )
     
    515518  //check if modelFileName is relative to datadir or absolute
    516519
     520
     521  PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName, scaling);
     522
    517523  if ( strcmp(modelFileName, "") )
    518524  {
    519     loadModel( modelFileName, scaling );
     525    loadModel( modelFileName, scaling);
     526    PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName());
    520527  }
    521528  delete[] modelFileName;
  • trunk/src/world_entities/world_entity.h

    r6512 r6695  
    111111  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
    112112  const char*             md2TextureFileName; //!< the file name of the md2 model texture, only if this
     113  const char*             modelLODName;       //!< the name of the model lod file
    113114  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
    114115
Note: See TracChangeset for help on using the changeset viewer.