Changeset 6678 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Jan 24, 2006, 10:22:33 PM (19 years ago)
- Location:
- branches/network/src/lib
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/coord/p_node.cc
r6674 r6678 1084 1084 this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); 1085 1085 1086 int n;1087 char * childName;1088 1089 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]);1090 SYNCHELP_READ_INT( n );1091 PRINTF(0)("read %s:n=%d\n", this->getName(), n);1092 1093 for (int i = 0; i<n; i++)1094 {1095 SYNCHELP_READ_STRINGM( childName );1096 PRINTF(0)("RCVD CHILD = %s\n", childName);1097 addChild( childName );1098 delete childName;1099 childName = NULL;1100 }1086 // int n; 1087 // char * childName; 1088 // 1089 // 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]); 1090 // SYNCHELP_READ_INT( n ); 1091 // PRINTF(0)("read %s:n=%d\n", this->getName(), n); 1092 // 1093 // for (int i = 0; i<n; i++) 1094 // { 1095 // SYNCHELP_READ_STRINGM( childName ); 1096 // PRINTF(0)("RCVD CHILD = %s\n", childName); 1097 // addChild( childName ); 1098 // delete childName; 1099 // childName = NULL; 1100 // } 1101 1101 1102 1102 return SYNCHELP_READ_N; … … 1135 1135 SYNCHELP_WRITE_FLOAT( this->relDirection.v.z ); 1136 1136 1137 int n = children.size();1138 1139 //check if camera is in children 1140 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1141 { 1142 if ( (*it)->isA(CL_CAMERA) ) 1143 n--; 1144 } 1145 PRINTF(0)("write %s:n=%d\n", this->getName(), n);1146 SYNCHELP_WRITE_INT( n);1147 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]); 1148 1149 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)1150 {1151 //dont add camera because there is only one camera attached to local player1152 if ( !(*it)->isA(CL_CAMERA) )1153 {1154 PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());1155 SYNCHELP_WRITE_STRING( (*it)->getName() );1156 }1157 }1137 // int n = children.size(); 1138 // //check if camera is in children 1139 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1140 // { 1141 // if ( (*it)->isA(CL_CAMERA) ) 1142 // n--; 1143 // } 1144 // PRINTF(0)("write %s:n=%d\n", this->getName(), n); 1145 // SYNCHELP_WRITE_INT( n ); 1146 // 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]); 1147 // 1148 // 1149 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1150 // { 1151 // //dont add camera because there is only one camera attached to local player 1152 // if ( !(*it)->isA(CL_CAMERA) ) 1153 // { 1154 // PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName()); 1155 // SYNCHELP_WRITE_STRING( (*it)->getName() ); 1156 // } 1157 // } 1158 1158 1159 1159 return SYNCHELP_WRITE_N; -
branches/network/src/lib/network/Makefile.am
r6139 r6678 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 \ -
branches/network/src/lib/network/netdefs.h
r5822 r6678 17 17 18 18 19 #define MAX_CONNECTIONS 1000 20 21 19 22 typedef unsigned char byte; 20 23 -
branches/network/src/lib/network/network_game_manager.cc
r6674 r6678 213 213 if ( this->isServer()) 214 214 { 215 if ( NetworkManager::getInstance()->getNewUniqueID() < 0 )215 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 216 216 { 217 217 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); 218 218 return -1; 219 219 } 220 return this->executeCreateEntity( classID, NetworkManager::getInstance()->getNewUniqueID(), owner );220 return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 221 221 } 222 222 else … … 237 237 if ( this->isServer() ) 238 238 { 239 if ( NetworkManager::getInstance()->getNewUniqueID() < 0 )239 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 240 240 { 241 241 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); … … 255 255 { 256 256 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 257 s->setUniqueID( NetworkManager::getInstance()->getNewUniqueID() );257 s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 258 258 s->setOwner( 0 ); 259 259 // all entities created via this function are added automaticaly to the synchronizeable list -
branches/network/src/lib/network/network_manager.cc
r6672 r6678 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" … … 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 … … 52 51 this->syncList = NULL; 53 52 this->defaultSyncStream = NULL; 54 55 this->hostID = -1; 56 this->newUniqueID = MAX_CONNECTIONS + 2; 57 this->bGameServer = false; 53 this->sharedNetworkData = SharedNetworkData::getInstance(); 58 54 59 55 PRINTF(0)("NetworkManager created\n"); … … 102 98 103 99 this->defaultSyncStream = new NetworkStream(ipAddress); 100 this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream); 104 101 this->defaultSyncStream->startHandshake(); 105 102 return 1; … … 113 110 int NetworkManager::createServer(unsigned int port) 114 111 { 115 this-> hostID = 0;116 this-> bGameServer = true;112 this->sharedNetworkData->setHostID(0); 113 this->sharedNetworkData->setGameServer(true); 117 114 this->defaultSyncStream = new NetworkStream(port); 115 this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream); 118 116 this->defaultSyncStream->createNetworkGameManager(); 119 117 PRINTF(0)("CREATE SERVER\n"); 120 this->bGameServer = true;121 118 SDL_Delay(20); 122 119 return 1; 123 }124 125 126 /**127 * creates a connection from one object to a host128 * @param address: the address of the destination host129 * @param synchronizeable: reference to the sync object130 */131 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)132 {133 /* creating a new network stream, it will register itself automaticaly to the class list */134 this->defaultSyncStream = new NetworkStream(address);135 this->defaultSyncStream->connectSynchronizeable(sync);136 }137 138 139 /**140 * teardown a connection141 */142 void NetworkManager::shutdownConnection()143 {144 PRINTF(0)("Shutdown connection\n");145 120 } 146 121 … … 167 142 } 168 143 169 /**170 * Sets the hostID to a specific number171 * @param id: The new ID172 */173 void NetworkManager::setHostID(int id)174 {175 this->hostID = id;176 }177 178 144 179 145 -
branches/network/src/lib/network/network_manager.h
r6673 r6678 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(); 52 53 inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; }54 55 /** @returns the next uniqueID free for an object */56 inline int getNewUniqueID() { return ( this->bGameServer)?this->newUniqueID++:-1; }57 48 58 49 void debug(); … … 68 59 static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class 69 60 NetworkStream* defaultSyncStream; //!< FIXME: this is only for testing purposes 70 int hostID; //!< The Host-ID of the Manager71 bool bGameServer; //!< true if it is a server72 int newUniqueID;73 61 62 SharedNetworkData* sharedNetworkData; //!< reference to the shared data 74 63 }; 75 64 -
branches/network/src/lib/network/network_stream.cc
r6673 r6678 194 194 if ( type != NET_SERVER ) 195 195 { 196 NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );196 SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() ); 197 197 myHostId = NetworkManager::getInstance()->getHostID(); 198 198 -
branches/network/src/lib/network/network_stream.h
r6672 r6678 14 14 #include "server_socket.h" 15 15 #include "handshake.h" 16 17 #define MAX_CONNECTIONS 100018 16 19 17 class Synchronizeable; -
branches/network/src/lib/network/synchronizeable.cc
r6675 r6678 17 17 #define DEBUG_MODULE_NETWORK 18 18 19 #include "synchronizeable.h" 20 21 #include "network_manager.h" 19 #include "shared_network_data.h" 22 20 #include "network_stream.h" 23 21 #include "netdefs.h" 24 22 25 23 #include "assert.h" 24 25 #include "synchronizeable.h" 26 26 27 27 28 … … 34 35 this->owner = 0; 35 36 this->state = 0; 36 this->hostID = NetworkManager::getInstance()->getHostID();37 this->hostID = SharedNetworkData::getInstance()->getHostID(); 37 38 this->setIsServer(this->hostID == 0); 38 39 this->uniqueID = -1; … … 40 41 this->setRequestedSync( false ); 41 42 this->setIsOutOfSync( !(this->isServer()) ); 42 43 43 this->bSynchronize = false; 44 44 45 NetworkStream* nd = NetworkManager::getInstance()->getDefaultSyncStream();45 NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream(); 46 46 assert(nd != NULL); 47 47 nd->connectSynchronizeable(*this); 48 this->setUniqueID( NetworkManager::getInstance()->getNewUniqueID());48 this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID()); 49 49 } 50 50
Note: See TracChangeset
for help on using the changeset viewer.