- Timestamp:
- Jan 25, 2006, 2:39:53 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 36 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r6655 r6695 147 147 CL_GLGUI_MAIN_WIDGET = 0x00000f41, 148 148 CL_NETWORK_MANAGER = 0x00000f50, 149 CL_SHARED_NETWORK_DATA = 0x00000f51, 149 150 150 151 -
trunk/src/lib/coord/p_node.cc
r6634 r6695 42 42 */ 43 43 PNode::PNode (PNode* parent, long nodeFlags) 44 : Synchronizeable(), BaseObject() 44 45 { 45 46 this->setClassID(CL_PARENT_NODE, "PNode"); … … 487 488 this->children.push_back(child); 488 489 child->parentCoorChanged(); 490 491 // if(this->getUniqueID() == NET_UID_UNASSIGNED) 492 // { 493 // PRINTF(1)("Adding to an UNASSIGNED PNode - looking for next assigned Node\n"); 494 // PNode* node = this->seekNextAssignedPNode(this); 495 // if( node == NULL) 496 // PRINTF(1)(" Got NULL - Is this the NULLParent - uid %i\n", this->getUniqueID()); 497 // else 498 // PRINTF(1)(" Found next assigned node: %i\n", node->getUniqueID()); 499 // } 489 500 } 490 501 else … … 495 506 child->parentCoorChanged(); 496 507 } 508 } 509 510 511 PNode* PNode::seekNextAssignedPNode(PNode* node) const 512 { 513 PNode* tmpNode = node->parent; 514 printf("entering seek PNode loop for name: %s, uid: %i\n", node->getName(), node->getUniqueID()); 515 if(tmpNode) 516 printf(" @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID()); 517 while( tmpNode != NULL && tmpNode->getUniqueID() == NET_UID_UNASSIGNED) 518 { 519 printf(" @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID()); 520 tmpNode = tmpNode->parent; 521 } 522 printf("leaving PNode loop\n\n"); 523 524 return tmpNode; 497 525 } 498 526 … … 695 723 { 696 724 PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL); 725 PNode::nullParent->setClassID(CL_NULL_PARENT, "NullParent"); 697 726 PNode::nullParent->setName("NullParent"); 727 PNode::nullParent->setSynchronized(true); 698 728 } 699 729 return PNode::nullParent; … … 1049 1079 SYNCHELP_READ_FKT( BaseObject::writeState ); 1050 1080 1051 char * parentName = NULL;1052 SYNCHELP_READ_STRINGM( parentName );1053 1054 if ( strcmp(parentName, "")==0 )1055 {1056 setParent( (char*)NULL );1057 }1058 else1059 {1060 setParent( parentName );1061 }1062 1063 delete[] parentName;1081 // char * parentName = NULL; 1082 // SYNCHELP_READ_STRINGM( parentName ); 1083 // 1084 // if ( strcmp(parentName, "")==0 ) 1085 // { 1086 // setParent( (char*)NULL ); 1087 // } 1088 // else 1089 // { 1090 // setParent( parentName ); 1091 // } 1092 // 1093 // delete[] parentName; 1064 1094 1065 1095 int parentMode; … … 1081 1111 this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); 1082 1112 1083 int n;1084 char * childName;1085 1086 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]);1087 SYNCHELP_READ_INT( n );1088 PRINTF(0)("read %s:n=%d\n", this->getName(), n);1089 1090 for (int i = 0; i<n; i++)1091 {1092 SYNCHELP_READ_STRINGM( childName );1093 PRINTF(0)("RCVD CHILD = %s\n", childName);1094 addChild( childName );1095 delete childName;1096 childName = NULL;1097 }1113 // int n; 1114 // char * childName; 1115 // 1116 // 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]); 1117 // SYNCHELP_READ_INT( n ); 1118 // PRINTF(0)("read %s:n=%d\n", this->getName(), n); 1119 // 1120 // for (int i = 0; i<n; i++) 1121 // { 1122 // SYNCHELP_READ_STRINGM( childName ); 1123 // PRINTF(0)("RCVD CHILD = %s\n", childName); 1124 // addChild( childName ); 1125 // delete childName; 1126 // childName = NULL; 1127 // } 1098 1128 1099 1129 return SYNCHELP_READ_N; … … 1112 1142 SYNCHELP_WRITE_FKT( BaseObject::readState ); 1113 1143 1114 if ( this->parent )1115 {1116 SYNCHELP_WRITE_STRING( parent->getName() );1117 }1118 else1119 {1120 SYNCHELP_WRITE_STRING( "" );1121 }1144 // if ( this->parent ) 1145 // { 1146 // SYNCHELP_WRITE_STRING( parent->getName() ); 1147 // } 1148 // else 1149 // { 1150 // SYNCHELP_WRITE_STRING( "" ); 1151 // } 1122 1152 1123 1153 SYNCHELP_WRITE_INT( this->parentMode ); … … 1132 1162 SYNCHELP_WRITE_FLOAT( this->relDirection.v.z ); 1133 1163 1134 int n = children.size();1135 1136 //check if camera is in children 1137 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1138 { 1139 if ( (*it)->isA(CL_CAMERA) ) 1140 n--; 1141 } 1142 PRINTF(0)("write %s:n=%d\n", this->getName(), n);1143 SYNCHELP_WRITE_INT( n);1144 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]); 1145 1146 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)1147 {1148 //dont add camera because there is only one camera attached to local player1149 if ( !(*it)->isA(CL_CAMERA) )1150 {1151 PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());1152 SYNCHELP_WRITE_STRING( (*it)->getName() );1153 }1154 }1164 // int n = children.size(); 1165 // //check if camera is in children 1166 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1167 // { 1168 // if ( (*it)->isA(CL_CAMERA) ) 1169 // n--; 1170 // } 1171 // PRINTF(0)("write %s:n=%d\n", this->getName(), n); 1172 // SYNCHELP_WRITE_INT( n ); 1173 // 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]); 1174 // 1175 // 1176 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1177 // { 1178 // //dont add camera because there is only one camera attached to local player 1179 // if ( !(*it)->isA(CL_CAMERA) ) 1180 // { 1181 // PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName()); 1182 // SYNCHELP_WRITE_STRING( (*it)->getName() ); 1183 // } 1184 // } 1155 1185 1156 1186 return SYNCHELP_WRITE_N; -
trunk/src/lib/coord/p_node.h
r6634 r6695 147 147 void removeNode(); 148 148 149 PNode* seekNextAssignedPNode(PNode* node) const; 150 149 151 /** @param parent the new parent of this node */ 150 152 inline void setParent (PNode* parent) { parent->addChild(this); }; -
trunk/src/lib/graphics/importer/vertex_array_model.cc
r6519 r6695 305 305 this->addColor(.125,.436,.246); ///FIXME 306 306 } 307 307 308 for (unsigned int loopNumber = 0; loopNumber <= loops; ++loopNumber) 308 309 { … … 326 327 } 327 328 } 329 328 330 for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber) 329 331 { … … 331 333 this->addIndice(segmentsPerLoop + loopSegmentNumber); 332 334 } 335 333 336 for (unsigned int loopNumber = 0; loopNumber < loops; ++loopNumber) 334 337 { -
trunk/src/lib/network/Makefile.am
r6139 r6695 6 6 libORXnet_a_SOURCES = synchronizeable.cc \ 7 7 network_manager.cc \ 8 shared_network_data.cc \ 8 9 network_socket.cc \ 9 10 connection_monitor.cc \ … … 21 22 noinst_HEADERS = synchronizeable.h \ 22 23 network_manager.h \ 24 shared_network_data.h \ 23 25 network_socket.h \ 24 26 connection_monitor.h \ -
trunk/src/lib/network/handshake.cc
r6341 r6695 23 23 24 24 Handshake::Handshake( bool server, int clientId, int networkGameManagerId ) 25 : Synchronizeable() 25 26 { 26 27 /* set the class id for the base object */ … … 34 35 this->setOwner(0); 35 36 37 this->setSynchronized(true); 36 38 PRINTF(5)("Handshake created clientId = %d\n", clientId); 37 39 } -
trunk/src/lib/network/netdefs.h
r5822 r6695 17 17 18 18 19 #define MAX_CONNECTIONS 1000 20 21 19 22 typedef unsigned char byte; 20 23 … … 25 28 } NodeType; 26 29 30 31 typedef enum { 32 NET_UID_UNASSIGNED = -1, 33 34 NET_UID_NUMBER 35 } UidType; 36 27 37 #endif /* _NETWORK_MANAGER */ -
trunk/src/lib/network/network_game_manager.cc
r6634 r6695 46 46 */ 47 47 NetworkGameManager::NetworkGameManager() 48 : Synchronizeable() 48 49 { 49 50 PRINTF(0)("START\n"); … … 52 53 this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager"); 53 54 54 newUniqueID = MAX_CONNECTIONS + 2;55 56 55 hasRequestedWorld = false; 56 this->setSynchronized(true); 57 57 } 58 58 … … 80 80 b = data[i++]; 81 81 82 /**************** Commands only processed by servers ****************/ 82 83 if ( isServer() ) 83 84 { 84 if ( b == REQUEST_CREATE )85 if ( b == NET_REQUEST_CREATE ) 85 86 { 86 87 if ( !handleRequestCreate( i, data, length, sender ) ) … … 88 89 continue; 89 90 } 90 if ( b ==REQUEST_REMOVE )91 else if ( b == NET_REQUEST_REMOVE ) 91 92 { 92 93 if ( !handleRequestRemove( i, data, length, sender ) ) … … 94 95 continue; 95 96 } 97 else if ( b == NET_REQUEST_PNODE_PATH ) 98 { 99 if ( !handleRequestPNodePath( i, data, length, sender ) ) 100 return i; 101 continue; 102 } 96 103 } 97 104 else 98 105 { 99 if ( b == CREATE_ENTITY ) 106 /**************** Commands only processed by clients ****************/ 107 if ( b == NET_CREATE_ENTITY ) 100 108 { 101 109 PRINTF(0)("CREATE_ENTITY\n"); … … 104 112 continue; 105 113 } 106 if ( b ==REMOVE_ENTITY )114 else if ( b == NET_REMOVE_ENTITY ) 107 115 { 108 116 if ( !handleRemoveEntity( i, data, length, sender ) ) … … 110 118 continue; 111 119 } 112 if ( b ==CREATE_ENTITY_LIST )120 else if ( b == NET_CREATE_ENTITY_LIST ) 113 121 { 114 122 if ( !handleCreateEntityList( i, data, length, sender ) ) … … 116 124 continue; 117 125 } 118 if ( b ==REMOVE_ENTITY_LIST )126 else if ( b == NET_REMOVE_ENTITY_LIST ) 119 127 { 120 128 if ( !handleRemoveEntityList( i, data, length, sender ) ) … … 122 130 continue; 123 131 } 124 if ( b ==YOU_ARE_ENTITY )132 else if ( b == NET_YOU_ARE_ENTITY ) 125 133 { 126 134 if ( !handleYouAreEntity( i, data, length, sender ) ) … … 130 138 } 131 139 132 if ( b == REQUEST_ENTITY_LIST ) 140 /**************** Commands processed by servers and clients ****************/ 141 if ( b == NET_REQUEST_ENTITY_LIST ) 133 142 { 134 143 sendEntityList( sender ); 135 144 continue; 136 145 } 137 138 if ( b == REQUEST_SYNC ) 146 else if ( b == NET_REQUEST_SYNC ) 139 147 { 140 148 if ( !handleRequestSync( i, data, length, sender ) ) … … 143 151 } 144 152 145 //if we get her something with data is wrong 153 154 PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender); 155 PRINTF(1)("Probably this is because the network protocol has different \n"); 156 PRINTF(1)("versions or there occured an error in the sending algorithm\n"); 146 157 PRINTF(1)("Data is not in the right format! i=%d\n", i); 147 158 return i; … … 156 167 { 157 168 SYNCHELP_WRITE_BEGIN(); 158 byte b = REQUEST_ENTITY_LIST;169 byte b = NET_REQUEST_ENTITY_LIST; 159 170 SYNCHELP_WRITE_BYTE( b ); 160 171 hasRequestedWorld = true; … … 200 211 int NetworkGameManager::createEntity( ClassID classID, int owner ) 201 212 { 202 if ( this->isServer() 203 { 204 if ( newUniqueID< 0 )213 if ( this->isServer()) 214 { 215 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 205 216 { 206 217 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); 207 218 return -1; 208 219 } 209 210 return this->executeCreateEntity( classID, newUniqueID++, owner ); 220 return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 211 221 } 212 222 else … … 227 237 if ( this->isServer() ) 228 238 { 229 if ( newUniqueID< 0 )239 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 230 240 { 231 241 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); … … 245 255 { 246 256 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 247 s->setUniqueID( newUniqueID++);257 s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 248 258 s->setOwner( 0 ); 249 this->networkStream->connectSynchronizeable( *s ); 259 // all entities created via this function are added automaticaly to the synchronizeable list 260 s->setSynchronized(true); 250 261 return b; 251 262 } … … 258 269 } 259 270 else 271 260 272 { 261 273 PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value()); … … 295 307 continue; 296 308 297 if ( !writeToClientBuffer( outBuffer[i], (byte) REQUEST_CREATE ) )309 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) ) 298 310 return; 299 311 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) … … 313 325 continue; 314 326 315 if ( !writeToClientBuffer( outBuffer[i], (byte) REQUEST_REMOVE ) )327 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) ) 316 328 return; 317 329 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) … … 332 344 continue; 333 345 334 if ( !writeToClientBuffer( outBuffer[i], (byte) CREATE_ENTITY ) )346 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) ) 335 347 return -1; 336 348 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) … … 342 354 } 343 355 356 PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 344 357 doCreateEntity( classID, uniqueID, owner ); 345 358 … … 359 372 continue; 360 373 361 if ( !writeToClientBuffer( outBuffer[i], (byte) REMOVE_ENTITY ) )374 if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) ) 362 375 return; 363 376 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) … … 394 407 e = this->networkStream->getSyncEnd(); 395 408 396 if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) ) 409 // send the packet header 410 if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) ) 397 411 return; 398 412 399 // -2 because you must not send network_game_manager and handshake413 // send the number of entities: -2 because you must not send network_game_manager and handshake 400 414 if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) ) 401 415 return; … … 403 417 //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 ); 404 418 405 int n = 0; 406 419 // first send the NullParent 420 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) ) 421 return; 422 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) ) 423 return; 424 if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) ) 425 return; 426 427 // now send the rest of the entities 407 428 while ( it != e ) 408 429 { 409 PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() ); 410 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) 411 return; 412 413 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) ) 414 return; 415 416 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) ) 417 return; 418 430 if( (*it)->beSynchronized() && (*it) != PNode::getNullParent()) 431 { 432 PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() ); 433 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) 434 return; 435 436 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) ) 437 return; 438 439 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) ) 440 return; 441 } 419 442 it++; 420 443 } … … 467 490 BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) 468 491 { 469 BaseObject * b = Factory::fabricate( classID ); 492 PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 493 494 BaseObject * b; 495 /* These are some small exeptions in creation: Not all objects can/should be created via Factory */ 496 /* Exception 1: NullParent */ 497 if( classID == CL_NULL_PARENT) 498 { 499 b = (BaseObject*)PNode::getNullParent(); 500 } 501 else 502 b = Factory::fabricate( classID ); 470 503 471 504 if ( !b ) … … 480 513 s->setUniqueID( uniqueID ); 481 514 s->setOwner( owner ); 482 this->networkStream->connectSynchronizeable( *s ); 515 s->setSynchronized(true); 516 //this->networkStream->connectSynchronizeable( *s ); 483 517 if ( !isServer() ) 484 518 s->setIsOutOfSync( true ); … … 646 680 if ( userID != 0 ) 647 681 { 648 if ( !writeToClientBuffer( outBuffer[userID], (byte) YOU_ARE_ENTITY ) )682 if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) ) 649 683 return; 650 684 … … 714 748 i += Converter::byteArrayToInt( &data[i], &owner ); 715 749 750 PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); 716 751 doCreateEntity( (ClassID)classID, uniqueID, owner ); 717 752 … … 779 814 { 780 815 BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner ); 781 782 /*if ( b != NULL )783 {784 if ( b->isA(CL_WORLD_ENTITY) )785 {786 int n = dynamic_cast<WorldEntity*>(b)->writeState( data, length, sender );787 788 i += n;789 }790 }*/791 816 } 792 817 … … 854 879 return true; 855 880 } 881 882 883 /** 884 * handles the network signal NET_REQUEST_PNODE_PATH 885 * @param i byte offset in the buffer 886 * @param data data array 887 * @param length length of the data arary 888 * @param sender the sender id 889 * @return true if process terminated sucessfully 890 */ 891 bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender) 892 { 893 if( INTSIZE > length-i ) 894 { 895 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 896 return false; 897 } 898 PRINTF(0)("HandleRequestPNodePath: data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]); 899 900 int uniqueID1, uniqueID2; 901 if( INTSIZE > length-i ) 902 { 903 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 904 return false; 905 } 906 i += Converter::byteArrayToInt( &data[i], &uniqueID1 ); 907 908 if( INTSIZE > length-i ) 909 { 910 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 911 return false; 912 } 913 i += Converter::byteArrayToInt( &data[i], &uniqueID2 ); 914 915 916 PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2); 917 918 return true; 919 } 920 856 921 857 922 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) … … 898 963 resizeBufferVector( user ); 899 964 900 if ( !writeToClientBuffer( outBuffer[user], (byte) REQUEST_SYNC ) )965 if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) ) 901 966 return; 902 967 if ( !writeToClientBuffer( outBuffer[user], uniqueID ) ) -
trunk/src/lib/network/network_game_manager.h
r6634 r6695 15 15 16 16 class TiXmlElement; 17 class PNode; 17 18 18 19 /** 19 20 * protocol definition 20 21 * 21 * CREATE_ENTITY: CLASS_ID, UNIQUE_ID, OWNER22 * REMOVE_ENTITY: UNIQUE_ID22 * CREATE_ENTITY: >> CLASS_ID, UNIQUE_ID, OWNER 23 * REMOVE_ENTITY: >> UNIQUE_ID 23 24 * 24 * CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]25 * REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]25 * CREATE_ENTITY_LIST: >> NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER] 26 * REMOVE_ENTITY_LIST: >> NUMBER, [UNIQUE_ID][0..NUMBER] 26 27 * 27 * REQUEST_CREATE: CLASS_ID 28 * REQUEST_REMOVE: UNIQUE_ID 28 * REQUEST_CREATE: >> CLASS_ID 29 * << [Sync Info] 30 * REQUEST_REMOVE: >> UNIQUE_ID 31 * << [Sync Info] 29 32 * 30 33 * //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER] … … 32 35 * 33 36 * REQUEST_ENTITY_LIST: //request the whole world :D 34 * REQUEST_SYNC: UNIQUE_ID 37 * REQUEST_SYNC: >> UNIQUE_ID 38 * << [Sync Info] 35 39 * //REQUEST_SYNC_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] 36 40 * 37 * YOU_ARE_ENTITY: UNIQUE_ID41 * YOU_ARE_ENTITY: >> UNIQUE_ID 38 42 * 43 * REQUEST_PNODE_PATH >> UNIQUE_ID_START UNIQUE_ID_STOP 44 * << UNIQUE_ID_1 UNIQUE_ID_2 UNIQUE_ID_3 ... UNIQUE_ID_N 45 * 46 * SEND_PNODE_PATH >> UNIQUE_ID_START UNIQUE_ID_STOP NUMBER [UNIQUE_ID][0..NUMBER] 39 47 */ 40 48 41 typedef enum NetworkGameManagerProtocol{ 42 CREATE_ENTITY = 0, 43 REMOVE_ENTITY, 44 CREATE_ENTITY_LIST, 45 REMOVE_ENTITY_LIST, 46 REQUEST_CREATE, 47 REQUEST_REMOVE, 48 REQUEST_SYNC, 49 YOU_ARE_ENTITY, 50 REQUEST_ENTITY_LIST 49 typedef enum NetworkGameManagerProtocol { 50 NET_CREATE_ENTITY = 0, 51 NET_REMOVE_ENTITY, 52 NET_CREATE_ENTITY_LIST, 53 NET_REMOVE_ENTITY_LIST, 54 NET_REQUEST_CREATE, 55 NET_REQUEST_REMOVE, 56 NET_REQUEST_SYNC, 57 NET_YOU_ARE_ENTITY, 58 NET_REQUEST_ENTITY_LIST, 59 NET_REQUEST_PNODE_PATH, 60 NET_SEND_PNODE_PATH, 61 62 NET_NUMBER 51 63 }; 52 64 … … 83 95 void sendEntityList(int userID); 84 96 97 85 98 private: 86 99 NetworkGameManager(); 87 100 101 102 /* some network signal handlers */ 103 bool handleRequestCreate( int& i, const byte* data, int length, int sender ); 104 bool handleRequestRemove( int& i, const byte* data, int length, int sender ); 105 bool handleCreateEntity( int& i, const byte* data, int length, int sender ); 106 bool handleRemoveEntity( int& i, const byte* data, int length, int sender ); 107 bool handleCreateEntityList( int& i, const byte* data, int length, int sender ); 108 bool handleRemoveEntityList( int& i, const byte* data, int length, int sender ); 109 bool handleYouAreEntity( int& i, const byte* data, int length, int sender ); 110 bool handleRequestSync( int& i, const byte* data, int length, int sender ); 111 bool handleRequestPNodePath(int& i, const byte* data, int length, int sender); 112 bool handleSendPNodePath(int& i, const byte* data, int length, int sender); 113 114 115 /* some network handlers helper functions */ 88 116 void requestCreateEntity(ClassID classID); 89 117 int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0); 118 BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner); 90 119 91 120 void requestRemoveEntity(int uniqueID); 92 121 void executeRemoveEntity(int uniqueID); 122 void doRemoveEntity(int uniqueID); 93 123 94 124 void executeRequestSync( int uniqueID, int user ); 125 void doRequestSync(int uniqueID, int userID); 95 126 96 BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);97 void doRemoveEntity(int uniqueID);98 void doRequestSync(int uniqueID, int userID);99 127 void doYouAre( int uniqueID ); 128 129 void requestPNodePath(const PNode* node1, const PNode* node2); 130 void executeRequestPNodePath(const PNode* node2, const PNode* node2); 131 void doRequestPNodePath(const PNode* node1, const PNode* node2); 100 132 101 133 bool canCreateEntity(ClassID classID); … … 105 137 void resizeBufferVector(int n); 106 138 107 inlinebool writeToClientBuffer( clientBuffer &cb, byte*data, int length );108 inlinebool writeToClientBuffer( clientBuffer &cb, byte b );109 inlinebool writeToClientBuffer( clientBuffer &cb, int i );110 inlinebool readFromClientBuffer( clientBuffer &cb, byte*data, int length );139 bool writeToClientBuffer( clientBuffer &cb, byte*data, int length ); 140 bool writeToClientBuffer( clientBuffer &cb, byte b ); 141 bool writeToClientBuffer( clientBuffer &cb, int i ); 142 bool readFromClientBuffer( clientBuffer &cb, byte*data, int length ); 111 143 112 //helper functions for writeBytes113 inline bool handleRequestCreate( int& i, const byte* data, int length, int sender );114 inline bool handleRequestRemove( int& i, const byte* data, int length, int sender );115 inline bool handleCreateEntity( int& i, const byte* data, int length, int sender );116 inline bool handleRemoveEntity( int& i, const byte* data, int length, int sender );117 inline bool handleCreateEntityList( int& i, const byte* data, int length, int sender );118 inline bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );119 inline bool handleYouAreEntity( int& i, const byte* data, int length, int sender );120 inline bool handleRequestSync( int& i, const byte* data, int length, int sender );121 144 122 145 private: … … 124 147 //clientBuffer allOutBuffer; 125 148 static NetworkGameManager* singletonRef; 126 127 int newUniqueID;128 149 bool hasRequestedWorld; 129 150 }; -
trunk/src/lib/network/network_manager.cc
r6341 r6695 20 20 #define DEBUG_MODULE_NETWORK 21 21 22 23 #include "network_stream.h"24 22 #include "class_list.h" 25 26 23 #include "debug.h" 27 24 #include "shell_command.h" 28 25 29 26 /* include your own header */ 30 27 #include "network_manager.h" 28 #include "shared_network_data.h" 29 #include "network_stream.h" 31 30 32 31 33 32 /* using namespace std is default, this needs to be here */ 34 33 using namespace std; 34 35 SHELL_COMMAND(debug, NetworkManager, debug); 35 36 36 37 … … 49 50 this->netStreamList = NULL; 50 51 this->syncList = NULL; 51 this->tmpStream = NULL; 52 53 this->hostID = -1; 54 this->bGameServer = false; 52 this->defaultSyncStream = NULL; 53 this->sharedNetworkData = SharedNetworkData::getInstance(); 55 54 56 55 PRINTF(0)("NetworkManager created\n"); … … 98 97 } 99 98 100 this->tmpStream = new NetworkStream(ipAddress); 99 this->defaultSyncStream = new NetworkStream(ipAddress); 100 this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream); 101 this->defaultSyncStream->startHandshake(); 101 102 return 1; 102 103 } … … 109 110 int NetworkManager::createServer(unsigned int port) 110 111 { 111 this->hostID = 0; 112 this->bGameServer = true; 113 this->tmpStream = new NetworkStream(port); 114 this->bGameServer = true; 112 this->sharedNetworkData->setHostID(0); 113 this->sharedNetworkData->setGameServer(true); 114 this->defaultSyncStream = new NetworkStream(port); 115 this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream); 116 this->defaultSyncStream->createNetworkGameManager(); 117 PRINTF(0)("CREATE SERVER\n"); 115 118 SDL_Delay(20); 116 119 return 1; … … 118 121 119 122 120 /**121 * creates a connection from one object to a host122 * @param address: the address of the destination host123 * @param synchronizeable: reference to the sync object124 */125 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)126 {127 /* creating a new network stream, it will register itself automaticaly to the class list */128 this->tmpStream = new NetworkStream(address);129 this->tmpStream->connectSynchronizeable(sync);130 }131 132 133 /**134 * teardown a connection135 */136 void NetworkManager::shutdownConnection()137 {138 PRINTF(0)("Shutdown connection\n");139 }140 141 142 123 void NetworkManager::connectSynchronizeable(Synchronizeable& sync) 143 124 { 144 this->tmpStream->connectSynchronizeable(sync); 125 if( this->defaultSyncStream) 126 this->defaultSyncStream->connectSynchronizeable(sync); 145 127 } 146 128 … … 157 139 if( static_cast<NetworkStream*>(*stream)->isActive()) 158 140 static_cast<NetworkStream*>(*stream)->processData(); 159 160 141 } 161 162 142 } 163 143 144 145 164 146 /** 165 * Sets the hostID to a specific number 166 * @param id: The new ID 147 * debug output 167 148 */ 168 void NetworkManager::setHostID(int id)149 void NetworkManager::debug() 169 150 { 170 this->hostID = id; 151 PRINT(0)("=================Network::debug()=========\n"); 152 this->defaultSyncStream->debug(); 153 PRINT(0)("===========================================\n"); 171 154 } -
trunk/src/lib/network/network_manager.h
r6341 r6695 6 6 /* you will want to add such a a line at your header file also, since it will 7 7 prevent c++ from including your code twice*/ 8 #ifndef _NETWORK_MAN GER8 #ifndef _NETWORK_MANAGER 9 9 #define _NETWORK_MANAGER 10 10 11 11 /* include this file, it contains some default definitions */ 12 12 #include "netdefs.h" 13 #include "shared_network_data.h" 13 14 14 15 /* include base_object.h since all classes are derived from this one */ … … 38 39 int createServer(unsigned int port); 39 40 40 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);41 void shutdownConnection();42 43 44 void setHostID(int id);45 41 /** Returns the hostID @return The hostID of the object */ 46 inline int getHostID() { return this-> hostID; }47 inline bool isGameServer() { return this-> bGameServer; }42 inline int getHostID() { return this->sharedNetworkData->getHostID(); } 43 inline bool isGameServer() { return this->sharedNetworkData->isGameServer(); } 48 44 49 45 50 46 void connectSynchronizeable(Synchronizeable& sync); 51 47 void synchronize(); 48 49 void debug(); 50 52 51 53 52 private: … … 59 58 const std::list<BaseObject*>* syncList; // list of synchronizeables 60 59 static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class 61 NetworkStream* tmpStream; //!< FIXME: this is only for testing purposes 62 int hostID; //!< The Host-ID of the Manager 63 bool bGameServer; //!< true if it is a server 60 NetworkStream* defaultSyncStream; //!< FIXME: this is only for testing purposes 64 61 62 SharedNetworkData* sharedNetworkData; //!< reference to the shared data 65 63 }; 66 64 -
trunk/src/lib/network/network_socket.cc
r6634 r6695 97 97 /** 98 98 * Default destructor 99 * dont use this from outside: use destroy() instead!! 99 100 */ 100 101 NetworkSocket::~NetworkSocket( ) -
trunk/src/lib/network/network_socket.h
r6139 r6695 81 81 void init(); 82 82 83 //dont make this public use destroy() instead84 ~NetworkSocket();85 86 83 public: 87 84 88 85 NetworkSocket(); 86 ~NetworkSocket(); 89 87 NetworkSocket(IPaddress ip); 90 88 NetworkSocket(TCPsocket sock); -
trunk/src/lib/network/network_stream.cc
r6634 r6695 53 53 } 54 54 55 55 56 NetworkStream::NetworkStream(IPaddress& address) 56 57 { … … 60 61 this->networkProtocol = new NetworkProtocol(); 61 62 this->connectionMonitor = new ConnectionMonitor(); 62 63 Handshake* hs = new Handshake(false);64 hs->setUniqueID( 0 );65 this->handshakes.push_back(hs);66 this->connectSynchronizeable(*hs);67 PRINTF(0)("NetworkStream: %s\n", hs->getName());68 63 this->maxConnections = 1; 69 64 } … … 81 76 this->handshakes.push_back( NULL ); 82 77 this->bActive = true; 83 this->networkGameManager = NetworkGameManager::getInstance();84 // setUniqueID( maxCon+2 ) because we need one id for every handshake85 // and one for handshake to reject client maxCon+186 this->networkGameManager->setUniqueID( this->maxConnections+2 );87 this->connectSynchronizeable( *(this->networkGameManager) );88 89 this->setMaxConnections( 10 );90 78 } 91 79 … … 132 120 133 121 122 void NetworkStream::createNetworkGameManager() 123 { 124 this->networkGameManager = NetworkGameManager::getInstance(); 125 // setUniqueID( maxCon+2 ) because we need one id for every handshake 126 // and one for handshake to reject client maxCon+1 127 this->networkGameManager->setUniqueID( this->maxConnections + 2 ); 128 //this->connectSynchronizeable( *(this->networkGameManager) ); 129 this->setMaxConnections( 10 ); 130 } 131 132 133 void NetworkStream::startHandshake() 134 { 135 Handshake* hs = new Handshake(false); 136 hs->setUniqueID( 0 ); 137 this->handshakes.push_back(hs); 138 //this->connectSynchronizeable(*hs); 139 PRINTF(0)("NetworkStream: %s\n", hs->getName()); 140 } 141 142 134 143 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 135 144 { … … 140 149 this->bActive = true; 141 150 } 151 142 152 143 153 void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync) … … 184 194 if ( type != NET_SERVER ) 185 195 { 186 NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );196 SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() ); 187 197 myHostId = NetworkManager::getInstance()->getHostID(); 188 198 189 199 this->networkGameManager = NetworkGameManager::getInstance(); 190 200 this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() ); 191 this->connectSynchronizeable( *(this->networkGameManager) );201 //this->connectSynchronizeable( *(this->networkGameManager) ); 192 202 } 193 203 else … … 216 226 /* DOWNSTREAM */ 217 227 228 229 218 230 int dataLength; 219 231 int reciever; … … 221 233 for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++) 222 234 { 223 if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )235 if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ ) 224 236 { 225 237 do { … … 357 369 PRINTF(0)("New Client: %d\n", clientId); 358 370 359 this->connectSynchronizeable(*handshakes[clientId]);371 //this->connectSynchronizeable(*handshakes[clientId]); 360 372 } 361 373 … … 416 428 417 429 430 431 void NetworkStream::debug() 432 { 433 if( this->isServer()) 434 PRINT(0)(" Host ist Server with ID: %i\n", this->myHostId); 435 else 436 PRINT(0)(" Host ist Client with ID: %i\n", this->myHostId); 437 438 PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size()); 439 for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++) 440 { 441 if( (*it)->beSynchronized() == true) 442 PRINT(0)(" Synchronizeable of class: %s::%s, with unique ID: %i, Synchronize: %i\n", (*it)->getClassName(), (*it)->getName(), 443 (*it)->getUniqueID(), (*it)->beSynchronized()); 444 } 445 PRINT(0)(" Maximal Connections: %i\n", this->maxConnections); 446 447 } 448 449 450 int NetworkStream::getSyncCount() 451 { 452 int n = 0; 453 for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++) 454 if( (*it)->beSynchronized() == true) 455 ++n; 456 457 //return synchronizeables.size(); 458 return n; 459 } 460 461 462 463 464 465 -
trunk/src/lib/network/network_stream.h
r6634 r6695 14 14 #include "server_socket.h" 15 15 #include "handshake.h" 16 17 #define MAX_CONNECTIONS 100018 16 19 17 class Synchronizeable; … … 40 38 void init(); 41 39 40 void createNetworkGameManager(); 41 void startHandshake(); 42 42 43 void connectSynchronizeable(Synchronizeable& sync); 43 44 void disconnectSynchronizeable(Synchronizeable& sync); … … 53 54 inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); } 54 55 inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); } 55 in line int getSyncCount(){ return synchronizeables.size(); }56 int getSyncCount(); 56 57 57 58 inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; } 58 59 60 void debug(); 61 62 59 63 private: 60 NetworkProtocol* networkProtocol; 61 ConnectionMonitor* connectionMonitor; 62 SynchronizeableList synchronizeables; 63 NetworkSocketVector networkSockets; 64 HandshakeVector handshakes; 65 ServerSocket* serverSocket; 66 int type; 67 Header packetHeader; 68 bool bActive; 69 std::list<int> freeSocketSlots; 64 void updateConnectionList(); 70 65 71 int myHostId;72 int maxConnections;73 66 74 NetworkGameManager* networkGameManager; 67 private: 68 NetworkProtocol* networkProtocol; 69 ConnectionMonitor* connectionMonitor; 70 SynchronizeableList synchronizeables; 71 NetworkSocketVector networkSockets; 72 HandshakeVector handshakes; 73 ServerSocket* serverSocket; 74 int type; 75 Header packetHeader; 76 bool bActive; 77 std::list<int> freeSocketSlots; 75 78 76 void updateConnectionList(); 79 int myHostId; 80 int maxConnections; 81 82 NetworkGameManager* networkGameManager; 77 83 }; 78 84 #endif /* _NETWORK_STREAM */ -
trunk/src/lib/network/synchronizeable.cc
r6424 r6695 17 17 #define DEBUG_MODULE_NETWORK 18 18 19 #include "shared_network_data.h" 20 #include "network_stream.h" 21 #include "netdefs.h" 22 23 #include "state.h" 24 25 #include "assert.h" 26 19 27 #include "synchronizeable.h" 20 #include "netdefs.h" 21 #include "network_manager.h" 22 #include "network_stream.h" 28 23 29 24 30 … … 29 35 { 30 36 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 31 owner = 0;32 state = 0;33 hostID = NetworkManager::getInstance()->getHostID();37 this->owner = 0; 38 this->state = 0; 39 this->hostID = SharedNetworkData::getInstance()->getHostID(); 34 40 this->setIsServer(this->hostID == 0); 35 uniqueID = -1;41 this->uniqueID = NET_UID_UNASSIGNED; 36 42 this->networkStream = NULL; 37 43 this->setRequestedSync( false ); 38 44 this->setIsOutOfSync( !(this->isServer()) ); 45 this->bSynchronize = false; 46 47 if( State::isOnline()) 48 { 49 NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream(); 50 assert(nd != NULL); 51 nd->connectSynchronizeable(*this); 52 this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID()); 53 } 39 54 } 40 55 … … 50 65 } 51 66 67 52 68 /** 53 69 * write data to NetworkStream … … 57 73 PRINTF(5)("Synchronizeable::writeBytes was called\n"); 58 74 } 75 59 76 60 77 /** … … 87 104 } 88 105 106 89 107 /** 90 108 * Sets the outofsync flag to a given value … … 100 118 } 101 119 120 102 121 /** 103 122 * Determines if the server flag is set … … 108 127 return (this->state & STATE_SERVER) >0; 109 128 } 129 110 130 111 131 /** … … 118 138 } 119 139 140 120 141 /** 121 142 * Determines if the requestedSync flag is set … … 126 147 return (this->state & STATE_REQUESTEDSYNC) >0; 127 148 } 149 128 150 129 151 /** -
trunk/src/lib/network/synchronizeable.h
r6341 r6695 163 163 164 164 class Synchronizeable : virtual public BaseObject 165 { 165 { 166 166 167 public: 167 168 Synchronizeable(); 168 ~Synchronizeable();169 virtual ~Synchronizeable(); 169 170 170 171 virtual int writeBytes(const byte* data, int length, int sender); … … 179 180 bool isOutOfSync(); 180 181 bool requestedSync(); 182 181 183 inline void setUniqueID( int id ){ uniqueID = id; } 182 inline int getUniqueID() const { return uniqueID; }; 184 inline int getUniqueID() const { return uniqueID; } 185 inline int getHostID() { return this->hostID; } 186 187 inline int getOwner(){ return owner; } 188 inline void setOwner(int owner){ this->owner = owner; } 189 190 /** @returns true if this Synchronizeable has to be synchronized over network */ 191 inline bool beSynchronized() { return this->bSynchronize; } 192 /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */ 193 inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; } 194 183 195 inline void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); } 184 196 inline int getRequestSync( void ){ if ( this->synchronizeRequests.size()>0 ){ int n = *(synchronizeRequests.begin()); synchronizeRequests.pop_front(); return n; } else { return -1; } }; 185 inline int getHostID() { return this->hostID; }186 187 inline int getOwner(){ return owner; }188 inline void setOwner(int owner){ this->owner = owner; }189 197 190 198 inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; } 199 inline NetworkStream* getNetworkStream() { return this->networkStream; } 200 201 202 protected: 203 NetworkStream* networkStream; 204 int state; 205 191 206 192 207 private: 193 194 208 int uniqueID; 195 196 197 198 //static std::vector<Synchronizeable*> classList; 199 int owner; 200 int hostID; 201 202 std::list<int> synchronizeRequests; 203 204 protected: 205 NetworkStream* networkStream; 206 int state; 207 208 }; 209 int owner; 210 int hostID; 211 bool bSynchronize; 212 213 std::list<int> synchronizeRequests; 214 215 }; 209 216 #endif /* _SYNCHRONIZEABLE_H */ -
trunk/src/orxonox.cc
r6426 r6695 56 56 57 57 #include "network_manager.h" 58 59 #include "state.h" 58 60 59 61 #include <string.h> … … 276 278 277 279 if( this->serverName != NULL) // we are a client 280 { 281 State::setOnline(true); 278 282 NetworkManager::getInstance()->establishConnection(this->serverName, port); 283 } 279 284 else if( this->port > 0) { // we are a server 285 State::setOnline(true); 280 286 NetworkManager::getInstance()->createServer(port); 281 287 } 282 283 288 return 0; 284 289 } -
trunk/src/util/state.cc
r6498 r6695 41 41 Player* State::player = NULL; 42 42 43 bool State::bOnline = false; 43 44 44 45 /** -
trunk/src/util/state.h
r6498 r6695 73 73 74 74 75 /////////////// 76 /// NETWORK /// 77 /////////////// 78 /** sets the online stat (multiplayer network) @param bOnline is true if node is online */ 79 static inline void setOnline(bool bOnline) { State::bOnline = bOnline; } 80 /** @returns true if this node is online (multiplayer network game) */ 81 static bool isOnline() { return State::bOnline; } 82 75 83 76 84 private: … … 87 95 static unsigned int resX; //!< The X Resolution of the screen. 88 96 static unsigned int resY; //!< The Y Resolution of the screen. 97 98 static bool bOnline; //!< Is true if this node is in multiplayer mode (via network) 99 89 100 }; 90 101 -
trunk/src/world_entities/environments/water.cc
r6684 r6695 28 28 #include "skybox.h" 29 29 30 #include "network_game_manager.h" 30 31 31 32 using namespace std; … … 238 239 this->grid->rebuildNormals(this->height); 239 240 } 241 242 243 /** 244 * Writes data from network containing information about the state 245 * @param data pointer to data 246 * @param length length of data 247 * @param sender hostID of sender 248 */ 249 int Water::writeBytes( const byte * data, int length, int sender ) 250 { 251 setRequestedSync( false ); 252 setIsOutOfSync( false ); 253 254 SYNCHELP_READ_BEGIN(); 255 256 SYNCHELP_READ_FKT( Water::writeState ); 257 258 return SYNCHELP_READ_N; 259 } 260 261 262 /** 263 * data copied in data will bee sent to another host 264 * @param data pointer to data 265 * @param maxLength max length of data 266 * @return the number of bytes writen 267 */ 268 int Water::readBytes( byte * data, int maxLength, int * reciever ) 269 { 270 SYNCHELP_WRITE_BEGIN(); 271 272 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 273 { 274 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 275 setRequestedSync( true ); 276 } 277 278 int rec = this->getRequestSync(); 279 if ( rec > 0 ) 280 { 281 *reciever = rec; 282 SYNCHELP_WRITE_FKT( Water::readState ); 283 } 284 285 *reciever = 0; 286 return SYNCHELP_WRITE_N; 287 } 288 289 290 291 /** 292 * data copied in data will bee sent to another host 293 * @param data pointer to data 294 * @param maxLength max length of data 295 * @return the number of bytes writen 296 */ 297 int Water::readState( byte * data, int maxLength ) 298 { 299 SYNCHELP_WRITE_BEGIN(); 300 301 SYNCHELP_WRITE_FKT( WorldEntity::readState ); 302 303 // sync the size 304 SYNCHELP_WRITE_FLOAT( this->sizeX ); 305 SYNCHELP_WRITE_FLOAT( this->sizeY ); 306 307 //sync resolution 308 SYNCHELP_WRITE_INT( this->resX ); 309 SYNCHELP_WRITE_INT( this->resY ); 310 311 //sync the height 312 SYNCHELP_WRITE_FLOAT( this->height ); 313 314 return SYNCHELP_WRITE_N; 315 } 316 317 318 /** 319 * Writes data from network containing information about the state 320 * @param data pointer to data 321 * @param length length of data 322 * @param sender hostID of sender 323 */ 324 int Water::writeState( const byte * data, int length, int sender ) 325 { 326 SYNCHELP_READ_BEGIN(); 327 328 SYNCHELP_READ_FKT( WorldEntity::writeState ); 329 330 float f1, f2; 331 int i1, i2; 332 333 //read the size 334 SYNCHELP_READ_FLOAT( f1 ); 335 SYNCHELP_READ_FLOAT( f2 ); 336 this->sizeX = f1; 337 this->sizeY = f2; 338 PRINTF(0)("Setting Water to size: %f x %f\n", f1, f2); 339 340 //read the resolution 341 SYNCHELP_READ_INT( i1 ); 342 SYNCHELP_READ_INT( i2 ); 343 this->resX = i1; 344 this->resY = i2; 345 PRINTF(0)("Setting Water to resolution: %i x %i\n", i1, i2); 346 347 //read the height 348 SYNCHELP_READ_FLOAT( f1 ); 349 this->height = f1; 350 351 this->rebuildGrid(); 352 353 return SYNCHELP_READ_N; 354 } 355 356 -
trunk/src/world_entities/environments/water.h
r6518 r6695 35 35 void tick(float dt); 36 36 37 virtual int writeBytes(const byte* data, int length, int sender); 38 virtual int readBytes(byte* data, int maxLength, int * reciever); 39 40 int writeState( const byte * data, int length, int sender ); 41 int readState( byte * data, int maxLength ); 42 43 37 44 private: 38 45 Grid* grid; //!< The water-surface-model to render with -
trunk/src/world_entities/movie_entity.cc
r6676 r6695 40 40 this->toList(OM_COMMON); 41 41 42 this->loadParams(root); 42 if( root != NULL) 43 this->loadParams(root); 43 44 44 45 counter = 0; … … 52 53 MovieEntity::~MovieEntity () 53 54 { 54 delete this->media_container; 55 if( this->media_container) 56 delete this->media_container; 55 57 } 56 58 -
trunk/src/world_entities/planet.cc
r6634 r6695 27 27 #include "network_game_manager.h" 28 28 #include "converter.h" 29 #include "vertex_array_model.h" 30 #include "primitive_model.h" 29 31 30 32 using namespace std; … … 44 46 45 47 this->material = new Material(); 46 this->material->setIllum(10); 48 //this->material->setIllum(20); 49 //this->material->setAmbient(0.1, 0.1, 0.1); 50 51 52 53 //st float radius, const unsigned int loops, const unsigned int segmentsPerLoop 47 54 48 55 this->loadParams(root); 56 57 // VertexArrayModel* model = new VertexArrayModel(); 58 // model->spiralSphere(this->size, 10, 10); 59 // this->setModel(model); 60 // model->debug(); 61 // 62 PrimitiveModel* model = new PrimitiveModel(PRIM_SPHERE, this->size, 50); 63 this->setModel(model); 49 64 } 50 65 … … 98 113 { 99 114 115 100 116 glMatrixMode(GL_MODELVIEW); 101 117 glPushMatrix(); 118 119 glShadeModel(GL_SMOOTH); 102 120 103 121 /* translate */ … … 109 127 this->material->select(); 110 128 111 112 Vector c; 113 double r = this->size; 114 int n = 200; 115 int method = 1; 116 double theta1 = 0; 117 double theta2 = 2 * M_PI; 118 double phi1 = -M_PI/2.0; 119 double phi2 = M_PI/2.0; 120 121 122 int i,j; 123 double jdivn,j1divn,idivn,dosdivn,unodivn=1/(double)n,ndiv2=(double)n/2,t1,t2,t3,cost1,cost2,cte1,cte3; 124 cte3 = (theta2-theta1)/n; 125 cte1 = (phi2-phi1)/ndiv2; 126 dosdivn = 2*unodivn; 127 Vector e,p,e2,p2; 128 129 130 t2=phi1; 131 cost2=cos(phi1); 132 j1divn=0; 133 for (j=0;j<ndiv2;j++) { 134 t1 = t2;//t1 = phi1 + j * cte1; 135 t2 += cte1;//t2 = phi1 + (j + 1) * cte1; 136 t3 = theta1 - cte3; 137 cost1 = cost2;//cost1=cos(t1); 138 cost2 = cos(t2); 139 e.y = sin(t1); 140 e2.y = sin(t2); 141 p.y = c.y + r * e.y; 142 p2.y = c.y + r * e2.y; 143 144 if (method == 0) 145 glBegin(GL_QUAD_STRIP); 146 else 147 glBegin(GL_TRIANGLE_STRIP); 148 149 idivn=0; 150 jdivn=j1divn; 151 j1divn+=dosdivn;//=2*(j+1)/(double)n; 152 for (i=0;i<=n;i++) { 153 //t3 = theta1 + i * (theta2 - theta1) / n; 154 t3 += cte3; 155 e.x = cost1 * cos(t3); 156 //e.y = sin(t1); 157 e.z = cost1 * sin(t3); 158 p.x = c.x + r * e.x; 159 //p.y = c.y + r * e.y; 160 p.z = c.z + r * e.z; 161 glNormal3f(e.x,e.y,e.z); 162 glTexCoord2f(idivn,jdivn); 163 glVertex3f(p.x,p.y,p.z); 164 165 166 e2.x = cost2 * cos(t3); 167 //e.y = sin(t2); 168 e2.z = cost2 * sin(t3); 169 p2.x = c.x + r * e2.x; 170 //p.y = c.y + r * e.y; 171 p2.z = c.z + r * e2.z; 172 glNormal3f(e2.x,e2.y,e2.z); 173 glTexCoord2f(idivn,j1divn); 174 glVertex3f(p2.x,p2.y,p2.z); 175 idivn += unodivn; 176 } 177 glEnd(); 178 } 129 // /WorldEntity::draw(); 130 this->getModel(0)->draw(); 131 // static_cast<VertexArrayModel*>(this->getModel(0))->debug(); 179 132 } 180 133 -
trunk/src/world_entities/playable.cc
r6676 r6695 36 36 // the reference to the Current Player is NULL, because we dont have one at the beginning. 37 37 this->currentPlayer = NULL; 38 } 38 39 this->setSynchronized(true); 40 } 41 42 39 43 40 44 Playable::~Playable() … … 57 61 } 58 62 63 59 64 void Playable::removeWeapon(Weapon* weapon) 60 65 { … … 63 68 this->weaponConfigChanged(); 64 69 } 70 65 71 66 72 void Playable::nextWeaponConfig() … … 70 76 } 71 77 78 72 79 void Playable::previousWeaponConfig() 73 80 { … … 76 83 } 77 84 85 78 86 void Playable::weaponConfigChanged() 79 87 { … … 81 89 this->currentPlayer->weaponConfigChanged(); 82 90 } 91 83 92 84 93 /** -
trunk/src/world_entities/power_ups/param_power_up.cc
r6547 r6695 46 46 { 47 47 this->init(); 48 this->loadParams(root); 48 if( root != NULL) 49 this->loadParams(root); 49 50 } 50 51 -
trunk/src/world_entities/power_ups/turret_power_up.cc
r6512 r6695 36 36 this->init(); 37 37 38 this->loadParams(root); 38 if( root != NULL) 39 this->loadParams(root); 39 40 } 40 41 -
trunk/src/world_entities/power_ups/weapon_power_up.cc
r6589 r6695 39 39 { 40 40 this->init(); 41 this->loadParams(root); 41 if( root != NULL) 42 this->loadParams(root); 42 43 } 43 44 -
trunk/src/world_entities/projectiles/laser.cc
r6692 r6695 30 30 #include <cassert> 31 31 32 #include "assert.h" 32 33 33 34 -
trunk/src/world_entities/skybox.cc
r6634 r6695 51 51 this->preInit(); 52 52 53 this->loadParams(root); 53 if( root != NULL) 54 this->loadParams(root); 54 55 55 56 this->postInit(); -
trunk/src/world_entities/space_ships/space_ship.cc
r6692 r6695 97 97 if (root != NULL) 98 98 this->loadParams(root); 99 else 100 { 101 this->loadModel("models/ships/reap_#.obj"); 102 } 103 104 } 105 106 107 /** 108 * initializes a Spaceship 109 */ 110 void SpaceShip::init() 111 { 112 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); 113 this->setClassID(CL_SPACE_SHIP, "SpaceShip"); 114 115 PRINTF(4)("SPACESHIP INIT\n"); 99 116 100 117 //weapons: … … 112 129 113 130 this->getWeaponManager()->changeWeaponConfig(1); 114 }115 116 117 /**118 * initializes a Spaceship119 */120 void SpaceShip::init()121 {122 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));123 this->setClassID(CL_SPACE_SHIP, "SpaceShip");124 125 PRINTF(4)("SPACESHIP INIT\n");126 131 127 132 EventHandler::getInstance()->grabEvents(true); … … 206 211 dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); 207 212 } 213 208 214 209 215 /** -
trunk/src/world_entities/terrain.cc
r6512 r6695 39 39 { 40 40 this->init(); 41 this->loadParams(root); 41 if( root != NULL) 42 this->loadParams(root); 42 43 43 44 // if (this->model != NULL) -
trunk/src/world_entities/weapons/targeting_turret.cc
r6671 r6695 48 48 { 49 49 this->init(); 50 this->loadParams(root); 50 if( root != NULL) 51 this->loadParams(root); 51 52 } 52 53 -
trunk/src/world_entities/weapons/weapon.cc
r6671 r6695 100 100 101 101 this->energyWidget = NULL; 102 103 // set this object to be synchronized over network 104 //this->setSynchronized(true); 102 105 } 103 106 -
trunk/src/world_entities/world_entity.cc
r6634 r6695 54 54 this->energyMax = 1.0f; 55 55 this->energy = 1.0f; 56 this->scaling = 1.0f; 57 58 /* OSOLETE */ 59 this->bVisible = true; 60 this->bCollide = true; 56 61 57 62 this->md2TextureFileName = NULL; 58 59 60 this->setVisibiliy(true);61 63 62 64 this->objectListNumber = OM_INIT; … … 122 124 void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber) 123 125 { 126 this->modelLODName = fileName; 124 127 this->scaling = scaling; 125 128 if ( fileName != NULL && strcmp(fileName, "") ) … … 515 518 //check if modelFileName is relative to datadir or absolute 516 519 520 521 PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName, scaling); 522 517 523 if ( strcmp(modelFileName, "") ) 518 524 { 519 loadModel( modelFileName, scaling ); 525 loadModel( modelFileName, scaling); 526 PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName()); 520 527 } 521 528 delete[] modelFileName; -
trunk/src/world_entities/world_entity.h
r6512 r6695 111 111 std::vector<Model*> models; //!< The model that should be loaded for this entity. 112 112 const char* md2TextureFileName; //!< the file name of the md2 model texture, only if this 113 const char* modelLODName; //!< the name of the model lod file 113 114 BVTree* obbTree; //!< this is the obb tree reference needed for collision detection 114 115
Note: See TracChangeset
for help on using the changeset viewer.