Changeset 905
- Timestamp:
- Mar 20, 2008, 2:31:45 PM (17 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r891 r905 203 203 if(id!=NULL) 204 204 id->setNetworkID(clid->clid); 205 COUT(4) << "received network id: " << clid->clid << "; classname: " << clid->message << std::endl; 205 206 return; 206 207 } -
code/branches/network/src/network/ConnectionManager.cc
r888 r905 257 257 258 258 void ConnectionManager::syncClassid(int clientID) { 259 int i=0;259 unsigned int network_id=0; 260 260 std::string classname; 261 bool abort=false;262 261 orxonox::Identifier *id; 263 while(!abort){ 264 id = ID(i); 265 std::cout << "syncid: " << i << ", ID(id): " << id << std::endl; 266 if(id == NULL){ 267 if(i!=0) 268 abort=true; 269 else{ 270 ++i; 271 continue; 272 } 273 } 274 else{ 275 classname = id->getName(); 276 addPacket(packet_gen.clid( i, classname ),clientID); 277 } 278 ++i; 262 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin(); 263 while(it != orxonox::Factory::getFactoryEnd()){ 264 id = (*it).second; 265 if(id == NULL) 266 continue; 267 classname = id->getName(); 268 network_id = id->getNetworkID(); 269 COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl; 270 271 addPacket(packet_gen.clid( (int)network_id, classname ), clientID); 272 273 ++it; 279 274 } 280 275 sendPackets(); -
code/branches/network/src/network/GameStateClient.cc
r871 r905 41 41 bool GameStateClient::pushGameState(GameStateCompressed *compstate) { 42 42 if(compstate->diffed) 43 return loadSnapshot(decode(reference, *compstate));43 return loadSnapshot(decode(reference, compstate)); 44 44 else 45 return loadSnapshot(decode( *compstate));45 return loadSnapshot(decode(compstate)); 46 46 } 47 47 … … 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 && it->objectID!=sync.objectID) {84 while(it && it->objectID!=sync.objectID) 85 85 removeObject(it); 86 } 87 if(it==0){ 88 std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl; 89 Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate()); 86 87 88 if(!it){ 89 COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; 90 Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate()); 90 91 no->objectID=sync.objectID; 91 92 no->classID=sync.classID; … … 93 94 // update data and create object/entity... 94 95 if( !no->updateData(sync) && !no->create() ) 95 COUT( 0) << "We couldn't create/update the object: " << sync.objectID << std::endl;96 COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl; 96 97 ++it; 97 98 } … … 99 100 // we have our object 100 101 if(! it->updateData(sync)) 101 std::cout<< "We couldn't update objectID: " \102 COUT(1) << "We couldn't update objectID: " \ 102 103 << sync.objectID << "; classID: " << sync.classID << std::endl; 103 104 } … … 108 109 } 109 110 110 GameState GameStateClient::diff(GameState a, GameStateb) {111 unsigned char *ap = a .data, *bp = b.data;111 GameState *GameStateClient::undiff(GameState *a, GameState *b) { 112 unsigned char *ap = a->data, *bp = b->data; 112 113 int of=0; // pointers offset 113 114 int dest_length=0; 114 if(a .size>=b.size)115 dest_length=a .size;115 if(a->size>=b->size) 116 dest_length=a->size; 116 117 else 117 dest_length=b .size;118 dest_length=b->size; 118 119 unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char)); 119 while(of<a .size && of<b.size){120 while(of<a->size && of<b->size){ 120 121 *(dp+of)=*(ap+of)^*(bp+of); // do the xor 121 122 ++of; 122 123 } 123 if(a .size!=b.size){ // do we have to fill up ?124 if(a->size!=b->size){ // do we have to fill up ? 124 125 unsigned char n=0; 125 if(a .size<b.size){126 if(a->size<b->size){ 126 127 while(of<dest_length){ 127 128 *(dp+of)=n^*(bp+of); … … 137 138 // should be finished now 138 139 // FIXME: is it true or false now? (struct has changed, producing warnings) 139 GameState r = {b.id, dest_length, true, dp}; 140 GameState *r = new GameState; 141 r->id = b->id; 142 r->size = dest_length; 143 r->diffed = false; 144 r->data = dp; 140 145 return r; 141 146 } 142 147 143 GameState GameStateClient::decompress(GameStateCompresseda) {144 int normsize = a .normsize;145 int compsize = a .compsize;148 GameState *GameStateClient::decompress(GameStateCompressed *a) { 149 int normsize = a->normsize; 150 int compsize = a->compsize; 146 151 int bufsize; 147 152 if(normsize < compsize) … … 154 159 //std::cout << "gamestateclient" << std::endl; 155 160 //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl; 156 retval = uncompress( dest, &length, a .data, (uLong)compsize );161 retval = uncompress( dest, &length, a->data, (uLong)compsize ); 157 162 //std::cout << "length " << length << std::endl; 158 163 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;164 case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break; 165 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL; 166 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL; 167 case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL; 163 168 } 164 169 165 GameState gamestate; 166 gamestate.id = a.id; 167 gamestate.size = normsize; 168 gamestate.data = dest; 169 gamestate.diffed = a.diffed; 170 GameState *gamestate = new GameState; 171 gamestate->id = a->id; 172 gamestate->size = normsize; 173 gamestate->data = dest; 174 gamestate->diffed = a->diffed; 175 176 delete a->data; //delete compressed data 177 delete a; //we do not need the old (struct) gamestate anymore 170 178 171 179 return gamestate; 172 180 } 173 181 174 GameState GameStateClient::decode(GameState a, GameStateCompressedx) {175 GameState t = decompress(x);176 return diff(a, t);182 GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) { 183 GameState *t = decompress(x); 184 return undiff(a, t); 177 185 } 178 186 179 GameState GameStateClient::decode(GameStateCompressedx) {180 GameState t = decompress(x);187 GameState *GameStateClient::decode(GameStateCompressed *x) { 188 GameState *t = decompress(x); 181 189 return t; 182 190 } -
code/branches/network/src/network/GameStateClient.h
r790 r905 25 25 bool pushGameState(GameStateCompressed *compstate); 26 26 private: 27 bool loadSnapshot(GameState state);28 GameState diff(GameState a, GameStateb);29 GameState decompress(GameStateCompresseda);30 GameState decode(GameState a, GameStateCompressedx);31 GameState decode(GameStateCompressedx);27 bool loadSnapshot(GameState *state); 28 GameState *undiff(GameState *a, GameState *b); 29 GameState *decompress(GameStateCompressed *a); 30 GameState *decode(GameState *a, GameStateCompressed *x); 31 GameState *decode(GameStateCompressed *x); 32 32 void removeObject(orxonox::Iterator<Synchronisable> &it); 33 33 34 GameState reference;34 GameState *reference; 35 35 }; 36 36 -
code/branches/network/src/network/GameStateManager.cc
r894 r905 43 43 44 44 #include "core/CoreIncludes.h" 45 45 46 #include "ClientInformation.h" 46 47 #include "Synchronisable.h" -
code/branches/network/src/orxonox/Orxonox.cc
r904 r905 107 107 usleep(10); 108 108 109 if(mode_!=CLIENT){ 109 110 mKeyboard->capture(); 110 111 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 112 }else 113 return true; 111 114 } 112 115 … … 225 228 226 229 227 setupInputSystem();230 //setupInputSystem(); 228 231 229 232 createFrameListener();
Note: See TracChangeset
for help on using the changeset viewer.