Changeset 868 for code/branches/network/src/orxonox
- Timestamp:
- Mar 6, 2008, 4:45:49 PM (17 years ago)
- Location:
- code/branches/network/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.