Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/GraphicsEngine.cc @ 927

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