Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6250 in orxonox.OLD


Ignore:
Timestamp:
Dec 21, 2005, 4:29:15 PM (18 years ago)
Author:
patrick
Message:

network: network game manager now sounds good

Location:
branches/network/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_game_manager.cc

    r6238 r6250  
    3838NetworkGameManager::NetworkGameManager()
    3939{
     40  PRINTF(0)("START\n");
     41
    4042  /* set the class id for the base object */
    4143  this->setClassID(CL_ENTITY_MANAGER, "EntityManager");
     
    204206}
    205207
     208
     209/*!
     210 * Checks whether this is connected to a server or a client
     211 * and afterwards creates the needed entity
     212 * @param classID: The ID of the class of which an entity should be created
     213 */
     214BaseObject* NetworkGameManager::createEntity( TiXmlElement* element)
     215{
     216  if ( this->isServer() )
     217  {
     218    if ( newUniqueID < 0 )
     219    {
     220      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
     221      return NULL;
     222    }
     223    newUniqueID++;
     224
     225    BaseObject * b = Factory::fabricate( element );
     226
     227    if ( !b )
     228    {
     229      PRINTF(1)("Could not fabricate Object with classID %x\n", element->Value() );
     230      return NULL;
     231    }
     232
     233    if ( b->isA(CL_SYNCHRONIZEABLE) )
     234    {
     235      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
     236      s->setUniqueID( newUniqueID );
     237      s->setOwner( 0 );
     238      this->networkStream->connectSynchronizeable( *s );
     239      return b;
     240    }
     241    else
     242    {
     243      PRINTF(1)("Class %s is not a synchronizeable!\n", b->getClassName() );
     244      delete b;
     245    }
     246  }
     247  else
     248  {
     249    PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value());
     250  }
     251  return NULL;
     252}
     253
     254
    206255/*!
    207256 * Checks whether this is connected to a server or a client
  • branches/network/src/lib/network/network_game_manager.h

    r6238 r6250  
    1414
    1515
     16class TiXmlElement;
    1617
    1718/**
     
    7273
    7374    void createEntity( ClassID classID, int owner = 0 );
     75    BaseObject* createEntity( TiXmlElement* element);
    7476    void removeEntity( int uniqueID );
    7577    void sendYouAre( int uniqueID, int userID );
  • branches/network/src/lib/network/network_manager.cc

    r6239 r6250  
    4444  /* set the class id for the base object */
    4545  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
     46  PRINTF(0)("START\n");
    4647
    4748  /* initialize the references */
     
    4950  this->syncList = NULL;
    5051  this->tmpStream = NULL;
     52
    5153  this->hostID = -1;
    5254  this->bGameServer = false;
     
    107109int NetworkManager::createServer(unsigned int port)
    108110{
     111  this->hostID = 0;
     112  this->bGameServer = true;
    109113  this->tmpStream = new NetworkStream(port);
    110114  this->bGameServer = true;
     
    124128  this->tmpStream = new NetworkStream(address);
    125129  this->tmpStream->connectSynchronizeable(sync);
    126 }
    127 
    128 
    129 /**
    130  *  creates a new NetworkStream of server type
    131  * @param sync: the listener
    132  */
    133 NetworkStream& NetworkManager::createServer(Synchronizeable& sync, unsigned int port)
    134 {
    135   PRINTF(0)("Create a new server socket\n");
    136   /* creating a new network stream, it will register itself automaticaly to the class list */
    137   this->tmpStream = new NetworkStream(port);
    138   this->tmpStream->connectSynchronizeable(sync);
    139   this->bGameServer = true;
    140130}
    141131
     
    178168void NetworkManager::setHostID(int id)
    179169{
    180   this->hostID = id;
     170    this->hostID = id;
    181171}
  • branches/network/src/lib/network/network_manager.h

    r6139 r6250  
    3939
    4040    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
    41     NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
    4241    void shutdownConnection();
    4342
  • branches/network/src/lib/network/synchronizeable.cc

    r6190 r6250  
    2828Synchronizeable::Synchronizeable()
    2929{
    30 
     30  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
    3131  owner = 0;
    3232  hostID = NetworkManager::getInstance()->getHostID();
     33  this->setIsServer(this->hostID == 0);
     34  PRINTF(0)("sync created,id %i\n", this->hostID);
    3335  uniqueID = -1;
    3436  this->networkStream = NULL;
     
    3739}
    3840
    39 /**
    40  *  default constructor
    41  */
    42 Synchronizeable::Synchronizeable(const char* name)
    43 {
    44   this->setName(name);
    45   this->networkStream = NULL;
    46 }
    4741
    4842
  • branches/network/src/lib/network/synchronizeable.h

    r6190 r6250  
    2525  {
    2626  public:
    27 
    28     Synchronizeable(const char* name);
    2927    Synchronizeable();
    3028    ~Synchronizeable();
  • branches/network/src/story_entities/network_world.cc

    r6239 r6250  
    7070#include "playable.h"
    7171#include "network_manager.h"
     72#include "network_game_manager.h"
    7273#include "playable.h"
    7374
     
    168169{
    169170  this->setClassID(CL_WORLD, "NetworkWorld");
     171  PRINTF(0)("START\n");
    170172
    171173  this->setName(name);
     
    354356      {
    355357
    356         BaseObject* created = Factory::fabricate(element);
     358        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
    357359        if( created != NULL )
    358360        {
     
    361363          printf("Created a %s: %s\n", created->getClassName(), created->getName());
    362364        }
     365        else
     366          PRINTF(1)("NetworkWorld: could not create this entity\n");
    363367
    364368          // if we load a 'Player' we use it as localPlayer
     
    442446//   this->spawn(testEntity);
    443447
    444   for(int i = 0; i < 100; i++)
    445   {
    446     WorldEntity* tmp = new NPCTest1();
    447     char npcChar[10];
    448     sprintf (npcChar, "NPC_%d", i);
    449         tmp->setName(npcChar);
    450     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    451     this->spawn(tmp);
    452   }
     448//   for(int i = 0; i < 100; i++)
     449//   {
     450//     WorldEntity* tmp = NetworkGameManager::;
     451//     char npcChar[10];
     452//     sprintf (npcChar, "NPC_%d", i);
     453//         tmp->setName(npcChar);
     454//     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
     455//     this->spawn(tmp);
     456//   }
    453457
    454458  this->music = NULL;
  • branches/network/src/util/loading/factory.cc

    r6240 r6250  
    155155}
    156156
     157
    157158/**
    158159 * Creates a new Object of type classID
Note: See TracChangeset for help on using the changeset viewer.