- Timestamp:
- May 19, 2006, 4:22:39 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/handshake.cc
r7681 r7731 31 31 32 32 this->setIsServer(server); 33 this->localState.hostId = clientId;34 this->localState.networkManagerId = networkGameManagerId;35 this->localState.messageManagerId = messageManagerId;36 33 37 34 orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) ); 38 35 version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) ); 39 36 netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) ); 40 netManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "networkManagerId", PERMISSION_ALL ) );37 msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) ); 41 38 hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) ); 42 39 completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) ); … … 49 46 localState.hostId = clientId; 50 47 localState.networkManagerId = networkGameManagerId; 48 this->localState.messageManagerId = messageManagerId; 51 49 localState.orxId = _ORXONOX_ID; 52 50 localState.version = _ORXONOX_VERSION; … … 57 55 remoteState.hostId = -1; 58 56 remoteState.networkManagerId = -1; 57 remoteState.messageManagerId = -1; 59 58 remoteState.orxId = 0; 60 59 remoteState.version = 0; -
branches/network/src/lib/network/handshake.h
r7681 r7731 47 47 48 48 int netManId_handler; 49 int msgManId_handler; 49 50 int hostId_handler; 50 51 int completed_handler; -
branches/network/src/lib/network/network_stream.cc
r7701 r7731 412 412 offset += INTSIZE; 413 413 414 n = sync.getStateDiff( peer->second.userId, buf + offset, UDP_PACKET_SIZE-offset, currentState, peer->second.lastAckedState, 0 );414 n = sync.getStateDiff( peer->second.userId, buf + offset, UDP_PACKET_SIZE-offset, currentState, peer->second.lastAckedState, -1000 ); 415 415 offset += n; 416 416 … … 421 421 422 422 assert( peer->second.socket->writePacket( buf, offset ) ); 423 peer->second.sentStateTicks[currentState] = SDL_GetTicks(); 423 424 PRINTF(0)("send packet: %d userId = %d\n", offset, peer->second.userId); 424 425 } … … 461 462 assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE ); 462 463 assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE ); 464 PRINTF(0)("ackedstate: %d\n", ackedState); 463 465 offset = 4*INTSIZE; 464 466 … … 475 477 continue; 476 478 } 477 479 478 480 while ( offset < length ) 479 481 { … … 485 487 486 488 Synchronizeable * sync = NULL; 487 489 488 490 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ ) 489 491 { … … 495 497 } 496 498 } 497 499 498 500 if ( sync == NULL ) 499 501 { … … 503 505 continue; 504 506 } 505 507 506 508 //TODO dont accept new object from all peers (probably only servers) 507 509 int leafClassId; … … 511 513 continue; 512 514 } 513 515 514 516 Converter::byteArrayToInt( buf + offset, &leafClassId ); 515 517 … … 532 534 continue; 533 535 } 534 536 535 537 if ( b->isA(CL_SYNCHRONIZEABLE) ) 536 538 { … … 550 552 } 551 553 552 offset += sync->setStateDiff( peer->second.userId, buf+offset, length-offset, state, fromState );554 offset += sync->setStateDiff( peer->second.userId, buf+offset, syncDataLength, state, fromState ); 553 555 } 554 556 555 557 if ( offset != length ) 556 558 { 559 PRINTF(0)("offset (%d) != length (%d)\n", offset, length); 557 560 peer->second.socket->disconnectServer(); 558 561 } 562 563 if ( peer->second.sentStateTicks.find( ackedState ) != peer->second.sentStateTicks.end() ) 564 { 565 peer->second.ackDelay.push_back( SDL_GetTicks() - peer->second.sentStateTicks[ackedState] ); 566 } 567 568 while ( peer->second.sentStateTicks.begin()->first <= ackedState ) 569 peer->second.sentStateTicks.erase( peer->second.sentStateTicks.begin() ); 570 571 while ( peer->second.ackDelay.size() > 20 ) 572 peer->second.ackDelay.erase( peer->second.ackDelay.begin() ); 573 574 peer->second.ping = 0; 575 576 for ( std::list<int>::iterator it = peer->second.ackDelay.begin(); it != peer->second.ackDelay.end(); it++ ) 577 peer->second.ping += *it; 578 579 if ( peer->second.ackDelay.size() == 0 ) 580 peer->second.ping = -1; 581 else 582 peer->second.ping /= peer->second.ackDelay.size(); 583 584 PRINTF(0)("PING: user: %d ping: %d\n", peer->second.userId, peer->second.ping ); 559 585 560 586 peer->second.lastAckedState = ackedState; 587 peer->second.lastRecvedState = state; 588 561 589 } 562 590 -
branches/network/src/lib/network/network_stream.h
r7671 r7731 28 28 PeerInfo() { clear(); } 29 29 void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; } 30 int userId; 31 bool isServer; 32 NetworkSocket * socket; 33 Handshake * handshake; 34 int lastAckedState; 35 int lastRecvedState; 30 int userId; 31 bool isServer; 32 NetworkSocket * socket; 33 Handshake * handshake; 34 int lastAckedState; 35 int lastRecvedState; 36 std::map<int,int> sentStateTicks; 37 std::list<int> ackDelay; 38 int ping; 36 39 }; 37 40 -
branches/network/src/lib/network/synchronizeable.cc
r7678 r7731 123 123 if ( (*it2)->data != NULL ) 124 124 { 125 delete (*it2)->data;125 delete [] (*it2)->data; 126 126 (*it2)->data = NULL; 127 127 } … … 154 154 stateTo->stateId = stateId; 155 155 stateTo->dataLength = neededSize; 156 stateTo->data = (byte*)malloc( neededSize );156 stateTo->data = new byte[ neededSize ]; 157 157 158 158 std::list<int>::iterator sizeIter = stateFrom->sizeList.begin(); … … 178 178 stateTo->sizeList.push_back( n ); 179 179 i += n; 180 }181 else if ( ! hasPermission )182 {183 for ( int j = 0; j < (*it)->getSize(); j++ )184 {185 //TODO this should be called!!!!!!!!!!1186 assert(false);187 stateTo->data[i] = 0;188 i++;189 }190 180 } 191 181 else … … 240 230 stateTo->stateId = stateId; 241 231 stateTo->dataLength = length; 242 stateTo->data = (byte*)malloc( length );232 stateTo->data = new byte[ length ]; 243 233 244 234 //remove old states … … 254 244 if ( (*it2)->data != NULL ) 255 245 { 256 delete (*it2)->data;246 delete [] (*it2)->data; 257 247 (*it2)->data = NULL; 258 248 } … … 290 280 291 281 } 292 282 293 283 //add state to state history 294 284 recvStates[userId].push_back( stateTo ); … … 366 356 { 367 357 if ( (*it2)->data ) 368 delete (*it2)->data;358 delete [] (*it2)->data; 369 359 (*it2)->data = NULL; 370 360 371 delete *it2;361 delete [] *it2; 372 362 } 373 363 } … … 380 370 { 381 371 if ( (*it2)->data ) 382 delete (*it2)->data;372 delete [] (*it2)->data; 383 373 (*it2)->data = NULL; 384 374 385 delete *it2;375 delete [] *it2; 386 376 } 387 377 } -
branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc
r7631 r7731 36 36 this->name = name; 37 37 this->bWatched = false; 38 this->changed = false; 38 39 } 39 40 -
branches/network/src/subprojects/network/network_unit_test.cc
r7681 r7731 220 220 for( int i = 0; i < 3; i++) 221 221 { 222 nm->synchronize( );222 nm->synchronize( 1000 ); 223 223 /* simulate the network delay */ 224 224 SDL_Delay(50); … … 237 237 } 238 238 239 voidtestCB( MessageId messageId, byte * data, int dataLength, void * someData, int userId )239 bool testCB( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 240 240 { 241 241 printf("GOT MESSAGE: %s\n", data); 242 return true; 242 243 } 243 244 … … 273 274 { 274 275 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL, 0, MP_HIGHBANDWIDTH ); 275 netMan->synchronize( );276 netMan->synchronize( 1000 ); 276 277 SDL_Delay(1000); 277 278 ss->debug(); … … 311 312 for(;;) 312 313 { 313 netMan->synchronize( );314 netMan->synchronize( 1000 ); 314 315 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL, 0, MP_HIGHBANDWIDTH ); 315 316 ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) ); … … 355 356 for(;;) 356 357 { 357 netMan->synchronize( );358 netMan->synchronize( 1000 ); 358 359 SDL_Delay(10); 359 360 }
Note: See TracChangeset
for help on using the changeset viewer.