- Timestamp:
- Jun 1, 2006, 2:28:16 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 24 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r8035 r8068 134 134 CL_GAME_WORLD_DATA = 0x00102000, 135 135 CL_GAME_RULES = 0x00104000, 136 CL_MISSION_GOAL = 0x00105000, 136 CL_NETWORK_GAME_RULES = 0x00108000, 137 CL_MISSION_GOAL = 0x00110000, 137 138 138 139 CL_CAMPAIGN = 0x00000101, … … 146 147 CL_MOVIE_LOADER = 0x00000109, 147 148 148 CL_MULTIPLAYER_TEAM_DEATHMATCH= 0x00 104001,149 CL_SINGLEPLAYER_SHOOTEMUP = 0x00 104002,149 CL_MULTIPLAYER_TEAM_DEATHMATCH= 0x00000121, 150 CL_SINGLEPLAYER_SHOOTEMUP = 0x00000122, 150 151 151 152 CL_KILL_TARGET = 0x00105001, … … 189 190 CL_HOVER = 0x0000035e, 190 191 CL_TURBINE_HOVER = 0x0000035f, 192 CL_SPECTATOR = 0x00000360, 191 193 192 194 // Powerups … … 368 370 CL_NETWORK_GAME_MANAGER = 0x00000d07, 369 371 CL_MESSAGE_MANAGER = 0x00000d08, 370 CL_SIMPLE_SYNC = 0x00000d09, 372 CL_PLAYER_STATS = 0x00000d09, 373 CL_SIMPLE_SYNC = 0x00000d0a, 371 374 372 375 -
trunk/src/lib/graphics/importer/height_map.cc
r7954 r8068 134 134 w = yOffset; 135 135 136 PRINTF(0)("Values: i = %i, w = %i\n", i, w);136 // PRINTF(0)("Values: i = %i, w = %i\n", i, w); 137 137 138 138 // add a vertex to the list … … 599 599 float c = normalVectorField [(xInt)][yInt].y; 600 600 601 PRINTF(0)("a: %f \n" ,a);602 PRINTF(0)("b: %f \n" ,b);603 PRINTF(0)("c: %f \n" ,c);601 // PRINTF(0)("a: %f \n" ,a); 602 // PRINTF(0)("b: %f \n" ,b); 603 // PRINTF(0)("c: %f \n" ,c); 604 604 605 605 -
trunk/src/lib/network/Makefile.am
r7954 r8068 23 23 network_log.cc \ 24 24 zip.cc \ 25 player_stats.cc \ 25 26 \ 26 27 synchronizeable_var/synchronizeable_var.cc \ … … 56 57 network_log.h \ 57 58 zip.h \ 59 player_stats.h \ 58 60 \ 59 61 synchronizeable_var/synchronizeable_var.h \ -
trunk/src/lib/network/connection_monitor.cc
r7954 r8068 61 61 * @param stateId packet's state id 62 62 */ 63 void ConnectionMonitor::processUnzippedOutgoingPacket( byte * data, int length, int stateId ) 64 { 65 int tick = SDL_GetTicks(); 66 63 void ConnectionMonitor::processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ) 64 { 67 65 nOutgoingPackets++; 68 66 … … 77 75 78 76 // count zero bytes 79 int nZeroBytes = 0;80 81 for ( int i = 0; i < length; i++ )82 if ( data[i] == '\0' )83 nZeroBytes++;77 //int nZeroBytes = 0; 78 79 //for ( int i = 0; i < length; i++ ) 80 // if ( data[i] == '\0' ) 81 // nZeroBytes++; 84 82 85 83 //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length ); … … 93 91 * @param ackedState state which was acked by this packet 94 92 */ 95 void ConnectionMonitor::processUnzippedIncomingPacket( byte * data, int length, int stateId, int ackedState ) 96 { 97 int tick = SDL_GetTicks(); 98 93 void ConnectionMonitor::processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ) 94 { 99 95 nIncomingPackets++; 100 96 … … 149 145 for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 150 146 { 151 res += it->second; 147 if ( it != packetHistory.begin() ) 148 res += it->second; 152 149 } 153 150 … … 155 152 res = 0.0f; 156 153 else 157 res /= (float)( (tick - packetHistory.begin()->first)*( 1 + 1/((float)(packetHistory.size()-1)) ));154 res /= (float)(tick - packetHistory.begin()->first); 158 155 159 156 res *= 1000.0f; … … 169 166 * @param stateId packet's state id 170 167 */ 171 void ConnectionMonitor::processZippedOutgoingPacket( byte * data, int length, int stateId ) 172 { 173 int tick = SDL_GetTicks(); 174 168 void ConnectionMonitor::processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ) 169 { 175 170 nZOutgoingPackets++; 176 171 … … 196 191 * @param ackedState state which was acked by this packet 197 192 */ 198 void ConnectionMonitor::processZippedIncomingPacket( byte * data, int length, int stateId, int ackedState ) 199 { 200 int tick = SDL_GetTicks(); 201 193 void ConnectionMonitor::processZippedIncomingPacket( int tick, byte * data, int length ) 194 { 202 195 nZIncomingPackets++; 203 196 … … 233 226 void ConnectionMonitor::printStatis( ) 234 227 { 235 NETPRINT(n)("========= NETWORKSTATS FOR USER %d=========\n", userId);236 NETPRINT(n)("PING = %d\n", ping );228 NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId); 229 NETPRINT(n)("PING = %d\n", ping ); 237 230 NETPRINT(n)("BANDWIDTH: UP: %f (%f) DOWN %f (%f)\n", outgoingZippedBandWidth, outgoingUnzippedBandWidth, incomingZippedBandWidth, incomingUnzippedBandWidth); 238 NETPRINT(n)("=========================================="); 239 } 240 241 231 NETPRINT(n)("PACKETS: RECIEVED %d; SENT %d\n", nIncomingPackets, nOutgoingPackets ); 232 NETPRINT(n)("================================================\n"); 233 } 234 235 -
trunk/src/lib/network/connection_monitor.h
r7954 r8068 22 22 virtual ~ConnectionMonitor(); 23 23 24 void processUnzippedOutgoingPacket( byte * data, int length, int stateId );25 void processUnzippedIncomingPacket( byte * data, int length, int stateId, int ackedState );24 void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); 25 void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); 26 26 27 void processZippedOutgoingPacket( byte * data, int length, int stateId );28 void processZippedIncomingPacket( byte * data, int length, int stateId, int ackedState);27 void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); 28 void processZippedIncomingPacket( int tick, byte * data, int length ); 29 29 30 30 void calculatePing(); -
trunk/src/lib/network/message_manager.cc
r7954 r8068 309 309 { 310 310 if ( 311 recieverType == RT_ALL || 311 recieverType == RT_ALL_ME || 312 recieverType == RT_ALL_NOT_ME || 312 313 recieverType == RT_USER && it->first == reciever || 313 314 recieverType == RT_NOT_USER && it->first != reciever … … 324 325 325 326 it->second.messages.push_back( msg ); 326 } 327 } 328 } 329 330 327 328 if ( recieverType == RT_ALL_ME ) 329 incomingMessabeBuffer.push_back( msg ); 330 } 331 } 332 } 333 334 -
trunk/src/lib/network/message_manager.h
r7954 r8068 29 29 { 30 30 TESTMESSAGEID = 1, 31 MSGID_ YOU_ARE31 MSGID_DELETESYNCHRONIZEABLE 32 32 }; 33 33 … … 36 36 enum RecieverType 37 37 { 38 RT_ALL = 1, //!< message is sent to all users 39 RT_USER, //!< message is only sent to reciever 40 RT_NOT_USER //!< message is sent to all but reciever 38 RT_ALL_NOT_ME = 1, //!< message is sent to all users 39 RT_ALL_ME, //!< message is sent to all users 40 RT_USER, //!< message is only sent to reciever 41 RT_NOT_USER //!< message is sent to all but reciever 41 42 }; 42 43 -
trunk/src/lib/network/network_game_manager.cc
r7954 r8068 34 34 #include "game_world.h" 35 35 36 #include "game_rules.h" 37 #include "network_game_rules.h" 38 36 39 #include "network_game_manager.h" 37 40 … … 55 58 this->setSynchronized(true); 56 59 57 MessageManager::getInstance()->registerMessageHandler( MSGID_YOU_ARE, youAreHandler, NULL ); 60 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 61 62 this->gameState = 0; 63 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); 58 64 } 59 65 … … 63 69 NetworkGameManager::~NetworkGameManager() 64 70 { 65 #if 066 for ( int i = 0; i<outBuffer.size(); i++)67 {68 if ( outBuffer[i].buffer )69 delete outBuffer[i].buffer;70 }71 #endif72 73 }74 75 #if 076 int NetworkGameManager::writeBytes(const byte* data, int length, int sender)77 {78 int i = 0;79 byte b;80 81 while ( i<length )82 {83 b = data[i++];84 85 /**************** Commands only processed by servers ****************/86 if ( isServer() )87 {88 if ( b == NET_REQUEST_CREATE )89 {90 if ( !handleRequestCreate( i, data, length, sender ) )91 return i;92 continue;93 }94 else if ( b == NET_REQUEST_REMOVE )95 {96 if ( !handleRequestRemove( i, data, length, sender ) )97 return i;98 continue;99 }100 else if ( b == NET_REQUEST_PNODE_PATH )101 {102 if ( !handleRequestPNodePath( i, data, length, sender ) )103 return i;104 continue;105 }106 }107 else108 {109 /**************** Commands only processed by clients ****************/110 if ( b == NET_CREATE_ENTITY )111 {112 PRINTF(0)("CREATE_ENTITY\n");113 if ( !handleCreateEntity( i, data, length, sender ) )114 return i;115 continue;116 }117 else if ( b == NET_REMOVE_ENTITY )118 {119 if ( !handleRemoveEntity( i, data, length, sender ) )120 return i;121 continue;122 }123 else if ( b == NET_CREATE_ENTITY_LIST )124 {125 if ( !handleCreateEntityList( i, data, length, sender ) )126 return i;127 continue;128 }129 else if ( b == NET_REMOVE_ENTITY_LIST )130 {131 if ( !handleRemoveEntityList( i, data, length, sender ) )132 return i;133 continue;134 }135 else if ( b == NET_YOU_ARE_ENTITY )136 {137 if ( !handleYouAreEntity( i, data, length, sender ) )138 return i;139 continue;140 }141 }142 143 /**************** Commands processed by servers and clients ****************/144 if ( b == NET_REQUEST_ENTITY_LIST )145 {146 sendEntityList( sender );147 continue;148 }149 150 151 PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender);152 PRINTF(1)("Probably this is because the network protocol has different \n");153 PRINTF(1)("versions or there occured an error in the sending algorithm\n");154 PRINTF(1)("Data is not in the right format! i=%d\n", i);155 return i;156 }157 158 return i;159 }160 #endif161 162 #if 0163 int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever)164 {165 if ( !isServer() && !hasRequestedWorld )166 {167 assert( maxLength >= 1 );168 data[0] = NET_REQUEST_ENTITY_LIST;169 hasRequestedWorld = true;170 return 1;171 }172 173 for ( int i = 0; i<outBuffer.size(); i++ )174 {175 *reciever = i;176 if ( outBuffer[i].length>0 )177 {178 int nbytes = outBuffer[i].length;179 outBuffer[i].length = 0;180 181 if ( nbytes > maxLength )182 {183 PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.maxLength\n", nbytes, maxLength);184 return 0;185 }186 187 memcpy(data, outBuffer[i].buffer, nbytes);188 return nbytes;189 }190 }191 192 return 0;193 }194 #endif195 196 #if 0197 void NetworkGameManager::writeDebug() const198 {199 }200 201 void NetworkGameManager::readDebug() const202 {203 }204 #endif205 206 207 /*!208 * Checks whether this is connected to a server or a client209 * and afterwards creates the needed entity210 * @param classID: The ID of the class of which an entity should be created211 */212 int NetworkGameManager::createEntity( ClassID classID, int owner )213 {214 if ( this->isServer())215 {216 int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );217 218 if ( res < 0 )219 {220 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");221 return -1;222 }223 224 return res;225 }226 else227 {228 #if 0229 this->requestCreateEntity( classID );230 #endif231 return -1;232 }233 71 } 234 72 235 73 236 /* !237 * Checks whether this is connected to a server or a client238 * and afterwards creates the needed entity239 * @ param classID: The ID of the class of which an entity should be created74 /** 75 * insert new player into game 76 * @param userId 77 * @return 240 78 */ 241 BaseObject* NetworkGameManager::createEntity(const TiXmlElement* element)79 bool NetworkGameManager::signalNewPlayer( int userId ) 242 80 { 243 if ( this->isServer() ) 244 { 245 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 246 { 247 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); 248 return NULL; 249 } 250 251 BaseObject * b = Factory::fabricate( element ); 252 253 if ( !b ) 254 { 255 PRINTF(1)("Could not fabricate Object with className %s\n", element->Value() ); 256 return NULL; 257 } 258 259 260 if ( b->isA(CL_SYNCHRONIZEABLE) ) 261 { 262 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 263 s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 264 s->setOwner( 0 ); 265 // all entities created via this function are added automaticaly to the synchronizeable list 266 s->setSynchronized(true); 267 return b; 268 } 269 else 270 { 271 PRINTF(1)("Class %s is not a synchronizeable!\n", b->getClassName() ); 272 delete b; 273 } 274 275 } 276 else 277 278 { 279 PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value()); 280 } 281 return NULL; 81 assert( SharedNetworkData::getInstance()->isGameServer() ); 82 assert( State::getGameRules() ); 83 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 84 85 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 86 87 int team = rules.getTeamForNewUser(); 88 ClassID playableClassId = rules.getPlayableClassId( team ); 89 std::string playableModel = rules.getPlayableModelFileName( team, playableClassId ); 90 91 BaseObject * bo = Factory::fabricate( playableClassId ); 92 93 assert( bo != NULL ); 94 assert( bo->isA( CL_PLAYABLE ) ); 95 96 Playable & playable = *(dynamic_cast<Playable*>(bo)); 97 98 playable.loadModel( playableModel ); 99 playable.setOwner( userId ); 100 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 101 playable.setSynchronized( true ); 102 103 PlayerStats * stats = rules.getNewPlayerStats( userId ); 104 105 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 106 stats->setSynchronized( true ); 107 stats->setOwner( getHostID() ); 108 109 stats->setTeamId( team ); 110 stats->setPlayableClassId( playableClassId ); 111 stats->setPlayableUniqueId( playable.getUniqueID() ); 112 stats->setModelFileName( playableModel ); 282 113 } 283 114 284 115 285 /* !286 * Checks whether this is connected to a server or a client287 * and afterwards removes the specified entity288 * @ param uniqueID: The ID of the entity object which should be removed116 /** 117 * remove player from game 118 * @param userID 119 * @return 289 120 */ 290 void NetworkGameManager::removeEntity(int uniqueID)121 bool NetworkGameManager::signalLeftPlayer(int userID) 291 122 { 292 if ( this->isServer() ) 293 { 294 this->executeRemoveEntity( uniqueID ); 295 } 296 else 297 { 298 #if 0 299 this->requestRemoveEntity( uniqueID ); 300 #endif 301 } 302 } 303 304 305 #if 0 306 /*! 307 * Creates the needed entity on the server if possible 308 * @param classID: The ID of the class of which an entity should be created 309 */ 310 void NetworkGameManager::requestCreateEntity(ClassID classID) 311 { 312 for ( int i = 0; i<outBuffer.size(); i++) 313 { 314 if ( !this->networkStream->isUserIdActive( i ) ) 315 continue; 316 317 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) ) 318 return; 319 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 320 return; 321 } 322 } 323 #endif 324 325 #if 0 326 /*! 327 * Removes the specified entity on the server 328 * @param uniqueID: The ID of the entity object which should be removed 329 */ 330 void NetworkGameManager::requestRemoveEntity(int uniqueID) 331 { 332 for ( int i = 0; i<outBuffer.size(); i++) 333 { 334 if ( !this->networkStream->isUserIdActive( i ) ) 335 continue; 336 337 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) ) 338 return; 339 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 340 return; 341 } 342 } 343 #endif 344 345 /*! 346 * Creates the needed entity if possible 347 * This function is called if this is a server 348 * @param classID: The ID of the class of which an entity should be created 349 */ 350 int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) 351 { 352 #if 0 353 for ( int i = 0; i<outBuffer.size(); i++) 354 { 355 if ( !this->networkStream->isUserIdActive( i ) ) 356 continue; 357 358 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) ) 359 return -1; 360 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 361 return -1; 362 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 363 return -1; 364 if ( !writeToClientBuffer( outBuffer[i], owner ) ) 365 return -1; 366 } 367 #endif 368 PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 369 doCreateEntity( classID, uniqueID, owner ); 370 371 return uniqueID; 372 } 373 374 /*! 375 * Removes the specified entity 376 * This function is called if this is a server 377 * @param uniqueID: The ID of the entity object which should be removed 378 */ 379 void NetworkGameManager::executeRemoveEntity(int uniqueID) 380 { 381 #if 0 382 for ( int i = 0; i<outBuffer.size(); i++) 383 { 384 if ( !this->networkStream->isUserIdActive( i ) ) 385 continue; 386 387 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) ) 388 return; 389 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 390 return; 391 } 392 #endif 393 394 doRemoveEntity(uniqueID); 395 } 396 397 /*! 398 * Checks whether it is possible to create an entity of a given class 399 * @return: true if the entity can be created, false otherwise 400 */ 401 bool NetworkGameManager::canCreateEntity(ClassID classID) 402 { 403 return true; 404 } 405 406 #if 0 407 /*! 408 * Sends the Entities to the new connected client 409 * @param userID: The ID of the user 410 */ 411 void NetworkGameManager::sendEntityList( int userID ) 412 { 413 if ( !isServer() ) 414 return; 415 416 if ( userID >= outBuffer.size() ) 417 resizeBufferVector( userID ); 418 419 SynchronizeableList::const_iterator it, e; 420 421 it = this->networkStream->getSyncBegin(); 422 e = this->networkStream->getSyncEnd(); 423 424 // send the packet header 425 if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) ) 426 return; 427 428 // send the number of entities: -2 because you must not send network_game_manager and handshake 429 if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) ) 430 return; 431 432 //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 ); 433 434 // first send the NullParent 435 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) ) 436 return; 437 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) ) 438 return; 439 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) ) 440 return; 441 442 // now send the rest of the entities 443 while ( it != e ) 444 { 445 if( (*it)->beSynchronized() && (*it) != PNode::getNullParent()) 446 { 447 PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() ); 448 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) 449 return; 450 451 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) ) 452 return; 453 454 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) ) 455 return; 456 } 457 it++; 458 } 459 460 signalNewPlayer( userID ); 461 } 462 #endif 463 464 465 466 bool NetworkGameManager::signalNewPlayer(int userId) 467 { 468 /* create new playable for Player*/ 469 PRINTF(0)("Request for creation: %i\n", userId); 470 int uniqueId = this->createEntity(CL_SPACE_SHIP, userId); 471 PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId); 472 this->sendYouAre(uniqueId, userId); 123 delete PlayerStats::getStats( userID )->getPlayable(); 124 delete PlayerStats::getStats( userID ); 473 125 } 474 126 475 127 476 128 477 bool NetworkGameManager::signalLeftPlayer(int userID) 129 /** 130 * handler for remove synchronizeable messages 131 * @param messageId 132 * @param data 133 * @param dataLength 134 * @param someData 135 * @param userId 136 * @return true on successfull handling else handler will be called again 137 */ 138 bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 478 139 { 479 const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); 140 if ( getInstance()->isServer() ) 141 { 142 PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId); 143 return true; 144 } 480 145 481 i f ( !playableList )482 return false;146 int uniqueId = 0; 147 int len = Converter::byteArrayToInt( data, &uniqueId ); 483 148 484 std::list<BaseObject*>::const_iterator it = playableList->begin(); 485 486 for(; it != playableList->end(); it++) 149 if ( len != dataLength ) 487 150 { 488 if( dynamic_cast<Synchronizeable*>(*it)->getOwner() == userID ) 151 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId); 152 return true; 153 } 154 155 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE ); 156 157 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 158 { 159 if ( dynamic_cast<Synchronizeable*>(*it)->getUniqueID() == uniqueId ) 489 160 { 490 PRINTF(0)("remove playable from %i\n", userID); 491 this->removeEntity(dynamic_cast<Synchronizeable*>(*it)->getUniqueID()); 161 delete dynamic_cast<Synchronizeable*>(*it); 492 162 return true; 493 163 } 494 164 } 495 return false;496 }497 498 #if 0499 /**500 * Creates a buffer for user n501 * @param n The ID of the user502 */503 void NetworkGameManager::resizeBufferVector( int n )504 {505 for ( int i = outBuffer.size(); i<=n; i++)506 {507 clientBuffer outBuf;508 509 outBuf.length = 0;510 511 outBuf.maxLength = 5*1024;512 513 outBuf.buffer = new byte[5*1014];514 515 outBuffer.push_back(outBuf);516 }517 }518 #endif519 520 /**521 * Creates the entity on this host522 * @param classID: ClassID of the entity to create523 * @param uniqueID: Unique ID to assign to the synchronizeable524 * @param owner: owner of this synchronizealbe525 */526 BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )527 {528 PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);529 530 BaseObject * b;531 /* These are some small exeptions in creation: Not all objects can/should be created via Factory */532 /* Exception 1: NullParent */533 if( classID == CL_NULL_PARENT)534 {535 b = (BaseObject*)PNode::getNullParent();536 }537 else538 b = Factory::fabricate( classID );539 540 if ( !b )541 {542 PRINTF(1)("Could not fabricate Object with classID %x\n", classID);543 return NULL;544 }545 546 if ( b->isA(CL_SYNCHRONIZEABLE) )547 {548 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);549 s->setUniqueID( uniqueID );550 s->setOwner( owner );551 s->setSynchronized(true);552 //this->networkStream->connectSynchronizeable( *s );553 554 PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());555 556 //TODO HACK: hack to prevent collision557 if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )558 {559 if ( SharedNetworkData::getInstance()->getHostID()!=0 )560 {561 static Vector pos = Vector(1000.0, 1000.0, 1000.0);562 PNode *p = dynamic_cast<PNode*>(b);563 p->setAbsCoor(pos);564 p->updateNode(0);565 pos += Vector(1000.0, 1000.0, 1000.0);566 }567 }568 ///TODO HACK this is only for network multiplayer games.569 if( b->isA(CL_PLAYABLE))570 {571 Playable* ss = dynamic_cast<Playable*>(b);572 if( owner%2 == 0)573 {574 575 ss->loadModel("models/ships/reap_0.obj");576 ss->toList(OM_GROUP_00);577 ss->setAbsCoor(213.37, 57.71, -47.98);578 ss->setAbsDir(Quaternion(0.16, 0.98, -0.10));579 }580 else581 {582 ss->loadModel( "models/ships/fighter.obj" );583 ss->toList(OM_GROUP_01);584 ss->setAbsCoor(-314.450, 40.701, 83.554);585 }586 }587 588 return b;589 }590 else591 {592 PRINTF(1)("Class with ID %x is not a synchronizeable!", (int)classID);593 delete b;594 }595 return NULL;596 165 } 597 166 598 167 /** 599 * Removes a entity on this host600 * @param uniqueI D: unique ID assigned with the entity to remove168 * removes synchronizeable (also on clients) 169 * @param uniqueId uniqueid to delete 601 170 */ 602 void NetworkGameManager:: doRemoveEntity( int uniqueID)171 void NetworkGameManager::removeSynchronizeable( int uniqueId ) 603 172 { 604 SynchronizeableList::const_iterator it,e;605 it = this->networkStream->getSyncBegin();606 e = this->networkStream->getSyncEnd();607 608 while ( it != e )609 {610 if ( (*it)->getUniqueID() == uniqueID )611 {612 assert((*it)->isA(CL_WORLD_ENTITY));613 dynamic_cast<WorldEntity*>(*it)->leaveWorld();614 dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD);615 break;616 }617 it++;618 }619 }620 621 #if 0622 /**623 * Copies length bytes to the clientBuffer with error checking624 * @param clientBuffer: the clientBuffer to write to625 * @param data: buffer to the data626 * @param length: length of data627 * @return false on error true else628 */629 bool NetworkGameManager::writeToClientBuffer( clientBuffer &cb, byte * data, int length )630 {631 if ( length > cb.maxLength-cb.length )632 {633 PRINTF(1)("No space left in clientBuffer\n");634 return false;635 }636 637 memcpy( cb.buffer+cb.length, data, length );638 return true;639 }640 #endif641 642 #if 0643 /**644 * Reads data from clientBuffer with error checking645 * @param clientBuffer: the clientBuffer to read from646 * @param data: pointer to the buffer647 * @param length:648 * @return649 */650 bool NetworkGameManager::readFromClientBuffer( clientBuffer &cb, byte * data, int length )651 {652 if ( cb.length < length )653 {654 PRINTF(0)("There is not enough data in clientBuffer\n");655 return 0;656 }657 658 memcpy( data, cb.buffer+cb.length-length, length );659 return true;660 }661 #endif662 663 /**664 * Tells this client that he has to control this entity665 * @param uniqueID: the entity's uniqeID666 */667 void NetworkGameManager::doYouAre( int uniqueID )668 {669 670 SynchronizeableList::const_iterator it = this->networkStream->getSyncBegin();671 672 Playable *p = NULL;673 Synchronizeable *s = NULL;674 675 for ( ; it !=networkStream->getSyncEnd(); it++ )676 {677 if ( (*it)->getUniqueID()==uniqueID )678 {679 if ( (*it)->isA( CL_SYNCHRONIZEABLE ) )680 {681 s = dynamic_cast<Synchronizeable*>(*it);682 }683 if ( (*it)->isA( CL_PLAYABLE ) )684 {685 p = dynamic_cast<Playable*>(*it);686 break;687 } else688 {689 PRINTF(1)("UniqueID %d is not a Playable\n", uniqueID);690 }691 }692 }693 694 Player* player = State::getPlayer();695 assert(p != NULL);696 assert(s != NULL);697 assert(player != NULL);698 699 PRINTF(0)("uniqueID = %d\n", s->getUniqueID());700 701 player->setPlayable(p);702 703 704 }705 706 /**707 * Tells a remote client that he has to control this entity708 * @param uniqueID: the entity's uniqeID709 * @param userID: the users ID710 */711 void NetworkGameManager::sendYouAre( int uniqueID, int userID )712 {713 if ( !isServer() )714 return;715 716 173 byte buf[INTSIZE]; 717 174 718 Converter::intToByteArray( uniqueID, buf,INTSIZE );175 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 719 176 720 MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH); 721 } 722 723 bool NetworkGameManager::handleRequestCreate( int & i, const byte * data, int length, int sender ) 724 { 725 if ( INTSIZE > length-i ) 726 { 727 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 728 return false; 729 } 730 int classID; 731 i += Converter::byteArrayToInt( &data[i], &classID ); 732 733 createEntity( (ClassID)classID ); 734 735 return true; 736 } 737 738 bool NetworkGameManager::handleRequestRemove( int & i, const byte * data, int length, int sender ) 739 { 740 if ( INTSIZE > length-i ) 741 { 742 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 743 return false; 744 } 745 int uniqueID; 746 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 747 748 removeEntity( uniqueID ); 749 750 return true; 751 } 752 753 bool NetworkGameManager::handleCreateEntity( int & i, const byte * data, int length, int sender ) 754 { 755 if ( INTSIZE > length-i ) 756 { 757 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 758 return false; 759 } 760 int classID; 761 i += Converter::byteArrayToInt( &data[i], &classID ); 762 763 if ( INTSIZE > length-i ) 764 { 765 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 766 return false; 767 } 768 int uniqueID; 769 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 770 771 if ( INTSIZE > length-i ) 772 { 773 PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); 774 return false; 775 } 776 int owner; 777 i += Converter::byteArrayToInt( &data[i], &owner ); 778 779 PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 780 doCreateEntity( (ClassID)classID, uniqueID, owner ); 781 782 return true; 783 } 784 785 bool NetworkGameManager::handleRemoveEntity( int & i, const byte * data, int length, int sender ) 786 { 787 if ( INTSIZE > length-i ) 788 { 789 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 790 return false; 791 } 792 int uniqueID; 793 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 794 795 doRemoveEntity( uniqueID ); 796 797 return true; 798 } 799 800 bool NetworkGameManager::handleCreateEntityList( int & i, const byte * data, int length, int sender ) 801 { 802 if ( INTSIZE > length-i ) 803 { 804 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 805 return false; 806 } 807 808 PRINTF(0)("HandleCreateEntityList: data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]); 809 810 int n; 811 i += Converter::byteArrayToInt( &data[i], &n ); 812 813 814 PRINTF(0)("HandleCreateEntityList: n = %d\n", n); 815 816 int classID, uniqueID, owner; 817 818 for ( int j = 0; j<n; j++ ) 819 { 820 821 if ( INTSIZE > length-i ) 822 { 823 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 824 return false; 825 } 826 i += Converter::byteArrayToInt( &data[i], &classID ); 827 828 if ( INTSIZE > length-i ) 829 { 830 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 831 return false; 832 } 833 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 834 835 if ( INTSIZE > length-i ) 836 { 837 PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); 838 return false; 839 } 840 i += Converter::byteArrayToInt( &data[i], &owner ); 841 842 if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE ) 843 { 844 BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner ); 845 } 846 847 } 848 849 return true; 850 } 851 852 bool NetworkGameManager::handleRemoveEntityList( int & i, const byte * data, int length, int sender ) 853 { 854 if ( INTSIZE > length-i ) 855 { 856 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 857 return false; 858 } 859 int n; 860 i += Converter::byteArrayToInt( &data[i], &n ); 861 862 int uniqueID; 863 864 for ( int j = 0; j<n; j++ ) 865 { 866 867 if ( INTSIZE > length-i ) 868 { 869 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 870 return false; 871 } 872 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 873 874 doRemoveEntity( uniqueID ); 875 } 876 877 return true; 878 } 879 880 bool NetworkGameManager::handleYouAreEntity( int & i, const byte * data, int length, int sender ) 881 { 882 if ( INTSIZE > length-i ) 883 { 884 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 885 return false; 886 } 887 888 int uniqueID; 889 i += Converter::byteArrayToInt( &data[i], &uniqueID ); 890 891 doYouAre( uniqueID ); 892 893 return true; 894 } 895 896 /** 897 * handles the network signal NET_REQUEST_PNODE_PATH 898 * @param i byte offset in the buffer 899 * @param data data array 900 * @param length length of the data arary 901 * @param sender the sender id 902 * @return true if process terminated sucessfully 903 */ 904 bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender) 905 { 906 if( INTSIZE > length-i ) 907 { 908 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 909 return false; 910 } 911 PRINTF(0)("HandleRequestPNodePath: data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]); 912 913 int uniqueID1, uniqueID2; 914 if( INTSIZE > length-i ) 915 { 916 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 917 return false; 918 } 919 i += Converter::byteArrayToInt( &data[i], &uniqueID1 ); 920 921 if( INTSIZE > length-i ) 922 { 923 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 924 return false; 925 } 926 i += Converter::byteArrayToInt( &data[i], &uniqueID2 ); 927 928 929 PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2); 930 931 return true; 932 } 933 934 bool NetworkGameManager::youAreHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 935 { 936 assert( dataLength == INTSIZE ); 937 int uniqueId; 938 939 Converter::byteArrayToInt( data, &uniqueId ); 940 941 SynchronizeableList::const_iterator it = NetworkGameManager::getInstance()->networkStream->getSyncBegin(); 942 943 Playable *p = NULL; 944 Synchronizeable *s = NULL; 945 946 for ( ; it !=NetworkGameManager::getInstance()->networkStream->getSyncEnd(); it++ ) 947 { 948 if ( (*it)->getUniqueID()==uniqueId ) 949 { 950 break; 951 } 952 } 953 954 if ( it == NetworkGameManager::getInstance()->networkStream->getSyncEnd() ) 955 return false; 956 957 NetworkGameManager::getInstance()->doYouAre( uniqueId ); 958 959 return true; 960 } 961 962 #if 0 963 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) 964 { 965 if ( cb.maxLength-cb.length < 1 ) 966 { 967 PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n"); 968 return false; 969 } 970 971 cb.buffer[cb.length++] = b; 972 973 return true; 177 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 974 178 } 975 179 976 180 977 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i )978 {979 int n = Converter::intToByteArray( i, cb.buffer+cb.length, cb.maxLength-cb.length );980 cb.length += n;981 982 if ( n <= 0 )983 {984 PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n");985 return false;986 }987 988 return true;989 }990 #endif991 181 992 182 183 184 -
trunk/src/lib/network/network_game_manager.h
r7954 r8068 47 47 public: 48 48 virtual ~NetworkGameManager(); 49 49 50 50 static NetworkGameManager* NetworkGameManager::getInstance() 51 51 { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } 52 52 53 #if 054 virtual int writeBytes(const byte* data, int length, int sender);55 virtual int readBytes(byte* data, int maxLength, int * reciever);56 virtual void writeDebug() const;57 virtual void readDebug() const;58 #endif59 53 60 int createEntity( ClassID classID, int owner = 0);61 BaseObject* createEntity(const TiXmlElement* element);62 void removeEntity( int uniqueID );63 void sendYouAre( int uniqueID, int userID);54 bool signalNewPlayer( int userId ); 55 bool signalLeftPlayer( int userID ); 56 57 void removeSynchronizeable( int uniqueId ); 64 58 65 #if 0 66 void sendEntityList(int userID); 67 #endif 68 69 bool signalNewPlayer(int userId); 70 bool signalLeftPlayer(int userID); 71 59 inline void setGameState( int gameState ){ this->gameState = gameState; } 60 inline int getGameState(){ return this->gameState; } 72 61 73 62 private: 74 63 NetworkGameManager(); 75 64 76 static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId );65 static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 77 66 78 79 /* some network signal handlers */80 bool handleRequestCreate( int& i, const byte* data, int length, int sender );81 bool handleRequestRemove( int& i, const byte* data, int length, int sender );82 bool handleCreateEntity( int& i, const byte* data, int length, int sender );83 bool handleRemoveEntity( int& i, const byte* data, int length, int sender );84 bool handleCreateEntityList( int& i, const byte* data, int length, int sender );85 bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );86 bool handleYouAreEntity( int& i, const byte* data, int length, int sender );87 bool handleRequestPNodePath(int& i, const byte* data, int length, int sender);88 bool handleSendPNodePath(int& i, const byte* data, int length, int sender);89 90 91 /* some network handlers helper functions */92 // void requestCreateEntity(ClassID classID);93 int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);94 BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);95 96 // void requestRemoveEntity(int uniqueID);97 void executeRemoveEntity(int uniqueID);98 void doRemoveEntity(int uniqueID);99 100 void doYouAre( int uniqueID );101 102 // void requestPNodePath(const PNode* node1, const PNode* node2);103 void executeRequestPNodePath(const PNode* node2, const PNode* node2);104 void doRequestPNodePath(const PNode* node1, const PNode* node2);105 106 bool canCreateEntity(ClassID classID);107 #if 0108 void resizeBufferVector(int n);109 110 111 bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );112 bool writeToClientBuffer( clientBuffer &cb, byte b );113 bool writeToClientBuffer( clientBuffer &cb, int i );114 bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );115 #endif116 117 private:118 #if 0119 std::vector<clientBuffer> outBuffer;120 //clientBuffer allOutBuffer;121 #endif122 67 static NetworkGameManager* singletonRef; 68 69 int gameState; 123 70 }; 124 71 -
trunk/src/lib/network/network_stream.cc
r7954 r8068 177 177 void NetworkStream::processData() 178 178 { 179 int tick = SDL_GetTicks(); 180 179 181 currentState++; 180 182 … … 207 209 // order of up/downstream is important!!!! 208 210 // don't change it 209 handleDownstream( );210 handleUpstream( );211 handleDownstream( tick ); 212 handleUpstream( tick ); 211 213 212 214 } … … 277 279 PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str()); 278 280 279 assert(false);281 //assert(false); 280 282 281 283 it->second.socket->disconnectServer(); … … 391 393 * handle upstream network traffic 392 394 */ 393 void NetworkStream::handleUpstream( )395 void NetworkStream::handleUpstream( int tick ) 394 396 { 395 397 int offset; 396 398 int n; 397 399 398 for ( PeerList:: iterator peer = peers.begin(); peer != peers.end(); peer++ )400 for ( PeerList::reverse_iterator peer = peers.rbegin(); peer != peers.rend(); peer++ ) 399 401 { 400 402 offset = INTSIZE; //make already space for length … … 496 498 writeToNewDict( buf, offset ); 497 499 498 peer->second.connectionMonitor->processUnzippedOutgoingPacket( buf, offset, currentState );499 peer->second.connectionMonitor->processZippedOutgoingPacket( compBuf, compLength, currentState );500 peer->second.connectionMonitor->processUnzippedOutgoingPacket( tick, buf, offset, currentState ); 501 peer->second.connectionMonitor->processZippedOutgoingPacket( tick, compBuf, compLength, currentState ); 500 502 501 503 //NETPRINTF(n)("send packet: %d userId = %d\n", offset, peer->second.userId); … … 506 508 * handle downstream network traffic 507 509 */ 508 void NetworkStream::handleDownstream( )510 void NetworkStream::handleDownstream( int tick ) 509 511 { 510 512 int offset = 0; … … 527 529 while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) ) 528 530 { 529 //TODO tell monitor about zipped packet. because dropped packets dont count to bandwidth 531 peer->second.connectionMonitor->processZippedIncomingPacket( tick, compBuf, compLength ); 532 530 533 //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength); 531 534 packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE ); … … 547 550 //NETPRINTF(n)("ackedstate: %d\n", ackedState); 548 551 offset = 4*INTSIZE; 552 553 peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, offset, state, ackedState ); 549 554 550 555 //NETPRINTF(n)("got packet: %d, %d\n", length, packetLength); … … 672 677 } 673 678 674 peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, state, ackedState );675 peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, state, ackedState );676 677 679 assert( peer->second.lastAckedState <= ackedState ); 678 680 peer->second.lastAckedState = ackedState; -
trunk/src/lib/network/network_stream.h
r7954 r8068 79 79 void updateConnectionList(); 80 80 void handleHandshakes(); 81 void handleUpstream( );82 void handleDownstream( );81 void handleUpstream( int tick ); 82 void handleDownstream(int tick ); 83 83 void handleNewClient( int userId ); 84 84 void cleanUpOldSyncList(); -
trunk/src/lib/network/synchronizeable.cc
r7954 r8068 21 21 #include "netdefs.h" 22 22 #include "network_log.h" 23 #include "network_game_manager.h" 23 24 24 25 #include "state.h" … … 36 37 { 37 38 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 38 this->owner = -1;39 this->owner = 0; 39 40 this->hostID = SharedNetworkData::getInstance()->getHostID(); 40 41 this->setIsServer(this->hostID == 0); … … 68 69 if ( this->networkStream ) 69 70 this->networkStream->disconnectSynchronizeable(*this); 71 72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 ) 73 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 70 74 } 71 75 … … 175 179 this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) || 176 180 this->owner == this->hostID && (*it)->checkPermission( PERMISSION_OWNER ) || 181 this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) || 177 182 (*it)->checkPermission( PERMISSION_ALL ) 178 183 ); … … 289 294 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) || 290 295 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 296 networkStream->isUserServer( userId ) && this->owner != getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 291 297 (*it)->checkPermission( PERMISSION_ALL ) 292 298 ) … … 331 337 void Synchronizeable::registerVar( SynchronizeableVar * var ) 332 338 { 333 PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());339 //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str()); 334 340 syncVarList.push_back( var ); 335 341 } … … 343 349 int Synchronizeable::registerVarId( SynchronizeableVar * var ) 344 350 { 345 PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());351 //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str()); 346 352 syncVarList.push_back( var ); 347 353 var->setWatched( true ); -
trunk/src/lib/network/synchronizeable.h
r7954 r8068 61 61 virtual void handleSentState( int userId, int stateId, int fromStateId ); 62 62 virtual void handleRecvState( int userId, int stateId, int fromStateId ); 63 63 64 64 void registerVar( SynchronizeableVar * var ); 65 65 int registerVarId( SynchronizeableVar * var ); -
trunk/src/story_entities/multi_player_world.cc
r7954 r8068 22 22 #include "util/loading/load_param.h" 23 23 #include "shell_command.h" 24 25 #include "cd_engine.h" 24 26 25 27 #include "network_manager.h" … … 86 88 87 89 /** 90 * kicks the CDEngine to detect the collisions between the object groups in the world 91 */ 92 void MultiPlayerWorld::collisionDetection() 93 { 94 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), 95 this->dataTank->objectManager->getObjectList(OM_PLAYERS)); 96 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), 97 this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); 98 99 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), 100 this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); 101 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), 102 this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); 103 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), 104 this->dataTank->objectManager->getObjectList(OM_GROUP_01)); 105 106 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), 107 this->dataTank->objectManager->getObjectList(OM_COMMON)); 108 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), 109 this->dataTank->objectManager->getObjectList(OM_COMMON)); 110 111 } 112 113 114 /** 88 115 * some debug ouptut - shell command 89 116 */ -
trunk/src/story_entities/multi_player_world.h
r6512 r8068 31 31 protected: 32 32 virtual void synchronize(); 33 virtual void collisionDetection(); 33 34 }; 34 35 -
trunk/src/story_entities/multi_player_world_data.cc
r7954 r8068 45 45 #include "network_manager.h" 46 46 #include "network_game_manager.h" 47 #include "player_stats.h" 47 48 48 49 … … 146 147 { 147 148 /* pass the entity to the NetworkGameManager to be created */ 148 BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);149 BaseObject* created = Factory::fabricate(element); 149 150 if( created != NULL ) 150 151 PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value()); … … 203 204 this->localPlayer = new Player(); 204 205 206 #if 0 205 207 Playable* playable; 206 208 const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); … … 215 217 playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0))); 216 218 } 219 #endif 217 220 } 218 221 else … … 244 247 245 248 State::setPlayer(this->localPlayer); 249 246 250 } 247 251 … … 265 269 /* call underlying function */ 266 270 GameWorldData::loadScene(root); 271 272 // create server playable 273 if ( NetworkManager::getInstance()->isGameServer() ) 274 { 275 NetworkGameManager::getInstance()->signalNewPlayer( 0 ); 276 State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() ); 277 } 267 278 } 268 279 -
trunk/src/util/Makefile.am
r7482 r8068 10 10 \ 11 11 game_rules.cc \ 12 network_game_rules.cc \ 12 13 multiplayer_team_deathmatch.cc \ 13 14 singleplayer_shootemup.cc \ … … 34 35 \ 35 36 game_rules.h \ 37 network_game_rules.h \ 36 38 multiplayer_team_deathmatch.h \ 37 39 singleplayer_shootemup.h \ -
trunk/src/util/multiplayer_team_deathmatch.cc
r7954 r8068 15 15 #define DEBUG_MODULE_GAME_RULES 16 16 17 #include <map> 18 17 19 #include "multiplayer_team_deathmatch.h" 18 20 … … 34 36 #include "space_ships/space_ship.h" 35 37 38 #include "network_game_manager.h" 39 36 40 37 41 using namespace std; … … 45 49 */ 46 50 MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) 47 : GameRules(root)51 : NetworkGameRules(root) 48 52 { 49 53 this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); … … 52 56 this->deathTimeout = 10.0f; // 5 seconds 53 57 this->timeout = 0.0f; 58 this->numTeams = 2; 59 this->currentGameState = GAMESTATE_PRE_GAME; 60 this->gameStateTimer = 10.0f; 54 61 55 62 this->deathScreen = new ImagePlane(); … … 87 94 LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) 88 95 .describe("sets the death screen image"); 96 97 LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) 98 .describe("sets number of teams"); 89 99 90 100 } … … 128 138 void MultiplayerTeamDeathmatch::tick(float dt) 129 139 { 140 if ( !SharedNetworkData::getInstance()->isGameServer() ) 141 return; 142 143 gameStateTimer -= dt; 144 PRINTF(0)("TICK %f\n", gameStateTimer); 145 146 if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 ) 147 nextGameState(); 148 149 this->currentGameState = NetworkGameManager::getInstance()->getGameState(); 150 151 if ( currentGameState == GAMESTATE_GAME ) 152 { 153 handleTeamChanges(); 154 } 155 156 this->calculateTeamScore(); 157 130 158 this->checkGameRules(); 131 159 … … 164 192 void MultiplayerTeamDeathmatch::checkGameRules() 165 193 { 166 167 Vector big_left(-201, 0, 0); 168 float rBig = 176.0f; 169 Vector big_right(177, 0, 0); 170 Vector small_left(10, 0, 0); 171 Vector small_middle(0, 0, 0); 172 Vector small_right(-10, 0, 0); 173 float rSmall = 90.0f; 174 175 194 if ( !SharedNetworkData::getInstance()->isGameServer() ) 195 return; 196 176 197 // check for max killing count 177 if( this->teamAKills >= this->maxKills) 178 { 179 // team A winns 180 } 181 else if( this->teamBKills >= this->maxKills) 182 { 183 // team B winns 184 } 185 186 187 if ( SharedNetworkData::getInstance()->isGameServer() ) 188 { 189 float offsetx = 500.0f; 190 float offsety = 323.0f; 191 float offsetz = 200.0f; 192 193 offsetz += 10; 194 195 Terrain * terrain = dynamic_cast<Terrain*>(*(ClassList::getList( CL_TERRAIN )->begin())); 196 const std::list<BaseObject*> * list = ClassList::getList( CL_SPACE_SHIP ); 197 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++) 198 { 199 SpaceShip * ss = dynamic_cast<SpaceShip*>(*it); 200 float terrx = ss->getAbsCoor().x + offsetx; 201 float terry = ss->getAbsCoor().z + offsetz; 202 float terrz = ss->getAbsCoor().y + offsety; 203 if ( terrz < terrain->getHeight( terrx, terry ) && ss->getAbsCoor().x > -1000 ) 198 for ( int i = 0; i<numTeams; i++ ) 199 { 200 if ( teamScore[i] >= maxKills ) 201 { 202 //team i wins 203 //TODO 204 } 205 } 206 } 207 208 /** 209 * find group for new player 210 * @return group id 211 */ 212 int MultiplayerTeamDeathmatch::getTeamForNewUser( ) 213 { 214 return TEAM_NOTEAM; 215 } 216 217 ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team ) 218 { 219 return CL_SPECTATOR; 220 } 221 222 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId ) 223 { 224 return ""; 225 } 226 227 /** 228 * calculate team score 229 */ 230 void MultiplayerTeamDeathmatch::calculateTeamScore( ) 231 { 232 teamScore.clear(); 233 234 for ( int i = 0; i<numTeams; i++ ) 235 teamScore[i] = 0; 236 237 238 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 239 240 if ( !list ) 241 return; 242 243 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 244 { 245 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 246 247 if ( stats.getTeamId() >= 0 ) 248 { 249 teamScore[stats.getTeamId()] += stats.getScore(); 250 } 251 } 252 } 253 254 /** 255 * get team for player who choose to join random team 256 * @return smallest team 257 */ 258 int MultiplayerTeamDeathmatch::getRandomTeam( ) 259 { 260 std::map<int,int> playersInTeam; 261 262 for ( int i = 0; i<numTeams; i++ ) 263 playersInTeam[i] = 0; 264 265 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 266 267 if ( !list ) 268 return 0; 269 270 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 271 { 272 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 273 274 if ( stats.getTeamId() >= 0 ) 275 { 276 playersInTeam[stats.getTeamId()]++; 277 } 278 } 279 280 281 int minPlayers = 0xFFFF; 282 int minTeam = -1; 283 284 for ( int i = 0; i<numTeams; i++ ) 285 { 286 if ( playersInTeam[i] < minPlayers ) 287 { 288 minTeam = i; 289 minPlayers = playersInTeam[i]; 290 } 291 } 292 293 assert( minTeam != -1 ); 294 295 return minTeam; 296 } 297 298 void MultiplayerTeamDeathmatch::nextGameState( ) 299 { 300 if ( currentGameState == GAMESTATE_PRE_GAME ) 301 { 302 NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME ); 303 304 return; 305 } 306 307 if ( currentGameState == GAMESTATE_GAME ) 308 { 309 NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME ); 310 311 return; 312 } 313 314 if ( currentGameState == GAMESTATE_POST_GAME ) 315 { 316 //TODO end game 317 318 return; 319 } 320 } 321 322 void MultiplayerTeamDeathmatch::handleTeamChanges( ) 323 { 324 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 325 326 if ( !list ) 327 return; 328 329 //first server players with choices 330 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 331 { 332 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 333 334 if ( stats.getTeamId() != stats.getPreferedTeamId() ) 335 { 336 if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) ) 204 337 { 205 //TODO handle this338 teamChange( stats.getUserId() ); 206 339 } 207 208 209 float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); 210 if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && 211 (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && 212 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && 213 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && 214 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall 215 && ss->getAbsCoor().x > -1000) 340 } 341 } 342 343 //now serve player who want join a random team 344 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 345 { 346 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 347 348 if ( stats.getTeamId() != stats.getPreferedTeamId() ) 349 { 350 if ( stats.getPreferedTeamId() == TEAM_RANDOM ) 216 351 { 217 PRINTF(0)("KILLLLLLLL\n"); 218 219 if((*it)->isA(CL_SPACE_SHIP)) 220 { 221 //TODO handle this 222 } 352 stats.setPreferedTeamId( getTeamForNewUser() ); 353 teamChange( stats.getUserId() ); 223 354 } 224 355 } 225 356 } 226 227 228 #if 0 229 std::list<BaseObject*>::const_iterator it; 230 const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE); 231 232 if( SharedNetworkData::getInstance()->isGameServer()) 233 { 234 for(it = list->begin(); it != list->end(); it++) 235 { 236 float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); 237 if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && 238 (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && 239 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && 240 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && 241 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall) 242 { 243 PRINTF(0)("KILLLLLLLL\n"); 244 245 if((*it)->isA(CL_SPACE_SHIP)) 246 dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f); 247 } 248 } 249 } 250 #endif 251 252 } 253 254 255 256 257 258 357 } 358 359 void MultiplayerTeamDeathmatch::teamChange( int userId ) 360 { 361 assert( PlayerStats::getStats( userId ) ); 362 PlayerStats & stats = *(PlayerStats::getStats( userId )); 363 364 assert(false); 365 } 366 367 368 369 370 371 -
trunk/src/util/multiplayer_team_deathmatch.h
r7810 r8068 10 10 #define _MULTIPLAYER_TEAM_DEATHMATCH_H 11 11 12 #include " game_rules.h"12 #include "network_game_rules.h" 13 13 14 14 … … 18 18 class ImagePlane; 19 19 20 enum 21 { 22 GAMESTATE_PRE_GAME = 0, 23 GAMESTATE_GAME, 24 GAMESTATE_POST_GAME 25 }; 20 26 21 class MultiplayerTeamDeathmatch : public GameRules 27 28 class MultiplayerTeamDeathmatch : public NetworkGameRules 22 29 { 23 30 … … 28 35 virtual void loadParams(const TiXmlElement* root); 29 36 37 virtual int getTeamForNewUser(); 38 virtual ClassID getPlayableClassId( int team ); 39 virtual std::string getPlayableModelFileName( int team, ClassID classId ); 30 40 31 41 virtual void onPlayerSpawn(); … … 39 49 inline void setMaxKills(int kills) { this->maxKills = kills; } 40 50 void setDeathScreen(const std::string& imageName); 51 52 inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; } 53 inline int getNumTeams(){ return this->numTeams; } 54 55 int getRandomTeam(); 41 56 42 57 protected: … … 49 64 int maxKills; //!< max kills for winning condition 50 65 51 int teamAKills; //!< kills of team A 52 int teamBKills; //!< kills of team B 66 int numTeams; //!< number of teams 53 67 54 ImagePlane* deathScreen; //!< the death screen 68 std::map<int,int> teamScore; //!< team score 69 70 ImagePlane* deathScreen; //!< the death screen 71 72 int currentGameState; //!< game state 73 float gameStateTimer; //!< if less than 0 -> change game state 74 75 void calculateTeamScore(); 76 void nextGameState(); 77 void handleTeamChanges(); 78 void teamChange( int userId ); 55 79 }; 56 80 -
trunk/src/util/object_manager.h
r7836 r8068 20 20 OM_BACKGROUND, 21 21 OM_COMMON, 22 23 OM_PLAYERS, 24 OM_PLAYERS_PROJ, 22 25 23 26 OM_GROUP_00, -
trunk/src/util/signal_handler.cc
r7461 r8068 81 81 assert( pid != -1 ); 82 82 83 83 84 if ( pid == 0 ) 84 85 { 85 86 getInstance()->dontCatch(); 86 87 87 88 sleep(2); 88 89 89 90 90 return; … … 92 92 else 93 93 { 94 getInstance()->dontCatch(); 94 95 if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE && fork() == 0 ) 95 96 { … … 104 105 { 105 106 dup2( fd[0], STDIN_FILENO ); 106 snprintf( command, 255, "gdb -p %d %s 1> " GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );107 snprintf( command, 255, "gdb -p %d %s 1>>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() ); 107 108 } 108 109 else -
trunk/src/world_entities/WorldEntities.am
r7785 r8068 39 39 world_entities/space_ships/turbine_hover.cc \ 40 40 world_entities/creatures/md2_creature.cc \ 41 world_entities/spectator.cc \ 41 42 \ 42 43 \ … … 90 91 space_ships/turbine_hover.h \ 91 92 creatures/md2_creature.h \ 93 spectator.h \ 92 94 \ 93 95 environments/water.h \ -
trunk/src/world_entities/spawning_point.cc
r7357 r8068 20 20 #include "util/loading/factory.h" 21 21 22 #include "world_entity.h" 23 22 24 #include "compiler.h" 25 26 #include <map> 23 27 24 28 … … 26 30 * constructor 27 31 */ 28 SpawningPoint::SpawningPoint (ClassID class ID, const Vector& position)32 SpawningPoint::SpawningPoint (ClassID classid, const Vector& position) 29 33 { 30 34 this->setAbsCoor(position); 31 this->class ID = classID;35 this->classid = classid; 32 36 this->mode = SPT_ALL_AT_ONCE; 33 37 this->delay = 0; … … 40 44 * standard constructor 41 45 */ 42 SpawningPoint::SpawningPoint (const Vector& position, ClassID class ID, SpawningPointMode mode, float delay)46 SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay) 43 47 { 44 48 this->setAbsCoor(position); 45 this->class ID = classID;49 this->classid = classid; 46 50 this->mode = mode; 47 51 this->delay = delay; … … 90 94 91 95 96 97 /** 98 * pushes a world entity to the spawning queue 99 * @param entity WorldEntity to be added 100 */ 101 void SpawningPoint::pushEntity(WorldEntity* entity, float delay) 102 { 103 this->queue[entity] = this->localTimer + delay; 104 } 105 106 92 107 /** 93 108 * spawn the entity 94 109 */ 95 void SpawningPoint::spawn( )110 void SpawningPoint::spawn(WorldEntity* entity) 96 111 { 97 PRINTF( 5)("Spangingpoint creates a new Entity (id: %i, delay: %f, mode: %f)\n", this->classID,98 this->delay, this->mode); 112 PRINTF(1)("Spawningpoint spawns new Entity (%s)\n", entity->getClassName()); 113 99 114 100 115 //BaseObject* spawningEntity = Factory::fabricate(this->classID); 101 102 // if( likely(this->world != NULL)) 103 // this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); 116 // if( likely(this->world != NULL)) 117 // this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); 104 118 } 105 119 … … 114 128 { 115 129 this->localTimer += dt; 116 if( this->localTimer > this->delay) 130 131 std::map<WorldEntity*, float>::iterator it = this->queue.begin(); 132 for( ; it != this->queue.end(); it++) 117 133 { 118 this->spawn(); 119 this->localTimer = 0.0f; 134 // 135 if( it->second <= this->localTimer) 136 { 137 //spawn the player 138 this->spawn(it->first); 139 } 120 140 } 141 121 142 } 122 143 -
trunk/src/world_entities/spawning_point.h
r7370 r8068 9 9 10 10 #include "world_entity.h" 11 12 #include <map> 11 13 12 14 class World; … … 43 45 44 46 /** sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */ 45 void SpawningPoint::setSpawningEntity(ClassID class ID) { this->classID = classID; }47 void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; } 46 48 /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */ 47 49 void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; } … … 49 51 void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; } 50 52 53 void pushEntity(WorldEntity* entity, float delay = 0); 51 54 52 55 /** activates the spawning point */ 53 void activate() { this->bSpawning = true; }56 inline void activate() { this->bSpawning = true; } 54 57 /** deactivates the spawning point */ 55 void deactivate() { this->bSpawning = false; } 58 inline void deactivate() { this->bSpawning = false; } 59 inline bool isActive() const { return this->bSpawning; } 56 60 57 61 … … 61 65 62 66 private: 63 void spawn( );67 void spawn(WorldEntity* entity); 64 68 65 69 66 70 private: 67 float delay; //!< the timer that counts down until the next spawn68 float localTimer; //!< the local timer69 float seed; //!< the random seed of the position70 ClassID classID; //!< the classid of the entity to spawn71 SpawningPointMode mode; //!< the mode of the spawning point72 ObjectManager::EntityListqueue; //!< queue of waiting WorldEntities to be spawned73 bool bSpawning; //!< flag to indicate if this spawning point is active or not71 float delay; //!< the timer that counts down until the next spawn 72 float localTimer; //!< the local timer 73 float seed; //!< the random seed of the position 74 ClassID classid; //!< the classid of the entity to spawn 75 SpawningPointMode mode; //!< the mode of the spawning point 76 std::map<WorldEntity*, float> queue; //!< queue of waiting WorldEntities to be spawned 77 bool bSpawning; //!< flag to indicate if this spawning point is active or not 74 78 }; 75 79
Note: See TracChangeset
for help on using the changeset viewer.