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