Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6678 in orxonox.OLD for branches/network


Ignore:
Timestamp:
Jan 24, 2006, 10:22:33 PM (19 years ago)
Author:
patrick
Message:

network: sys better now, got less errors and removed the pnode link sync alg, replacing

Location:
branches/network/src
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/class_id.h

    r6634 r6678  
    147147  CL_GLGUI_MAIN_WIDGET          =    0x00000f41,
    148148  CL_NETWORK_MANAGER            =    0x00000f50,
     149  CL_SHARED_NETWORK_DATA        =    0x00000f51,
    149150
    150151
  • branches/network/src/lib/coord/p_node.cc

    r6674 r6678  
    10841084  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    10851085
    1086   int n;
    1087   char * childName;
    1088 
    1089   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]);
    1090   SYNCHELP_READ_INT( n );
    1091   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
    1092 
    1093   for (int i = 0; i<n; i++)
    1094   {
    1095     SYNCHELP_READ_STRINGM( childName );
    1096     PRINTF(0)("RCVD CHILD = %s\n", childName);
    1097     addChild( childName );
    1098     delete childName;
    1099     childName = NULL;
    1100   }
     1086//   int n;
     1087//   char * childName;
     1088//
     1089//   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]);
     1090//   SYNCHELP_READ_INT( n );
     1091//   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
     1092//
     1093//   for (int i = 0; i<n; i++)
     1094//   {
     1095//     SYNCHELP_READ_STRINGM( childName );
     1096//     PRINTF(0)("RCVD CHILD = %s\n", childName);
     1097//     addChild( childName );
     1098//     delete childName;
     1099//     childName = NULL;
     1100//   }
    11011101
    11021102  return SYNCHELP_READ_N;
     
    11351135  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
    11361136
    1137   int n = children.size();
    1138 
    1139   //check if camera is in children
    1140   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1141   {
    1142     if ( (*it)->isA(CL_CAMERA) )
    1143       n--;
    1144   }
    1145   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
    1146   SYNCHELP_WRITE_INT( n );
    1147   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]);
    1148 
    1149   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1150   {
    1151     //dont add camera because there is only one camera attached to local player
    1152     if ( !(*it)->isA(CL_CAMERA) )
    1153     {
    1154       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
    1155       SYNCHELP_WRITE_STRING( (*it)->getName() );
    1156     }
    1157   }
     1137//   int n = children.size();
     1138//   //check if camera is in children
     1139//   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1140//   {
     1141//     if ( (*it)->isA(CL_CAMERA) )
     1142//       n--;
     1143//   }
     1144//   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
     1145//   SYNCHELP_WRITE_INT( n );
     1146//   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]);
     1147//
     1148//
     1149//   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1150//   {
     1151//     //dont add camera because there is only one camera attached to local player
     1152//     if ( !(*it)->isA(CL_CAMERA) )
     1153//     {
     1154//       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
     1155//       SYNCHELP_WRITE_STRING( (*it)->getName() );
     1156//     }
     1157//   }
    11581158
    11591159  return SYNCHELP_WRITE_N;
  • branches/network/src/lib/network/Makefile.am

    r6139 r6678  
    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 \
  • branches/network/src/lib/network/netdefs.h

    r5822 r6678  
    1717
    1818
     19#define MAX_CONNECTIONS 1000
     20
     21
    1922typedef unsigned char byte;
    2023
  • branches/network/src/lib/network/network_game_manager.cc

    r6674 r6678  
    213213  if ( this->isServer())
    214214  {
    215     if ( NetworkManager::getInstance()->getNewUniqueID() < 0 )
     215    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
    216216    {
    217217      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
    218218      return -1;
    219219    }
    220     return this->executeCreateEntity( classID, NetworkManager::getInstance()->getNewUniqueID(), owner );
     220    return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
    221221  }
    222222  else
     
    237237  if ( this->isServer() )
    238238  {
    239     if ( NetworkManager::getInstance()->getNewUniqueID() < 0 )
     239    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
    240240    {
    241241      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
     
    255255    {
    256256      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
    257       s->setUniqueID( NetworkManager::getInstance()->getNewUniqueID() );
     257      s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    258258      s->setOwner( 0 );
    259259      // all entities created via this function are added automaticaly to the synchronizeable list
  • branches/network/src/lib/network/network_manager.cc

    r6672 r6678  
    2020#define DEBUG_MODULE_NETWORK
    2121
    22 
    23 #include "network_stream.h"
    2422#include "class_list.h"
    25 
    2623#include "debug.h"
    2724#include "shell_command.h"
     
    2926/* include your own header */
    3027#include "network_manager.h"
     28#include "shared_network_data.h"
     29#include "network_stream.h"
    3130
    3231
     
    5251  this->syncList = NULL;
    5352  this->defaultSyncStream = NULL;
    54 
    55   this->hostID = -1;
    56   this->newUniqueID = MAX_CONNECTIONS + 2;
    57   this->bGameServer = false;
     53  this->sharedNetworkData = SharedNetworkData::getInstance();
    5854
    5955  PRINTF(0)("NetworkManager created\n");
     
    10298
    10399  this->defaultSyncStream = new NetworkStream(ipAddress);
     100  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
    104101  this->defaultSyncStream->startHandshake();
    105102  return 1;
     
    113110int NetworkManager::createServer(unsigned int port)
    114111{
    115   this->hostID = 0;
    116   this->bGameServer = true;
     112  this->sharedNetworkData->setHostID(0);
     113  this->sharedNetworkData->setGameServer(true);
    117114  this->defaultSyncStream = new NetworkStream(port);
     115  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
    118116  this->defaultSyncStream->createNetworkGameManager();
    119117  PRINTF(0)("CREATE SERVER\n");
    120   this->bGameServer = true;
    121118  SDL_Delay(20);
    122119  return 1;
    123 }
    124 
    125 
    126 /**
    127  *  creates a connection from one object to a host
    128  * @param address: the address of the destination host
    129  * @param synchronizeable: reference to the sync object
    130  */
    131 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
    132 {
    133   /* creating a new network stream, it will register itself automaticaly to the class list */
    134   this->defaultSyncStream = new NetworkStream(address);
    135   this->defaultSyncStream->connectSynchronizeable(sync);
    136 }
    137 
    138 
    139 /**
    140  *  teardown a connection
    141  */
    142 void NetworkManager::shutdownConnection()
    143 {
    144   PRINTF(0)("Shutdown connection\n");
    145120}
    146121
     
    167142}
    168143
    169 /**
    170  * Sets the hostID to a specific number
    171  * @param id: The new ID
    172  */
    173 void NetworkManager::setHostID(int id)
    174 {
    175     this->hostID = id;
    176 }
    177 
    178144
    179145
  • branches/network/src/lib/network/network_manager.h

    r6673 r6678  
    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();
    52 
    53     inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; }
    54 
    55     /** @returns the next uniqueID free for an object */
    56     inline int getNewUniqueID() { return ( this->bGameServer)?this->newUniqueID++:-1; }
    5748
    5849    void debug();
     
    6859    static NetworkManager*           singletonRef;            //!< Pointer to the only instance of this Class
    6960    NetworkStream*                   defaultSyncStream;       //!< FIXME: this is only for testing purposes
    70     int                              hostID;                  //!< The Host-ID of the Manager
    71     bool                             bGameServer;             //!< true if it is a server
    72     int                              newUniqueID;
    7361
     62    SharedNetworkData*               sharedNetworkData;       //!< reference to the shared data
    7463};
    7564
  • branches/network/src/lib/network/network_stream.cc

    r6673 r6678  
    194194          if ( type != NET_SERVER )
    195195          {
    196             NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
     196            SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() );
    197197            myHostId = NetworkManager::getInstance()->getHostID();
    198198
  • branches/network/src/lib/network/network_stream.h

    r6672 r6678  
    1414#include "server_socket.h"
    1515#include "handshake.h"
    16 
    17 #define MAX_CONNECTIONS 1000
    1816
    1917class Synchronizeable;
  • branches/network/src/lib/network/synchronizeable.cc

    r6675 r6678  
    1717#define DEBUG_MODULE_NETWORK
    1818
    19 #include "synchronizeable.h"
    20 
    21 #include "network_manager.h"
     19#include "shared_network_data.h"
    2220#include "network_stream.h"
    2321#include "netdefs.h"
    2422
    2523#include "assert.h"
     24
     25#include "synchronizeable.h"
     26
    2627
    2728
     
    3435  this->owner = 0;
    3536  this->state = 0;
    36   this->hostID = NetworkManager::getInstance()->getHostID();
     37  this->hostID = SharedNetworkData::getInstance()->getHostID();
    3738  this->setIsServer(this->hostID == 0);
    3839  this->uniqueID = -1;
     
    4041  this->setRequestedSync( false );
    4142  this->setIsOutOfSync( !(this->isServer()) );
    42 
    4343  this->bSynchronize = false;
    4444
    45   NetworkStream* nd = NetworkManager::getInstance()->getDefaultSyncStream();
     45  NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream();
    4646  assert(nd != NULL);
    4747  nd->connectSynchronizeable(*this);
    48   this->setUniqueID(NetworkManager::getInstance()->getNewUniqueID());
     48  this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
    4949}
    5050
  • branches/network/src/world_entities/movie_entity.cc

    r6675 r6678  
    5656MovieEntity::~MovieEntity ()
    5757{
    58   delete this->media_container;
     58  if( this->media_container)
     59    delete this->media_container;
    5960}
    6061
Note: See TracChangeset for help on using the changeset viewer.