Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7731 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
May 19, 2006, 4:22:39 PM (19 years ago)
Author:
rennerc
Message:

fixed bug

Location:
branches/network/src/lib/network
Files:
6 edited

Legend:

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

    r7681 r7731  
    3131
    3232  this->setIsServer(server);
    33   this->localState.hostId = clientId;
    34   this->localState.networkManagerId = networkGameManagerId;
    35   this->localState.messageManagerId = messageManagerId;
    3633 
    3734  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
    3835  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
    3936  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 ) );
    4138  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
    4239  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
     
    4946  localState.hostId = clientId;
    5047  localState.networkManagerId = networkGameManagerId;
     48  this->localState.messageManagerId = messageManagerId;
    5149  localState.orxId = _ORXONOX_ID;
    5250  localState.version = _ORXONOX_VERSION;
     
    5755  remoteState.hostId = -1;
    5856  remoteState.networkManagerId = -1;
     57  remoteState.messageManagerId = -1;
    5958  remoteState.orxId = 0;
    6059  remoteState.version = 0;
  • branches/network/src/lib/network/handshake.h

    r7681 r7731  
    4747   
    4848    int netManId_handler;
     49    int msgManId_handler;
    4950    int hostId_handler;
    5051    int completed_handler;
  • branches/network/src/lib/network/network_stream.cc

    r7701 r7731  
    412412      offset += INTSIZE;
    413413
    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 );
    415415      offset += n;
    416416     
     
    421421   
    422422    assert( peer->second.socket->writePacket( buf, offset ) );
     423    peer->second.sentStateTicks[currentState] = SDL_GetTicks();
    423424    PRINTF(0)("send packet: %d userId = %d\n", offset, peer->second.userId);
    424425  }
     
    461462      assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE );
    462463      assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE );
     464      PRINTF(0)("ackedstate: %d\n", ackedState);
    463465      offset = 4*INTSIZE;
    464466
     
    475477        continue;
    476478      }
    477 
     479     
    478480      while ( offset < length )
    479481      {
     
    485487     
    486488        Synchronizeable * sync = NULL;
    487      
     489       
    488490        for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
    489491        {
     
    495497          }
    496498        }
    497      
     499       
    498500        if ( sync == NULL )
    499501        {
     
    503505            continue;
    504506          }
    505        
     507
    506508        //TODO dont accept new object from all peers (probably only servers)
    507509          int leafClassId;
     
    511513            continue;
    512514          }
    513        
     515
    514516          Converter::byteArrayToInt( buf + offset, &leafClassId );
    515517       
     
    532534            continue;
    533535          }
    534        
     536
    535537          if ( b->isA(CL_SYNCHRONIZEABLE) )
    536538          {
     
    550552        }
    551553
    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 );
    553555      }
    554    
     556     
    555557      if ( offset != length )
    556558      {
     559        PRINTF(0)("offset (%d) != length (%d)\n", offset, length);
    557560        peer->second.socket->disconnectServer();
    558561      }
     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 );
    559585   
    560586      peer->second.lastAckedState = ackedState;
     587      peer->second.lastRecvedState = state;
     588     
    561589    }
    562590 
  • branches/network/src/lib/network/network_stream.h

    r7671 r7731  
    2828    PeerInfo() { clear(); }
    2929    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;
    3639};
    3740
  • branches/network/src/lib/network/synchronizeable.cc

    r7678 r7731  
    123123      if ( (*it2)->data != NULL )
    124124      {
    125         delete (*it2)->data;
     125        delete [] (*it2)->data;
    126126        (*it2)->data = NULL;
    127127      }
     
    154154  stateTo->stateId = stateId;
    155155  stateTo->dataLength = neededSize;
    156   stateTo->data = (byte*)malloc( neededSize );
     156  stateTo->data = new byte[ neededSize ];
    157157
    158158  std::list<int>::iterator sizeIter = stateFrom->sizeList.begin();
     
    178178      stateTo->sizeList.push_back( n );
    179179      i += n;
    180     }
    181     else if ( ! hasPermission )
    182     {
    183       for ( int j = 0; j < (*it)->getSize(); j++ )
    184       {
    185         //TODO this should be called!!!!!!!!!!1
    186         assert(false);
    187         stateTo->data[i] = 0;
    188         i++;
    189       }
    190180    }
    191181    else
     
    240230  stateTo->stateId = stateId;
    241231  stateTo->dataLength = length;
    242   stateTo->data = (byte*)malloc( length );
     232  stateTo->data = new byte[ length ];
    243233
    244234  //remove old states
     
    254244      if ( (*it2)->data != NULL )
    255245      {
    256         delete (*it2)->data;
     246        delete [] (*it2)->data;
    257247        (*it2)->data = NULL;
    258248      }
     
    290280   
    291281  }
    292 
     282 
    293283  //add state to state history
    294284  recvStates[userId].push_back( stateTo );
     
    366356    {
    367357      if ( (*it2)->data )
    368         delete (*it2)->data;
     358        delete [] (*it2)->data;
    369359      (*it2)->data = NULL;
    370360     
    371       delete *it2;
     361      delete [] *it2;
    372362    }
    373363  }
     
    380370    {
    381371      if ( (*it2)->data )
    382         delete (*it2)->data;
     372        delete [] (*it2)->data;
    383373      (*it2)->data = NULL;
    384374     
    385       delete *it2;
     375      delete [] *it2;
    386376    }
    387377  }
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc

    r7631 r7731  
    3636  this->name = name;
    3737  this->bWatched = false;
     38  this->changed = false;
    3839}
    3940
Note: See TracChangeset for help on using the changeset viewer.