Changeset 929 for code/branches/network/src/orxonox/Orxonox.cc
- Timestamp:
- Mar 26, 2008, 11:39:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/orxonox/Orxonox.cc
r928 r929 37 37 //#include <OgreException.h> 38 38 #include <OgreFrameListener.h> 39 #include <OgreRoot.h>40 39 #include <OgreOverlay.h> 41 40 #include <OgreOverlayManager.h> … … 86 85 this->auMan_ = 0; 87 86 this->inputHandler_ = 0; 88 this->root_ = 0;87 //this->root_ = 0; 89 88 // turn on frame smoothing by setting a value different from 0 90 89 this->frameSmoothingTime_ = 0.0f; … … 97 96 Orxonox::~Orxonox() 98 97 { 99 // nothing to delete as for now 100 inputHandler_->destroy(); 98 // keep in mind: the order of deletion is very important! 99 100 if (this->bulletMgr_) 101 delete this->bulletMgr_; 102 if (this->orxonoxHUD_) 103 delete this->orxonoxHUD_; 104 Loader::close(); 105 this->inputHandler_->destroy(); 106 if (this->auMan_) 107 delete this->auMan_; 108 if (this->timer_) 109 delete this->timer_; 110 if (this->ogre_) 111 delete this->ogre_; 112 113 if (client_g) 114 delete client_g; 115 if (server_g) 116 delete server_g; 117 } 118 119 /** 120 * error kills orxonox 121 */ 122 void Orxonox::abortImmediate(/* some error code */) 123 { 124 //TODO: destroy and destruct everything and print nice error msg 125 delete this; 126 } 127 128 /** 129 Asks the mainloop nicely to abort. 130 */ 131 void Orxonox::abortRequest() 132 { 133 bAbort_ = true; 134 } 135 136 /** 137 * @return singleton object 138 */ 139 Orxonox* Orxonox::getSingleton() 140 { 141 static Orxonox theOnlyInstance; 142 return &theOnlyInstance; 101 143 } 102 144 … … 118 160 ar.checkArgument("data", this->dataPath_, false); 119 161 ar.checkArgument("ip", serverIp_, false); 120 if(ar.errorHandling()) die();162 if(ar.errorHandling()) abortImmediate(); 121 163 if(mode == std::string("client")) 122 164 { … … 134 176 } 135 177 178 void Orxonox::serverInit(std::string path) 179 { 180 COUT(2) << "initialising server" << std::endl; 181 182 ogre_->setConfigPath(path); 183 ogre_->setup(); 184 //root_ = ogre_->getRoot(); 185 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 186 187 server_g = new network::Server(); 188 } 189 190 void Orxonox::clientInit(std::string path) 191 { 192 COUT(2) << "initialising client" << std::endl;\ 193 194 ogre_->setConfigPath(path); 195 ogre_->setup(); 196 if(serverIp_.compare("")==0) 197 client_g = new network::Client(); 198 else 199 client_g = new network::Client(serverIp_, NETWORK_PORT); 200 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 201 } 202 203 void Orxonox::standaloneInit(std::string path) 204 { 205 COUT(2) << "initialising standalone mode" << std::endl; 206 207 ogre_->setConfigPath(path); 208 ogre_->setup(); 209 //root_ = ogre_->getRoot(); 210 if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */); 211 } 136 212 137 213 /** … … 153 229 154 230 void Orxonox::clientStart(){ 155 ogre_-> startRender();231 ogre_->initialise(); 156 232 Factory::createClassHierarchy(); 157 233 … … 179 255 void Orxonox::serverStart(){ 180 256 //TODO: start modules 181 ogre_-> startRender();257 ogre_->initialise(); 182 258 //TODO: run engine 183 259 Factory::createClassHierarchy(); … … 192 268 void Orxonox::standaloneStart(){ 193 269 //TODO: start modules 194 ogre_-> startRender();270 ogre_->initialise(); 195 271 //TODO: run engine 196 272 Factory::createClassHierarchy(); … … 199 275 200 276 startRenderLoop(); 201 }202 203 /**204 * @return singleton object205 */206 Orxonox* Orxonox::getSingleton()207 {208 static Orxonox theOnlyInstance;209 return &theOnlyInstance;210 }211 212 /**213 * error kills orxonox214 */215 void Orxonox::die(/* some error code */)216 {217 //TODO: destroy and destruct everything and print nice error msg218 delete this;219 }220 221 /**222 Asks the mainloop nicely to abort.223 */224 void Orxonox::abortRequest()225 {226 bAbort_ = true;227 }228 229 230 void Orxonox::serverInit(std::string path)231 {232 COUT(2) << "initialising server" << std::endl;233 234 ogre_->setConfigPath(path);235 ogre_->setup();236 root_ = ogre_->getRoot();237 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);238 239 server_g = new network::Server();240 }241 242 void Orxonox::clientInit(std::string path)243 {244 COUT(2) << "initialising client" << std::endl;\245 246 ogre_->setConfigPath(path);247 ogre_->setup();248 if(serverIp_.compare("")==0)249 client_g = new network::Client();250 else251 client_g = new network::Client(serverIp_, NETWORK_PORT);252 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);253 }254 255 void Orxonox::standaloneInit(std::string path)256 {257 COUT(2) << "initialising standalone mode" << std::endl;258 259 ogre_->setConfigPath(path);260 ogre_->setup();261 root_ = ogre_->getRoot();262 if(!ogre_->load(this->dataPath_)) die(/* unable to load */);263 277 } 264 278 … … 285 299 auMan_->ambientAdd("a3"); 286 300 //auMan->ambientAdd("ambient1"); 287 auMan_->ambientStart();*/ 301 auMan_->ambientStart(); 302 */ 288 303 } 289 304 … … 316 331 { 317 332 // use the ogre timer class to measure time. 318 Ogre::Timer *timer = new Ogre::Timer(); 319 timer->reset(); 333 if (!timer_) 334 timer_ = new Ogre::Timer(); 335 timer_->reset(); 320 336 321 337 // Contains the times of recently fired events … … 331 347 332 348 // get current time 333 unsigned long now = timer ->getMilliseconds();349 unsigned long now = timer_->getMilliseconds(); 334 350 335 351 // create an event to pass to the frameStarted method in ogre … … 341 357 orxonoxHUD_->setTime((int)now, 0); 342 358 343 // don't forget to call _fireFrameStarted in ogre to make sure344 // everything goes smoothly345 if (!ogre_->getRoot()->_fireFrameStarted(evt))346 break;347 348 359 // Iterate through all Tickables and call their tick(dt) function 349 360 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 350 361 (it++)->tick((float)evt.timeSinceLastFrame); 351 362 363 // don't forget to call _fireFrameStarted in ogre to make sure 364 // everything goes smoothly 365 ogre_->frameStarted(evt); 366 352 367 if (mode_ != SERVER) 353 { 354 // only render in non-server mode 355 ogre_->getRoot()->_updateAllRenderTargets(); 356 } 368 ogre_->renderOneFrame(); // only render in non-server mode 357 369 358 370 // get current time 359 now = timer ->getMilliseconds();371 now = timer_->getMilliseconds(); 360 372 361 373 // create an event to pass to the frameEnded method in ogre … … 364 376 365 377 // again, just to be sure ogre works fine 366 if (!ogre_->getRoot()->_fireFrameEnded(evt)) 367 break; 378 ogre_->frameEnded(evt); 368 379 } 369 380 } … … 406 417 } 407 418 419 /** 420 @brief Test method for the InputHandler. 421 But: Is actually responsible for catching an exit event.. 422 */ 408 423 void Orxonox::eventOccured(InputEvent &evt) 409 424 {
Note: See TracChangeset
for help on using the changeset viewer.