Changeset 288 for code/branches/main_reto_vs05/src
- Timestamp:
- Nov 27, 2007, 11:49:42 PM (17 years ago)
- Location:
- code/branches/main_reto_vs05/src
- Files:
-
- 6 added
- 3 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/main.cc
r232 r288 26 26 */ 27 27 28 //#define WITH_HIERARCHY 29 28 30 #include "OgrePlatform.h" 29 31 #include "OgreException.h" … … 31 33 #include "orxonox.h" 32 34 35 #ifdef WITH_HIERARCHY 33 36 #include "class_hierarchy/BaseObject.h" 34 37 #include "class_hierarchy/Test.h" … … 36 39 #include "class_hierarchy/test2.h" 37 40 #include "class_hierarchy/test3.h" 41 #endif 38 42 39 43 … … 50 54 #endif 51 55 { 52 #if 156 #ifndef WITH_HIERARCHY 53 57 try { 54 58 // create an orxonox application and run it -
code/branches/main_reto_vs05/src/orxonox.cc
r169 r288 99 99 ogre_->initialise(); 100 100 101 runMgr_ = new RunManager(ogre_); 101 runMgr_ = RunManager::createSingleton(); 102 runMgr_->initialise(ogre_); 102 103 103 104 return true; … … 113 114 delete timer_; 114 115 if (runMgr_) 115 delete runMgr_;116 RunManager::destroySingleton(); 116 117 if (ogre_) 117 118 delete ogre_; -
code/branches/main_reto_vs05/src/orxonox_prerequisites.h
r232 r288 52 52 } 53 53 54 55 namespace hud { 56 57 class HUDOverlay; 58 class TestOverlay; 59 60 } 61 54 62 } 55 63 -
code/branches/main_reto_vs05/src/orxonox_ship.cc
r232 r288 32 32 #include "OgreEntity.h" 33 33 #include "OgreSceneManager.h" 34 #include "OgreParticleSystem.h" 34 35 35 36 #include "inertial_node.h" … … 127 128 railGunStation_->selectWeapon(0); 128 129 130 // create some nice effects 131 132 ParticleSystem *particles = RunManager::getSingletonPtr() 133 ->getSceneManagerPtr()->createParticleSystem("asdf", "Examples/Smoke"); 134 135 fishNode->getSceneNode()->attachObject(particles); 136 137 138 139 129 140 return true; 130 141 } -
code/branches/main_reto_vs05/src/run_manager.cc
r232 r288 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 … … 58 53 #include "weapon/base_weapon.h" 59 54 55 #include "hud/hud_overlay.h" 56 #include "hud/test_overlay.h" 57 60 58 #include "run_manager.h" 61 59 62 namespace Ogre {63 using namespace orxonox;64 template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;65 }66 60 67 61 namespace orxonox { 68 62 using namespace Ogre; 69 63 using namespace weapon; 64 using namespace hud; 70 65 71 66 /** … … 82 77 */ 83 78 84 RunManager* RunManager::getSingletonPtr(void) 85 { 86 return ms_Singleton; 87 } 88 RunManager& RunManager::getSingleton(void) 89 { 90 assert( ms_Singleton ); return ( *ms_Singleton ); 91 } 92 93 94 /** 95 * Contructor only needs the render window and the Root object which are both 96 * the OgreControl object. 97 * Right now the constructor does all the initialisation work. This could also 98 * be done in a new method "initialize()", for whatever purpose. 99 * 100 * 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 /** 101 94 * @param ogre_ The OgreControl object holding the render window and the Root 102 95 */ 103 RunManager::RunManager(OgreControl * ogre) 104 : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false), 105 statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0), 106 filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0), 107 mouseSensitivity_(0.003), 108 debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0) 109 { 96 void RunManager::initialise(OgreControl *ogre) 97 { 98 ogre_ = ogre; 99 window_ = ogre->getRenderWindow(); 100 110 101 // SETTING UP THE SCENE 111 102 … … 126 117 127 118 // Create a space ship object and its SceneNode. 128 // Some ideas about the steering: The ship should only receive events like129 // up, down, left, right, roll left, roll right, move down, move up, etc).130 // Multiple interpretations of these commands would make the game more131 // but it also makes AI steering more difficult, since for every type of132 // steering, new methods have to be written.133 // --> clearly define how a space ship can fly (rolling?, conservation of134 // impuls?, direct mouse sight steeering?, etc.)135 119 // It should also be considered, that the ship should provide another Node 136 120 // for a camera to be attached (otherwise the spaceship in front of the 137 // would be very static, never moving at all).121 // ship would be very static, never moving at all). 138 122 139 123 // Construct a new spaceship and give it the node … … 145 129 146 130 // load all resources and create the entities by calling the initialise() 147 // methods for each object ( don't initialise in the constructor!).131 // methods for each object (no constructor initialisations!). 148 132 backgroundScene_->initialise(); 149 133 playerShip_->initialise(); … … 151 135 152 136 // CAMERA AND VIEWPORT 153 // TODO: create a camera manager. It should be able to change its position154 // around the space ship (predefined states would be nice too). And it should155 // also be able to switch between different locations (like ship, spactator,156 // certain fixed positions (e.g. finish line, etc.)). These are just ideas.157 137 158 138 // create camera and viewport … … 160 140 createViewports(); 161 141 142 // create HUD 143 hud_ = new hud::TestOverlay(window_); 144 hud_->show(); 145 162 146 163 147 // Set default mipmap level (NB some APIs ignore this) 164 148 TextureManager::getSingleton().setDefaultNumMipmaps(5); 165 149 166 167 150 168 151 // HUMAN INTERFACE 169 152 170 using namespace OIS; 171 172 debugOverlay_ = OverlayManager::getSingleton() 173 .getByName("Core/DebugOverlay"); 153 using namespace OIS; 174 154 175 155 LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); … … 201 181 windowResized(window_); 202 182 203 showDebugOverlay(true);183 //showDebugOverlay(true); 204 184 205 185 // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE … … 225 205 if (bulletManager_) 226 206 delete bulletManager_; 227 } 228 229 230 /** 231 * 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. 232 214 * 233 215 * Everything that needs to be computed during the games happens right here. … … 250 232 251 233 252 // Update the 'HUD' 253 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); 254 244 255 245 // update the bullet positions … … 404 394 { 405 395 statsOn_ = !statsOn_; 406 showDebugOverlay(statsOn_);407 timeUntilNextToggle_ = 1;408 }409 410 if( keyboard_->isKeyDown(KC_T) && timeUntilNextToggle_ <= 0 )411 {412 switch(filtering_)413 {414 case TFO_BILINEAR:415 filtering_ = TFO_TRILINEAR;416 aniso_ = 1;417 break;418 case TFO_TRILINEAR:419 filtering_ = TFO_ANISOTROPIC;420 aniso_ = 8;421 break;422 case TFO_ANISOTROPIC:423 filtering_ = TFO_BILINEAR;424 aniso_ = 1;425 break;426 default: break;427 }428 MaterialManager::getSingleton().setDefaultTextureFiltering(filtering_);429 MaterialManager::getSingleton().setDefaultAnisotropy(aniso_);430 431 showDebugOverlay(statsOn_);432 396 timeUntilNextToggle_ = 1; 433 397 } … … 439 403 window_->writeContentsToFile(ss.str()); 440 404 timeUntilNextToggle_ = 0.5; 441 debugText_ = "Saved: " + ss.str(); 442 } 443 444 if(keyboard_->isKeyDown(KC_R) && timeUntilNextToggle_ <=0) 445 { 446 sceneDetailIndex_ = (sceneDetailIndex_+1)%3 ; 447 switch(sceneDetailIndex_) { 448 case 0 : camera_->setPolygonMode(PM_SOLID); break; 449 case 1 : camera_->setPolygonMode(PM_WIREFRAME); break; 450 case 2 : camera_->setPolygonMode(PM_POINTS); break; 451 } 452 timeUntilNextToggle_ = 0.5; 453 } 454 455 static bool displayCameraDetails = false; 456 if(keyboard_->isKeyDown(KC_P) && timeUntilNextToggle_ <= 0) 457 { 458 displayCameraDetails = !displayCameraDetails; 459 timeUntilNextToggle_ = 0.5; 460 if (!displayCameraDetails) 461 debugText_ = ""; 462 } 463 464 // Print camera details 465 if(displayCameraDetails) 466 debugText_ = " | Speed = " 467 + StringConverter::toString(playerShip_->getSpeed()) 468 + " | Left Ammo = " 469 + StringConverter::toString(playerShip_ 470 ->getMainWeapon()->getAmmoState()) 471 + " | Ammo stock = " 472 + StringConverter::toString(playerShip_->getAmmoStock()); 473 // debugText_ = "P: " + StringConverter::toString(camera_ 474 // ->getDerivedPosition()) + " " + "O: " 475 // + StringConverter::toString(camera_->getDerivedOrientation()); 405 } 476 406 477 407 // Return true to continue rendering … … 507 437 508 438 /** 509 * Show the debug overlay ofdesired.439 * Show an overlay desired. 510 440 * @param show Whether or not to show the debug overlay 511 441 */ 512 442 void RunManager::showDebugOverlay(bool show) 513 443 { 514 if ( debugOverlay_)444 if (hud_) 515 445 { 516 446 if (show) 517 debugOverlay_->show();447 hud_->show(); 518 448 else 519 debugOverlay_->hide(); 520 } 521 } 522 523 524 /** 525 * Show stats (e.g. FPS) in the left lower corner of the screen. 526 * Copied from the ExampleFrameListener.h in the Ogre SDK 527 */ 528 void RunManager::updateStats(void) 529 { 530 static String currFps = "Current FPS: "; 531 static String avgFps = "Average FPS: "; 532 static String bestFps = "Best FPS: "; 533 static String worstFps = "Worst FPS: "; 534 static String tris = "Triangle Count: "; 535 static String batches = "Batch Count: "; 536 537 // update stats when necessary 538 try { 539 OverlayElement* guiAvg = OverlayManager::getSingleton() 540 .getOverlayElement("Core/AverageFps"); 541 OverlayElement* guiCurr = OverlayManager::getSingleton() 542 .getOverlayElement("Core/CurrFps"); 543 OverlayElement* guiBest = OverlayManager::getSingleton() 544 .getOverlayElement("Core/BestFps"); 545 OverlayElement* guiWorst = OverlayManager::getSingleton() 546 .getOverlayElement("Core/WorstFps"); 547 548 const RenderTarget::FrameStats& stats = window_->getStatistics(); 549 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 550 guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); 551 guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) 552 +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); 553 guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) 554 +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); 555 556 OverlayElement* guiTris = OverlayManager::getSingleton() 557 .getOverlayElement("Core/NumTris"); 558 guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); 559 560 OverlayElement* guiBatches = OverlayManager::getSingleton() 561 .getOverlayElement("Core/NumBatches"); 562 guiBatches->setCaption(batches 563 + StringConverter::toString(stats.batchCount)); 564 565 OverlayElement* guiDbg = OverlayManager::getSingleton() 566 .getOverlayElement("Core/DebugText"); 567 guiDbg->setCaption(debugText_); 568 } 569 catch(...) { /* ignore */ } 570 } 571 449 hud_->hide(); 450 } 451 } 572 452 573 453 574 454 /** 575 455 * Simple camera creator. 576 * playerShip_Node->attachObject(camera_) should no be here! This is what the camera577 * manager is for. Right now, this method should do just fine, setting the578 * cam behind the ship.579 */ 580 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() 581 461 { 582 462 camera_ = sceneMgr_->createCamera("PlayerCam"); … … 589 469 /** 590 470 * Simple viewport creator. 591 * TODO: fully understand the concept of viewports concerning orxnox.592 * E.g. do we need splitscreen mode?593 471 * For now the viewport uses the entire render window and is based on the one 594 472 * camera created so far. 595 473 */ 596 void RunManager::createViewports( void)474 void RunManager::createViewports() 597 475 { 598 476 // Create one viewport, entire window … … 605 483 } 606 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 607 511 } -
code/branches/main_reto_vs05/src/run_manager.h
r232 r288 32 32 #include "OgrePrerequisites.h" 33 33 #include "OgreWindowEventUtilities.h" 34 #include "OgreTextureManager.h" 35 #include "OgreSingleton.h" 34 //#include "OgreTextureManager.h" 36 35 37 36 #include <OIS/OISPrereqs.h> … … 44 43 // let the class inherit from WindowEventListener in order for the RunMgr 45 44 // to act as the central point of all the calcuations in Orxonox 46 class RunManager : public Ogre::WindowEventListener, 47 public Ogre::Singleton<RunManager> 45 class RunManager : public Ogre::WindowEventListener 48 46 { 49 47 public: 50 RunManager(OgreControl*);51 52 48 virtual ~RunManager(); 53 //void initialise(OgreControl*); 49 50 void initialise(OgreControl*); 54 51 55 52 bool tick(unsigned long, Ogre::Real); … … 65 62 int getNumberOfAmmos(); 66 63 64 static RunManager* createSingleton(); 65 66 static void destroySingleton(); 67 67 68 static RunManager& getSingleton(void); 68 69 … … 71 72 72 73 protected: 74 RunManager(); 75 73 76 void createCamera(void); 74 77 … … 93 96 /** OUTPUT **/ 94 97 95 void updateStats(void);96 97 98 void showDebugOverlay(bool); 98 99 99 100 protected: 101 // directly Ogre related fields 100 102 Ogre::SceneManager *sceneMgr_; 101 103 Ogre::RenderWindow *window_; 102 104 Ogre::Camera *camera_; 105 106 107 // self made orxonox fields 103 108 OgreControl *ogre_; 104 109 OrxonoxScene *backgroundScene_; 105 110 OrxonoxShip *playerShip_; 111 hud::TestOverlay *hud_; 106 112 113 // Bullet manager 114 weapon::BulletManager *bulletManager_; 115 116 const Ogre::Real mouseSensitivity_; 117 118 // previously elapsed render time 119 unsigned long totalTime_; 120 121 122 // fields from the example framework 107 123 bool statsOn_; 108 std::string debugText_;109 124 110 125 unsigned int screenShotCounter_; 111 126 // just to stop toggles flipping too fast 112 127 Ogre::Real timeUntilNextToggle_; 113 //bool leftButtonDown_;114 Ogre::TextureFilterOptions filtering_;115 int aniso_;116 117 int sceneDetailIndex_;118 Ogre::Overlay* debugOverlay_;119 128 120 129 //OIS Input devices … … 124 133 OIS::JoyStick* joystick_; 125 134 126 const Ogre::Real mouseSensitivity_; 127 128 // Bullet array 129 /*Bullet **bullets_; 130 int bulletsSize_; 131 int bulletsIndex_;*/ 132 weapon::BulletManager *bulletManager_; 133 134 // previously elapsed render time 135 unsigned long totalTime_; 135 // singleton pointer 136 static RunManager *singletonPtr_s; 136 137 137 138 }; -
code/branches/main_reto_vs05/src/weapon/barrel_gun.cc
r232 r288 95 95 void BarrelGun::primaryFiring(unsigned int time) 96 96 { 97 if (time > 1000/primaryFiringRate_)97 if (time > (unsigned int)1000/primaryFiringRate_) 98 98 { 99 99 currentState_ = IDLE; … … 133 133 void BarrelGun::secondaryFiring(unsigned int time) 134 134 { 135 if (time > 1000/secondaryFiringRate_)135 if (time > (unsigned int)1000/secondaryFiringRate_) 136 136 currentState_ = IDLE; 137 137 } -
code/branches/main_reto_vs05/src/weapon/base_weapon.cc
r232 r288 98 98 } 99 99 100 switch (currentState_)100 if (currentState_ != IDLE) 101 101 { 102 case IDLE: 102 switch (currentState_) 103 { 104 case PRIMARY_FIRE: 105 primaryFiring((unsigned int)(time - actionStartTime_)); 106 break; 107 108 case SECONDARY_FIRE: 109 secondaryFiring((unsigned int)(time - actionStartTime_)); 110 break; 111 112 case RELOADING: 113 break; 114 115 case CHANGING_AMMO: 116 break; 117 } 118 } 119 120 if (currentState_ == IDLE) 121 { 103 122 // first, process next action 104 123 if (nextAction_ != NOTHING) … … 142 161 } 143 162 } 144 145 break;146 147 case PRIMARY_FIRE:148 primaryFiring((unsigned int)(time - actionStartTime_));149 break;150 151 case SECONDARY_FIRE:152 secondaryFiring((unsigned int)(time - actionStartTime_));153 break;154 155 case RELOADING:156 break;157 158 case CHANGING_AMMO:159 break;160 163 } 161 164
Note: See TracChangeset
for help on using the changeset viewer.