Changeset 6250 in orxonox.OLD for branches/network
- Timestamp:
- Dec 21, 2005, 4:29:15 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_game_manager.cc
r6238 r6250 38 38 NetworkGameManager::NetworkGameManager() 39 39 { 40 PRINTF(0)("START\n"); 41 40 42 /* set the class id for the base object */ 41 43 this->setClassID(CL_ENTITY_MANAGER, "EntityManager"); … … 204 206 } 205 207 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 */ 214 BaseObject* 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 206 255 /*! 207 256 * Checks whether this is connected to a server or a client -
branches/network/src/lib/network/network_game_manager.h
r6238 r6250 14 14 15 15 16 class TiXmlElement; 16 17 17 18 /** … … 72 73 73 74 void createEntity( ClassID classID, int owner = 0 ); 75 BaseObject* createEntity( TiXmlElement* element); 74 76 void removeEntity( int uniqueID ); 75 77 void sendYouAre( int uniqueID, int userID ); -
branches/network/src/lib/network/network_manager.cc
r6239 r6250 44 44 /* set the class id for the base object */ 45 45 this->setClassID(CL_NETWORK_MANAGER, "NetworkManager"); 46 PRINTF(0)("START\n"); 46 47 47 48 /* initialize the references */ … … 49 50 this->syncList = NULL; 50 51 this->tmpStream = NULL; 52 51 53 this->hostID = -1; 52 54 this->bGameServer = false; … … 107 109 int NetworkManager::createServer(unsigned int port) 108 110 { 111 this->hostID = 0; 112 this->bGameServer = true; 109 113 this->tmpStream = new NetworkStream(port); 110 114 this->bGameServer = true; … … 124 128 this->tmpStream = new NetworkStream(address); 125 129 this->tmpStream->connectSynchronizeable(sync); 126 }127 128 129 /**130 * creates a new NetworkStream of server type131 * @param sync: the listener132 */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;140 130 } 141 131 … … 178 168 void NetworkManager::setHostID(int id) 179 169 { 180 this->hostID = id;170 this->hostID = id; 181 171 } -
branches/network/src/lib/network/network_manager.h
r6139 r6250 39 39 40 40 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 41 NetworkStream& createServer(Synchronizeable& sync, unsigned int port);42 41 void shutdownConnection(); 43 42 -
branches/network/src/lib/network/synchronizeable.cc
r6190 r6250 28 28 Synchronizeable::Synchronizeable() 29 29 { 30 30 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 31 31 owner = 0; 32 32 hostID = NetworkManager::getInstance()->getHostID(); 33 this->setIsServer(this->hostID == 0); 34 PRINTF(0)("sync created,id %i\n", this->hostID); 33 35 uniqueID = -1; 34 36 this->networkStream = NULL; … … 37 39 } 38 40 39 /**40 * default constructor41 */42 Synchronizeable::Synchronizeable(const char* name)43 {44 this->setName(name);45 this->networkStream = NULL;46 }47 41 48 42 -
branches/network/src/lib/network/synchronizeable.h
r6190 r6250 25 25 { 26 26 public: 27 28 Synchronizeable(const char* name);29 27 Synchronizeable(); 30 28 ~Synchronizeable(); -
branches/network/src/story_entities/network_world.cc
r6239 r6250 70 70 #include "playable.h" 71 71 #include "network_manager.h" 72 #include "network_game_manager.h" 72 73 #include "playable.h" 73 74 … … 168 169 { 169 170 this->setClassID(CL_WORLD, "NetworkWorld"); 171 PRINTF(0)("START\n"); 170 172 171 173 this->setName(name); … … 354 356 { 355 357 356 BaseObject* created = Factory::fabricate(element);358 BaseObject* created = NetworkGameManager::getInstance()->createEntity(element); 357 359 if( created != NULL ) 358 360 { … … 361 363 printf("Created a %s: %s\n", created->getClassName(), created->getName()); 362 364 } 365 else 366 PRINTF(1)("NetworkWorld: could not create this entity\n"); 363 367 364 368 // if we load a 'Player' we use it as localPlayer … … 442 446 // this->spawn(testEntity); 443 447 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 // } 453 457 454 458 this->music = NULL; -
branches/network/src/util/loading/factory.cc
r6240 r6250 155 155 } 156 156 157 157 158 /** 158 159 * Creates a new Object of type classID
Note: See TracChangeset
for help on using the changeset viewer.