Changeset 265
- Timestamp:
- Nov 26, 2007, 5:24:39 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/orxonox.cc
r263 r265 76 76 namespace orxonox 77 77 { 78 class OrxExitListener : public Ogre::FrameListener 79 { 80 public: 81 OrxExitListener(OIS::Keyboard *keyboard) 82 : mKeyboard(keyboard) 78 class OrxExitListener : public Ogre::FrameListener 79 { 80 public: 81 OrxExitListener(OIS::Keyboard *keyboard) 82 : mKeyboard(keyboard) 83 { 84 } 85 86 bool frameStarted(const Ogre::FrameEvent& evt) 87 { 88 mKeyboard->capture(); 89 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 90 } 91 92 private: 93 OIS::Keyboard *mKeyboard; 94 }; 95 96 class OrxApplication 97 { 98 public: 99 void go() 100 { 101 createRoot(); 102 defineResources(); 103 setupRenderSystem(); 104 createRenderWindow(); 105 initializeResourceGroups(); 106 createScene(); 107 setupScene(); 108 setupInputSystem(); 109 setupCEGUI(); 110 createFrameListener(); 111 startRenderLoop(); 112 } 113 114 ~OrxApplication() 115 { 116 mInputManager->destroyInputObject(mKeyboard); 117 OIS::InputManager::destroyInputSystem(mInputManager); 118 119 // delete mRenderer; 120 // delete mSystem; 121 122 delete mListener; 123 delete mRoot; 124 } 125 126 private: 127 Ogre::Root *mRoot; 128 OIS::Keyboard *mKeyboard; 129 OIS::Mouse *mMouse; 130 OIS::InputManager *mInputManager; 131 CEGUI::OgreCEGUIRenderer *mRenderer; 132 CEGUI::System *mSystem; 133 OrxExitListener *mListener; 134 135 void createRoot() 136 { 137 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 138 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 139 #else 140 mRoot = new Ogre::Root(); 141 #endif 142 } 143 144 void defineResources() 145 { 146 Ogre::String secName, typeName, archName; 147 Ogre::ConfigFile cf; 148 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 149 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 150 #else 151 cf.load("resources.cfg"); 152 #endif 153 154 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 155 while (seci.hasMoreElements()) 83 156 { 84 } 85 86 bool frameStarted(const Ogre::FrameEvent& evt) 87 { 88 mKeyboard->capture(); 89 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 90 } 91 92 private: 93 OIS::Keyboard *mKeyboard; 94 }; 95 96 class OrxApplication 97 { 98 public: 99 void go() 100 { 101 createRoot(); 102 defineResources(); 103 setupRenderSystem(); 104 createRenderWindow(); 105 initializeResourceGroups(); 106 createScene(); 107 setupScene(); 108 setupInputSystem(); 109 setupCEGUI(); 110 createFrameListener(); 111 startRenderLoop(); 112 } 113 114 ~OrxApplication() 115 { 116 mInputManager->destroyInputObject(mKeyboard); 117 OIS::InputManager::destroyInputSystem(mInputManager); 118 119 // delete mRenderer; 120 // delete mSystem; 121 122 delete mListener; 123 delete mRoot; 124 } 125 126 private: 127 Ogre::Root *mRoot; 128 OIS::Keyboard *mKeyboard; 129 OIS::Mouse *mMouse; 130 OIS::InputManager *mInputManager; 131 CEGUI::OgreCEGUIRenderer *mRenderer; 132 CEGUI::System *mSystem; 133 OrxExitListener *mListener; 134 135 void createRoot() 136 { 137 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 138 mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 139 #else 140 mRoot = new Ogre::Root(); 141 #endif 142 } 143 144 void defineResources() 145 { 146 Ogre::String secName, typeName, archName; 147 Ogre::ConfigFile cf; 148 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 149 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 150 #else 151 cf.load("resources.cfg"); 152 #endif 153 154 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); 155 while (seci.hasMoreElements()) 157 secName = seci.peekNextKey(); 158 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 159 Ogre::ConfigFile::SettingsMultiMap::iterator i; 160 for (i = settings->begin(); i != settings->end(); ++i) 156 161 { 157 secName = seci.peekNextKey(); 158 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); 159 Ogre::ConfigFile::SettingsMultiMap::iterator i; 160 for (i = settings->begin(); i != settings->end(); ++i) 161 { 162 typeName = i->first; 163 archName = i->second; 164 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 165 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 166 #else 167 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 168 #endif 169 } 162 typeName = i->first; 163 archName = i->second; 164 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 165 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 166 #else 167 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 168 #endif 170 169 } 171 170 } 172 173 void setupRenderSystem() 171 } 172 173 void setupRenderSystem() 174 { 175 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 176 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 177 } 178 179 void createRenderWindow() 180 { 181 mRoot->initialise(true, "Ogre Render Window"); 182 } 183 184 void initializeResourceGroups() 185 { 186 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 187 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 188 } 189 190 void createScene(void) 191 { 192 193 string levelFile = "sp_level_moonstation.oxw"; 194 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 195 } 196 197 void setupScene() 198 { 199 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 200 Ogre::Camera *cam = mgr->createCamera("Camera"); 201 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 202 } 203 204 void setupInputSystem() 205 { 206 size_t windowHnd = 0; 207 std::ostringstream windowHndStr; 208 OIS::ParamList pl; 209 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 210 211 win->getCustomAttribute("WINDOW", &windowHnd); 212 windowHndStr << windowHnd; 213 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 214 mInputManager = OIS::InputManager::createInputSystem(pl); 215 216 try 174 217 { 175 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())176 throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()");218 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 219 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 177 220 } 178 179 void createRenderWindow() 221 catch (const OIS::Exception &e) 180 222 { 181 mRoot->initialise(true, "Ogre Render Window");223 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 182 224 } 183 184 void initializeResourceGroups() 185 { 186 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); 187 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 188 } 189 190 void createScene(void) 191 { 192 193 string levelFile = "sp_level_moonstation.oxw"; 194 loader::LevelLoader* loader = new loader::LevelLoader(levelFile); 195 } 196 197 void setupScene() 198 { 199 Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); 200 Ogre::Camera *cam = mgr->createCamera("Camera"); 201 Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 202 } 203 204 void setupInputSystem() 205 { 206 size_t windowHnd = 0; 207 std::ostringstream windowHndStr; 208 OIS::ParamList pl; 209 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 210 211 win->getCustomAttribute("WINDOW", &windowHnd); 212 windowHndStr << windowHnd; 213 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 214 mInputManager = OIS::InputManager::createInputSystem(pl); 215 216 try 217 { 218 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 219 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 220 } 221 catch (const OIS::Exception &e) 222 { 223 throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); 224 } 225 } 226 227 void setupCEGUI() 228 { 229 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 230 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 231 232 // CEGUI setup 233 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 234 // mSystem = new CEGUI::System(mRenderer); 235 236 // Other CEGUI setup here. 237 } 238 239 void createFrameListener() 240 { 241 mListener = new OrxExitListener(mKeyboard); 242 mRoot->addFrameListener(mListener); 243 } 244 245 void startRenderLoop() 246 { 247 mRoot->startRendering(); 248 } 249 }; 225 } 226 227 void setupCEGUI() 228 { 229 Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 230 Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); 231 232 // CEGUI setup 233 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 234 // mSystem = new CEGUI::System(mRenderer); 235 236 // Other CEGUI setup here. 237 } 238 239 void createFrameListener() 240 { 241 mListener = new OrxExitListener(mKeyboard); 242 mRoot->addFrameListener(mListener); 243 } 244 245 void startRenderLoop() 246 { 247 mRoot->startRendering(); 248 } 249 }; 250 250 } 251 251
Note: See TracChangeset
for help on using the changeset viewer.