Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7444 in orxonox.OLD


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

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

Location:
branches/network/src
Files:
17 added
37 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};
  • branches/network/src/util/multiplayer_team_deathmatch.cc

    r7221 r7444  
    203203      if ( terrz < terrain->getHeight( terrx, terry ) && ss->getAbsCoor().x > -1000 )
    204204      {
    205         //PRINTF(0)("COLLLLLLIIIIIDDDDEEEE\n");
    206         ss->networkCollisionList.push_back( 1234567890 );
    207         ss->doCollideNetwork( 1234567890 );
     205        //TODO handle this
    208206      }
    209       //PRINTF(0)("x = %f, y = %f, z = %f, height = %f\n", terrx, terry, terrz, terrain->getHeight( terrx, terry ));
    210       //ss->setRelCoorSoft( ss->getAbsCoor().x, terrain->getHeight( terrx, terry )-offsety, ss->getAbsCoor().z );
     207
    211208
    212209      float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len();
     
    222219        if((*it)->isA(CL_SPACE_SHIP))
    223220        {
    224           dynamic_cast<SpaceShip*>(*it)->networkCollisionList.push_back(1163692);
    225           dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(11636922);
     221          //TODO handle this
    226222        }
    227223      }
  • branches/network/src/world_entities/environments/water.cc

    r7370 r7444  
    5959  // To test the Wave equation
    6060  //this->wave(5.0,4.0, 1, 10);
     61 
     62  height_handle = registerVarId( new SynchronizeableFloat( &height, &height, "height" ) );
     63  resX_handle = registerVarId( new SynchronizeableUInt( &resX, &resX, "resX" ) );
     64  resY_handle = registerVarId( new SynchronizeableUInt( &resY, &resY, "resY" ) );
     65  sizeX_handle = registerVarId( new SynchronizeableFloat( &sizeX, &sizeX, "sizeX" ) );
     66  sizeY_handle = registerVarId( new SynchronizeableFloat( &sizeY, &sizeY, "sizeY" ) );
    6167}
    6268
     
    291297
    292298
    293 /**
    294  * Writes data from network containing information about the state
    295  * @param data pointer to data
    296  * @param length length of data
    297  * @param sender hostID of sender
    298  */
    299 int Water::writeBytes( const byte * data, int length, int sender )
    300 {
    301   setRequestedSync( false );
    302   setIsOutOfSync( false );
    303 
    304   SYNCHELP_READ_BEGIN();
    305 
    306   SYNCHELP_READ_FKT( Water::writeState, NWT_WAT_STATE );
    307 
    308   return SYNCHELP_READ_N;
    309 }
    310 
    311 
    312 /**
    313  * data copied in data will bee sent to another host
    314  * @param data pointer to data
    315  * @param maxLength max length of data
    316  * @return the number of bytes writen
    317  */
    318 int Water::readBytes( byte * data, int maxLength, int * reciever )
    319 {
    320   SYNCHELP_WRITE_BEGIN();
    321 
    322   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    323   {
    324     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    325     setRequestedSync( true );
    326   }
    327 
    328   int rec = this->getRequestSync();
    329   if ( rec > 0 )
    330   {
    331     *reciever = rec;
    332     SYNCHELP_WRITE_FKT( Water::readState, NWT_WAT_STATE );
    333   }
    334 
    335   *reciever = 0;
    336   return SYNCHELP_WRITE_N;
    337 }
    338 
    339 
    340 
    341 /**
    342  * data copied in data will bee sent to another host
    343  * @param data pointer to data
    344  * @param maxLength max length of data
    345  * @return the number of bytes writen
    346  */
    347 int Water::readState( byte * data, int maxLength )
    348 {
    349   SYNCHELP_WRITE_BEGIN();
    350 
    351   SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_WAT_WE_STATE );
    352 
    353   // sync the size
    354   SYNCHELP_WRITE_FLOAT( this->sizeX, NWT_WAT_SIZEX );
    355   SYNCHELP_WRITE_FLOAT( this->sizeY, NWT_WAT_SIZEY );
    356 
    357   //sync resolution
    358   SYNCHELP_WRITE_INT( this->resX, NWT_WAT_RESX );
    359   SYNCHELP_WRITE_INT( this->resY, NWT_WAT_RESY );
    360 
    361   //sync the height
    362   SYNCHELP_WRITE_FLOAT( this->height, NWT_WAT_HEIGHT );
    363 
    364   return SYNCHELP_WRITE_N;
    365 }
    366 
    367 
    368 /**
    369  * Writes data from network containing information about the state
    370  * @param data pointer to data
    371  * @param length length of data
    372  * @param sender hostID of sender
    373  */
    374 int Water::writeState( const byte * data, int length, int sender )
    375 {
    376   SYNCHELP_READ_BEGIN();
    377 
    378   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_WAT_WE_STATE );
    379 
    380   float f1, f2;
    381   int i1, i2;
    382 
    383   //read the size
    384   SYNCHELP_READ_FLOAT( f1, NWT_WAT_SIZEX );
    385   SYNCHELP_READ_FLOAT( f2, NWT_WAT_SIZEY );
    386   this->sizeX = f1;
    387   this->sizeY = f2;
    388   PRINTF(0)("Setting Water to size: %f x %f\n", f1, f2);
    389 
    390   //read the resolution
    391   SYNCHELP_READ_INT( i1, NWT_WAT_RESX );
    392   SYNCHELP_READ_INT( i2, NWT_WAT_RESY );
    393   this->resX = i1;
    394   this->resY = i2;
    395   PRINTF(0)("Setting Water to resolution: %i x %i\n", i1, i2);
    396 
    397   //read the height
    398   SYNCHELP_READ_FLOAT( f1, NWT_WAT_HEIGHT );
    399   this->height = f1;
    400 
    401   this->rebuildGrid();
    402 
    403   return SYNCHELP_READ_N;
    404 }
    405 
    406 
     299
     300/**
     301 * function to handle changes in synced vars
     302 * @param id ids which have changed
     303 */
     304void Water::varChangeHandler( std::list< int > & id )
     305{
     306  if ( std::find( id.begin(), id.end(), height_handle ) != id.end() ||
     307       std::find( id.begin(), id.end(), resX_handle ) != id.end() ||
     308       std::find( id.begin(), id.end(), resY_handle ) != id.end() ||
     309       std::find( id.begin(), id.end(), sizeX_handle ) != id.end() ||
     310       std::find( id.begin(), id.end(), sizeY_handle ) != id.end()
     311     )
     312  {
     313    this->rebuildGrid();
     314  }
     315}
  • branches/network/src/world_entities/environments/water.h

    r7125 r7444  
    3838   void draw() const;
    3939   void tick(float dt);
    40 
    41    virtual int writeBytes(const byte* data, int length, int sender);
    42    virtual int readBytes(byte* data, int maxLength, int * reciever);
    43 
    44    int writeState( const byte * data, int length, int sender );
    45    int readState( byte * data, int maxLength );
     40   
     41   virtual void varChangeHandler( std::list<int> & id );
    4642
    4743  private:
     
    5652    Material        waterMaterial;
    5753    Shader*         waterShader;
     54   
    5855    float           height;          //!< The hight of the Water
     56    int             height_handle;   //!< Handle to notify about changes of height
    5957
    60     unsigned int    resX, resY;
    61     float           sizeX, sizeY;
     58    unsigned int    resX, resY;      //!< Grid resolution
     59    int             resX_handle;     //!< Handle to notify about changes of resX
     60    int             resY_handle;     //!< Handle to notify about changes of resY
     61    float           sizeX, sizeY;    //!< waters size
     62    int             sizeX_handle;    //!< Handle to notify about changes of sizeX
     63    int             sizeY_handle;    //!< Handle to notify about changes of sizeY
    6264
    6365    float phase;
  • branches/network/src/world_entities/npcs/ground_turret.cc

    r7193 r7444  
    180180  Explosion::explode(this, Vector(10,10,10));
    181181}
    182 
    183 /**
    184  * Writes data from network containing information about the state
    185  * @param data pointer to data
    186  * @param length length of data
    187  * @param sender hostID of sender
    188  */
    189 int GroundTurret::writeBytes( const byte * data, int length, int sender )
    190 {
    191   setRequestedSync( false );
    192   setIsOutOfSync( false );
    193 
    194   SYNCHELP_READ_BEGIN();
    195 
    196   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
    197 
    198   return SYNCHELP_READ_N;
    199 }
    200 
    201 /**
    202  * data copied in data will bee sent to another host
    203  * @param data pointer to data
    204  * @param maxLength max length of data
    205  * @return the number of bytes writen
    206  */
    207 int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
    208 {
    209   SYNCHELP_WRITE_BEGIN();
    210 
    211   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    212   {
    213     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    214     setRequestedSync( true );
    215   }
    216 
    217   int rec = this->getRequestSync();
    218   if ( rec > 0 )
    219   {
    220     *reciever = rec;
    221 
    222     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
    223 
    224   }
    225 
    226   *reciever = 0;
    227   return SYNCHELP_WRITE_N;
    228 }
  • branches/network/src/world_entities/npcs/ground_turret.h

    r7102 r7444  
    3030  virtual void tick(float time);
    3131
    32   virtual int writeBytes(const byte* data, int length, int sender);
    33   virtual int readBytes(byte* data, int maxLength, int * reciever);
    34 
    3532 private:
    3633   PNode  weaponHolder[2];
  • branches/network/src/world_entities/playable.cc

    r7356 r7444  
    6060
    6161  this->score = 0;
    62   this->oldScore = 0;
    6362
    6463  this->bDead = false;
     64 
     65  registerVar( new SynchronizeableInt( &score, &score, "score" ) );
    6566}
    6667
     
    480481
    481482
    482 #define DATA_FLAGS    1
    483 #define DATA_SCORE    2
    484 
    485 #define FLAGS_bFire   1
    486 
    487 int Playable::writeSync( const byte * data, int length, int sender )
    488 {
    489   SYNCHELP_READ_BEGIN();
    490 
    491   byte b;
    492   SYNCHELP_READ_BYTE( b, NWT_PL_B );
    493 
    494   byte flags;
    495 
    496   if ( b == DATA_FLAGS )
    497   {
    498     SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS );
    499 
    500     bFire = (flags & FLAGS_bFire) != 0;
    501 
    502     return SYNCHELP_READ_N;
    503   }
    504 
    505   if ( b == DATA_SCORE )
    506   {
    507     int newScore;
    508     SYNCHELP_READ_BYTE( newScore, NWT_PL_SCORE );
    509     setScore( newScore );
    510 
    511     return SYNCHELP_READ_N;
    512   }
    513 
    514   return SYNCHELP_READ_N;
    515 }
    516 
    517 int Playable::readSync( byte * data, int maxLength )
    518 {
    519   SYNCHELP_WRITE_BEGIN();
    520 
    521   if ( score != oldScore && isServer() )
    522   {
    523     SYNCHELP_WRITE_BYTE( DATA_SCORE, NWT_PL_B);
    524     SYNCHELP_WRITE_INT( score, NWT_PL_SCORE );
    525     oldScore = score;
    526 
    527     return SYNCHELP_WRITE_N;
    528   }
    529 
    530   byte flags = 0;
    531 
    532   if ( bFire )
    533     flags |= FLAGS_bFire;
    534 
    535 
    536   SYNCHELP_WRITE_BYTE( DATA_FLAGS, NWT_PL_B);
    537   SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS );
    538   oldFlags = flags;
    539 
    540 
    541   return SYNCHELP_WRITE_N;
    542 }
    543 
    544 bool Playable::needsReadSync( )
    545 {
    546   if ( score != oldScore && isServer() )
    547     return true;
    548 
    549   byte flags = 0;
    550 
    551   if ( bFire )
    552     flags |= FLAGS_bFire;
    553 
    554   return flags!=oldFlags;
    555 }
    556 
    557483
    558484/**
  • branches/network/src/world_entities/playable.h

    r7351 r7444  
    7979  virtual void tick(float dt);
    8080
    81   // NETWORK
    82   int       writeSync(const byte* data, int length, int sender);
    83   int       readSync(byte* data, int maxLength );
    84   bool      needsReadSync();
    85 
    86 
    8781  // Transformations:
    8882  static Playable::Playmode stringToPlaymode(const std::string& playmode);
     
    111105  int                   oldFlags;           //!< Used for synchronisation
    112106
    113   int                   score;
    114   int                   oldScore;
     107  int                   score;              //!< players score
    115108
    116109  bool                  bDead;
  • branches/network/src/world_entities/power_ups/laser_power_up.cc

    r7193 r7444  
    120120}
    121121
    122 int LaserPowerUp::writeBytes( const byte * data, int length, int sender )
    123 {
    124   setRequestedSync( false );
    125   setIsOutOfSync( false );
    126122
    127   SYNCHELP_READ_BEGIN();
    128 
    129   SYNCHELP_READ_FKT( PowerUp::writeState, NWT_LPU_WE_STATE );
    130 
    131   return SYNCHELP_READ_N;
    132 }
    133 
    134 
    135 
    136 int LaserPowerUp::readBytes( byte * data, int maxLength, int * reciever )
    137 {
    138   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    139   {
    140     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    141     setRequestedSync( true );
    142   }
    143 
    144   int rec = this->getRequestSync();
    145   if ( rec > 0 )
    146   {
    147     *reciever = rec;
    148 
    149     SYNCHELP_WRITE_BEGIN();
    150 
    151     SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_LPU_WE_STATE );
    152 
    153     return SYNCHELP_WRITE_N;
    154   }
    155 
    156   *reciever = 0;
    157   return 0;
    158 }
    159 
  • branches/network/src/world_entities/power_ups/laser_power_up.h

    r6512 r7444  
    2626  virtual void draw() const;
    2727
    28   virtual int writeBytes(const byte* data, int length, int sender);
    29   virtual int readBytes(byte* data, int maxLength, int * reciever );
    30 
    3128  private:
    3229   void init();
  • branches/network/src/world_entities/power_ups/param_power_up.cc

    r7221 r7444  
    4343  if( root != NULL)
    4444    this->loadParams(root);
     45 
     46  registerVar( new SynchronizeableInt( (int*)&type, (int*)&type, "type" ) );
     47  registerVar( new SynchronizeableFloat( &value, &value, "value" ) );
     48  registerVar( new SynchronizeableFloat( &max_value, &max_value, "max_value" ) );
     49  registerVar( new SynchronizeableFloat( &min_value, &min_value, "min_value" ) );
    4550}
    4651
     
    119124}
    120125
    121 int ParamPowerUp::writeBytes( const byte * data, int length, int sender )
    122 {
    123   setRequestedSync( false );
    124   setIsOutOfSync( false );
    125 
    126   SYNCHELP_READ_BEGIN();
    127 
    128   SYNCHELP_READ_FKT( PowerUp::writeState, NWT_PPU_WE_STATE );
    129 
    130   int i;
    131   SYNCHELP_READ_INT( i, NWT_PPU_TYPE );
    132   this->type = (EnumParamPowerUpType)i;
    133   SYNCHELP_READ_FLOAT( this->value, NWT_PPU_VALUE );
    134 
    135   if ( this->value != 0 )
    136   {
    137     SYNCHELP_READ_FLOAT( this->min_value, NWT_PPU_MINVALUE );
    138     SYNCHELP_READ_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
    139     respawn();
    140   }
    141 
    142   return SYNCHELP_READ_N;
    143 }
    144 
    145 
    146 
    147 int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever )
    148 {
    149   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    150   {
    151     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    152     setRequestedSync( true );
    153   }
    154 
    155   int rec = this->getRequestSync();
    156   if ( rec > 0 )
    157   {
    158     *reciever = rec;
    159 
    160     SYNCHELP_WRITE_BEGIN();
    161 
    162     SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_PPU_WE_STATE );
    163 
    164     int i = (int)this->type;
    165     SYNCHELP_WRITE_INT( i, NWT_PPU_TYPE );
    166     SYNCHELP_WRITE_FLOAT( this->value, NWT_PPU_VALUE );
    167 
    168     if ( this->value != 0 )
    169     {
    170       SYNCHELP_WRITE_FLOAT( this->min_value, NWT_PPU_MINVALUE );
    171       SYNCHELP_WRITE_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
    172     }
    173 
    174     return SYNCHELP_WRITE_N;
    175   }
    176 
    177   *reciever = 0;
    178   return 0;
    179 }
    180 
  • branches/network/src/world_entities/power_ups/param_power_up.h

    r7221 r7444  
    3232  float getValue();
    3333
    34   virtual int writeBytes(const byte* data, int length, int sender);
    35   virtual int readBytes(byte* data, int maxLength, int * reciever );
    36 
    3734protected:
    3835  virtual void respawn();
  • branches/network/src/world_entities/power_ups/power_up.cc

    r7221 r7444  
    201201
    202202
    203 /********************************************************************************************
    204  NETWORK STUFF
    205  ********************************************************************************************/
    206 
    207 
    208 /**
    209  * data copied in data will bee sent to another host
    210  * @param data pointer to data
    211  * @param maxLength max length of data
    212  * @return the number of bytes writen
    213  */
    214 int PowerUp::readState( byte * data, int maxLength )
    215 {
    216   SYNCHELP_WRITE_BEGIN();
    217   SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_PU_WE_STATE );
    218   return SYNCHELP_WRITE_N;
    219 }
    220 
    221 
    222 /**
    223  * Writes data from network containing information about the state
    224  * @param data pointer to data
    225  * @param length length of data
    226  * @param sender hostID of sender
    227  */
    228 int PowerUp::writeState( const byte * data, int length, int sender )
    229 {
    230   SYNCHELP_READ_BEGIN();
    231   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_PU_WE_STATE );
    232   return SYNCHELP_READ_N;
    233 }
    234 
  • branches/network/src/world_entities/power_ups/power_up.h

    r7221 r7444  
    3434  void setRespawnTime(const float respawn);
    3535
    36   int       writeState(const byte* data, int length, int sender);
    37   int       readState(byte* data, int maxLength );
    38 
    3936protected:
    4037  PowerUp(float r, float g, float b);
  • branches/network/src/world_entities/power_ups/turret_power_up.cc

    r7193 r7444  
    115115  glPopMatrix();
    116116}
    117 
    118 
    119 
    120 
    121 /********************************************************************************************
    122  NETWORK STUFF
    123  ********************************************************************************************/
    124 
    125 
    126 int TurretPowerUp::writeBytes( const byte * data, int length, int sender )
    127 {
    128   setRequestedSync( false );
    129   setIsOutOfSync( false );
    130 
    131   SYNCHELP_READ_BEGIN();
    132 
    133   SYNCHELP_READ_FKT( PowerUp::writeState, NWT_TPU_WE_STATE );
    134 
    135   return SYNCHELP_READ_N;
    136 }
    137 
    138 
    139 int TurretPowerUp::readBytes( byte * data, int maxLength, int * reciever )
    140 {
    141   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    142   {
    143     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    144     setRequestedSync( true );
    145   }
    146 
    147   int rec = this->getRequestSync();
    148   if ( rec > 0 )
    149   {
    150     *reciever = rec;
    151 
    152     SYNCHELP_WRITE_BEGIN();
    153 
    154     SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_TPU_WE_STATE );
    155 
    156     return SYNCHELP_WRITE_N;
    157   }
    158 
    159   *reciever = 0;
    160   return 0;
    161 }
  • branches/network/src/world_entities/power_ups/turret_power_up.h

    r7065 r7444  
    2424  virtual void draw() const;
    2525
    26   virtual int writeBytes(const byte* data, int length, int sender);
    27   virtual int readBytes(byte* data, int maxLength, int * reciever );
    28 
    2926  private:
    3027   void init();
  • branches/network/src/world_entities/power_ups/weapon_power_up.cc

    r7370 r7444  
    103103}
    104104
    105 int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )
    106 {
    107   setRequestedSync( false );
    108   setIsOutOfSync( false );
    109 
    110   SYNCHELP_READ_BEGIN();
    111 
    112   SYNCHELP_READ_FKT( PowerUp::writeState, NWT_WPU_WE_STATE );
    113 
    114   //TODO: sync weapon class ( see loadParams )
    115 
    116   return SYNCHELP_READ_N;
    117 }
    118 
    119 
    120 
    121 int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )
    122 {
    123   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    124   {
    125     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    126     setRequestedSync( true );
    127   }
    128 
    129   int rec = this->getRequestSync();
    130   if ( rec > 0 )
    131   {
    132     *reciever = rec;
    133 
    134     SYNCHELP_WRITE_BEGIN();
    135 
    136     SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_WPU_WE_STATE );
    137 
    138     //TODO: sync weapon class ( see loadParams )
    139 
    140     return SYNCHELP_WRITE_N;
    141   }
    142 
    143   *reciever = 0;
    144   return 0;
    145 }
  • branches/network/src/world_entities/power_ups/weapon_power_up.h

    r7221 r7444  
    2424  void setWeaponClass(const std::string& name);
    2525
    26   virtual int writeBytes(const byte* data, int length, int sender);
    27   virtual int readBytes(byte* data, int maxLength, int * reciever );
    28 
    2926  bool process(WeaponManager* manager);
    3027
  • branches/network/src/world_entities/skybox.cc

    r7328 r7444  
    9595{
    9696  this->rebuild();
     97 
     98  textureName_handle = registerVarId( new SynchronizeableString( &textureName, &textureName, "textureName") );
     99  size_handle = registerVarId( new SynchronizeableFloat( &size, &size, "size" ) );
    97100}
    98101
     
    292295}
    293296
    294 int SkyBox::writeBytes( const byte * data, int length, int sender )
    295 {
    296   setRequestedSync( false );
    297   setIsOutOfSync( false );
    298 
    299   SYNCHELP_READ_BEGIN();
    300 
    301   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SB_WE_STATE );
    302 
    303   SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE );
    304   if ( !this->textureName.empty() )
    305   {
    306     textureName = "";
    307   }
    308   std::string texName;
    309   SYNCHELP_READ_STRING( texName, NWT_SB_TEXTURENAME );
    310 
    311   this->setSize( size );
    312   this->setTextureAndType( texName, "jpg" );
    313   this->rebuild();
    314 
    315   return SYNCHELP_READ_N;
    316 }
    317 
    318 
    319 
    320 int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
    321 {
    322   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    323   {
    324     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    325     setRequestedSync( true );
    326   }
    327 
    328   int rec = this->getRequestSync();
    329   if ( rec > 0 )
    330   {
    331     *reciever = rec;
    332 
    333     SYNCHELP_WRITE_BEGIN();
    334 
    335     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SB_WE_STATE );
    336 
    337     SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE);
    338     SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME);
    339 
    340     return SYNCHELP_WRITE_N;
    341   }
    342 
    343   *reciever = 0;
    344   return 0;
    345 }
    346 
    347 void SkyBox::writeDebug( ) const
    348 {
    349 }
    350 
    351 void SkyBox::readDebug( ) const
    352 {
    353 }
     297void SkyBox::varChangeHandler( std::list< int > & id )
     298{
     299#warning implement this
     300}
  • branches/network/src/world_entities/skybox.h

    r7328 r7444  
    5858  static void disableCubeMap();
    5959
    60   virtual int       writeBytes(const byte* data, int length, int sender);
    61   virtual int       readBytes(byte* data, int maxLength, int * reciever);
    62   virtual void      writeDebug() const;
    63   virtual void      readDebug() const;
     60  virtual void varChangeHandler( std::list<int> & id );
    6461
    6562 private:
     
    7269  float           textureSize;     //!< this is the length of a texture (assumes a square texture)
    7370  std::string     textureName;     //!< Name of the Texture
     71 
     72  int textureName_handle;          //!< used to notify about changes of textureName
     73  int size_handle;                 //!< used to notify about changes of size
    7474
    7575};
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r7346 r7444  
    9494  if (root != NULL)
    9595    this->loadParams(root);
    96   else
    97   {
    98     //this->loadModel("models/ships/reap_#.obj");
    99     //TODO HACK this is only for network multiplayer games.
    100     if( this->getOwner()%2 == 0)
    101     {
    102       this->loadModel("models/ships/reap_#.obj");
    103       this->toList(OM_GROUP_00);
    104     }
    105     else
    106     {
    107       this->loadModel( "models/ships/fighter.obj" );
    108       this->toList(OM_GROUP_01);
    109     }
    110   }
    11196
    11297}
     
    235220  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    236221  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    237 
     222 
     223  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) );
     224  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir" ) );
     225
     226  registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp" ) );
     227  registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown" ) );
     228  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft" ) );
     229  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight" ) );
     230  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend" ) );
     231  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend" ) );
     232  registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL" ) );
     233  registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR" ) );
    238234}
    239235
     
    307303    if ( isServer() )
    308304    {
    309       networkCollisionList.push_back( entity->getHealth() );
    310       doCollideNetwork( entity->getHealth() );
     305      //TODO handle this
    311306    }
    312307  }
     
    510505
    511506
    512 #define MASK_bUp         1
    513 #define MASK_bDown       2
    514 #define MASK_bLeft       4
    515 #define MASK_bRight      8
    516 #define MASK_bAscend    16
    517 #define MASK_bDescend   32
    518 #define MASK_bRollL     64
    519 #define MASK_bRollR    128
    520 
    521 #define DATA_state       1
    522 #define DATA_flags       2
    523 #define DATA_mouse       3
    524 #define DATA_sync        4
    525 #define DATA_velocity    5
    526 #define DATA_playables   6
    527 #define DATA_collision   7
    528 
    529 int SpaceShip::writeBytes( const byte * data, int length, int sender )
    530 {
    531   SYNCHELP_READ_BEGIN();
    532 
    533   byte b;
    534 
    535   while ( SYNCHELP_READ_REMAINING()>0 )
    536   {
    537     SYNCHELP_READ_BYTE( b, NWT_SS_B );
    538 
    539     if ( b == DATA_state )
    540     {
    541       setRequestedSync( false );
    542       setIsOutOfSync( false );
    543       SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
    544 
    545       continue;
    546     }
    547 
    548     if ( b == DATA_flags )
    549     {
    550       if ( this->getOwner() != this->getHostID() )
    551       {
    552         byte flags = 0;
    553         SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
    554 
    555         bUp = (flags & MASK_bUp) != 0;
    556         bDown = (flags & MASK_bDown) != 0;
    557         bLeft = (flags & MASK_bLeft) != 0;
    558         bRight = (flags & MASK_bRight) != 0;
    559         bAscend = (flags & MASK_bAscend) != 0;
    560         bDescend = (flags & MASK_bDescend) != 0;
    561         bRollL = (flags & MASK_bRollL) != 0;
    562         bRollR = (flags & MASK_bRollR) != 0;
    563 
    564       }
    565       else
    566         assert(false);
    567 
    568       continue;
    569     }
    570 
    571     if ( b == DATA_mouse )
    572     {
    573       if ( this->getOwner() != this->getHostID() )
    574       {
    575         SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    576         SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    577         SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    578         SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    579       }
    580       else
    581         assert(false);
    582 
    583       continue;
    584     }
    585 
    586     if ( b == DATA_sync )
    587     {
    588       if ( this->getOwner() != this->getHostID() )
    589       {
    590         SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
    591       }
    592       else
    593         assert(false);
    594 
    595       continue;
    596     }
    597 
    598     if ( b == DATA_velocity )
    599     {
    600       if ( this->getOwner() != this->getHostID() )
    601       {
    602         SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
    603         SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
    604         SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
    605       }
    606       else
    607         assert(false);
    608 
    609       continue;
    610     }
    611 
    612     if ( b == DATA_playables )
    613     {
    614       if ( this->getOwner() != this->getHostID() )
    615       {
    616         SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
    617       }
    618       else
    619         assert(false);
    620     }
    621 
    622     if ( b == DATA_collision )
    623     {
    624       int n;
    625       float energy;
    626       SYNCHELP_READ_INT( n, NWT_SS_CO_N );
    627 
    628       for ( int i = 0; i<n; i++ )
    629       {
    630         SYNCHELP_READ_FLOAT( energy, NWT_SS_CO_CLID );
    631         doCollideNetwork( energy );
    632       }
    633     }
    634   }
    635 
    636   return SYNCHELP_READ_N;
    637 }
    638 
    639 
    640 
    641 int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
    642 {
    643   SYNCHELP_WRITE_BEGIN();
    644 
    645   if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
    646   {
    647     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    648     setRequestedSync( true );
    649     PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
    650   }
    651 
    652   int rec = this->getRequestSync();
    653   if ( rec > 0 )
    654   {
    655     *reciever = rec;
    656 
    657     PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
    658 
    659     SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
    660 
    661     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
    662 
    663     return SYNCHELP_WRITE_N;
    664   }
    665 
    666   *reciever = 0 - this->getOwner();
    667   //TODO: implement with SYNCHELP_WRITE_SENT()
    668   bool sentSomething = false;
    669 
    670   if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
    671   {
    672     PRINTF(0)("sending PNode::readSync\n");
    673     SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
    674     SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
    675     sentSomething = true;
    676   }
    677 
    678   if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
    679   {
    680     byte mask = 0;
    681 
    682     if ( bUp )
    683       mask |= MASK_bUp;
    684     if ( bDown )
    685       mask |= MASK_bDown;
    686     if ( bLeft )
    687       mask |= MASK_bLeft;
    688     if ( bRight )
    689       mask |= MASK_bRight;
    690     if ( bAscend )
    691       mask |= MASK_bAscend;
    692     if ( bRollL )
    693       mask |= MASK_bRollL;
    694     if ( bRollR )
    695       mask |= MASK_bRollR;
    696 
    697 
    698     if ( mask != oldMask )
    699     {
    700       oldMask = mask;
    701       PRINTF(0)("sending mask\n");
    702       sentSomething = true;
    703       SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
    704       SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
    705     }
    706 #define __OFFSET_MDIR_W 0.01
    707 #define __OFFSET_MDIR_V 0.01
    708     if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
    709          fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
    710          fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
    711          fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
    712     {
    713       oldMouseDir = mouseDir;
    714 
    715       SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
    716       PRINTF(0)("SENDING mousedir\n");
    717       sentSomething = true;
    718       SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    719       SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    720       SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    721       SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    722     }
    723 #define __OFFSET_VEL 0.05
    724     if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*fabs(oldVelocity.x)+0.1 ||
    725          fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*fabs(oldVelocity.y)+0.1 ||
    726          fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*fabs(oldVelocity.z)+0.1 )
    727     {
    728       oldVelocity.x = velocity.x;
    729       oldVelocity.y = velocity.y;
    730       oldVelocity.z = velocity.z;
    731       PRINTF(0)("SENDING velocity\n");
    732       sentSomething = true;
    733       SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
    734       SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
    735       SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
    736       SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
    737     }
    738 
    739     while ( Playable::needsReadSync() )
    740     {
    741       sentSomething = true;
    742       PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
    743       SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
    744       SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
    745     }
    746 
    747   }
    748 
    749   if ( !sentSomething )
    750   {
    751     *reciever = 0;
    752 
    753     if ( networkCollisionList.size()>0 )
    754     {
    755       SYNCHELP_WRITE_BYTE( DATA_collision, NWT_SS_B );
    756 
    757       SYNCHELP_WRITE_INT( networkCollisionList.size(), NWT_SS_CO_N );
    758 
    759       for ( std::list<float>::iterator it = networkCollisionList.begin(); it!=networkCollisionList.end(); it++ )
    760       {
    761         SYNCHELP_WRITE_FLOAT( *it, NWT_SS_CO_CLID );
    762       }
    763 
    764       networkCollisionList.clear();
    765     }
    766   }
    767 
    768   return SYNCHELP_WRITE_N;
    769 }
    770 
    771 
    772 void SpaceShip::doCollideNetwork( float energy )
    773 {
    774   this->decreaseHealth( energy );
    775   if( this->getHealth() <= 0)
    776   {
    777     this->die();
    778   }
    779 }
    780 
    781 
    782 
     507
     508
  • branches/network/src/world_entities/space_ships/space_ship.h

    r7346 r7444  
    4646    virtual int       readBytes(byte* data, int maxLength, int * reciever);
    4747
    48     //HACK HACK HACK HACK make this private or remove it
    49     void doCollideNetwork( float energy );
    50     std::list<float>        networkCollisionList;
    51 
    5248  private:
    5349    void init();
  • branches/network/src/world_entities/terrain.cc

    r7221 r7444  
    423423}
    424424
    425 int Terrain::writeBytes( const byte * data, int length, int sender )
    426 {
    427   setRequestedSync( false );
    428   setIsOutOfSync( false );
    429 
    430   SYNCHELP_READ_BEGIN();
    431   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_TER_WE_STATE );
    432 
    433   return SYNCHELP_READ_N;
    434 }
    435 
    436 int Terrain::readBytes( byte * data, int maxLength, int * reciever )
    437 {
    438   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    439   {
    440     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    441     setRequestedSync( true );
    442   }
    443 
    444   int rec = this->getRequestSync();
    445   if ( rec > 0 )
    446   {
    447     *reciever = rec;
    448 
    449     SYNCHELP_WRITE_BEGIN();
    450     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_TER_WE_STATE );
    451     return SYNCHELP_WRITE_N;
    452 
    453   }
    454 
    455   *reciever = 0;
    456   return 0;
    457 }
    458 
    459 void Terrain::writeDebug( ) const
    460   {}
    461 
    462 void Terrain::readDebug( ) const
    463   {}
    464 
    465425float Terrain::getHeight(float x, float y)
    466426{
  • branches/network/src/world_entities/terrain.h

    r7221 r7444  
    3333  virtual ~Terrain();
    3434
    35   virtual int       writeBytes(const byte* data, int length, int sender);
    36   virtual int       readBytes(byte* data, int maxLength, int * reciever);
    37   virtual void      writeDebug() const;
    38   virtual void      readDebug() const;
    39 
    4035  void init();
    4136  virtual void loadParams(const TiXmlElement* root);
  • branches/network/src/world_entities/world_entity.cc

    r7230 r7444  
    6565
    6666  this->toList(OM_NULL);
     67 
     68  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
     69  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) );
    6770}
    6871
     
    123126  this->modelLODName = fileName;
    124127  this->scaling = scaling;
     128 
     129  std::string name = fileName;
     130
     131  if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
     132  {
     133    name.erase(ResourceManager::getInstance()->getDataDir().size());
     134  }
     135
     136  this->modelFileName = name;
     137 
    125138  if (!fileName.empty())
    126139  {
     
    504517
    505518
    506 
    507 
    508 /********************************************************************************************
    509  NETWORK STUFF
    510  ********************************************************************************************/
    511 
    512 
    513 /**
    514  * Writes data from network containing information about the state
    515  * @param data pointer to data
    516  * @param length length of data
    517  * @param sender hostID of sender
    518  */
    519 int WorldEntity::writeState( const byte * data, int length, int sender )
    520 {
    521   std::string modelFileName;
    522   SYNCHELP_READ_BEGIN();
    523 
    524   SYNCHELP_READ_FKT( PNode::writeState, NWT_WE_PN_WRITESTATE );
    525 
    526   SYNCHELP_READ_STRING( modelFileName, NWT_WE_PN_MODELFILENAME );
    527   SYNCHELP_READ_FLOAT( scaling, NWT_WE_PN_SCALING );
    528   //check if modelFileName is relative to datadir or absolute
    529 
    530 
    531   PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName.c_str(), scaling);
    532 
    533   if ( modelFileName != "" )
    534   {
    535     loadModel( modelFileName, scaling);
    536     PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName());
    537   }
    538 
    539   /*SYNCHELP_READ_STRINGM( modelFileName );
    540 
    541   if ( strcmp(modelFileName, "") )
    542     if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) )
    543     {
    544       this->md2TextureFileName = new char[strlen(modelFileName)-strlen(ResourceManager::getInstance()->getDataDir())+1];
    545       strcpy((char*)this->md2TextureFileName, modelFileName+strlen(ResourceManager::getInstance()->getDataDir()));
    546     }
    547     else
    548     {
    549       this->md2TextureFileName = modelFileName;
    550     }
    551   */
    552 
    553   return SYNCHELP_READ_N;
    554 }
    555 
    556 
    557 /**
    558  * data copied in data will bee sent to another host
    559  * @param data pointer to data
    560  * @param maxLength max length of data
    561  * @return the number of bytes writen
    562  */
    563 int WorldEntity::readState( byte * data, int maxLength )
    564 {
    565   SYNCHELP_WRITE_BEGIN();
    566 
    567   SYNCHELP_WRITE_FKT( PNode::readState, NWT_WE_PN_WRITESTATE );
    568 
    569   if ( getModel(0) && getModel(0)->getName() != "" )
    570   {
    571     std::string name = getModel( 0 )->getName();
    572 
    573     if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
    574     {
    575       name.erase(ResourceManager::getInstance()->getDataDir().size());
    576     }
    577 
    578     SYNCHELP_WRITE_STRING( name, NWT_WE_PN_MODELFILENAME );
    579   }
    580   else
    581   {
    582     SYNCHELP_WRITE_STRING("", NWT_WE_PN_MODELFILENAME);
    583   }
    584 
    585   SYNCHELP_WRITE_FLOAT( scaling, NWT_WE_PN_SCALING );
    586   /*if ( this->md2TextureFileName!=NULL && strcmp(this->md2TextureFileName, "") )
    587   {
    588     SYNCHELP_WRITE_STRING(this->md2TextureFileName);
    589   }
    590   else
    591   {
    592     SYNCHELP_WRITE_STRING("");
    593   }*/
    594 
    595   return SYNCHELP_WRITE_N;
    596 }
     519/**
     520 * handler for changes on registred vars
     521 * @param id id's which changed
     522 */
     523void WorldEntity::varChangeHandler( std::list< int > & id )
     524{
     525#warning implement this
     526}
  • branches/network/src/world_entities/world_entity.h

    r7370 r7444  
    9696  GLGuiWidget* getHealthWidget();
    9797  bool hasHealthWidget() const { return this->healthWidget; };
     98 
     99  virtual void varChangeHandler( std::list<int> & id );
    98100
    99101protected:
     
    123125  ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.
    124126
    125   float                   scaling;
     127 
     128  //network stuff
     129 
     130  float       scaling;                         //!< model's scaling factor
     131  int         scaling_handle;                  //!< handle for syncing var
     132 
     133  std::string modelFileName;                  //!< model's file name
     134  int         modelFileName_handle;           //!< handle for syncing var
    126135
    127136
Note: See TracChangeset for help on using the changeset viewer.