Changeset 868 for code/branches/network
- Timestamp:
- Mar 6, 2008, 4:45:49 PM (17 years ago)
- Location:
- code/branches/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/bin/levels/sample.oxw
r790 r868 33 33 34 34 <!--Fighter camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf3.mesh" forward="500" rotateupdown="200" rotaterightleft="200" looprightleft="200" /--> 35 <SpaceShip camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf 5.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />35 <SpaceShip camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf3.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" /> 36 36 37 37 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/> … … 41 41 <NPC position="100,0,400" scale="1" mesh="razor.mesh"/> 42 42 43 <Model position="200,0,500" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" />44 <Model position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90" /> 43 <!-- <Model position="200,0,500" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" /> 44 <Model position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90" />--> 45 45 46 46 <Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yaw="-90" pitch="-90" /> -
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 -
code/branches/network/src/network/GameStateClient.h
r790 r868 25 25 bool pushGameState(GameStateCompressed *compstate); 26 26 private: 27 bool loadSnapshot(GameState state);28 GameState diff(GameState a, GameState b);29 GameState decompress(GameStateCompressed a);30 GameState decode(GameState a, GameStateCompressed x);31 GameState decode(GameStateCompressed x);27 bool loadSnapshot(GameState *state); 28 GameState *diff(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 -
code/branches/network/src/network/GameStateManager.cc
r790 r868 109 109 int offset=0; 110 110 // go through all Synchronisables 111 for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){111 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 112 112 //std::cout << "gamestatemanager: in for loop" << std::endl; 113 113 //get size of the synchronisable -
code/branches/network/src/orxonox/Orxonox.cc
r790 r868 80 80 namespace orxonox 81 81 { 82 // put this in a seperate Class or solve the problem in another fashion 83 class OrxListener : public Ogre::FrameListener 82 83 84 85 // put this in a seperate Class or solve the problem in another fashion 86 class OrxListenerStandalone : public Ogre::FrameListener 84 87 { 85 88 public: 86 OrxListener (OIS::Keyboard *keyboard, audio::AudioManager* auMan, gameMode mode)89 OrxListenerStandalone(OIS::Keyboard *keyboard, audio::AudioManager* auMan) 87 90 { 88 91 mKeyboard = keyboard; 89 mode_=mode;90 92 auMan_ = auMan; 91 93 } … … 96 98 updateAI(); 97 99 98 if(mode_ == PRESENTATION)99 server_g->tick(evt.timeSinceLastFrame);100 else if(mode_ == CLIENT)101 client_g->tick(evt.timeSinceLastFrame);102 100 103 101 usleep(10); … … 116 114 117 115 private: 118 gameMode mode_;119 116 OIS::Keyboard *mKeyboard; 120 117 audio::AudioManager* auMan_; 121 118 }; 122 119 120 class OrxListenerServer : public Ogre::FrameListener 121 { 122 public: 123 OrxListenerServer(){} 124 125 bool frameStarted(const Ogre::FrameEvent& evt) 126 { 127 updateAI(); 128 129 server_g->tick(evt.timeSinceLastFrame); 130 usleep(10); 131 132 return true; 133 } 134 135 void updateAI() 136 { 137 for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) 138 { 139 it->update(); 140 } 141 } 142 143 private: 144 }; 145 146 147 class OrxListenerClient : public Ogre::FrameListener 148 { 149 public: 150 OrxListenerClient(OIS::Keyboard *keyboard, audio::AudioManager* auMan) 151 { 152 mKeyboard = keyboard; 153 auMan_ = auMan; 154 } 155 156 bool frameStarted(const Ogre::FrameEvent& evt) 157 { 158 auMan_->update(); 159 updateAI(); 160 161 client_g->tick(evt.timeSinceLastFrame); 162 163 usleep(10); 164 165 mKeyboard->capture(); 166 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 167 } 168 169 void updateAI() 170 { 171 for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) 172 { 173 it->update(); 174 } 175 } 176 177 private: 178 OIS::Keyboard *mKeyboard; 179 audio::AudioManager* auMan_; 180 }; 181 123 182 // init static singleton reference of Orxonox 124 183 Orxonox* Orxonox::singletonRef_ = NULL; … … 137 196 this->mouse_ = 0; 138 197 this->inputManager_ = 0; 139 this->frameListener_ = 0;198 this->frameListener_.client = 0; 140 199 this->root_ = 0; 141 200 } … … 181 240 mode_ = CLIENT; 182 241 } 183 else if(mode == std::string("presentation"))184 {185 serverInit(path);186 mode_ = PRESENTATION;187 }188 242 else{ 189 243 standaloneInit(path); … … 193 247 194 248 /** 195 * start modules249 * calls the appropriate start function 196 250 */ 197 251 void Orxonox::start() 252 { 253 switch (mode_){ 254 case CLIENT: 255 startClient(); 256 break; 257 case SERVER: 258 startServer(); 259 break; 260 case STANDALONE: 261 default: 262 startStandalone(); 263 break; 264 } 265 } 266 267 /** 268 * start server modules 269 */ 270 void Orxonox::startServer() 271 { 272 //TODO: start modules 273 //ogre_->startRender(); 274 //TODO: run engine 275 Factory::createClassHierarchy(); 276 createScene(); 277 setupScene(); 278 //setupInputSystem(); 279 COUT(4) << "************** Server here *************" << std::endl; 280 createFrameListener(); 281 282 //TODO make a server framelistener caller 283 // startRenderLoop(); 284 } 285 286 /** 287 * start client modules 288 */ 289 void Orxonox::startClient() 290 { 291 //TODO: start modules 292 ogre_->startRender(); 293 //TODO: run engine 294 Factory::createClassHierarchy(); 295 createScene(); 296 setupInputSystem(); 297 298 COUT(4) << "************** Client here *************" << std::endl; 299 createFrameListener(); 300 client_g->establishConnection(); 301 // TODO : server-client initialization 302 startRenderLoop(); 303 } 304 305 /** 306 * start standalone modules 307 */ 308 void Orxonox::startStandalone() 198 309 { 199 310 //TODO: start modules … … 210 321 createFrameListener(); 211 322 switch(mode_){ 212 case PRESENTATION: 213 //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener()); 214 //std::cout << "could not add framelistener" << std::endl; 215 server_g->open(); 216 break; 217 case CLIENT: 218 client_g->establishConnection(); 219 break; 220 case SERVER: 221 case STANDALONE: 222 default: 223 break; 323 case CLIENT: 324 client_g->establishConnection(); 325 break; 326 case SERVER: 327 case STANDALONE: 328 default: 329 break; 224 330 } 225 331 startRenderLoop(); 226 332 } 227 333 228 334 /** 229 335 * @return singleton object … … 379 485 380 486 // load this file from config 381 loader_ = new loader::LevelLoader("sample.oxw"); 382 loader_->loadLevel(); 487 if(mode_==STANDALONE){ 488 loader_ = new loader::LevelLoader("sample.oxw"); 489 loader_->loadLevel(); 490 } 383 491 384 492 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); … … 458 566 459 567 //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future 460 frameListener_ = new OrxListener(keyboard_, auMan_, mode_); 461 ogre_->getRoot()->addFrameListener(frameListener_); 568 if(mode_==CLIENT){ 569 frameListener_.client = new OrxListenerClient(keyboard_, auMan_); 570 ogre_->getRoot()->addFrameListener(frameListener_.client); 571 }else if(mode_==SERVER){ 572 frameListener_.server = new OrxListenerServer(); 573 ogre_->getRoot()->addFrameListener(frameListener_.server); 574 }else{ 575 frameListener_.standalone = new OrxListenerStandalone(keyboard_, auMan_); 576 ogre_->getRoot()->addFrameListener(frameListener_.standalone); 577 } 578 462 579 } 463 580 … … 479 596 ogre_->getRoot()->startRendering(); 480 597 } 598 481 599 } 600 -
code/branches/network/src/orxonox/Orxonox.h
r790 r868 27 27 STANDALONE, 28 28 SERVER, 29 CLIENT, 30 PRESENTATION 29 CLIENT 31 30 }; 32 31 32 union OrxListener{ 33 OrxListenerClient *client; 34 OrxListenerServer *server; 35 OrxListenerStandalone *standalone; 36 }; 37 33 38 class _OrxonoxExport Orxonox 34 39 { … … 50 55 virtual ~Orxonox(); 51 56 // init functions 57 void startStandalone(); 58 void startServer(); 59 void startClient(); 52 60 void serverInit(std::string path); 53 61 void clientInit(std::string path); … … 76 84 OIS::Mouse* mouse_; 77 85 OIS::InputManager* inputManager_; 78 OrxListener *frameListener_;86 OrxListener frameListener_; 79 87 Ogre::Root* root_; 80 88 -
code/branches/network/src/orxonox/OrxonoxPrereqs.h
r790 r868 71 71 class Model; 72 72 class NPC; 73 class OrxListener; 73 class OrxListenerServer; 74 class OrxListenerClient; 75 class OrxListenerStandalone; 74 76 class Orxonox; 75 77 class Skybox;
Note: See TracChangeset
for help on using the changeset viewer.