/* * ORXONOX - the hottest 3D action shooter ever to exist * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Benjamin Knecht , (C) 2007 * Co-authors: * ... * */ /** @file orxonox.cc @brief Orxonox class */ #include "OrxonoxStableHeaders.h" #include #include #include #include #include #include "core/CoreIncludes.h" #include "core/Debug.h" #include "GraphicsEngine.h" namespace orxonox { using namespace Ogre; GraphicsEngine::GraphicsEngine() { RegisterObject(GraphicsEngine); //this->bOverwritePath_ = false; this->setConfigValues(); // set to standard values this->configPath_ = ""; this->root_ = 0; this->scene_ = 0; this->renderWindow_ = 0; } GraphicsEngine::~GraphicsEngine() { if (!this->root_) delete this->root_; } void GraphicsEngine::setConfigValues() { SetConfigValue(dataPath_, dataPath_).description("relative path to media data"); } void GraphicsEngine::setup() { //TODO: Check if file exists (maybe not here) /*#ifndef OGRE_STATIC_LIB root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); #else root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log"); #endif*/ #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG) std::string plugin_filename = "plugins_d.cfg"; #else std::string plugin_filename = "plugins.cfg"; #endif root_ = new Root(plugin_filename); } /** * @return scene manager */ SceneManager* GraphicsEngine::getSceneManager() { if(!scene_) { scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager"); COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl; } return scene_; } bool GraphicsEngine::load(std::string dataPath) { // temporary overwrite of dataPath, change ini file for permanent change if( dataPath != "" ) dataPath_ = dataPath; loadRessourceLocations(this->dataPath_); if (!root_->restoreConfig() && !root_->showConfigDialog()) return false; return true; } void GraphicsEngine::initialise() { this->renderWindow_ = root_->initialise(true, "OrxonoxV2"); TextureManager::getSingleton().setDefaultNumMipmaps(5); //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load... ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); } void GraphicsEngine::loadRessourceLocations(std::string dataPath) { //TODO: Specify layout of data file and maybe use xml-loader //TODO: Work with ressource groups (should be generated by a special loader) // Load resource paths from data file using configfile ressource type ConfigFile cf; cf.load(dataPath + "resources.cfg"); // Go through all sections & settings in the file ConfigFile::SectionIterator seci = cf.getSectionIterator(); std::string secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); ConfigFile::SettingsMultiMap *settings = seci.getNext(); ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; // for instance "FileSystem" or "Zip" archName = i->second; // name (and location) of archive ResourceGroupManager::getSingleton().addResourceLocation( std::string(dataPath + archName), typeName, secName); } } } /** Returns the window handle of the render window. At least the InputHandler uses this to create the OIS::InputManager @return The window handle of the render window */ size_t GraphicsEngine::getWindowHandle() { if (this->renderWindow_) { Ogre::RenderWindow *renderWindow = this->root_->getAutoCreatedWindow(); size_t windowHnd = 0; renderWindow->getCustomAttribute("WINDOW", &windowHnd); return windowHnd; } else return 0; } /** Get the width of the current render window @return The width of the current render window */ int GraphicsEngine::getWindowWidth() const { if (this->renderWindow_) { return this->renderWindow_->getWidth(); } else return 0; } /** Get the height of the current render window @return The height of the current render window */ int GraphicsEngine::getWindowHeight() const { if (this->renderWindow_) { return this->renderWindow_->getHeight(); } else return 0; } }