| [462] | 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 |
|---|
| 8 | * modify it under the terms of the GNU General Public License |
|---|
| 9 | * as published by the Free Software Foundation; either version 2 |
|---|
| 10 | * of the License, or (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, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 20 | * |
|---|
| 21 | * Author: |
|---|
| 22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
|---|
| 23 | * Co-authors: |
|---|
| 24 | * ... |
|---|
| 25 | * |
|---|
| 26 | */ |
|---|
| 27 | /** |
|---|
| 28 | @file orxonox.cc |
|---|
| 29 | @brief Orxonox class |
|---|
| 30 | */ |
|---|
| 31 | |
|---|
| 32 | #include "graphicsEngine.h" |
|---|
| 33 | |
|---|
| 34 | #include <OgreRoot.h> |
|---|
| 35 | #include <OgreConfigFile.h> |
|---|
| 36 | #include <OgreTextureManager.h> |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | namespace orxonox { |
|---|
| 40 | |
|---|
| 41 | using namespace Ogre; |
|---|
| 42 | |
|---|
| 43 | GraphicsEngine::GraphicsEngine() |
|---|
| 44 | { |
|---|
| 45 | // set to standard values |
|---|
| 46 | this->configPath_ = ""; |
|---|
| 47 | this->dataPath_ = ""; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | GraphicsEngine::~GraphicsEngine() |
|---|
| 52 | { |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | void GraphicsEngine::setup() |
|---|
| 56 | { |
|---|
| 57 | //TODO: Check if file exists (maybe not here) |
|---|
| 58 | #ifndef OGRE_STATIC_LIB |
|---|
| 59 | root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", |
|---|
| 60 | configPath_ + "Ogre.log"); |
|---|
| 61 | #endif |
|---|
| 62 | root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * returns scene manager |
|---|
| 67 | */ |
|---|
| 68 | SceneManager* GraphicsEngine::getSceneManager() |
|---|
| 69 | { |
|---|
| 70 | if(!scene_) |
|---|
| 71 | scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager"); |
|---|
| 72 | return scene_; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | bool GraphicsEngine::load() |
|---|
| 76 | { |
|---|
| 77 | loadRessourceLocations(this->dataPath_); |
|---|
| 78 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
|---|
| 79 | return false; |
|---|
| 80 | return true; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | void GraphicsEngine::startRender() |
|---|
| 84 | { |
|---|
| 85 | root_->initialise(true, "OrxonoxV2"); |
|---|
| 86 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
|---|
| 87 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | void GraphicsEngine::loadRessourceLocations(std::string dataPath) |
|---|
| 91 | { |
|---|
| 92 | //TODO: Specify layout of data file and maybe use xml-loader |
|---|
| 93 | //TODO: Work with ressource groups (should be generated by a special loader) |
|---|
| 94 | // Load resource paths from data file using configfile ressource type |
|---|
| 95 | ConfigFile cf; |
|---|
| 96 | cf.load(dataPath_ + "resources.cfg"); |
|---|
| 97 | |
|---|
| 98 | // Go through all sections & settings in the file |
|---|
| 99 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
|---|
| 100 | |
|---|
| 101 | String secName, typeName, archName; |
|---|
| 102 | while (seci.hasMoreElements()) |
|---|
| 103 | { |
|---|
| 104 | secName = seci.peekNextKey(); |
|---|
| 105 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
|---|
| 106 | ConfigFile::SettingsMultiMap::iterator i; |
|---|
| 107 | for (i = settings->begin(); i != settings->end(); ++i) |
|---|
| 108 | { |
|---|
| 109 | typeName = i->first; |
|---|
| 110 | archName = i->second; |
|---|
| 111 | |
|---|
| 112 | ResourceGroupManager::getSingleton().addResourceLocation( |
|---|
| 113 | String(dataPath + archName), |
|---|
| 114 | typeName, secName); |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | } |
|---|