[612] | 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 | |
---|
[926] | 32 | #include "OrxonoxStableHeaders.h" |
---|
[612] | 33 | |
---|
| 34 | #include <OgreRoot.h> |
---|
[929] | 35 | #include <OgreException.h> |
---|
[612] | 36 | #include <OgreConfigFile.h> |
---|
[940] | 37 | #include <OgreLogManager.h> |
---|
[612] | 38 | #include <OgreTextureManager.h> |
---|
[919] | 39 | #include <OgreRenderWindow.h> |
---|
[612] | 40 | |
---|
[926] | 41 | #include "core/CoreIncludes.h" |
---|
| 42 | #include "core/Debug.h" |
---|
[789] | 43 | #include "GraphicsEngine.h" |
---|
[612] | 44 | |
---|
[789] | 45 | |
---|
[612] | 46 | namespace orxonox { |
---|
| 47 | |
---|
| 48 | using namespace Ogre; |
---|
| 49 | |
---|
| 50 | GraphicsEngine::GraphicsEngine() |
---|
| 51 | { |
---|
[926] | 52 | RegisterObject(GraphicsEngine); |
---|
| 53 | //this->bOverwritePath_ = false; |
---|
| 54 | this->setConfigValues(); |
---|
[612] | 55 | // set to standard values |
---|
| 56 | this->configPath_ = ""; |
---|
[919] | 57 | this->root_ = 0; |
---|
| 58 | this->scene_ = 0; |
---|
| 59 | this->renderWindow_ = 0; |
---|
[612] | 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | GraphicsEngine::~GraphicsEngine() |
---|
| 64 | { |
---|
[929] | 65 | if (!this->root_) |
---|
| 66 | delete this->root_; |
---|
[612] | 67 | } |
---|
| 68 | |
---|
[926] | 69 | void GraphicsEngine::setConfigValues() |
---|
| 70 | { |
---|
| 71 | SetConfigValue(dataPath_, dataPath_).description("relative path to media data"); |
---|
[940] | 72 | SetConfigValue(ogreLogfile_, "ogre.log").description("Logfile for messages from Ogre. Use to \"\" to suppress log file creation."); |
---|
| 73 | SetConfigValue(ogreLogLevelTrivial_ , 5).description("relative path to media data"); |
---|
| 74 | SetConfigValue(ogreLogLevelNormal_ , 4).description("relative path to media data"); |
---|
| 75 | SetConfigValue(ogreLogLevelCritical_, 2).description("relative path to media data"); |
---|
[926] | 76 | } |
---|
| 77 | |
---|
[940] | 78 | /** |
---|
| 79 | @brief Creates the Ogre Root object and sets up the ogre log. |
---|
| 80 | */ |
---|
[612] | 81 | void GraphicsEngine::setup() |
---|
| 82 | { |
---|
| 83 | //TODO: Check if file exists (maybe not here) |
---|
| 84 | /*#ifndef OGRE_STATIC_LIB |
---|
| 85 | root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", |
---|
| 86 | configPath_ + "Ogre.log"); |
---|
| 87 | #else |
---|
| 88 | root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); |
---|
| 89 | #endif*/ |
---|
[929] | 90 | #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) |
---|
[715] | 91 | std::string plugin_filename = "plugins_d.cfg"; |
---|
[679] | 92 | #else |
---|
[715] | 93 | std::string plugin_filename = "plugins.cfg"; |
---|
[679] | 94 | #endif |
---|
[940] | 95 | |
---|
| 96 | // create a logManager |
---|
| 97 | LogManager *logger; |
---|
| 98 | if(LogManager::getSingletonPtr() == 0) |
---|
| 99 | logger = new LogManager(); |
---|
| 100 | else |
---|
| 101 | logger = LogManager::getSingletonPtr(); |
---|
| 102 | |
---|
| 103 | // create our own log that we can listen to |
---|
| 104 | Log *myLog; |
---|
| 105 | if (this->ogreLogfile_ == "") |
---|
| 106 | myLog = logger->createLog("ogre.log", true, false, true); |
---|
| 107 | else |
---|
| 108 | myLog = logger->createLog(this->ogreLogfile_, true, false, false); |
---|
| 109 | |
---|
| 110 | myLog->setLogDetail(LL_BOREME); |
---|
| 111 | myLog->addListener(this); |
---|
| 112 | |
---|
| 113 | // Root will detect that we've already created a Log |
---|
[679] | 114 | root_ = new Root(plugin_filename); |
---|
[612] | 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * @return scene manager |
---|
| 119 | */ |
---|
| 120 | SceneManager* GraphicsEngine::getSceneManager() |
---|
| 121 | { |
---|
| 122 | if(!scene_) |
---|
| 123 | { |
---|
| 124 | scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager"); |
---|
| 125 | COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; |
---|
| 126 | } |
---|
| 127 | return scene_; |
---|
| 128 | } |
---|
| 129 | |
---|
[926] | 130 | bool GraphicsEngine::load(std::string dataPath) |
---|
[612] | 131 | { |
---|
[926] | 132 | // temporary overwrite of dataPath, change ini file for permanent change |
---|
| 133 | if( dataPath != "" ) |
---|
| 134 | dataPath_ = dataPath; |
---|
[612] | 135 | loadRessourceLocations(this->dataPath_); |
---|
| 136 | if (!root_->restoreConfig() && !root_->showConfigDialog()) |
---|
| 137 | return false; |
---|
| 138 | return true; |
---|
| 139 | } |
---|
| 140 | |
---|
[929] | 141 | void GraphicsEngine::initialise() |
---|
[612] | 142 | { |
---|
[929] | 143 | this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); |
---|
[612] | 144 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
[926] | 145 | //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... |
---|
[612] | 146 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 147 | } |
---|
| 148 | |
---|
[715] | 149 | void GraphicsEngine::loadRessourceLocations(std::string dataPath) |
---|
[612] | 150 | { |
---|
| 151 | //TODO: Specify layout of data file and maybe use xml-loader |
---|
| 152 | //TODO: Work with ressource groups (should be generated by a special loader) |
---|
| 153 | // Load resource paths from data file using configfile ressource type |
---|
| 154 | ConfigFile cf; |
---|
| 155 | cf.load(dataPath + "resources.cfg"); |
---|
| 156 | |
---|
| 157 | // Go through all sections & settings in the file |
---|
| 158 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 159 | |
---|
[715] | 160 | std::string secName, typeName, archName; |
---|
[612] | 161 | while (seci.hasMoreElements()) |
---|
| 162 | { |
---|
| 163 | secName = seci.peekNextKey(); |
---|
| 164 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 165 | ConfigFile::SettingsMultiMap::iterator i; |
---|
| 166 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 167 | { |
---|
| 168 | typeName = i->first; // for instance "FileSystem" or "Zip" |
---|
| 169 | archName = i->second; // name (and location) of archive |
---|
| 170 | |
---|
| 171 | ResourceGroupManager::getSingleton().addResourceLocation( |
---|
[715] | 172 | std::string(dataPath + archName), |
---|
[612] | 173 | typeName, secName); |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
[919] | 178 | /** |
---|
| 179 | Returns the window handle of the render window. |
---|
| 180 | At least the InputHandler uses this to create the OIS::InputManager |
---|
| 181 | @return The window handle of the render window |
---|
| 182 | */ |
---|
| 183 | size_t GraphicsEngine::getWindowHandle() |
---|
| 184 | { |
---|
| 185 | if (this->renderWindow_) |
---|
| 186 | { |
---|
| 187 | Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow(); |
---|
| 188 | size_t windowHnd = 0; |
---|
| 189 | renderWindow->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 190 | return windowHnd; |
---|
| 191 | } |
---|
| 192 | else |
---|
| 193 | return 0; |
---|
| 194 | } |
---|
[612] | 195 | |
---|
[919] | 196 | /** |
---|
| 197 | Get the width of the current render window |
---|
| 198 | @return The width of the current render window |
---|
| 199 | */ |
---|
| 200 | int GraphicsEngine::getWindowWidth() const |
---|
| 201 | { |
---|
| 202 | if (this->renderWindow_) |
---|
| 203 | { |
---|
| 204 | return this->renderWindow_->getWidth(); |
---|
| 205 | } |
---|
| 206 | else |
---|
| 207 | return 0; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | /** |
---|
| 211 | Get the height of the current render window |
---|
| 212 | @return The height of the current render window |
---|
| 213 | */ |
---|
| 214 | int GraphicsEngine::getWindowHeight() const |
---|
| 215 | { |
---|
| 216 | if (this->renderWindow_) |
---|
| 217 | { |
---|
| 218 | return this->renderWindow_->getHeight(); |
---|
| 219 | } |
---|
| 220 | else |
---|
| 221 | return 0; |
---|
| 222 | } |
---|
| 223 | |
---|
[940] | 224 | /** |
---|
| 225 | @brief Method called by the LogListener interface from Ogre. |
---|
| 226 | We use it to capture Ogre log messages and handle it ourselves. |
---|
| 227 | @param message The message to be logged |
---|
| 228 | @param lml The message level the log is using |
---|
| 229 | @param maskDebug If we are printing to the console or not |
---|
| 230 | @param logName the name of this log (so you can have several listeners |
---|
| 231 | for different logs, and identify them) |
---|
| 232 | */ |
---|
| 233 | void GraphicsEngine::messageLogged(const std::string& message, |
---|
| 234 | LogMessageLevel lml, bool maskDebug, const std::string &logName) |
---|
| 235 | { |
---|
| 236 | int orxonoxLevel; |
---|
| 237 | switch (lml) |
---|
| 238 | { |
---|
| 239 | case LML_TRIVIAL: |
---|
| 240 | orxonoxLevel = this->ogreLogLevelTrivial_; |
---|
| 241 | break; |
---|
| 242 | case LML_NORMAL: |
---|
| 243 | orxonoxLevel = this->ogreLogLevelNormal_; |
---|
| 244 | break; |
---|
| 245 | case LML_CRITICAL: |
---|
| 246 | orxonoxLevel = this->ogreLogLevelCritical_; |
---|
| 247 | break; |
---|
| 248 | default: |
---|
| 249 | orxonoxLevel = 0; |
---|
| 250 | } |
---|
| 251 | OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) |
---|
| 252 | << "*** Ogre: " << message << std::endl; |
---|
| 253 | } |
---|
[612] | 254 | } |
---|