Changeset 266
- Timestamp:
- Nov 26, 2007, 5:26:36 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/orxonox.cc
r264 r266 83 83 namespace orxonox 84 84 { 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 /* 109 110 111 112 113 114 115 116 117 118 119 85 class OrxExitListener : public Ogre::FrameListener 86 { 87 public: 88 OrxExitListener(OIS::Keyboard *keyboard) 89 : mKeyboard(keyboard) 90 { 91 } 92 93 bool frameStarted(const Ogre::FrameEvent& evt) 94 { 95 mKeyboard->capture(); 96 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 97 } 98 99 private: 100 OIS::Keyboard *mKeyboard; 101 }; 102 103 class OrxApplication 104 { 105 public: 106 void go() 107 { 108 /* 109 createRoot(); 110 defineResources(); 111 setupRenderSystem(); 112 createRenderWindow(); 113 initializeResourceGroups(); 114 createScene(); 115 setupScene(); 116 setupInputSystem(); 117 setupCEGUI(); 118 createFrameListener(); 119 startRenderLoop(); 120 120 */ 121 121 … … 583 583 std::cout << "13\n"; 584 584 585 } 586 587 ~OrxApplication() 585 } 586 587 ~OrxApplication() 588 { 589 mInputManager->destroyInputObject(mKeyboard); 590 OIS::InputManager::destroyInputSystem(mInputManager); 591 592 // delete mRenderer; 593 // delete mSystem; 594 595 delete mListener; 596 delete mRoot; 597 } 598 599 private: 600 Ogre::Root *mRoot; 601 OIS::Keyboard *mKeyboard; 602 OIS::Mouse *mMouse; 603 OIS::InputManager *mInputManager; 604 CEGUI::OgreCEGUIRenderer *mRenderer; 605 CEGUI::System *mSystem; 606 OrxExitListener *mListener; 607 608 void createRoot() 609 { 610 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 611 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 612 #else 613 mRoot = new Ogre::Root(); 614 #endif 615 } 616 617 void defineResources() 618 { 619 Ogre::String secName, typeName, archName; 620 Ogre::ConfigFile cf; 621 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 622 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 623 #else 624 cf.load("resources.cfg"); 625 #endif 626 627 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 628 while (seci.hasMoreElements()) 588 629 { 589 mInputManager->destroyInputObject(mKeyboard); 590 OIS::InputManager::destroyInputSystem(mInputManager); 591 592 // delete mRenderer; 593 // delete mSystem; 594 595 delete mListener; 596 delete mRoot; 597 } 598 599 private: 600 Ogre::Root *mRoot; 601 OIS::Keyboard *mKeyboard; 602 OIS::Mouse *mMouse; 603 OIS::InputManager *mInputManager; 604 CEGUI::OgreCEGUIRenderer *mRenderer; 605 CEGUI::System *mSystem; 606 OrxExitListener *mListener; 607 608 void createRoot() 609 { 610 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 611 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 612 #else 613 mRoot = new Ogre::Root(); 614 #endif 615 } 616 617 void defineResources() 618 { 619 Ogre::String secName, typeName, archName; 620 Ogre::ConfigFile cf; 621 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 622 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 623 #else 624 cf.load("resources.cfg"); 625 #endif 626 627 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 628 while (seci.hasMoreElements()) 630 secName = seci.peekNextKey(); 631 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 632 Ogre::ConfigFile::SettingsMultiMap::iterator i; 633 for (i = settings->begin(); i != settings->end(); ++i) 629 634 { 630 secName = seci.peekNextKey(); 631 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 632 Ogre::ConfigFile::SettingsMultiMap::iterator i; 633 for (i = settings->begin(); i != settings->end(); ++i) 634 { 635 typeName = i->first; 636 archName = i->second; 637 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 638 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 639 #else 640 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 641 #endif 642 } 635 typeName = i->first; 636 archName = i->second; 637 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 638 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 639 #else 640 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 641 #endif 643 642 } 644 643 } 645 646 void setupRenderSystem() 644 } 645 646 void setupRenderSystem() 647 { 648 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 649 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 650 } 651 652 void createRenderWindow() 653 { 654 mRoot->initialise(true, "Ogre Render Window"); 655 } 656 657 void initializeResourceGroups() 658 { 659 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 660 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 661 } 662 663 void createScene(void) 664 { 665 666 string levelFile = "sp_level_moonstation.oxw"; 667 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 668 } 669 670 void setupScene() 671 { 672 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 673 Ogre::Camera *cam = mgr->createCamera("Camera"); 674 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 675 } 676 677 void setupInputSystem() 678 { 679 size_t windowHnd = 0; 680 std::ostringstream windowHndStr; 681 OIS::ParamList pl; 682 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 683 684 win->getCustomAttribute("WINDOW", &windowHnd); 685 windowHndStr << windowHnd; 686 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 687 mInputManager = OIS::InputManager::createInputSystem(pl); 688 689 try 647 690 { 648 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())649 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");691 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 692 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 650 693 } 651 652 void createRenderWindow() 694 catch (const OIS::Exception &e) 653 695 { 654 mRoot->initialise(true, "Ogre Render Window");696 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 655 697 } 656 657 void initializeResourceGroups() 658 { 659 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 660 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 661 } 662 663 void createScene(void) 664 { 665 666 string levelFile = "sp_level_moonstation.oxw"; 667 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 668 } 669 670 void setupScene() 671 { 672 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 673 Ogre::Camera *cam = mgr->createCamera("Camera"); 674 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 675 } 676 677 void setupInputSystem() 678 { 679 size_t windowHnd = 0; 680 std::ostringstream windowHndStr; 681 OIS::ParamList pl; 682 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 683 684 win->getCustomAttribute("WINDOW", &windowHnd); 685 windowHndStr << windowHnd; 686 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 687 mInputManager = OIS::InputManager::createInputSystem(pl); 688 689 try 690 { 691 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 692 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 693 } 694 catch (const OIS::Exception &e) 695 { 696 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 697 } 698 } 699 700 void setupCEGUI() 701 { 702 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 703 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 704 705 // CEGUI setup 706 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 707 // mSystem = new CEGUI::System(mRenderer); 708 709 // Other CEGUI setup here. 710 } 711 712 void createFrameListener() 713 { 714 mListener = new OrxExitListener(mKeyboard); 715 mRoot->addFrameListener(mListener); 716 } 717 718 void startRenderLoop() 719 { 720 mRoot->startRendering(); 721 } 722 }; 698 } 699 700 void setupCEGUI() 701 { 702 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 703 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 704 705 // CEGUI setup 706 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 707 // mSystem = new CEGUI::System(mRenderer); 708 709 // Other CEGUI setup here. 710 } 711 712 void createFrameListener() 713 { 714 mListener = new OrxExitListener(mKeyboard); 715 mRoot->addFrameListener(mListener); 716 } 717 718 void startRenderLoop() 719 { 720 mRoot->startRendering(); 721 } 722 }; 723 723 } 724 724
Note: See TracChangeset
for help on using the changeset viewer.