[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> |
---|
[560] | 37 | #include "core/Debug.h" |
---|
[462] | 38 | |
---|
| 39 | |
---|
| 40 | namespace orxonox { |
---|
| 41 | |
---|
| 42 | using namespace Ogre; |
---|
| 43 | |
---|
| 44 | GraphicsEngine::GraphicsEngine() |
---|
| 45 | { |
---|
| 46 | // set to standard values |
---|
| 47 | this->configPath_ = ""; |
---|
| 48 | this->dataPath_ = ""; |
---|
[473] | 49 | scene_ = NULL; |
---|
[462] | 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | GraphicsEngine::~GraphicsEngine() |
---|
| 54 | { |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void GraphicsEngine::setup() |
---|
| 58 | { |
---|
| 59 | //TODO: Check if file exists (maybe not here) |
---|
[473] | 60 | /*#ifndef OGRE_STATIC_LIB |
---|
[462] | 61 | root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", |
---|
| 62 | configPath_ + "Ogre.log"); |
---|
[473] | 63 | #else |
---|
[462] | 64 | root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); |
---|
[473] | 65 | #endif*/ |
---|
| 66 | root_ = new Root(); |
---|
[462] | 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
[473] | 70 | * @return scene manager |
---|
[462] | 71 | */ |
---|
| 72 | SceneManager* GraphicsEngine::getSceneManager() |
---|
| 73 | { |
---|
| 74 | if(!scene_) |
---|
[473] | 75 | { |
---|
[462] | 76 | scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager"); |
---|
[560] | 77 | COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; |
---|
[473] | 78 | } |
---|
[462] | 79 | return scene_; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | bool GraphicsEngine::load() |
---|
| 83 | { |
---|
| 84 | loadRessourceLocations(this->dataPath_); |
---|
| 85 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
---|
| 86 | return false; |
---|
| 87 | return true; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void GraphicsEngine::startRender() |
---|
| 91 | { |
---|
| 92 | root_->initialise(true, "OrxonoxV2"); |
---|
| 93 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
| 94 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | void GraphicsEngine::loadRessourceLocations(std::string dataPath) |
---|
| 98 | { |
---|
| 99 | //TODO: Specify layout of data file and maybe use xml-loader |
---|
| 100 | //TODO: Work with ressource groups (should be generated by a special loader) |
---|
| 101 | // Load resource paths from data file using configfile ressource type |
---|
| 102 | ConfigFile cf; |
---|
[473] | 103 | cf.load(dataPath + "resources.cfg"); |
---|
[462] | 104 | |
---|
| 105 | // Go through all sections & settings in the file |
---|
| 106 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 107 | |
---|
| 108 | String secName, typeName, archName; |
---|
| 109 | while (seci.hasMoreElements()) |
---|
| 110 | { |
---|
| 111 | secName = seci.peekNextKey(); |
---|
| 112 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 113 | ConfigFile::SettingsMultiMap::iterator i; |
---|
| 114 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 115 | { |
---|
[546] | 116 | typeName = i->first; // for instance "FileSystem" or "Zip" |
---|
| 117 | archName = i->second; // name (and location) of archive |
---|
[462] | 118 | |
---|
| 119 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
| 120 | String(dataPath + archName), |
---|
[546] | 121 | typeName, secName); |
---|
[462] | 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | } |
---|