Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
May 10, 2006, 12:11:43 AM (18 years ago)
Author:
patrick
Message:

network: added some comments and found some small bugs

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

Legend:

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

    r7512 r7559  
    8989/**
    9090 * get the diff to last acked state of userId
     91 *
     92 * each synchrinizeable defines its own stack of states received and sent over the network. The stack contains
     93 * a per user entry for the last sent/received state This function returns a delta compressed state of the
     94 * synchronizeable. This state will be transmitted over the network to the other participants
     95 *
    9196 * @param userId user to create diff for
    9297 * @param data buffer to copy diff in
    9398 * @param maxLength max bytes to copy into data
    9499 * @param stateId id of current state
     100 * @param fromStateId the reference state for the delta state
    95101 * @param priorityTH tells getStateDiff to not send element with priority \< priorityTH
    96102 * @return n bytes copied into data
     
    115121  while ( it != sentStates[userId].end() && (*it)->stateId < fromStateId )
    116122    it++;
    117 
    118   if ( it != sentStates[userId].begin() )
     123  ///FIXED: altered begin() -> end()
     124  if ( it != sentStates[userId].end() )
    119125  {
    120126    for ( StateHistory::iterator it2 = sentStates[userId].begin(); it2 != it; it2++ )
     
    160166  int n;
    161167
     168  // now do the actual synchronization: kick all variables to write into a common buffer
    162169  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    163170  {
  • branches/network/src/lib/network/synchronizeable.h

    r7508 r7559  
    5858    void setIsServer( bool isServer );
    5959    bool isServer();
    60    
     60
    6161    virtual void varChangeHandler( std::list<int> & id );
    62    
     62
    6363    int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
    6464    bool setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
    65    
     65
    6666    void registerVar( SynchronizeableVar * var );
    6767    int registerVarId( SynchronizeableVar * var );
    68    
     68
    6969    inline void setUniqueID( int id ){ uniqueID = id; }
    7070    inline int  getUniqueID() const { return uniqueID; }
     
    7474    inline void setOwner(int owner){ this->owner = owner; }
    7575
    76     /** @returns true if this Synchronizeable has to be synchronized over network */
     76    /** @returns true if this Synchronizeable wants to be synchronized over network */
    7777    inline bool beSynchronized() { return this->bSynchronize; }
    7878    /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */
     
    9292    int               hostID;         //!< my own host id
    9393    bool              bSynchronize;   //!< do we need beeing synchronized?
    94    
     94
    9595    SyncVarList       syncVarList;    //!< list containing variables to synchronize
    96    
    97     UserStateHistory  sentStates;     //!< store already sent states to create diffs from
    98     UserStateHistory  recvStates;     //!< store recieved states to apply diffs
     96
     97    UserStateHistory  sentStates;     //!< store already sent states to create diffs from, offset corresponds to the user id
     98    UserStateHistory  recvStates;     //!< store recieved states to apply diffs, offset corresponds to the user id
    9999
    100100};
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc

    r7459 r7559  
    4646  int n = 0;
    4747  int res;
    48  
    49   res = Converter::floatToByteArray( vPtrIn->v.x, buf, maxLength - n );
     48
     49  res = Converter::floatToByteArray( vPtrIn->v.x, buf + n, maxLength - n );
    5050  assert( res > 0 );
    5151  n += res;
    52  
    53   res = Converter::floatToByteArray( vPtrIn->v.y, buf, maxLength - n );
     52
     53  res = Converter::floatToByteArray( vPtrIn->v.y, buf + n, maxLength - n );
    5454  assert( res > 0 );
    5555  n += res;
    56  
    57   res = Converter::floatToByteArray( vPtrIn->v.z, buf, maxLength - n );
     56
     57  res = Converter::floatToByteArray( vPtrIn->v.z, buf + n, maxLength - n );
    5858  assert( res > 0 );
    5959  n += res;
    60  
    61   res = Converter::floatToByteArray( vPtrIn->w, buf, maxLength - n );
     60
     61  res = Converter::floatToByteArray( vPtrIn->w, buf +  n, maxLength - n );
    6262  assert( res > 0 );
    6363  n += res;
    64  
     64
    6565  assert( 4*FLOATSIZE == n );
    66  
     66
    6767  return n;
    6868}
     
    7777{
    7878  assert( maxLength >= 4*FLOATSIZE );
    79  
     79
    8080  float x,y,z,w;
    81  
     81
    8282  int res;
    8383  int n = 0;
    84  
     84
    8585  res += Converter::byteArrayToFloat( buf + n, &x );
    8686  assert( res > 0 );
    8787  n += res;
    88  
     88
    8989  res += Converter::byteArrayToFloat( buf + n, &x );
    9090  assert( res > 0 );
    9191  n += res;
    92  
     92
    9393  res += Converter::byteArrayToFloat( buf + n, &x );
    9494  assert( res > 0 );
    9595  n += res;
    96  
     96
    9797  res += Converter::byteArrayToFloat( buf + n, &w );
    9898  assert( res > 0 );
    9999  n += res;
    100  
     100
    101101  *vPtrOut = Quaternion( Vector(x, y, z), w );
    102  
     102
    103103  assert( res == 4*FLOATSIZE );
    104104  return res;
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc

    r7459 r7559  
    1818
    1919
     20
    2021/**
    2122 * standard constructor
     
    2627  assert( ptrIn );
    2728  assert( ptrOut );
    28  
     29
    2930  this->ptrIn = ptrIn;
    3031  this->ptrOut = ptrOut;
     
    3233  this->permission = permission;
    3334  this->priority = priority;
    34   this->real_priority = priority;
     35  this->realPriority = priority;
    3536  this->name = name;
    3637}
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.h

    r7508 r7559  
    99#include <string>
    1010#include "netdefs.h"
     11#include <assert.h>
    1112
    1213class SynchronizeableVar {
     
    1516    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = 0, int priority = 0 );
    1617    virtual ~SynchronizeableVar();
    17    
     18
    1819    /**
    1920     * check if synchronizeable wants to be informed on changes
     
    2122     */
    2223    inline bool beWatched(){ return this->bWatched; }
    23    
     24
    2425    /**
    2526     * write var data to byte buffer
     
    2930     */
    3031    virtual int writeToBuf( byte * buf, int maxLength ) = 0;
    31    
     32
    3233    /**
    3334     * read var data from byte buffer
     
    3738     */
    3839    virtual int readFromBuf( byte * buf, int maxLength ) = 0;
    39    
     40
    4041    /**
    4142     * check if writeToBuf will return the same size every time
     
    4344     */
    4445    virtual bool hasStaticSize() = 0;
    45    
     46
    4647    /**
    4748     * get size writeToBuf needs
     
    4950     */
    5051    virtual int getSize(){ return length; }
    51    
     52
    5253    /**
    5354     * check for permission to write
     
    5556     */
    5657    inline bool checkPremission( int permission ){ return (permission & this->permission) != 0; }
    57    
     58
    5859    /**
    5960     * get variable name
     
    6162     */
    6263    inline std::string getName(){ return name; }
    63    
     64
    6465    /**
    6566     * set variable name
     
    6768     */
    6869    inline void setName( std::string name ) { this->name = name; }
    69    
     70
    7071    /**
    7172     * get priority
     
    7374     */
    7475    inline int getPriority() { return this->priority; }
    75    
     76
    7677    /**
    7778     * set priority
     
    7980     */
    8081    inline void setPriority( int p ) { this->priority = p; }
    81    
     82
    8283    /**
    8384     * reset priority to variable specific default value
    8485     */
    85     inline void resetPriority() { this->priority = this->real_priority; }
     86    inline void resetPriority() { this->priority = this->realPriority; }
    8687
    8788
     
    9596    int permission;     //!< who is allowed to change this var
    9697    int priority;       //!< priority assigned to var
    97     int real_priority;  //!< priority assigned to var, increased every time not sent
    98    
    99    
     98    int realPriority;  //!< priority assigned to var, increased every time not sent
     99
     100
    100101    std::string name;    //!< variable name (for debugging)
    101102
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.cc

    r7459 r7559  
    4747  int n = 0;
    4848  int res;
    49  
    50   res = Converter::floatToByteArray( vPtrIn->x, buf, maxLength - n );
     49
     50  res = Converter::floatToByteArray( vPtrIn->x, buf + n, maxLength - n );
    5151  assert( res > 0 );
    5252  n += res;
    53  
    54   res = Converter::floatToByteArray( vPtrIn->y, buf, maxLength - n );
     53
     54  res = Converter::floatToByteArray( vPtrIn->y, buf + n, maxLength - n );
    5555  assert( res > 0 );
    5656  n += res;
    57  
    58   res = Converter::floatToByteArray( vPtrIn->z, buf, maxLength - n );
     57
     58  res = Converter::floatToByteArray( vPtrIn->z, buf + n, maxLength - n );
    5959  assert( res > 0 );
    6060  n += res;
    61  
     61
    6262  assert( 3*FLOATSIZE == n );
    63  
     63
    6464  return n;
    6565}
     
    7474{
    7575  assert( maxLength >= 3*FLOATSIZE );
    76  
     76
    7777  float x,y,z;
    78  
     78
    7979  int res;
    8080  int n = 0;
    81  
     81
    8282  res += Converter::byteArrayToFloat( buf + n, &x );
    8383  assert( res > 0 );
    8484  n += res;
    85  
     85
    8686  res += Converter::byteArrayToFloat( buf + n, &x );
    8787  assert( res > 0 );
    8888  n += res;
    89  
     89
    9090  res += Converter::byteArrayToFloat( buf + n, &x );
    9191  assert( res > 0 );
    9292  n += res;
    93  
     93
    9494  *vPtrOut = Vector( x, y, z );
    95  
     95
    9696  assert( res == 3*FLOATSIZE );
    9797  return res;
Note: See TracChangeset for help on using the changeset viewer.