Changeset 7954 in orxonox.OLD for trunk/src/lib/network/network_game_manager.cc
- Timestamp:
- May 29, 2006, 3:28:41 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_game_manager.cc
r7354 r7954 27 27 #include "shared_network_data.h" 28 28 #include "converter.h" 29 #include "message_manager.h" 29 30 30 31 #include "playable.h" … … 52 53 this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager"); 53 54 54 hasRequestedWorld = false;55 55 this->setSynchronized(true); 56 57 MessageManager::getInstance()->registerMessageHandler( MSGID_YOU_ARE, youAreHandler, NULL ); 56 58 } 57 59 … … 61 63 NetworkGameManager::~NetworkGameManager() 62 64 { 65 #if 0 63 66 for ( int i = 0; i<outBuffer.size(); i++) 64 67 { … … 66 69 delete outBuffer[i].buffer; 67 70 } 68 69 } 70 71 71 #endif 72 73 } 74 75 #if 0 72 76 int NetworkGameManager::writeBytes(const byte* data, int length, int sender) 73 77 { … … 141 145 { 142 146 sendEntityList( sender ); 143 continue;144 }145 else if ( b == NET_REQUEST_SYNC )146 {147 if ( !handleRequestSync( i, data, length, sender ) )148 return i;149 147 continue; 150 148 } … … 160 158 return i; 161 159 } 162 160 #endif 161 162 #if 0 163 163 int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever) 164 164 { … … 192 192 return 0; 193 193 } 194 194 #endif 195 196 #if 0 195 197 void NetworkGameManager::writeDebug() const 196 198 { … … 200 202 { 201 203 } 204 #endif 202 205 203 206 … … 211 214 if ( this->isServer()) 212 215 { 213 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 216 int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 217 218 if ( res < 0 ) 214 219 { 215 220 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); 216 221 return -1; 217 222 } 218 return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 223 224 return res; 219 225 } 220 226 else 221 227 { 228 #if 0 222 229 this->requestCreateEntity( classID ); 230 #endif 223 231 return -1; 224 232 } … … 288 296 else 289 297 { 298 #if 0 290 299 this->requestRemoveEntity( uniqueID ); 291 } 292 } 293 294 295 300 #endif 301 } 302 } 303 304 305 #if 0 296 306 /*! 297 307 * Creates the needed entity on the server if possible … … 311 321 } 312 322 } 313 323 #endif 324 325 #if 0 314 326 /*! 315 327 * Removes the specified entity on the server … … 329 341 } 330 342 } 343 #endif 331 344 332 345 /*! … … 337 350 int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) 338 351 { 352 #if 0 339 353 for ( int i = 0; i<outBuffer.size(); i++) 340 354 { … … 351 365 return -1; 352 366 } 353 367 #endif 354 368 PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 355 369 doCreateEntity( classID, uniqueID, owner ); … … 365 379 void NetworkGameManager::executeRemoveEntity(int uniqueID) 366 380 { 381 #if 0 367 382 for ( int i = 0; i<outBuffer.size(); i++) 368 383 { … … 375 390 return; 376 391 } 392 #endif 377 393 378 394 doRemoveEntity(uniqueID); … … 388 404 } 389 405 406 #if 0 390 407 /*! 391 408 * Sends the Entities to the new connected client … … 443 460 signalNewPlayer( userID ); 444 461 } 462 #endif 445 463 446 464 … … 448 466 bool NetworkGameManager::signalNewPlayer(int userId) 449 467 { 450 if ( userId >= outBuffer.size() )451 resizeBufferVector( userId );452 453 468 /* create new playable for Player*/ 454 469 PRINTF(0)("Request for creation: %i\n", userId); … … 456 471 PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId); 457 472 this->sendYouAre(uniqueId, userId); 458 459 473 } 460 474 … … 464 478 { 465 479 const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); 480 481 if ( !playableList ) 482 return false; 483 466 484 std::list<BaseObject*>::const_iterator it = playableList->begin(); 467 485 … … 478 496 } 479 497 480 498 #if 0 481 499 /** 482 500 * Creates a buffer for user n … … 498 516 } 499 517 } 518 #endif 500 519 501 520 /** … … 532 551 s->setSynchronized(true); 533 552 //this->networkStream->connectSynchronizeable( *s ); 534 if ( !isServer() ) 535 s->setIsOutOfSync( true ); 553 536 554 PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID()); 537 555 … … 601 619 } 602 620 603 /** 604 * Tell the synchronizeable that a user's synchronizeable is out of sync 605 * @param uniqueID: unique ID assigned with the entity which is out of sync 606 * @param userID: user ID who's synchronizeable is out of sync 607 */ 608 void NetworkGameManager::doRequestSync( int uniqueID, int userID ) 609 { 610 SynchronizeableList::const_iterator it,e; 611 it = this->networkStream->getSyncBegin(); 612 e = this->networkStream->getSyncEnd(); 613 614 while ( it != e ) 615 { 616 if ( (*it)->getUniqueID() == uniqueID ) 617 { 618 (*it)->requestSync( userID ); 619 break; 620 } 621 it++; 622 } 623 } 624 621 #if 0 625 622 /** 626 623 * Copies length bytes to the clientBuffer with error checking … … 641 638 return true; 642 639 } 643 640 #endif 641 642 #if 0 644 643 /** 645 644 * Reads data from clientBuffer with error checking … … 660 659 return true; 661 660 } 661 #endif 662 662 663 663 /** … … 687 687 } else 688 688 { 689 PRINTF(1)("UniqueID is not a Playable\n");689 PRINTF(1)("UniqueID %d is not a Playable\n", uniqueID); 690 690 } 691 691 } … … 697 697 assert(player != NULL); 698 698 699 s->setIsOutOfSync( true );700 701 699 PRINTF(0)("uniqueID = %d\n", s->getUniqueID()); 702 700 … … 715 713 if ( !isServer() ) 716 714 return; 717 718 if ( userID != 0 ) 719 { 720 if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) ) 721 return; 722 723 if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) ) 724 return; 725 } 726 else 727 { 728 doYouAre(uniqueID); 729 } 715 716 byte buf[INTSIZE]; 717 718 Converter::intToByteArray( uniqueID, buf, INTSIZE ); 719 720 MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH); 730 721 } 731 722 … … 902 893 return true; 903 894 } 904 905 bool NetworkGameManager::handleRequestSync( int & i, const byte * data, int length, int sender )906 {907 if ( INTSIZE > length-i )908 {909 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");910 return false;911 }912 int uniqueID;913 i += Converter::byteArrayToInt( &data[i], &uniqueID );914 915 PRINTF(0)("handleRequestSync %d %d\n", uniqueID, sender);916 doRequestSync( uniqueID, sender );917 918 return true;919 }920 921 895 922 896 /** … … 958 932 } 959 933 960 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 961 963 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) 962 964 { … … 971 973 return true; 972 974 } 975 973 976 974 977 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i ) … … 985 988 return true; 986 989 } 987 988 void NetworkGameManager::sync( int uniqueID, int owner ) 989 { 990 /*if ( owner==this->getHostID() ) 991 return;*/ 992 993 if ( !isServer() ) 994 executeRequestSync( uniqueID, 0 ); 995 else 996 executeRequestSync( uniqueID, owner ); 997 } 998 999 void NetworkGameManager::executeRequestSync( int uniqueID, int user ) 1000 { 1001 PRINTF(0)("executeRequestSync %d %d\n", uniqueID, user); 1002 if ( user >= outBuffer.size() ) 1003 resizeBufferVector( user ); 1004 1005 if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) ) 1006 return; 1007 if ( !writeToClientBuffer( outBuffer[user], uniqueID ) ) 1008 return; 1009 } 1010 990 #endif 991 992
Note: See TracChangeset
for help on using the changeset viewer.