Changeset 7512 in orxonox.OLD for branches/network/src
- Timestamp:
- May 3, 2006, 2:53:30 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/synchronizeable.cc
r7508 r7512 49 49 this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID()); 50 50 } 51 51 52 52 this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) ); 53 53 } … … 101 101 if ( sentStates.size() <= userId ) 102 102 sentStates.resize( userId+1 ); 103 103 104 104 //calculate needed memory 105 105 int neededSize = 0; 106 106 107 107 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 108 108 neededSize += (*it)->getSize(); 109 109 110 110 assert( neededSize <= maxLength ); 111 111 112 112 //remove older states from history than fromStateId 113 113 StateHistory::iterator it = sentStates[userId].begin(); 114 114 115 115 while ( it != sentStates[userId].end() && (*it)->stateId < fromStateId ) 116 116 it++; 117 117 118 118 if ( it != sentStates[userId].begin() ) 119 119 { … … 128 128 sentStates[userId].erase( sentStates[userId].begin(), it ); 129 129 } 130 130 131 131 //find state to create diff from 132 132 StateHistoryEntry * stateFrom = NULL; 133 133 134 134 it = sentStates[userId].begin(); 135 135 while ( it != sentStates[userId].end() && (*it)->stateId != fromStateId ) 136 136 it++; 137 137 138 138 if ( it == sentStates[userId].end() ) 139 139 { 140 140 StateHistoryEntry * initialEntry = new StateHistoryEntry(); 141 141 142 142 initialEntry->stateId = fromStateId; 143 143 initialEntry->dataLength = 0; 144 144 initialEntry->data = NULL; 145 145 146 146 stateFrom = initialEntry; 147 147 } 148 148 else 149 149 stateFrom = (*it); 150 150 151 151 StateHistoryEntry * stateTo = new StateHistoryEntry(); 152 152 153 153 stateTo->stateId = stateId; 154 154 stateTo->dataLength = neededSize; 155 155 stateTo->data = (byte*)malloc( neededSize ); 156 156 157 157 std::list<int>::iterator sizeIter = stateFrom->sizeList.begin(); 158 158 159 159 int i = 0; 160 160 int n; 161 161 162 162 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 163 163 { … … 178 178 stateTo->sizeList.push_back( (*sizeIter) ); 179 179 } 180 180 181 181 if ( sizeIter != stateFrom->sizeList.end() ) 182 182 sizeIter++; 183 183 } 184 184 185 185 sentStates[userId].push_back( stateTo ); 186 186 187 187 //write diff to data 188 188 for ( i = 0; i<neededSize; i++ ) … … 193 193 data[i] = stateTo->data[i]; 194 194 } 195 195 196 196 return neededSize; 197 197 } … … 203 203 * @param length length of diff 204 204 * @param stateId id of current state 205 * @param fromStateId id of the base state id 205 206 * @return true on success 206 207 */ … … 210 211 if ( recvStates.size() <= userId ) 211 212 recvStates.resize( userId+1 ); 212 213 213 214 //create new state 214 215 StateHistoryEntry * stateTo = new StateHistoryEntry(); … … 216 217 stateTo->dataLength = length; 217 218 stateTo->data = (byte*)malloc( length ); 218 219 //remove old states 219 220 //remove old states 220 221 StateHistory::iterator it = recvStates[userId].begin(); 221 222 222 223 while ( it != recvStates[userId].end() && (*it)->stateId < fromStateId ) 223 224 it++; 224 225 225 226 if ( it != recvStates[userId].begin() ) 226 227 { … … 235 236 recvStates[userId].erase( recvStates[userId].begin(), it ); 236 237 } 237 238 238 239 //find state to apply diff to 239 240 StateHistoryEntry * stateFrom = NULL; 240 241 241 242 it = recvStates[userId].begin(); 242 243 while ( it != recvStates[userId].end() && (*it)->stateId != fromStateId ) 243 244 it++; 244 245 245 246 if ( it == recvStates[userId].end() ) 246 247 { 247 248 StateHistoryEntry * initialEntry = new StateHistoryEntry(); 248 249 249 250 initialEntry->stateId = fromStateId; 250 251 initialEntry->dataLength = 0; 251 252 initialEntry->data = NULL; 252 253 253 254 stateFrom = initialEntry; 254 255 } 255 256 else 256 257 stateFrom = (*it); 257 258 258 259 //apply diff 259 260 for ( int i = 0; i<length; i++ ) … … 264 265 stateTo->data[i] = data[i]; 265 266 } 266 267 267 268 //add state to state history 268 269 recvStates[userId].push_back( stateTo ); 269 270 int i = 0; 271 270 271 int i = 0; 272 272 273 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 273 274 { 274 275 i += (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i ); 275 276 } 276 277 277 278 assert( i == length -1 ); 278 279 279 280 return length; 280 281 }
Note: See TracChangeset
for help on using the changeset viewer.