Changeset 157 for code/branches/main_reto_vs05
- Timestamp:
- Nov 3, 2007, 7:52:58 PM (17 years ago)
- Location:
- code/branches/main_reto_vs05
- Files:
-
- 69 added
- 13 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05
-
Property
svn:ignore
set to
obj
-
Property
svn:ignore
set to
-
code/branches/main_reto_vs05/src/orxonox.cc
r151 r157 20 20 * 21 21 * Author: 22 * Benjamin Knecht <beni_at_orxonox.net>, (C) 200722 * Reto Grieder 23 23 * Co-authors: 24 24 * ... … … 26 26 */ 27 27 28 /**29 @file orxonox.cc30 @brief Orxonox Main File31 */32 28 33 #include <Ogre.h> 34 #include <OIS/OIS.h> 35 #include <CEGUI/CEGUI.h> 36 #include <OgreCEGUIRenderer.h> 29 #include "orxonox.h" 37 30 38 // some tests to see if enet works without includsion39 //#include <enet/enet.h>40 //#include <enet/protocol.h>41 31 42 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 43 #include <CoreFoundation/CoreFoundation.h> 32 void Orxonox::go(void) 33 { 34 if (!setup()) 35 return; 44 36 45 // This function will locate the path to our application on OS X, 46 // unlike windows you can not rely on the curent working directory 47 // for locating your configuration files and resources. 48 std::string macBundlePath() 49 { 50 char path[1024]; 51 CFBundleRef mainBundle = CFBundleGetMainBundle(); 52 assert(mainBundle); 37 mTimer = new Timer(); 53 38 54 CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); 55 assert(mainBundleURL); 39 unsigned long lastTime = mTimer->getMilliseconds(); 56 40 57 CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); 58 assert(cfStringRef); 41 while (true) 42 { 43 //Pump messages in all registered RenderWindow windows 44 WindowEventUtilities::messagePump(); 59 45 60 CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);46 mOgre->getRoot()->renderOneFrame(); 61 47 62 CFRelease(mainBundleURL); 63 CFRelease(cfStringRef); 48 if (!mRunMgr->tick(mTimer->getMilliseconds(), 49 (mTimer->getMilliseconds() - lastTime) / 1000.0)) 50 break; 51 lastTime = mTimer->getMilliseconds(); 52 } 64 53 65 return std::string(path); 66 } 67 #endif 68 69 using namespace Ogre; 70 71 class OrxExitListener : public FrameListener 72 { 73 public: 74 OrxExitListener(OIS::Keyboard *keyboard) 75 : mKeyboard(keyboard) 76 { 77 } 78 79 bool frameStarted(const FrameEvent& evt) 80 { 81 mKeyboard->capture(); 82 return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); 83 } 84 85 private: 86 OIS::Keyboard *mKeyboard; 87 }; 88 89 class OrxApplication 90 { 91 public: 92 void go() 93 { 94 createRoot(); 95 defineResources(); 96 setupRenderSystem(); 97 createRenderWindow(); 98 initializeResourceGroups(); 99 setupScene(); 100 setupInputSystem(); 101 setupCEGUI(); 102 createFrameListener(); 103 startRenderLoop(); 104 } 105 106 ~OrxApplication() 107 { 108 mInputManager->destroyInputObject(mKeyboard); 109 OIS::InputManager::destroyInputSystem(mInputManager); 110 111 // delete mRenderer; 112 // delete mSystem; 113 114 delete mListener; 115 delete mRoot; 116 } 117 118 private: 119 Root *mRoot; 120 OIS::Keyboard *mKeyboard; 121 OIS::Mouse *mMouse; 122 OIS::InputManager *mInputManager; 123 CEGUI::OgreCEGUIRenderer *mRenderer; 124 CEGUI::System *mSystem; 125 OrxExitListener *mListener; 126 127 void createRoot() 128 { 129 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 130 mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); 131 #else 132 mRoot = new Root(); 133 #endif 134 } 135 136 void defineResources() 137 { 138 String secName, typeName, archName; 139 ConfigFile cf; 140 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 141 cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); 142 #else 143 cf.load("resources.cfg"); 144 #endif 145 146 ConfigFile::SectionIterator seci = cf.getSectionIterator(); 147 while (seci.hasMoreElements()) 148 { 149 secName = seci.peekNextKey(); 150 ConfigFile::SettingsMultiMap *settings = seci.getNext(); 151 ConfigFile::SettingsMultiMap::iterator i; 152 for (i = settings->begin(); i != settings->end(); ++i) 153 { 154 typeName = i->first; 155 archName = i->second; 156 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 157 ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); 158 #else 159 ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); 160 #endif 161 } 162 } 163 } 164 165 void setupRenderSystem() 166 { 167 if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) 168 throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); 169 } 170 171 void createRenderWindow() 172 { 173 mRoot->initialise(true, "Ogre Render Window"); 174 } 175 176 void initializeResourceGroups() 177 { 178 TextureManager::getSingleton().setDefaultNumMipmaps(5); 179 ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 180 } 181 182 void setupScene() 183 { 184 SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); 185 Camera *cam = mgr->createCamera("Camera"); 186 Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); 187 } 188 189 void setupInputSystem() 190 { 191 size_t windowHnd = 0; 192 std::ostringstream windowHndStr; 193 OIS::ParamList pl; 194 RenderWindow *win = mRoot->getAutoCreatedWindow(); 195 196 win->getCustomAttribute("WINDOW", &windowHnd); 197 windowHndStr << windowHnd; 198 pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 199 mInputManager = OIS::InputManager::createInputSystem(pl); 200 201 try 202 { 203 mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); 204 mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); 205 } 206 catch (const OIS::Exception &e) 207 { 208 throw new Exception(42, e.eText, "OrxApplication::setupInputSystem"); 209 } 210 } 211 212 void setupCEGUI() 213 { 214 SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); 215 RenderWindow *win = mRoot->getAutoCreatedWindow(); 216 217 // CEGUI setup 218 // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); 219 // mSystem = new CEGUI::System(mRenderer); 220 221 // Other CEGUI setup here. 222 } 223 224 void createFrameListener() 225 { 226 mListener = new OrxExitListener(mKeyboard); 227 mRoot->addFrameListener(mListener); 228 } 229 230 void startRenderLoop() 231 { 232 mRoot->startRendering(); 233 } 234 }; 235 236 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 237 #define WIN32_LEAN_AND_MEAN 238 #include "windows.h" 239 240 INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) 241 #else 242 int main(int argc, char **argv) 243 #endif 244 { 245 try 246 { 247 OrxApplication orxonox; 248 orxonox.go(); 249 } 250 catch(Exception& e) 251 { 252 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 253 MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); 254 #else 255 fprintf(stderr, "An exception has occurred: %s\n", 256 e.getFullDescription().c_str()); 257 #endif 258 } 259 260 return 0; 54 // clean up 55 destroy(); 261 56 } 262 57 58 59 bool Orxonox::setup(void) 60 { 61 // create new 3D ogre render engine 62 mOgre = new OgreControl(); 63 mOgre->initialise(); 64 65 mRunMgr = new RunManager(mOgre); 66 67 return true; 68 } 69 70 71 void Orxonox::destroy() 72 { 73 if (mTimer) 74 delete mTimer; 75 if (mRunMgr) 76 delete mRunMgr; 77 if (mOgre) 78 delete mOgre; 79 }
Note: See TracChangeset
for help on using the changeset viewer.