Changeset 868 for code/branches/network/src/network/GameStateClient.cc
- Timestamp:
- Mar 6, 2008, 4:45:49 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/GameStateClient.cc
r790 r868 61 61 * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot) 62 62 */ 63 bool GameStateClient::loadSnapshot(GameState state) {64 unsigned char *data=state .data;65 std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;63 bool GameStateClient::loadSnapshot(GameState *state) { 64 unsigned char *data=state->data; 65 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 66 66 // get the start of the Synchronisable list 67 67 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); 68 68 syncData sync; 69 69 // loop as long as we have some data ;) 70 while(data < state .data+state.size){70 while(data < state->data+state->size){ 71 71 // prepare the syncData struct 72 72 sync.length = (int)*data; … … 82 82 // bad luck ;) 83 83 // delete the synchronisable (obviously seems to be deleted on the server) 84 while(it != 0&& it->objectID!=sync.objectID){84 while(it && it->objectID!=sync.objectID){ 85 85 removeObject(it); 86 86 } 87 if( it==0){88 std::cout<< "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;87 if(!it){ 88 COUT(4) << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl; 89 89 Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate()); 90 90 no->objectID=sync.objectID; … … 93 93 // update data and create object/entity... 94 94 if( !no->updateData(sync) && !no->create() ) 95 COUT( 0) << "We couldn't create/update the object: " << sync.objectID << std::endl;95 COUT(2) << "We couldn't create/update the object: " << sync.objectID << std::endl; 96 96 ++it; 97 97 } … … 99 99 // we have our object 100 100 if(! it->updateData(sync)) 101 std::cout<< "We couldn't update objectID: " \101 COUT(2) << "We couldn't update objectID: " \ 102 102 << sync.objectID << "; classID: " << sync.classID << std::endl; 103 103 } … … 108 108 } 109 109 110 GameState GameStateClient::diff(GameState a, GameState b) {110 GameState *GameStateClient::diff(GameState a, GameState b) { 111 111 unsigned char *ap = a.data, *bp = b.data; 112 112 int of=0; // pointers offset … … 137 137 // should be finished now 138 138 // FIXME: is it true or false now? (struct has changed, producing warnings) 139 GameState r = {b.id, dest_length, true, dp}; 139 GameState *r = new GameState; 140 r->id = b.id; 141 r->size = dest_length; 142 r->diffed = true; 143 r->data = dp; 140 144 return r; 141 145 } 142 146 143 GameState GameStateClient::decompress(GameStateCompressed a) {147 GameState *GameStateClient::decompress(GameStateCompressed a) { 144 148 int normsize = a.normsize; 145 149 int compsize = a.compsize; … … 157 161 //std::cout << "length " << length << std::endl; 158 162 switch ( retval ) { 159 case Z_OK: std::cout << "successfully decompressed" << std::endl; break; 160 case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break; 161 case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break; 162 case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break; 163 } 164 165 GameState gamestate; 166 gamestate.id = a.id; 167 gamestate.size = normsize; 168 gamestate.data = dest; 169 gamestate.diffed = a.diffed; 170 163 case Z_OK: 164 COUT(3) << "successfully decompressed" << std::endl; break; 165 case Z_MEM_ERROR: 166 COUT(1) << "not enough memory available" << std::endl; 167 return NULL; 168 case Z_BUF_ERROR: 169 COUT(2) << "not enough memory available in the buffer" << std::endl; 170 return NULL; 171 case Z_DATA_ERROR: 172 COUT(2) << "data corrupted" << std::endl; 173 return NULL; 174 } 175 176 GameState *gamestate = new GameState; 177 gamestate->id = a.id; 178 gamestate->size = normsize; 179 gamestate->data = dest; 180 gamestate->diffed = a.diffed; 181 182 free(a.data); 183 171 184 return gamestate; 172 185 } 173 186 174 GameState GameStateClient::decode(GameState a, GameStateCompressed x) { 175 GameState t = decompress(x); 176 return diff(a, t); 177 } 178 179 GameState GameStateClient::decode(GameStateCompressed x) { 180 GameState t = decompress(x); 181 return t; 187 GameState *GameStateClient::decode(GameState a, GameStateCompressed x) { 188 GameState *t = decompress(x); 189 if(t==NULL) 190 return NULL; 191 else 192 return diff(a, *t); 193 } 194 195 GameState *GameStateClient::decode(GameStateCompressed x) { 196 GameState *t = decompress(x); 197 if(t==NULL) 198 return NULL; 199 else 200 return t; 182 201 } 183 202
Note: See TracChangeset
for help on using the changeset viewer.