Changeset 8147 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 5, 2006, 12:09:15 PM (19 years ago)
- Location:
- trunk/src/lib/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/message_manager.h
r8068 r8147 29 29 { 30 30 TESTMESSAGEID = 1, 31 MSGID_DELETESYNCHRONIZEABLE 31 MSGID_DELETESYNCHRONIZEABLE, 32 MSGID_PREFEREDTEAM 32 33 }; 33 34 -
trunk/src/lib/network/network_game_manager.cc
r8068 r8147 59 59 60 60 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 61 MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL ); 61 62 62 63 this->gameState = 0; … … 86 87 87 88 int team = rules.getTeamForNewUser(); 88 ClassID playableClassId = rules.getPlayableClassId( team );89 std::string playableModel = rules.getPlayableModelFileName( team, playableClassId );89 ClassID playableClassId = rules.getPlayableClassId( userId, team ); 90 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId ); 90 91 91 92 BaseObject * bo = Factory::fabricate( playableClassId ); … … 159 160 if ( dynamic_cast<Synchronizeable*>(*it)->getUniqueID() == uniqueId ) 160 161 { 162 if ( (*it)->isA(CL_PLAYABLE) ) 163 { 164 getInstance()->playablesToDelete.push_back( dynamic_cast<Playable*>(*it) ); 165 return true; 166 } 167 161 168 delete dynamic_cast<Synchronizeable*>(*it); 162 169 return true; … … 180 187 181 188 182 183 184 189 /** 190 * handler for MSGID_PREFEREDTEAM message 191 * @param messageId 192 * @param data 193 * @param dataLength 194 * @param someData 195 * @param userId 196 * @return 197 */ 198 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 199 { 200 assert( NetworkGameManager::getInstance()->isServer() ); 201 202 int teamId = 0; 203 int len = Converter::byteArrayToInt( data, &teamId ); 204 205 if ( len != dataLength ) 206 { 207 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId); 208 return true; 209 } 210 211 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 212 } 213 214 void NetworkGameManager::setPreferedTeam( int userId, int teamId ) 215 { 216 if ( !PlayerStats::getStats( userId ) ) 217 return; 218 219 PlayerStats & stats = *(PlayerStats::getStats( userId )); 220 221 stats.setPreferedTeamId( teamId ); 222 223 } 224 225 /** 226 * set prefered team for this host 227 * @param teamId 228 */ 229 void NetworkGameManager::prefereTeam( int teamId ) 230 { 231 if ( isServer() ) 232 setPreferedTeam( getHostID(), teamId ); 233 else 234 { 235 byte buf[INTSIZE]; 236 237 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 238 239 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 240 } 241 } 242 243 /** 244 * this function will be called periodically by networkManager 245 * @param ds time elapsed since last call of tick 246 */ 247 void NetworkGameManager::tick( float ds ) 248 { 249 //delete playables if they are not assigned to local player anymore 250 for ( std::list<Playable*>::iterator it = playablesToDelete.begin(); it != playablesToDelete.end(); ) 251 { 252 if ( State::getPlayer()->getPlayable() != *it ) 253 { 254 PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassName(), (*it)->getOwner() ); 255 std::list<Playable*>::iterator delit = it; 256 it++; 257 delete *delit; 258 playablesToDelete.erase( delit ); 259 continue; 260 } 261 it++; 262 } 263 } 264 265 266 267 -
trunk/src/lib/network/network_game_manager.h
r8068 r8147 12 12 /* include base_object.h since all classes are derived from this one */ 13 13 #include "synchronizeable.h" 14 #include "playable.h" 14 15 #include "message_manager.h" 15 16 … … 56 57 57 58 void removeSynchronizeable( int uniqueId ); 59 60 void prefereTeam( int teamId ); 58 61 59 62 inline void setGameState( int gameState ){ this->gameState = gameState; } 60 63 inline int getGameState(){ return this->gameState; } 64 65 void tick( float ds ); 61 66 62 67 private: … … 64 69 65 70 static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 71 static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 72 73 void setPreferedTeam( int userId, int teamId ); 66 74 67 75 static NetworkGameManager* singletonRef; 68 76 69 77 int gameState; 78 79 std::list<Playable*> playablesToDelete; 70 80 }; 71 81 -
trunk/src/lib/network/network_manager.cc
r7954 r8147 30 30 #include "preferences.h" 31 31 #include "network_log.h" 32 #include "network_game_manager.h" 32 33 33 34 … … 149 150 static_cast<NetworkStream*>(*stream)->processData(); 150 151 } 152 153 NetworkGameManager::getInstance()->tick( this->elapsedTime ); 151 154 } 152 155 -
trunk/src/lib/network/player_stats.cc
r8068 r8147 86 86 87 87 PRINTF(0)("uniqueID changed %d %d\n", userId, getHostID()); 88 89 if ( userId == getHostID() )90 State::getPlayer()->setPlayable( getPlayable() );91 88 } 92 89 } … … 100 97 { 101 98 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 99 100 if ( !list ) 101 return NULL; 102 102 103 103 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 121 121 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 122 122 123 if ( !list ) 124 { 125 this->playableUniqueId = uniqueId; 126 return; 127 } 128 123 129 this->playable = NULL; 124 130 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 130 136 } 131 137 } 138 139 if ( this->playable && userId == getHostID() ) 140 State::getPlayer()->setPlayable( this->playable ); 132 141 133 142 this->playableUniqueId = uniqueId; -
trunk/src/lib/network/synchronizeable.cc
r8068 r8147 108 108 109 109 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 110 { 111 //PRINTF(0)("SIZE = %d %s\n", (*it)->getSize(), (*it)->getName().c_str()); 110 112 neededSize += (*it)->getSize(); 113 } 111 114 112 115 if ( !( neededSize <= maxLength ) ) … … 183 186 ); 184 187 185 if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )188 if ( ( sizeIter != stateFrom->sizeList.end() && *sizeIter != (*it)->getSize() ) || ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() ) 186 189 { 187 190 n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i ); … … 209 212 sentStates[userId].push_back( stateTo ); 210 213 211 assert( i == neededSize ); 214 if ( i != neededSize ) 215 { 216 PRINTF(0)("strange error: (%s) %d != %d\n", this->getClassName(), i, neededSize); 217 assert(false); 218 } 212 219 213 220 //write diff to data -
trunk/src/lib/network/synchronizeable_var/synchronizeable_string.cc
r7954 r8147 48 48 49 49 assert( res > 0 ); 50 assert( res == vPtrIn->length()+INTSIZE ); 50 51 51 52 return res;
Note: See TracChangeset
for help on using the changeset viewer.