[74] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software: you can redistribute it and/or modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[142] | 28 | /** |
---|
| 29 | @file orxonox.cc |
---|
| 30 | @brief Orxonox Main File |
---|
| 31 | */ |
---|
| 32 | |
---|
[137] | 33 | #include <Ogre.h> |
---|
| 34 | #include <OIS/OIS.h> |
---|
| 35 | #include <CEGUI/CEGUI.h> |
---|
| 36 | #include <OgreCEGUIRenderer.h> |
---|
[74] | 37 | |
---|
[164] | 38 | #include <string> |
---|
| 39 | #include <iostream> |
---|
| 40 | |
---|
| 41 | #include "xml/xmlParser.h" |
---|
| 42 | #include "loader/LevelLoader.h" |
---|
[212] | 43 | #include "Flocking.h" |
---|
[164] | 44 | |
---|
[151] | 45 | // some tests to see if enet works without includsion |
---|
| 46 | //#include <enet/enet.h> |
---|
| 47 | //#include <enet/protocol.h> |
---|
[142] | 48 | |
---|
[137] | 49 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 50 | #include <CoreFoundation/CoreFoundation.h> |
---|
[74] | 51 | |
---|
[137] | 52 | // This function will locate the path to our application on OS X, |
---|
| 53 | // unlike windows you can not rely on the curent working directory |
---|
| 54 | // for locating your configuration files and resources. |
---|
| 55 | std::string macBundlePath() |
---|
[74] | 56 | { |
---|
[137] | 57 | char path[1024]; |
---|
| 58 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 59 | assert(mainBundle); |
---|
| 60 | |
---|
| 61 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 62 | assert(mainBundleURL); |
---|
| 63 | |
---|
| 64 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 65 | assert(cfStringRef); |
---|
| 66 | |
---|
| 67 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
| 68 | |
---|
| 69 | CFRelease(mainBundleURL); |
---|
| 70 | CFRelease(cfStringRef); |
---|
| 71 | |
---|
| 72 | return std::string(path); |
---|
| 73 | } |
---|
| 74 | #endif |
---|
| 75 | |
---|
| 76 | using namespace Ogre; |
---|
| 77 | |
---|
[212] | 78 | //my-stuff |
---|
| 79 | //globale definition eines Arrays welches alle nodes enthält |
---|
| 80 | Vector3 ElementLocationArray[2]; |
---|
| 81 | Vector3 ElementSpeedArray[2]; |
---|
| 82 | Vector3 ElementAccelerationArray[2]; |
---|
| 83 | |
---|
[233] | 84 | Element* arrayOfElements[2]; |
---|
[212] | 85 | |
---|
| 86 | |
---|
[137] | 87 | class OrxExitListener : public FrameListener |
---|
| 88 | { |
---|
[74] | 89 | public: |
---|
[212] | 90 | OrxExitListener(OIS::Keyboard *keyboard, Root* root) |
---|
[137] | 91 | : mKeyboard(keyboard) |
---|
[74] | 92 | { |
---|
[212] | 93 | root_ = root; |
---|
[74] | 94 | } |
---|
| 95 | |
---|
[137] | 96 | bool frameStarted(const FrameEvent& evt) |
---|
[74] | 97 | { |
---|
[212] | 98 | moving(evt); |
---|
[137] | 99 | mKeyboard->capture(); |
---|
| 100 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
---|
| 101 | } |
---|
[212] | 102 | |
---|
| 103 | //code the movments of the nodes here |
---|
| 104 | void moving(const FrameEvent& evt) { |
---|
| 105 | SceneManager *mgr = root_->getSceneManager("Default SceneManager"); |
---|
[233] | 106 | arrayOfElements[0]->update(*arrayOfElements); |
---|
| 107 | mgr->getSceneNode("HeadNode1")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[0]->location); |
---|
| 108 | arrayOfElements[1]->update(*arrayOfElements); |
---|
| 109 | mgr->getSceneNode("HeadNode2")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[1]->location); |
---|
| 110 | arrayOfElements[2]->update(*arrayOfElements); |
---|
| 111 | mgr->getSceneNode("HeadNode3")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[2]->location); |
---|
| 112 | //mgr->getSceneNode("HeadNode1")->yaw((Radian)10*evt.timeSinceLastFrame); |
---|
[212] | 113 | } |
---|
[135] | 114 | |
---|
[74] | 115 | private: |
---|
[137] | 116 | OIS::Keyboard *mKeyboard; |
---|
[212] | 117 | Root* root_; |
---|
[74] | 118 | }; |
---|
| 119 | |
---|
[137] | 120 | class OrxApplication |
---|
[74] | 121 | { |
---|
| 122 | public: |
---|
[137] | 123 | void go() |
---|
[74] | 124 | { |
---|
[137] | 125 | createRoot(); |
---|
| 126 | defineResources(); |
---|
| 127 | setupRenderSystem(); |
---|
| 128 | createRenderWindow(); |
---|
| 129 | initializeResourceGroups(); |
---|
[164] | 130 | createScene(); |
---|
[137] | 131 | setupScene(); |
---|
| 132 | setupInputSystem(); |
---|
| 133 | setupCEGUI(); |
---|
| 134 | createFrameListener(); |
---|
| 135 | startRenderLoop(); |
---|
[74] | 136 | } |
---|
| 137 | |
---|
[137] | 138 | ~OrxApplication() |
---|
[74] | 139 | { |
---|
[137] | 140 | mInputManager->destroyInputObject(mKeyboard); |
---|
| 141 | OIS::InputManager::destroyInputSystem(mInputManager); |
---|
| 142 | |
---|
[148] | 143 | // delete mRenderer; |
---|
| 144 | // delete mSystem; |
---|
[137] | 145 | |
---|
| 146 | delete mListener; |
---|
| 147 | delete mRoot; |
---|
[74] | 148 | } |
---|
[137] | 149 | |
---|
| 150 | private: |
---|
| 151 | Root *mRoot; |
---|
| 152 | OIS::Keyboard *mKeyboard; |
---|
| 153 | OIS::Mouse *mMouse; |
---|
| 154 | OIS::InputManager *mInputManager; |
---|
| 155 | CEGUI::OgreCEGUIRenderer *mRenderer; |
---|
| 156 | CEGUI::System *mSystem; |
---|
| 157 | OrxExitListener *mListener; |
---|
| 158 | |
---|
| 159 | void createRoot() |
---|
[74] | 160 | { |
---|
[137] | 161 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 162 | mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); |
---|
| 163 | #else |
---|
| 164 | mRoot = new Root(); |
---|
| 165 | #endif |
---|
[74] | 166 | } |
---|
| 167 | |
---|
[137] | 168 | void defineResources() |
---|
[74] | 169 | { |
---|
[137] | 170 | String secName, typeName, archName; |
---|
| 171 | ConfigFile cf; |
---|
| 172 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 173 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
---|
| 174 | #else |
---|
| 175 | cf.load("resources.cfg"); |
---|
| 176 | #endif |
---|
[74] | 177 | |
---|
[137] | 178 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 179 | while (seci.hasMoreElements()) |
---|
| 180 | { |
---|
| 181 | secName = seci.peekNextKey(); |
---|
| 182 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 183 | ConfigFile::SettingsMultiMap::iterator i; |
---|
| 184 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 185 | { |
---|
| 186 | typeName = i->first; |
---|
| 187 | archName = i->second; |
---|
| 188 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 189 | ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); |
---|
| 190 | #else |
---|
| 191 | ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
---|
| 192 | #endif |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | } |
---|
[74] | 196 | |
---|
[137] | 197 | void setupRenderSystem() |
---|
| 198 | { |
---|
| 199 | if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) |
---|
| 200 | throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
---|
| 201 | } |
---|
[74] | 202 | |
---|
[137] | 203 | void createRenderWindow() |
---|
| 204 | { |
---|
| 205 | mRoot->initialise(true, "Ogre Render Window"); |
---|
| 206 | } |
---|
[74] | 207 | |
---|
[137] | 208 | void initializeResourceGroups() |
---|
| 209 | { |
---|
| 210 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
| 211 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 212 | } |
---|
[74] | 213 | |
---|
[164] | 214 | void createScene(void) |
---|
| 215 | { |
---|
| 216 | |
---|
| 217 | string levelFile = "sp_level_moonstation.oxw"; |
---|
| 218 | loader::LevelLoader* loader = new loader::LevelLoader(levelFile); |
---|
| 219 | } |
---|
| 220 | |
---|
[137] | 221 | void setupScene() |
---|
| 222 | { |
---|
| 223 | SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); |
---|
| 224 | Camera *cam = mgr->createCamera("Camera"); |
---|
[233] | 225 | cam->setPosition(Vector3(0,0,1000)); |
---|
[212] | 226 | cam->lookAt(Vector3(0,0,0)); |
---|
[137] | 227 | Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); |
---|
[212] | 228 | example(); //my stuff |
---|
[137] | 229 | } |
---|
[74] | 230 | |
---|
[137] | 231 | void setupInputSystem() |
---|
| 232 | { |
---|
| 233 | size_t windowHnd = 0; |
---|
| 234 | std::ostringstream windowHndStr; |
---|
| 235 | OIS::ParamList pl; |
---|
| 236 | RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
[74] | 237 | |
---|
[137] | 238 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 239 | windowHndStr << windowHnd; |
---|
| 240 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
| 241 | mInputManager = OIS::InputManager::createInputSystem(pl); |
---|
[74] | 242 | |
---|
[137] | 243 | try |
---|
| 244 | { |
---|
| 245 | mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); |
---|
| 246 | mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); |
---|
| 247 | } |
---|
| 248 | catch (const OIS::Exception &e) |
---|
| 249 | { |
---|
| 250 | throw new Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
---|
| 251 | } |
---|
[74] | 252 | } |
---|
| 253 | |
---|
[137] | 254 | void setupCEGUI() |
---|
[74] | 255 | { |
---|
[137] | 256 | SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); |
---|
| 257 | RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
| 258 | |
---|
| 259 | // CEGUI setup |
---|
| 260 | // mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); |
---|
| 261 | // mSystem = new CEGUI::System(mRenderer); |
---|
| 262 | |
---|
| 263 | // Other CEGUI setup here. |
---|
[74] | 264 | } |
---|
[137] | 265 | |
---|
| 266 | void createFrameListener() |
---|
| 267 | { |
---|
[212] | 268 | mListener = new OrxExitListener(mKeyboard, mRoot); |
---|
[137] | 269 | mRoot->addFrameListener(mListener); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | void startRenderLoop() |
---|
| 273 | { |
---|
| 274 | mRoot->startRendering(); |
---|
| 275 | } |
---|
[212] | 276 | |
---|
| 277 | //declaration of the 3 Ogreheads |
---|
[233] | 278 | //muss leider global sein..... |
---|
| 279 | //Element* arrayOfElements[2]; |
---|
| 280 | |
---|
[212] | 281 | void example() { |
---|
| 282 | SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); |
---|
| 283 | mgr->setAmbientLight(ColourValue(1.0,1.0,1.0)); |
---|
| 284 | Entity* ent1 = mgr->createEntity("Head1", "ogrehead.mesh"); |
---|
| 285 | Entity* ent2 = mgr->createEntity("Head2", "ogrehead.mesh"); |
---|
| 286 | Entity* ent3 = mgr->createEntity("Head3", "ogrehead.mesh"); |
---|
[233] | 287 | SceneNode *node1 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode1", Vector3(0,100,0)); |
---|
[212] | 288 | SceneNode *node2 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode2", Vector3(100,0,0)); |
---|
| 289 | SceneNode *node3 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode3", Vector3(-100,0,0)); |
---|
| 290 | node1->attachObject(ent1); |
---|
| 291 | node2->attachObject(ent2); |
---|
| 292 | node3->attachObject(ent3); |
---|
[233] | 293 | //Camera* cam = mgr->getCamera("Camera"); |
---|
| 294 | //node1->attachObject(cam); |
---|
[212] | 295 | ElementLocationArray[0] = node1->getPosition(); |
---|
| 296 | ElementLocationArray[1] = node2->getPosition(); |
---|
| 297 | ElementLocationArray[2] = node3->getPosition(); |
---|
| 298 | ElementSpeedArray[0] = (0,0,0); |
---|
| 299 | ElementSpeedArray[1] = (0,0,0); |
---|
| 300 | ElementSpeedArray[2] = (0,0,0); |
---|
| 301 | ElementAccelerationArray[0] = (0,0,0); |
---|
| 302 | ElementAccelerationArray[1] = (0,0,0); |
---|
| 303 | ElementAccelerationArray[2] = (0,0,0); |
---|
[233] | 304 | arrayOfElements[0] = new Element( ElementLocationArray[0], ElementSpeedArray[0], ElementAccelerationArray[0] ); |
---|
| 305 | arrayOfElements[1] = new Element( ElementLocationArray[1], ElementSpeedArray[1], ElementAccelerationArray[1] ); |
---|
| 306 | arrayOfElements[2] = new Element( ElementLocationArray[2], ElementSpeedArray[2], ElementAccelerationArray[2] ); |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | /* for (int i=0; i<3; i++) { |
---|
| 312 | Element* arrayOfElements[i] = new Element( ElementLocationArray[i], ElementSpeedArray[i], ElementAccelerationArray[i] ); |
---|
| 313 | } */ |
---|
| 314 | /* for (int i=0; i<3; i++) { |
---|
| 315 | arrayOfElements[i]->update(arrayOfElements); |
---|
| 316 | } */ |
---|
[212] | 317 | } |
---|
[74] | 318 | }; |
---|
| 319 | |
---|
[212] | 320 | |
---|
| 321 | |
---|
[137] | 322 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
[74] | 323 | #define WIN32_LEAN_AND_MEAN |
---|
| 324 | #include "windows.h" |
---|
| 325 | |
---|
[137] | 326 | INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) |
---|
[74] | 327 | #else |
---|
[137] | 328 | int main(int argc, char **argv) |
---|
[74] | 329 | #endif |
---|
| 330 | { |
---|
[137] | 331 | try |
---|
| 332 | { |
---|
| 333 | OrxApplication orxonox; |
---|
[74] | 334 | orxonox.go(); |
---|
[137] | 335 | } |
---|
| 336 | catch(Exception& e) |
---|
| 337 | { |
---|
| 338 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
| 339 | MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
[74] | 340 | #else |
---|
| 341 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
| 342 | e.getFullDescription().c_str()); |
---|
| 343 | #endif |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | return 0; |
---|
| 347 | } |
---|
[137] | 348 | |
---|