Changeset 289 for code/branches/main_reto/src/run_manager.cc
- Timestamp:
- Nov 27, 2007, 11:54:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto/src/run_manager.cc
r267 r289 26 26 27 27 28 #include "Ogre.h" 29 //#include "OgreRoot.h" 30 //#include "OgreSceneManager.h" 31 //#include "OgreSceneNode.h" 32 //#include "OgreCamera.h" 33 //#include "OgreViewport.h" 34 //#include "OgreRenderWindow.h" 35 //#include "OgreOverlay.h" 36 //#include "OgreOverlayManager.h" 37 //#include "OgreOverlayElement.h" 38 //#include "OgreTextureManager.h" 39 //#include "OgreMaterialManager.h" 40 //#include "OgreLogManager.h" 41 //#include "OgreVector3.h" 42 //#include "OgreStringConverter.h" 43 //#include "OgreWindowEventUtilities.h" 28 #include "OgreVector3.h" 29 #include "OgreStringConverter.h" 30 #include "OgreRoot.h" 31 #include "OgreSceneManager.h" 32 #include "OgreSceneNode.h" 33 #include "OgreCamera.h" 34 #include "OgreViewport.h" 35 #include "OgreRenderWindow.h" 36 #include "OgreTextureManager.h" 37 #include "OgreMaterialManager.h" 38 #include "OgreLogManager.h" 39 #include "OgreWindowEventUtilities.h" 44 40 45 41 //Use this define to signify OIS will be used as a DLL … … 51 47 #include "orxonox_scene.h" 52 48 #include "orxonox_ship.h" 53 #include "camera_manager.h"54 49 #include "inertial_node.h" 55 50 … … 59 54 60 55 #include "hud/hud_overlay.h" 56 #include "hud/test_overlay.h" 61 57 62 58 #include "run_manager.h" 63 59 64 namespace Ogre {65 using namespace orxonox;66 template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;67 }68 60 69 61 namespace orxonox { … … 85 77 */ 86 78 87 RunManager* RunManager::getSingletonPtr(void) 88 { 89 return ms_Singleton; 90 } 91 RunManager& RunManager::getSingleton(void) 92 { 93 assert( ms_Singleton ); return ( *ms_Singleton ); 94 } 95 96 97 /** 98 * Contructor only needs the render window and the Root object which are both 99 * the OgreControl object. 100 * Right now the constructor does all the initialisation work. This could also 101 * be done in a new method "initialize()", for whatever purpose. 102 * 103 * 79 80 RunManager* RunManager::singletonPtr_s = NULL; 81 82 83 /** 84 * Contructor only needs the Root object. 85 */ 86 RunManager::RunManager() 87 : ogre_(NULL), window_(NULL), screenShotCounter_(0), 88 timeUntilNextToggle_(0), mouseSensitivity_(0.003), inputManager_(0), 89 mouse_(0), keyboard_(0), joystick_(0), statsOn_(true) 90 { 91 } 92 93 /** 104 94 * @param ogre_ The OgreControl object holding the render window and the Root 105 95 */ 106 RunManager::RunManager(OgreControl * ogre) 107 : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false), 108 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 109 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), 110 mouseSensitivity_(0.003), 111 debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0) 112 { 96 void RunManager::initialise(OgreControl *ogre) 97 { 98 ogre_ = ogre; 99 window_ = ogre->getRenderWindow(); 100 113 101 // SETTING UP THE SCENE 114 102 … … 129 117 130 118 // Create a space ship object and its SceneNode. 131 // Some ideas about the steering: The ship should only receive events like132 // up, down, left, right, roll left, roll right, move down, move up, etc).133 // Multiple interpretations of these commands would make the game more134 // but it also makes AI steering more difficult, since for every type of135 // steering, new methods have to be written.136 // --> clearly define how a space ship can fly (rolling?, conservation of137 // impuls?, direct mouse sight steeering?, etc.)138 119 // It should also be considered, that the ship should provide another Node 139 120 // for a camera to be attached (otherwise the spaceship in front of the 140 // would be very static, never moving at all).121 // ship would be very static, never moving at all). 141 122 142 123 // Construct a new spaceship and give it the node … … 148 129 149 130 // load all resources and create the entities by calling the initialise() 150 // methods for each object ( don't initialise in the constructor!).131 // methods for each object (no constructor initialisations!). 151 132 backgroundScene_->initialise(); 152 133 playerShip_->initialise(); … … 154 135 155 136 // CAMERA AND VIEWPORT 156 // TODO: create a camera manager. It should be able to change its position157 // around the space ship (predefined states would be nice too). And it should158 // also be able to switch between different locations (like ship, spactator,159 // certain fixed positions (e.g. finish line, etc.)). These are just ideas.160 137 161 138 // create camera and viewport … … 164 141 165 142 // create HUD 166 hud_ = new HUDOverlay();143 hud_ = new hud::TestOverlay(window_); 167 144 hud_->show(); 168 145 … … 171 148 TextureManager::getSingleton().setDefaultNumMipmaps(5); 172 149 173 174 150 175 151 // HUMAN INTERFACE 176 152 177 using namespace OIS; 178 179 //debugOverlay_ = OverlayManager::getSingleton() 180 // .getByName("Core/DebugOverlay"); 181 153 using namespace OIS; 182 154 183 155 LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); … … 233 205 if (bulletManager_) 234 206 delete bulletManager_; 235 } 236 237 238 /** 239 * Method to compute anyting between 2 frames. 207 if (hud_) 208 delete hud_; 209 } 210 211 212 /** 213 * Method to compute anything between 2 frames. 240 214 * 241 215 * Everything that needs to be computed during the games happens right here. … … 258 232 259 233 260 // Update the 'HUD' 261 //updateStats(); 234 // Update the HUD 235 hud_->setDebugText(" | Speed = " 236 + StringConverter::toString(playerShip_->getSpeed()) 237 + " | Left Ammo = " 238 + StringConverter::toString(playerShip_ 239 ->getMainWeapon()->getAmmoState()) 240 + " | Ammo stock = " 241 + StringConverter::toString(playerShip_->getAmmoStock())); 242 243 hud_->tick(time, deltaTime); 262 244 263 245 // update the bullet positions … … 412 394 { 413 395 statsOn_ = !statsOn_; 414 //showDebugOverlay(statsOn_);415 timeUntilNextToggle_ = 1;416 }417 418 if( keyboard_->isKeyDown(KC_T) && timeUntilNextToggle_ <= 0 )419 {420 switch(filtering_)421 {422 case TFO_BILINEAR:423 filtering_ = TFO_TRILINEAR;424 aniso_ = 1;425 break;426 case TFO_TRILINEAR:427 filtering_ = TFO_ANISOTROPIC;428 aniso_ = 8;429 break;430 case TFO_ANISOTROPIC:431 filtering_ = TFO_BILINEAR;432 aniso_ = 1;433 break;434 default: break;435 }436 MaterialManager::getSingleton().setDefaultTextureFiltering(filtering_);437 MaterialManager::getSingleton().setDefaultAnisotropy(aniso_);438 439 //showDebugOverlay(statsOn_);440 396 timeUntilNextToggle_ = 1; 441 397 } … … 447 403 window_->writeContentsToFile(ss.str()); 448 404 timeUntilNextToggle_ = 0.5; 449 debugText_ = "Saved: " + ss.str(); 450 } 451 452 if(keyboard_->isKeyDown(KC_R) && timeUntilNextToggle_ <=0) 453 { 454 sceneDetailIndex_ = (sceneDetailIndex_+1)%3 ; 455 switch(sceneDetailIndex_) { 456 case 0 : camera_->setPolygonMode(PM_SOLID); break; 457 case 1 : camera_->setPolygonMode(PM_WIREFRAME); break; 458 case 2 : camera_->setPolygonMode(PM_POINTS); break; 459 } 460 timeUntilNextToggle_ = 0.5; 461 } 462 463 static bool displayCameraDetails = false; 464 if(keyboard_->isKeyDown(KC_P) && timeUntilNextToggle_ <= 0) 465 { 466 displayCameraDetails = !displayCameraDetails; 467 timeUntilNextToggle_ = 0.5; 468 if (!displayCameraDetails) 469 debugText_ = ""; 470 } 471 472 // Print camera details 473 if(displayCameraDetails) 474 debugText_ = " | Speed = " 475 + StringConverter::toString(playerShip_->getSpeed()) 476 + " | Left Ammo = " 477 + StringConverter::toString(playerShip_ 478 ->getMainWeapon()->getAmmoState()) 479 + " | Ammo stock = " 480 + StringConverter::toString(playerShip_->getAmmoStock()); 481 // debugText_ = "P: " + StringConverter::toString(camera_ 482 // ->getDerivedPosition()) + " " + "O: " 483 // + StringConverter::toString(camera_->getDerivedOrientation()); 405 } 484 406 485 407 // Return true to continue rendering … … 515 437 516 438 /** 517 * Show the debug overlay ofdesired.439 * Show an overlay desired. 518 440 * @param show Whether or not to show the debug overlay 519 441 */ 520 442 void RunManager::showDebugOverlay(bool show) 521 443 { 522 if ( debugOverlay_)444 if (hud_) 523 445 { 524 446 if (show) 525 debugOverlay_->show();447 hud_->show(); 526 448 else 527 debugOverlay_->hide(); 528 } 529 } 530 531 532 /** 533 * Show stats (e.g. FPS) in the left lower corner of the screen. 534 * Copied from the ExampleFrameListener.h in the Ogre SDK 535 */ 536 void RunManager::updateStats(void) 537 { 538 static String currFps = "Current FPS: "; 539 static String avgFps = "Average FPS: "; 540 static String bestFps = "Best FPS: "; 541 static String worstFps = "Worst FPS: "; 542 static String tris = "Triangle Count: "; 543 static String batches = "Batch Count: "; 544 545 // update stats when necessary 546 try { 547 OverlayElement* guiAvg = OverlayManager::getSingleton() 548 .getOverlayElement("Core/AverageFps"); 549 OverlayElement* guiCurr = OverlayManager::getSingleton() 550 .getOverlayElement("Core/CurrFps"); 551 OverlayElement* guiBest = OverlayManager::getSingleton() 552 .getOverlayElement("Core/BestFps"); 553 OverlayElement* guiWorst = OverlayManager::getSingleton() 554 .getOverlayElement("Core/WorstFps"); 555 556 const RenderTarget::FrameStats& stats = window_->getStatistics(); 557 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 558 guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); 559 guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) 560 +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); 561 guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) 562 +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); 563 564 OverlayElement* guiTris = OverlayManager::getSingleton() 565 .getOverlayElement("Core/NumTris"); 566 guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); 567 568 OverlayElement* guiBatches = OverlayManager::getSingleton() 569 .getOverlayElement("Core/NumBatches"); 570 guiBatches->setCaption(batches 571 + StringConverter::toString(stats.batchCount)); 572 573 OverlayElement* guiDbg = OverlayManager::getSingleton() 574 .getOverlayElement("Core/DebugText"); 575 guiDbg->setCaption(debugText_); 576 } 577 catch(...) { /* ignore */ } 449 hud_->hide(); 450 } 578 451 } 579 452 … … 581 454 /** 582 455 * Simple camera creator. 583 * playerShip_Node->attachObject(camera_) should no be here! This is what the camera584 * manager is for. Right now, this method should do just fine, setting the585 * cam behind the ship.586 */ 587 void RunManager::createCamera( void)456 * playerShip_Node->attachObject(camera_) should not be here! This is what 457 * the camera manager is for. Right now, this method should do just fine, 458 * setting the cam behind the ship. 459 */ 460 void RunManager::createCamera() 588 461 { 589 462 camera_ = sceneMgr_->createCamera("PlayerCam"); … … 599 472 * camera created so far. 600 473 */ 601 void RunManager::createViewports( void)474 void RunManager::createViewports() 602 475 { 603 476 // Create one viewport, entire window … … 610 483 } 611 484 485 486 RunManager* RunManager::createSingleton() 487 { 488 if (singletonPtr_s) 489 return NULL; 490 singletonPtr_s = new RunManager(); 491 return singletonPtr_s; 492 } 493 494 void RunManager::destroySingleton() 495 { 496 if (singletonPtr_s) 497 delete singletonPtr_s; 498 } 499 500 501 RunManager& RunManager::getSingleton() 502 { 503 return *singletonPtr_s; 504 } 505 506 RunManager* RunManager::getSingletonPtr() 507 { 508 return singletonPtr_s; 509 } 510 612 511 }
Note: See TracChangeset
for help on using the changeset viewer.