Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 29, 2006, 1:57:48 PM (19 years ago)
Author:
rennerc
Message:

new network system implemented. yet with a lot of empty function bodys

Location:
branches/network/src/lib
Files:
17 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/coord/p_node.cc

    r7221 r7444  
    5959  if (parent != NULL)
    6060    parent->addChild(this);
     61 
     62  this->relCoordinate_handle = this->registerVarId( new SynchronizeableVector( &relCoordinate, &relCoordinate_write, "coordinate" ) );
     63  this->relDirection_handle = this->registerVarId( new SynchronizeableQuaternion( &relDirection, &relDirection_write, "direction" ) );
    6164}
    6265
     
    10831086
    10841087/**
    1085  * Writes data from network containing information about the state
    1086  * @param data pointer to data
    1087  * @param length length of data
    1088  * @param sender hostID of sender
    1089  */
    1090 int PNode::writeState( const byte * data, int length, int sender )
    1091 {
    1092   SYNCHELP_READ_BEGIN();
    1093 
    1094   SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE );
    1095 
    1096   //   char * parentName = NULL;
    1097   //   SYNCHELP_READ_STRINGM( parentName );
    1098   //
    1099   //   if ( strcmp(parentName, "")==0 )
    1100   //   {
    1101   //     setParent( (char*)NULL );
    1102   //   }
    1103   //   else
    1104   //   {
    1105   //     setParent( parentName );
    1106   //   }
    1107   //
    1108   //  delete[] parentName;
    1109 
    1110   int parentMode;
    1111   SYNCHELP_READ_INT( parentMode, NWT_PN_PARENTMODE );
    1112   this->setParentMode((PARENT_MODE)parentMode);
    1113 
    1114   float f1, f2, f3, f4;
    1115 
    1116   SYNCHELP_READ_FLOAT( f1, NWT_PN_COORX );
    1117   SYNCHELP_READ_FLOAT( f2, NWT_PN_COORY );
    1118   SYNCHELP_READ_FLOAT( f3, NWT_PN_COORZ );
    1119   this->setRelCoor( f1, f2, f3 );
    1120 
    1121 
    1122   SYNCHELP_READ_FLOAT( f1, NWT_PN_ROTV );
    1123   SYNCHELP_READ_FLOAT( f2, NWT_PN_ROTX );
    1124   SYNCHELP_READ_FLOAT( f3, NWT_PN_ROTY );
    1125   SYNCHELP_READ_FLOAT( f4, NWT_PN_ROTZ );
    1126   this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1127 
    1128   //   int n;
    1129   //   char * childName;
    1130   //
    1131   //   PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]);
    1132   //   SYNCHELP_READ_INT( n );
    1133   //   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
    1134   //
    1135   //   for (int i = 0; i<n; i++)
    1136   //   {
    1137   //     SYNCHELP_READ_STRINGM( childName );
    1138   //     PRINTF(0)("RCVD CHILD = %s\n", childName);
    1139   //     addChild( childName );
    1140   //     delete childName;
    1141   //     childName = NULL;
    1142   //   }
    1143 
    1144   return SYNCHELP_READ_N;
    1145 }
    1146 
    1147 /**
    1148  * data copied in data will bee sent to another host
    1149  * @param data pointer to data
    1150  * @param maxLength max length of data
    1151  * @return the number of bytes writen
    1152  */
    1153 int PNode::readState( byte * data, int maxLength )
    1154 {
    1155   SYNCHELP_WRITE_BEGIN();
    1156 
    1157   SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE );
    1158 
    1159   //   if ( this->parent )
    1160   //   {
    1161   //     SYNCHELP_WRITE_STRING( parent->getName() );
    1162   //   }
    1163   //   else
    1164   //   {
    1165   //     SYNCHELP_WRITE_STRING( "" );
    1166   //   }
    1167 
    1168   SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE );
    1169 
    1170   SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_COORX );
    1171   SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_COORY );
    1172   SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_COORZ );
    1173 
    1174   SYNCHELP_WRITE_FLOAT( this->relDirection.w, NWT_PN_ROTV );
    1175   SYNCHELP_WRITE_FLOAT( this->relDirection.v.x, NWT_PN_ROTX );
    1176   SYNCHELP_WRITE_FLOAT( this->relDirection.v.y, NWT_PN_ROTY );
    1177   SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ );
    1178 
    1179   //   int n = children.size();
    1180   //   //check if camera is in children
    1181   //   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1182   //   {
    1183   //     if ( (*it)->isA(CL_CAMERA) )
    1184   //       n--;
    1185   //   }
    1186   //   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
    1187   //   SYNCHELP_WRITE_INT( n );
    1188   //   PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]);
    1189   //
    1190   //
    1191   //   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1192   //   {
    1193   //     //dont add camera because there is only one camera attached to local player
    1194   //     if ( !(*it)->isA(CL_CAMERA) )
    1195   //     {
    1196   //       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
    1197   //       SYNCHELP_WRITE_STRING( (*it)->getName() );
    1198   //     }
    1199   //   }
    1200 
    1201   return SYNCHELP_WRITE_N;
    1202 }
    1203 
    1204 #define __FLAG_COOR 1
    1205 #define __FLAG_ROT  2
    1206 
    1207 #define __OFFSET_POS 1
    1208 #define __OFFSET_ROT 0.05
    1209 
    1210 /**
    1211  * Writes data from network containing information about the state which has changed
    1212  * @param data pointer to data
    1213  * @param length length of data
    1214  * @param sender hostID of sender
    1215  */
    1216 int PNode::writeSync( const byte * data, int length, int sender )
    1217 {
    1218   SYNCHELP_READ_BEGIN();
    1219 
    1220   if ( this->getHostID()==this->getOwner() )
    1221   {
    1222     return SYNCHELP_READ_N;
    1223   }
    1224 
    1225   byte flags = 0;
    1226   SYNCHELP_READ_BYTE( flags, NWT_PN_FLAGS );
    1227   //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags);
    1228 
    1229   float f1, f2, f3, f4;
    1230 
    1231   if ( flags & __FLAG_COOR )
    1232   {
    1233     SYNCHELP_READ_FLOAT( f1, NWT_PN_SCOORX );
    1234     SYNCHELP_READ_FLOAT( f2, NWT_PN_SCOORY );
    1235     SYNCHELP_READ_FLOAT( f3, NWT_PN_SCOORZ );
    1236     PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3);
    1237     this->setRelCoor( f1, f2, f3 );
    1238   }
    1239 
    1240   if ( flags & __FLAG_ROT )
    1241   {
    1242     SYNCHELP_READ_FLOAT( f1, NWT_PN_SROTV );
    1243     SYNCHELP_READ_FLOAT( f2, NWT_PN_SROTX );
    1244     SYNCHELP_READ_FLOAT( f3, NWT_PN_SROTY );
    1245     SYNCHELP_READ_FLOAT( f4, NWT_PN_SROTZ );
    1246     PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4);
    1247     //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1248     Quaternion q;
    1249     q.w = f1;
    1250     q.v.x = f2;
    1251     q.v.y = f3;
    1252     q.v.z = f4;
    1253     this->setAbsDir( q );
    1254   }
    1255 
    1256   return SYNCHELP_READ_N;
    1257 }
    1258 
    1259 /**
    1260  * data copied in data will bee sent to another host
    1261  * @param data pointer to data
    1262  * @param maxLength max length of data
    1263  * @return the number of bytes writen
    1264  */
    1265 int PNode::readSync( byte * data, int maxLength )
    1266 {
    1267   //WARNING: if you change this file make sure you also change needsReadSync
    1268   SYNCHELP_WRITE_BEGIN();
    1269 
    1270   if ( this->getHostID()!=0 && this->getHostID()!=this->getOwner() )
    1271   {
    1272     return SYNCHELP_WRITE_N;
    1273   }
    1274 
    1275   byte flags = 0;
    1276   if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1277        fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1278        fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
    1279     flags |= __FLAG_COOR;
    1280 
    1281   if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
    1282        fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
    1283        fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
    1284        fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
    1285     flags |= __FLAG_ROT;
    1286 
    1287 
    1288   SYNCHELP_WRITE_BYTE( flags, NWT_PN_FLAGS );
    1289   PRINTF(0)("FLAGS = %d\n", flags);
    1290 
    1291   if ( flags & __FLAG_COOR )
    1292   {
    1293 
    1294     PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
    1295 
    1296     SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_SCOORX );
    1297     SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_SCOORY );
    1298     SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_SCOORZ );
    1299 
    1300     coorx = relCoordinate.x;
    1301     coory = relCoordinate.y;
    1302     coorz = relCoordinate.z;
    1303   }
    1304 
    1305   if ( flags & __FLAG_ROT )
    1306   {
    1307 
    1308     PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
    1309 
    1310     SYNCHELP_WRITE_FLOAT( this->absDirection.w, NWT_PN_SROTV );
    1311     SYNCHELP_WRITE_FLOAT( this->absDirection.v.x, NWT_PN_SROTX );
    1312     SYNCHELP_WRITE_FLOAT( this->absDirection.v.y, NWT_PN_SROTY );
    1313     SYNCHELP_WRITE_FLOAT( this->absDirection.v.z, NWT_PN_SROTZ );
    1314 
    1315     rotw = absDirection.w;
    1316     rotx = absDirection.v.x;
    1317     roty = absDirection.v.y;
    1318     rotz = absDirection.v.z;
    1319   }
    1320 
    1321   return SYNCHELP_WRITE_N;
    1322 }
    1323 
    1324 bool PNode::needsReadSync( )
    1325 {
    1326   if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1327        fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1328        fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
    1329     return true;
    1330 
    1331   if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
    1332        fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
    1333        fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
    1334        fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
    1335     return true;
    1336 
    1337   return false;
    1338 }
     1088 * handles changes in synchronizable variables
     1089 * @param id id's which changed
     1090 */
     1091void PNode::varChangeHandler( std::list< int > & id )
     1092{
     1093#warning implement this
     1094}
     1095
     1096
  • branches/network/src/lib/coord/p_node.h

    r7221 r7444  
    187187  float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); };
    188188
    189   int       writeState(const byte* data, int length, int sender);
    190   int       readState(byte* data, int maxLength );
    191   int       writeSync(const byte* data, int length, int sender);
    192   int       readSync(byte* data, int maxLength );
    193   bool      needsReadSync();
    194 
    195189 private:
    196190  /** tells the child that the parent's Coordinate has changed */
     
    244238    float roty;
    245239    float rotz;
     240   
     241  private:
     242    int relCoordinate_handle;
     243    int relDirection_handle;
     244    Vector relCoordinate_write;
     245    Quaternion relDirection_write;
     246   
     247  public:
     248    virtual void varChangeHandler( std::list<int> & id );
    246249};
    247250
  • branches/network/src/lib/lang/base_object.cc

    r7230 r7444  
    177177
    178178}
    179 
    180 /**
    181  * Writes data from network containing information about the state
    182  * @param data pointer to data
    183  * @param length length of data
    184  * @param sender hostID of sender
    185  */
    186 int BaseObject::writeState( const byte * data, int length, int sender )
    187 {
    188   SYNCHELP_READ_BEGIN();
    189 
    190   SYNCHELP_READ_STRING( this->objectName, NWT_BO_NAME );
    191 
    192   return SYNCHELP_READ_N;
    193 }
    194 
    195 /**
    196  * data copied in data will bee sent to another host
    197  * @param data pointer to data
    198  * @param maxLength max length of data
    199  * @return the number of bytes writen
    200  */
    201 int BaseObject::readState( byte * data, int maxLength )
    202 {
    203   SYNCHELP_WRITE_BEGIN();
    204 
    205   //PRINTF(0)("objectname = %s\n", this->objectName);
    206   SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
    207 
    208   return SYNCHELP_WRITE_N;
    209 }
  • branches/network/src/lib/lang/base_object.h

    r7221 r7444  
    5151  bool operator==(ClassID classID) { return this->isA(classID); };
    5252
    53   int       writeState(const byte* data, int length, int sender);
    54   int       readState(byte* data, int maxLength );
    55 
    5653 protected:
    5754   void setClassID(ClassID classID, const std::string& className);
     55   std::string        objectName;        //!< The name of this object
    5856
    5957 private:
    6058    std::string        className;        //!< the name of the class
    6159    long               classID;          //!< this is the id from the class_id.h enumeration
    62     std::string        objectName;       //!< The name of this object
    6360
    6461    ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
  • branches/network/src/lib/network/Makefile.am

    r7026 r7444  
    1515                      handshake.cc \
    1616                      network_game_manager.cc \
    17                       converter.cc
     17                      converter.cc \
     18                      \
     19                      synchronizeable_var/synchronizeable_var.cc \
     20                      synchronizeable_var/synchronizeable_vector.cc \
     21                      synchronizeable_var/synchronizeable_int.cc \
     22                      synchronizeable_var/synchronizeable_quaternion.cc \
     23                      synchronizeable_var/synchronizeable_string.cc \
     24                      synchronizeable_var/synchronizeable_float.cc \
     25                      synchronizeable_var/synchronizeable_bool.cc \
     26                      synchronizeable_var/synchronizeable_uint.cc
    1827
    1928
     
    3241                 network_game_manager.h \
    3342                 converter.h \
    34                  netdefs.h
     43                 netdefs.h \
     44                 \
     45                 synchronizeable_var/synchronizeable_var.h \
     46                 synchronizeable_var/synchronizeable_vector.h \
     47                 synchronizeable_var/synchronizeable_int.h \
     48                 synchronizeable_var/synchronizeable_quaternion.h \
     49                 synchronizeable_var/synchronizeable_string.h \
     50                 synchronizeable_var/synchronizeable_float.h \
     51                 synchronizeable_var/synchronizeable_bool.h \
     52                 synchronizeable_var/synchronizeable_uint.h
    3553
    3654
  • branches/network/src/lib/network/handshake.cc

    r6815 r7444  
    3131
    3232  this->setIsServer(server);
    33   this->clientId = clientId;
    34   this->networkGameManagerId = networkGameManagerId;
    35   this->state = 0;
    36   this->isOk = false;
    37   this->setOwner(0);
     33  this->localState.hostId = clientId;
     34  this->localState.networkManagerId = networkGameManagerId;
     35 
     36  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId" ) );
     37  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version" ) );
     38  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId" ) );
     39  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId" ) );
     40  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed" ) );
     41  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error" ) );
     42  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString" ) );
     43
    3844
    3945  this->setSynchronized(true);
     
    4147}
    4248
    43 int Handshake::writeBytes( const byte * data, int length, int sender)
    44 {
    45   PRINTF(5)("Handshake::writeBytes states = %d %d %d %d (%d)\n", hasState( HS_RECVD_INIT ), hasState( HS_RECVD_VER ), hasState( HS_RECVD_HID ), hasState( HS_COMPLETED ), state);
    46 
    47   SYNCHELP_READ_BEGIN();
    48 
    49   if ( hasState( HS_COMPLETED ) )
    50        return 0;
    51 
    52   if ( !hasState( HS_RECVD_INIT ) )
    53   {
    54     if ( length != _INITIAL_DATA_LENGTH )
    55     {
    56       PRINTF(0)("initial packet has wrong size %d instead of %d\n", length, _INITIAL_DATA_LENGTH);
    57       setState( HS_COMPLETED );
    58       return 0;
    59     }
    60 
    61     if ( strncmp((char*)data, _INITIAL_DATA, length) )
    62     {
    63       PRINTF(0)("initial packed does not match\n");
    64       setState( HS_COMPLETED );
    65       return length;
    66     }
    67 
    68     setState( HS_RECVD_INIT );
    69     PRINTF(0)("got valid initial packet from client %d\n", clientId);
    70     return length;
    71   }
    72 
    73   if ( hasState( HS_RECVD_INIT ) && !hasState( HS_RECVD_VER ) )
    74   {
    75     if ( length != _ORXONOX_VERSION_LENGTH )
    76     {
    77       PRINTF(0)("version number packet has wrong size %d instead of %d\n", length, _ORXONOX_VERSION_LENGTH);
    78       setState( HS_COMPLETED );
    79       return 0;
    80     }
    81 
    82     if ( strncmp((char*)data, _ORXONOX_VERSION, length) )
    83     {
    84       PRINTF(0)("versions do not match\n");
    85       setState( HS_COMPLETED );
    86       return length;
    87     }
    88 
    89     setState( HS_RECVD_VER );
    90 
    91     PRINTF(0)("client %d's version does match\n", clientId);
    92     return length;
    93   }
    94 
    95   if ( !isServer() && hasState( HS_RECVD_VER ) && !hasState( HS_RECVD_HID ) )
    96   {
    97     /*if ( length != INTSIZE+INTSIZE )
    98     {
    99       PRINTF(0)("hostID packet has wrong size %d instead of %d\n", length, INTSIZE+INTSIZE);
    100       setState( HS_COMPLETED );
    101       return 0;
    102   }*/
    103 
    104     setState( HS_COMPLETED );
    105     setState( HS_RECVD_HID );
    106     this->isOk = true;
    107     SYNCHELP_READ_INT( this->newHostId, NWT_HS_HOST_ID );
    108     SYNCHELP_READ_INT( this->newNetworkGameManagerId, NWT_HS_NGM_ID );
    109 
    110     if ( newHostId == 0 )
    111     {
    112       setState( HS_WAS_REJECT );
    113       isOk = false;
    114       PRINTF(0)("Server did not accept handshake!\n");
    115     }
    116     else
    117     {
    118       PRINTF(0)("got my hostID: %d and networkGameManagerId: %d\n", newHostId, newNetworkGameManagerId);
    119     }
    120     return SYNCHELP_READ_N;
    121   }
    122 
    123 }
    124 
    125 int Handshake::readBytes( byte * data, int maxLength, int * reciever )
    126 {
    127   PRINTF(5)("Handshake::readBytes states = %d %d %d %d (%d)\n", hasState( HS_SENT_INIT ), hasState( HS_SENT_VER ), hasState( HS_SENT_HID ), hasState( HS_COMPLETED ), state);
    128 
    129   SYNCHELP_WRITE_BEGIN();
    130 
    131   if ( hasState( HS_COMPLETED ) )
    132     return 0;
    133 
    134   if ( !hasState( HS_SENT_INIT ) )
    135   {
    136     if ( maxLength < _INITIAL_DATA_LENGTH )
    137     {
    138       PRINTF(0)("buffer too small for _INITIAL_DATA");
    139       setState( HS_COMPLETED );
    140       return 0;
    141     }
    142 
    143     setState( HS_SENT_INIT );
    144     memcpy(data, _INITIAL_DATA, _INITIAL_DATA_LENGTH);
    145     if ( this->isServer() )
    146       *reciever = clientId;
    147     return _INITIAL_DATA_LENGTH;
    148   }
    149 
    150   if ( hasState( HS_RECVD_INIT ) && hasState( HS_SENT_INIT ) && !hasState( HS_SENT_VER ) )
    151   {
    152     if ( maxLength < _ORXONOX_VERSION_LENGTH )
    153     {
    154       PRINTF(0)("buffer too small for version number");
    155       setState( HS_COMPLETED );
    156       return 0;
    157     }
    158 
    159     setState( HS_SENT_VER );
    160     memcpy(data, _ORXONOX_VERSION, _ORXONOX_VERSION_LENGTH);
    161     if ( this->isServer() )
    162       *reciever = clientId;
    163     return _ORXONOX_VERSION_LENGTH;
    164   }
    165 
    166   if ( isServer() && hasState( HS_RECVD_VER) && hasState( HS_SENT_VER ) && !hasState( HS_SENT_HID ) )
    167   {
    168     if ( maxLength < 2 )
    169     {
    170       PRINTF(0)("buffer too small for ID");
    171       setState( HS_COMPLETED );
    172       return 0;
    173     }
    174 
    175     setState( HS_SENT_HID );
    176     setState( HS_COMPLETED );
    177 
    178     if ( hasState( HS_DO_REJECT ) )
    179     {
    180       isOk = false;
    181       //memcpy(data, (byte*)0, 4);
    182       SYNCHELP_WRITE_INT( 0, NWT_HS_HOST_ID);
    183       SYNCHELP_WRITE_INT( 0, NWT_HS_NGM_ID);
    184     }
    185     else
    186     {
    187       isOk = true;
    188       //memcpy(data, &clientId, 4);
    189       SYNCHELP_WRITE_INT( clientId, NWT_HS_HOST_ID );
    190       SYNCHELP_WRITE_INT( networkGameManagerId, NWT_HS_NGM_ID );
    191     }
    192     *reciever = clientId;
    193     return SYNCHELP_WRITE_N;
    194   }
    195 
    196   return 0;
    197 }
    198 
    199 void Handshake::writeDebug( ) const
     49/**
     50 * handler for changes in synced vars
     51 * @param id id's which have changed
     52 */
     53void Handshake::varChangeHandler( std::list< int > & id )
    20054{
    20155}
    20256
    203 void Handshake::readDebug( ) const
    204 {
    205 }
  • branches/network/src/lib/network/handshake.h

    r6341 r7444  
    1010#include "synchronizeable.h"
    1111
    12 #define _INITIAL_DATA "orxonox"
    13 #define _INITIAL_DATA_LENGTH 7
     12#define _INITIAL_DATA 0xF91337A0
    1413
    15 #define _ORXONOX_VERSION "\x00\x00\x00\x01"
    16 #define _ORXONOX_VERSION_LENGTH 4
     14#define _ORXONOX_VERSION 1
    1715
    18 typedef enum HandshakeState {
    19   HS_SENT_INIT  = 0x00000001,
    20   HS_RECVD_INIT = 0x00000002,
    21   HS_SENT_VER   = 0x00000004,
    22   HS_RECVD_VER  = 0x00000008,
    23   HS_SENT_HID   = 0x00000010,
    24   HS_RECVD_HID  = 0x00000020,
    25   HS_COMPLETED  = 0x00000040,
    26 
    27   HS_DO_REJECT  = 0x00010000,
    28   HS_WAS_REJECT = 0x00020000,
    29 
    30   NUM_STATES
     16struct HandshakeState {
     17  int orxId;
     18  int version;
     19 
     20  int networkManagerId;
     21  int hostId;
     22 
     23  int completed;
     24 
     25  int error;
     26 
     27  std::string errorString;
    3128};
    3229
     
    3431{
    3532  public:
    36     Handshake(bool server, int clientId = 0, int networkGameManagerId = 0);
    37     inline bool       completed(){ return hasState( HS_COMPLETED ); }
    38     inline bool       ok(){ return isOk; }
    39     inline int        getHostId(){ return newHostId; }
    40     inline int        getNetworkGameManagerId(){ return newNetworkGameManagerId; }
    41 
    42     inline void       doReject(){ setState(HS_DO_REJECT); }
    43 
    44     virtual int       writeBytes(const byte* data, int length, int sender);
    45     virtual int       readBytes(byte* data, int maxLength, int * reciever);
    46     virtual void      writeDebug() const;
    47     virtual void      readDebug() const;
     33    Handshake( bool server, int clientId = 0, int networkGameManagerId = 0 );
     34    inline bool       completed(){ return localState.completed != 0 && remoteState.completed != 0; }
     35    inline bool       ok(){ return localState.error == 0 && remoteState.error == 0; }
     36    inline int        getHostId(){ return localState.hostId; }
     37    inline int        getNetworkGameManagerId(){ return localState.networkManagerId; }
     38    inline void       doReject( std::string reason ){ remoteState.error = 1; remoteState.errorString = "the server rejected your connection ["+ reason +"]"; }
     39   
     40    virtual void varChangeHandler( std::list<int> & id );
    4841
    4942  private:
    50     int               state;
    51     int               clientId;
    52     int               networkGameManagerId;
    53     int               newHostId;
    54     int               newNetworkGameManagerId;
    55     bool              isOk;
    56 
    57     inline bool       hasState( int a ){ return (state & a) == a; }
    58     inline void       setState( int a ){ state = state | a; }
    59     inline void       unsetState( int a ){ state = state & (~a); }
     43    HandshakeState localState;
     44    HandshakeState remoteState;
     45   
     46    int netManId_handler;
     47    int hostId_handler;
     48    int completed_handler;
     49    int error_handler;
     50    int errorString_handler;
     51    int orxId_handler;
     52    int version_handler;
    6053
    6154};
  • branches/network/src/lib/network/network_game_manager.cc

    r7354 r7444  
    141141    {
    142142      sendEntityList( sender );
    143       continue;
    144     }
    145     else if ( b == NET_REQUEST_SYNC )
    146     {
    147       if ( !handleRequestSync( i, data, length, sender ) )
    148         return i;
    149143      continue;
    150144    }
     
    532526    s->setSynchronized(true);
    533527    //this->networkStream->connectSynchronizeable( *s );
    534     if ( !isServer() )
    535       s->setIsOutOfSync( true );
     528
    536529    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
    537530
     
    601594}
    602595
    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 }
    624596
    625597/**
     
    697669  assert(player != NULL);
    698670
    699   s->setIsOutOfSync( true );
    700 
    701671  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
    702672
     
    902872  return true;
    903873}
    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 
    921874
    922875/**
     
    986939}
    987940
    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 
     941
  • branches/network/src/lib/network/network_game_manager.h

    r6981 r7444  
    3535 *
    3636 *  REQUEST_ENTITY_LIST: //request the whole world :D
    37  *  REQUEST_SYNC:        >> UNIQUE_ID
    38  *                       << [Sync Info]
    39  *  //REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
    40  *
    4137 *  YOU_ARE_ENTITY:      >> UNIQUE_ID
    4238 *
     
    5450  NET_REQUEST_CREATE,
    5551  NET_REQUEST_REMOVE,
    56   NET_REQUEST_SYNC,
    5752  NET_YOU_ARE_ENTITY,
    5853  NET_REQUEST_ENTITY_LIST,
     
    9186    void sendYouAre( int uniqueID, int userID );
    9287
    93     void sync(int uniqueID, int owner);
    94 
    9588    void sendEntityList(int userID);
    9689
     
    111104    bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
    112105    bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
    113     bool handleRequestSync( int& i, const byte* data, int length, int sender );
    114106    bool handleRequestPNodePath(int& i, const byte* data, int length, int sender);
    115107    bool handleSendPNodePath(int& i, const byte* data, int length, int sender);
     
    124116    void executeRemoveEntity(int uniqueID);
    125117    void doRemoveEntity(int uniqueID);
    126 
    127     void executeRequestSync( int uniqueID, int user );
    128     void doRequestSync(int uniqueID, int userID);
    129118
    130119    void doYouAre( int uniqueID );
  • branches/network/src/lib/network/network_stream.cc

    r6959 r7444  
    250250
    251251        reciever = 0;
    252         dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
     252#warning fix this
     253dataLength = 0;
     254//TODO fix
     255        //dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
    253256
    254257        if ( dataLength<=0 ){
     
    345348        for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    346349        {
     350#warning fix this
     351#if 0
    347352          if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
    348353          {
     
    354359            continue;
    355360          }
     361#endif
    356362        }
    357363
     
    388394    if ( clientId > this->maxConnections )
    389395    {
    390       handshakes[clientId]->doReject();
     396      handshakes[clientId]->doReject( "too many connections" );
    391397      PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    392398    }
  • branches/network/src/lib/network/synchronizeable.cc

    r6753 r7444  
    3636  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
    3737  this->owner = -1;
    38   this->state = 0;
    3938  this->hostID = SharedNetworkData::getInstance()->getHostID();
    4039  this->setIsServer(this->hostID == 0);
    4140  this->uniqueID = NET_UID_UNASSIGNED;
    4241  this->networkStream = NULL;
    43   this->setRequestedSync( false );
    44   this->setIsOutOfSync( !(this->isServer()) );
    4542  this->bSynchronize = false;
    4643
     
    5249    this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
    5350  }
     51 
     52  this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );
    5453}
    5554
     
    6463    this->networkStream->disconnectSynchronizeable(*this);
    6564}
    66 
    67 
    68 /**
    69  *  write data to NetworkStream
    70  */
    71 int Synchronizeable::writeBytes(const byte* data, int length, int sender)
    72 {
    73   PRINTF(5)("Synchronizeable::writeBytes was called\n");
    74 }
    75 
    76 
    77 /**
    78  *  read data from NetworkStream
    79  */
    80 int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
    81 {
    82   PRINTF(5)("Synchronizeable::readBytes was called\n");
    83 }
    84 
    85 
    86 void Synchronizeable::writeDebug() const
    87 {}
    88 
    89 
    90 void Synchronizeable::readDebug() const
    91 {}
    92 
    9365
    9466/**
     
    10678
    10779/**
    108  * Sets the outofsync flag to a given value
    109  * @param outOfSync: the boolean value which the outofsync flag is to set to
    110  */
    111 void Synchronizeable::setIsOutOfSync(bool outOfSync)
    112 {
    113   if( outOfSync )
    114     this->state = this->state | STATE_OUTOFSYNC;
    115   else
    116     this->state = this->state & (~STATE_OUTOFSYNC);
    117   //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
    118 }
    119 
    120 
    121 /**
    12280 * Determines if the server flag is set
    12381 * @return true, if the server flag is true, false else
     
    13088
    13189/**
    132  * Determines if the outofsync flag is set
    133  * @return true, if the outofsync flag is true, false else
     90 * get the diff to last acked state of userId
     91 * @param userId user to create diff for
     92 * @param data buffer to copy diff in
     93 * @param maxLength max bytes to copy into data
     94 * @param stateId id of current state
     95 * @param priorityTH tells getStateDiff to not send element with priority \< priorityTH
     96 * @return n bytes copied into data
    13497 */
    135 bool Synchronizeable::isOutOfSync()
     98int Synchronizeable::getStateDiff( int userId, byte* data, int maxLength, int stateId, int priorityTH )
    13699{
    137   return (this->state & STATE_OUTOFSYNC) >0;
     100#warning implement this
     101}
     102
     103/**
     104 * sets a new state out of a diff created on another host
     105 * @param userId hostId of user who send me that diff
     106 * @param data pointer to diff
     107 * @param length length of diff
     108 * @param stateId id of current state
     109 * @return true on success
     110 */
     111bool Synchronizeable::setStateDiff( int userId, byte* data, int length, int stateId )
     112{
     113#warning implement this
     114}
     115
     116 /**
     117 * override this function to be notified on change
     118 * of your registred variables.
     119 * @param id id's which have changed
     120 */
     121void varChangeHandler( std::list<int> & id )
     122{
     123#warning implement this
     124}
     125
     126/**
     127 * registers a varable to be synchronized over network
     128 * @param var see src/lib/network/synchronizeable_var/ for available classes
     129 */
     130void Synchronizeable::registerVar( SynchronizeableVar * var )
     131{
     132#warning implement this
     133}
     134
     135/**
     136 * registers a varable to be synchronized over network
     137 * return value is passed to varChangeHandler on change
     138 * @param var see src/lib/network/synchronizeable_var/ for available classes
     139 * @return handle passed to varChangeHandler on changes
     140 */
     141int Synchronizeable::registerVarId( SynchronizeableVar * var )
     142{
     143#warning implement this
    138144}
    139145
    140146
    141 /**
    142  * Determines if the requestedSync flag is set
    143  * @return true, if the requestedSync flag is true, false else
    144  */
    145 bool Synchronizeable::requestedSync()
    146 {
    147   return (this->state & STATE_REQUESTEDSYNC) >0;
    148 }
    149 
    150 
    151 /**
    152  * Sets the requestedsync flag to a given value
    153  * @param requestedSync: the boolean value which the requestedsync flag is to set to
    154  */
    155 void Synchronizeable::setRequestedSync( bool requestedSync )
    156 {
    157   if( requestedSync )
    158     this->state = this->state | STATE_REQUESTEDSYNC;
    159   else
    160     this->state = this->state & (~STATE_REQUESTEDSYNC);
    161 }
    162 
    163 
    164 
  • branches/network/src/lib/network/synchronizeable.h

    r7230 r7444  
    11/*!
    2  * @file connection_monitor.h
     2 * @file synchronizeable.h
    33    \brief interface for all classes that have to be synchronized
    44 */
     
    1010#include "netdefs.h"
    1111#include "converter.h"
    12 
     12#include "vector.h"
     13#include "quaternion.h"
     14#include "synchronizeable_var/synchronizeable_var.h"
     15#include "synchronizeable_var/synchronizeable_vector.h"
     16#include "synchronizeable_var/synchronizeable_quaternion.h"
     17#include "synchronizeable_var/synchronizeable_string.h"
     18#include "synchronizeable_var/synchronizeable_int.h"
     19#include "synchronizeable_var/synchronizeable_float.h"
     20#include "synchronizeable_var/synchronizeable_bool.h"
     21#include "synchronizeable_var/synchronizeable_uint.h"
    1322
    1423
     
    1827//State constants: They have to be of the form 2^n
    1928#define STATE_SERVER 1
    20 #define STATE_OUTOFSYNC 2
    21 #define STATE_REQUESTEDSYNC 4
    2229
    2330enum {
    24   NWT_SS_WE_STATE = 1000000,
    25   NWT_SS_B,
    26   NWT_SS_FLAGS,
    27   NWT_SS_MOUSEDIRX,
    28   NWT_SS_MOUSEDIRY,
    29   NWT_SS_MOUSEDIRZ,
    30   NWT_SS_MOUSEDIRW,
    31   NWT_SS_PN_SYNC,
    32   NWT_SS_VELX,
    33   NWT_SS_VELY,
    34   NWT_SS_VELZ,
    35   NWT_SS_PL_SYNC,
    36   NWT_SS_CO_N,
    37   NWT_SS_CO_CLID,
    38 
    39   NWT_HS_HOST_ID,
    40   NWT_HS_NGM_ID,
    41 
    42   NWT_PL_B,
    43   NWT_PL_FLAGS,
    44   NWT_PL_SCORE,
    45 
    46   NWT_PN_BO_WRITESTATE,
    47   NWT_PN_PARENTMODE,
    48   NWT_PN_COORX,
    49   NWT_PN_COORY,
    50   NWT_PN_COORZ,
    51   NWT_PN_ROTX,
    52   NWT_PN_ROTY,
    53   NWT_PN_ROTZ,
    54   NWT_PN_ROTV,
    55 
    56   NWT_PN_FLAGS,
    57   NWT_PN_SCOORX,
    58   NWT_PN_SCOORY,
    59   NWT_PN_SCOORZ,
    60   NWT_PN_SROTX,
    61   NWT_PN_SROTY,
    62   NWT_PN_SROTZ,
    63   NWT_PN_SROTV,
    64 
    65   NWT_BO_NAME,
    66 
    67   NWT_WE_PN_WRITESTATE,
    68   NWT_WE_PN_MODELFILENAME,
    69   NWT_WE_PN_SCALING,
    70 
    71   NWT_GT_WE_STATE,
    72 
    73   NWT_SB_WE_STATE,
    74   NWT_SB_SIZE,
    75   NWT_SB_TEXTURENAME,
    76 
    77   NWT_TER_WE_STATE,
    78 
    79   NWT_PU_WE_STATE,
    80 
    81   NWT_TPU_WE_STATE,
    82 
    83   NWT_LPU_WE_STATE,
    84 
    85   NWT_WPU_WE_STATE,
    86 
    87   NWT_PPU_WE_STATE,
    88   NWT_PPU_TYPE,
    89   NWT_PPU_VALUE,
    90   NWT_PPU_MINVALUE,
    91   NWT_PPU_MAXVALUE,
    92 
    93   NWT_WAT_STATE,
    94   NWT_WAT_WE_STATE,
    95   NWT_WAT_SIZEX,
    96   NWT_WAT_SIZEY,
    97   NWT_WAT_RESX,
    98   NWT_WAT_RESY,
    99   NWT_WAT_HEIGHT
     31  PERMISSION_OWNER = 1,
     32  PERMISSION_ALL   = 2
    10033};
    10134
    102 
    103 //macros to help writing data in byte buffer
    104 /*
    105  * Important: these macros must be used in
    106  *     SYNCHELP_READ_*:  virtual void      writeBytes(const byte* data, int length, int sender);
    107  *     SYNCHELP_WRITE_*: virtual int       readBytes(byte* data, int maxLength, int * reciever);
    108  * with the same argument names!
    109  *
    110  * id is one int out of that enum on top of this comment it is used to identify
    111  * read/write. when you read a value you have to use exactly the same as you used
    112  * to write or you will see an assertion failing.
    113  *
    114  * SYNCHELP_WRITE_BEGIN()
    115  * SYNCHELP_WRITE_INT(i,id)
    116  * SYNCHELP_WRITE_FLOAT(f,id)
    117  * SYNCHELP_WRITE_BYTE(b,id)
    118  * SYNCHELP_WRITE_STRING(s,id)
    119  * SYNCHELP_WRITE_N
    120  *
    121  * SYNCHELP_READ_BEGIN()
    122  * SYNCHELP_READ_INT(i,id)
    123  * SYNCHELP_READ_FLOAT(f,id)
    124  * SYNCHELP_READ_STRING(s,l,id) l = size of buffer s
    125  * SYNCHELP_READ_STRINGM(s,id)  allocates memory for string! you have to delete this later
    126  * SYNCHELP_READ_BYTE(b,id)
    127  * SYNCHELP_READ_REMAINING() returns the remaining buffer size
    128  * SYNCHELP_READ_NEXTBYTE()  reads the next byte but it is not removed from the buffer
    129  * SYNCHELP_READ_N
    130  *
    131  *
    132  *
    133  * Example 1:
    134  *  SYNCHELP_READ_BEGIN();
    135  *  SYNCHELP_READ_FLOAT(size);
    136  *  SYNCHELP_READ_STRING( textureName, 1024 ); //1024 is the length of textureName
    137  *  delete[] textureName;
    138  *  textureName = NULL;
    139  *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1]
    140  *
    141  * Example 2:
    142  *  SYNCHELP_WRITE_BEGIN();
    143  *  SYNCHELP_WRITE_FLOAT(this->size);
    144  *  SYNCHELP_WRITE_STRING(this->textureName);
    145  *  return SYNCHELP_WRITE_N;
    146  *
    147  */
    148 
    149 #define SYNCHELP_WRITE_DEBUG(n) {\
    150   __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
    151   assert( __synchelp_write_n == INTSIZE ); \
    152   __synchelp_write_i += __synchelp_write_n; \
    153 }
    154 
    155 #define SYNCHELP_READ_DEBUG(n) {  \
    156   int nn; \
    157   __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &nn );  \
    158   assert( __synchelp_read_n == INTSIZE ); \
    159   if ( n != nn ) { \
    160     PRINTF(1)("Check your code! read/writes not in right order! read %d instead of %d\n", nn, n); \
    161     assert( false ); \
    162   } \
    163   __synchelp_read_i += __synchelp_read_n; \
    164 }
    165 
    166 #define SYNCHELP_WRITE_BEGIN()    int __synchelp_write_i = 0; \
    167                                   int __synchelp_write_n
    168 #define SYNCHELP_WRITE_INT(i,n) { SYNCHELP_WRITE_DEBUG(n); \
    169                                 __synchelp_write_n = \
    170                                 Converter::intToByteArray( i, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
    171                                 assert( __synchelp_write_n == INTSIZE ); \
    172                                 if ( __synchelp_write_n <= 0) \
    173 { \
    174                                   PRINTF(1)("Buffer is too small to store a int\n"); \
    175                                   return 0; \
    176 } \
    177                                 __synchelp_write_i += __synchelp_write_n; \
    178 }
    179 #define SYNCHELP_WRITE_FLOAT(f,n) { SYNCHELP_WRITE_DEBUG(n); \
    180                                 __synchelp_write_n = \
    181                                 Converter::floatToByteArray( f, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
    182                                 assert( __synchelp_write_n == FLOATSIZE ); \
    183                                 if ( __synchelp_write_n <= 0) \
    184 { \
    185                                   PRINTF(1)("Buffer is too small to store a float\n"); \
    186                                   return 0; \
    187 } \
    188                                 __synchelp_write_i += __synchelp_write_n; \
    189 }
    190 #define SYNCHELP_WRITE_BYTE(b,n) { SYNCHELP_WRITE_DEBUG(n); \
    191                                 \
    192                                 if (maxLength - __synchelp_write_i < 1) \
    193 { \
    194                                   PRINTF(1)("Buffer is too small to store string\n"); \
    195                                   return 0; \
    196 } \
    197                                 data[__synchelp_write_i] = b; \
    198                                 __synchelp_write_i++; \
    199 }
    200 #define SYNCHELP_WRITE_STRING(s,n) { SYNCHELP_WRITE_DEBUG(n); \
    201                                 __synchelp_write_n = \
    202                                 Converter::stringToByteArray( s, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
    203                                 assert( __synchelp_write_n == ((std::string)s).length()+INTSIZE ); \
    204                                 if ( __synchelp_write_n <= 0) \
    205 { \
    206                                   PRINTF(1)("Buffer is too small to store string\n"); \
    207                                   return 0; \
    208 } \
    209                                 __synchelp_write_i += __synchelp_write_n; \
    210 }
    211 #define SYNCHELP_WRITE_N        __synchelp_write_i
    212 #define SYNCHELP_WRITE_FKT(f,n)   { SYNCHELP_WRITE_DEBUG(n); \
    213                                   PRINTF(0)("calling %s with %d left\n", #f, maxLength - __synchelp_write_i);  \
    214                                   byte * spos = data+__synchelp_write_i;  \
    215                                   if (maxLength - __synchelp_write_i < INTSIZE) \
    216 { \
    217                                     PRINTF(1)("Buffer is too small to store more data\n"); \
    218                                     return 0; \
    219 } \
    220                                   __synchelp_write_i += INTSIZE; \
    221                                   __synchelp_write_n = \
    222                                   f( data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
    223                                   __synchelp_write_i += __synchelp_write_n;  \
    224                                   Converter::intToByteArray( __synchelp_write_n, spos, INTSIZE ); \
    225                                 }
    226 
    227 
    228 #define SYNCHELP_READ_BEGIN()     int __synchelp_read_i = 0; \
    229                                   int __synchelp_read_n
    230 
    231 #define SYNCHELP_READ_INT(i,n)       { SYNCHELP_READ_DEBUG(n); \
    232                                     if ( length-__synchelp_read_i < INTSIZE ) \
    233 { \
    234                                       PRINTF(1)("There is not enough data to read an int\n");  \
    235                                       return 0; \
    236 } \
    237                                     __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &i );  \
    238                                     assert( __synchelp_read_n == INTSIZE ); \
    239                                     __synchelp_read_i += __synchelp_read_n; \
    240 }
    241 #define SYNCHELP_READ_FLOAT(f,n)    { SYNCHELP_READ_DEBUG(n); \
    242                                     if ( length-__synchelp_read_i < FLOATSIZE ) \
    243 { \
    244                                       PRINTF(1)("There is not enough data to read a flaot\n");  \
    245                                       return 0; \
    246 } \
    247                                     __synchelp_read_n = Converter::byteArrayToFloat( data+__synchelp_read_i, &f );  \
    248                                     assert( __synchelp_read_n == FLOATSIZE ) ;\
    249                                     __synchelp_read_i += __synchelp_read_n; \
    250 }
    251 #define SYNCHELP_READ_STRING(s,n)    {SYNCHELP_READ_DEBUG(n); \
    252                                     __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, length-__synchelp_read_i );  \
    253                                     assert( __synchelp_read_n == s.length()+INTSIZE ) ;\
    254                                     if ( __synchelp_read_n <0 )  \
    255 { \
    256                                       PRINTF(1)("There is not enough data to read string\n");  \
    257                                       return 0; \
    258 } \
    259                                     __synchelp_read_i += __synchelp_read_n; \
    260 }
    261 #if 0 //not needed any more
    262 #define SYNCHELP_READ_STRINGM(s,n)    { SYNCHELP_READ_DEBUG(n); \
    263                                     __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s );  \
    264                                     assert( __synchelp_read_n == strlen(s)+INTSIZE ) ;\
    265                                     if ( __synchelp_read_n <0 )  \
    266 { \
    267                                       PRINTF(1)("There is not enough data to read string\n");  \
    268                                       return 0; \
    269 } \
    270                                     __synchelp_read_i += __synchelp_read_n; \
    271 }
    272 #endif
    273 #define SYNCHELP_READ_BYTE(b,n)      { SYNCHELP_READ_DEBUG(n); \
    274                                     if ( length-__synchelp_read_i < 1 ) \
    275 { \
    276                                       PRINTF(1)("There is not enough data to read a byte\n");  \
    277                                       return 0; \
    278 } \
    279                                     b = data[__synchelp_read_i]; \
    280                                     __synchelp_read_i ++;  \
    281 }
    282 #define SYNCHELP_READ_FKT(f,n)   { SYNCHELP_READ_DEBUG(n); \
    283                                   int s; \
    284                                   if ( length-__synchelp_read_i < INTSIZE ) \
    285 { \
    286                                       PRINTF(1)("There is not enough data to read an int\n");  \
    287                                       return 0; \
    288 } \
    289                                     __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &s );  \
    290                                     assert( __synchelp_read_n == INTSIZE ); \
    291                                     __synchelp_read_i += __synchelp_read_n; \
    292                                   __synchelp_read_i += \
    293                                   f( data+__synchelp_read_i, s, sender); \
    294                                   }
    295 #define SYNCHELP_READ_REMAINING() ( length-__synchelp_read_i )
    296 #define SYNCHELP_READ_NEXTBYTE() ( data[__synchelp_read_i] )
    297 #define SYNCHELP_READ_N           __synchelp_read_i
     35typedef std::vector<SynchronizeableVar> SyncVarList;
    29836
    29937class NetworkStream;
    300 
    30138
    30239class Synchronizeable : virtual public BaseObject
     
    30744    virtual ~Synchronizeable();
    30845
    309     virtual int       writeBytes(const byte* data, int length, int sender);
    310     virtual int       readBytes(byte* data, int maxLength, int * reciever);
    311     virtual void      writeDebug() const;
    312     virtual void      readDebug() const;
    313 
    31446    void setIsServer( bool isServer );
    315     void setIsOutOfSync( bool outOfSync );
    316     void setRequestedSync( bool requestedSync );
    31747    bool isServer();
    318     bool isOutOfSync();
    319     bool requestedSync();
    320 
     48   
     49    virtual void varChangeHandler( std::list<int> & id );
     50   
     51    int getStateDiff( int userId, byte* data, int maxLength, int stateId, int priorityTH );
     52    bool setStateDiff( int userId, byte* data, int length, int stateId );
     53   
     54    void registerVar( SynchronizeableVar * var );
     55    int registerVarId( SynchronizeableVar * var );
     56   
    32157    inline void setUniqueID( int id ){ uniqueID = id; }
    32258    inline int  getUniqueID() const { return uniqueID; }
     
    33167    inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; }
    33268
    333     inline void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); }
    334     inline int getRequestSync( void ){ if ( this->synchronizeRequests.size()>0 ){ int n = *(synchronizeRequests.begin()); synchronizeRequests.pop_front(); return n; } else { return -1; } };
    335 
    33669    inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
    33770    inline NetworkStream* getNetworkStream() { return this->networkStream; }
     
    33972
    34073  protected:
    341     NetworkStream*    networkStream;
     74    NetworkStream*    networkStream;  //!< reference network stream we are connected to
    34275    int               state;
    34376
    344 
    34577  private:
    346     int               uniqueID;
    347     int               owner;
    348     int               hostID;
    349     bool              bSynchronize;
    350 
    351     std::list<int>    synchronizeRequests;
     78    int               uniqueID;       //!< unique id assigned to synchronizeable
     79    int               owner;          //!< hostId of owner ( 0 if none / server )
     80    int               hostID;         //!< my own host id
     81    bool              bSynchronize;   //!< do we need beeing synchronized?
    35282
    35383};
Note: See TracChangeset for help on using the changeset viewer.