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