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 <OgreException.h> |
---|
36 | #include <OgreConfigFile.h> |
---|
37 | #include <OgreTextureManager.h> |
---|
38 | #include <OgreRenderWindow.h> |
---|
39 | |
---|
40 | #include "core/CoreIncludes.h" |
---|
41 | #include "core/Debug.h" |
---|
42 | #include "GraphicsEngine.h" |
---|
43 | |
---|
44 | |
---|
45 | namespace orxonox { |
---|
46 | |
---|
47 | using namespace Ogre; |
---|
48 | |
---|
49 | GraphicsEngine::GraphicsEngine() |
---|
50 | { |
---|
51 | RegisterObject(GraphicsEngine); |
---|
52 | //this->bOverwritePath_ = false; |
---|
53 | this->setConfigValues(); |
---|
54 | // set to standard values |
---|
55 | this->configPath_ = ""; |
---|
56 | this->root_ = 0; |
---|
57 | this->scene_ = 0; |
---|
58 | this->renderWindow_ = 0; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | GraphicsEngine::~GraphicsEngine() |
---|
63 | { |
---|
64 | if (!this->root_) |
---|
65 | delete this->root_; |
---|
66 | } |
---|
67 | |
---|
68 | void GraphicsEngine::setConfigValues() |
---|
69 | { |
---|
70 | SetConfigValue(dataPath_, dataPath_).description("relative path to media data"); |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | void GraphicsEngine::setup() |
---|
75 | { |
---|
76 | //TODO: Check if file exists (maybe not here) |
---|
77 | /*#ifndef OGRE_STATIC_LIB |
---|
78 | root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", |
---|
79 | configPath_ + "Ogre.log"); |
---|
80 | #else |
---|
81 | root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); |
---|
82 | #endif*/ |
---|
83 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) |
---|
84 | std::string plugin_filename = "plugins_d.cfg"; |
---|
85 | #else |
---|
86 | std::string plugin_filename = "plugins.cfg"; |
---|
87 | #endif |
---|
88 | root_ = new Root(plugin_filename); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * @return scene manager |
---|
93 | */ |
---|
94 | SceneManager* GraphicsEngine::getSceneManager() |
---|
95 | { |
---|
96 | if(!scene_) |
---|
97 | { |
---|
98 | scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager"); |
---|
99 | COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; |
---|
100 | } |
---|
101 | return scene_; |
---|
102 | } |
---|
103 | |
---|
104 | bool GraphicsEngine::load(std::string dataPath) |
---|
105 | { |
---|
106 | // temporary overwrite of dataPath, change ini file for permanent change |
---|
107 | if( dataPath != "" ) |
---|
108 | dataPath_ = dataPath; |
---|
109 | loadRessourceLocations(this->dataPath_); |
---|
110 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
---|
111 | return false; |
---|
112 | return true; |
---|
113 | } |
---|
114 | |
---|
115 | void GraphicsEngine::initialise() |
---|
116 | { |
---|
117 | this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); |
---|
118 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
119 | //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... |
---|
120 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
121 | } |
---|
122 | |
---|
123 | void GraphicsEngine::loadRessourceLocations(std::string dataPath) |
---|
124 | { |
---|
125 | //TODO: Specify layout of data file and maybe use xml-loader |
---|
126 | //TODO: Work with ressource groups (should be generated by a special loader) |
---|
127 | // Load resource paths from data file using configfile ressource type |
---|
128 | ConfigFile cf; |
---|
129 | cf.load(dataPath + "resources.cfg"); |
---|
130 | |
---|
131 | // Go through all sections & settings in the file |
---|
132 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
133 | |
---|
134 | std::string secName, typeName, archName; |
---|
135 | while (seci.hasMoreElements()) |
---|
136 | { |
---|
137 | secName = seci.peekNextKey(); |
---|
138 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
139 | ConfigFile::SettingsMultiMap::iterator i; |
---|
140 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
141 | { |
---|
142 | typeName = i->first; // for instance "FileSystem" or "Zip" |
---|
143 | archName = i->second; // name (and location) of archive |
---|
144 | |
---|
145 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
146 | std::string(dataPath + archName), |
---|
147 | typeName, secName); |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | Returns the window handle of the render window. |
---|
154 | At least the InputHandler uses this to create the OIS::InputManager |
---|
155 | @return The window handle of the render window |
---|
156 | */ |
---|
157 | size_t GraphicsEngine::getWindowHandle() |
---|
158 | { |
---|
159 | if (this->renderWindow_) |
---|
160 | { |
---|
161 | Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow(); |
---|
162 | size_t windowHnd = 0; |
---|
163 | renderWindow->getCustomAttribute("WINDOW", &windowHnd); |
---|
164 | return windowHnd; |
---|
165 | } |
---|
166 | else |
---|
167 | return 0; |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | Get the width of the current render window |
---|
172 | @return The width of the current render window |
---|
173 | */ |
---|
174 | int GraphicsEngine::getWindowWidth() const |
---|
175 | { |
---|
176 | if (this->renderWindow_) |
---|
177 | { |
---|
178 | return this->renderWindow_->getWidth(); |
---|
179 | } |
---|
180 | else |
---|
181 | return 0; |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | Get the height of the current render window |
---|
186 | @return The height of the current render window |
---|
187 | */ |
---|
188 | int GraphicsEngine::getWindowHeight() const |
---|
189 | { |
---|
190 | if (this->renderWindow_) |
---|
191 | { |
---|
192 | return this->renderWindow_->getHeight(); |
---|
193 | } |
---|
194 | else |
---|
195 | return 0; |
---|
196 | } |
---|
197 | |
---|
198 | } |
---|