Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script/src/orxonox/GraphicsEngine.cc @ 924

Last change on this file since 924 was 924, checked in by bknecht, 16 years ago

those changes enable setting the data-repos via arguments and ini-file

File size: 4.2 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
38#include "core/CoreIncludes.h"
39#include "core/Debug.h"
40#include "GraphicsEngine.h"
41
42
43namespace orxonox {
44
45  using namespace Ogre;
46
47  GraphicsEngine::GraphicsEngine()
48  {
49    RegisterObject(GraphicsEngine);
50    //this->bOverwritePath_ = false;
51    this->setConfigValues();
52    // set to standard values
53    this->configPath_ = "";
54    scene_ = NULL;
55  }
56
57
58  GraphicsEngine::~GraphicsEngine()
59  {
60  }
61
62  void GraphicsEngine::setConfigValues()
63  {
64    SetConfigValue(dataPath_, dataPath_).description("relative path to media data");
65
66  }
67
68  void GraphicsEngine::setup()
69  {
70    //TODO: Check if file exists (maybe not here)
71/*#ifndef OGRE_STATIC_LIB
72    root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",
73                     configPath_ + "Ogre.log");
74#else
75    root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
76#endif*/
77#if defined(_DEBUG) && defined(WIN32)
78    std::string plugin_filename = "plugins_d.cfg";
79#else
80    std::string plugin_filename = "plugins.cfg";
81#endif
82    root_ = new Root(plugin_filename);
83  }
84
85  /**
86   * @return scene manager
87   */
88  SceneManager* GraphicsEngine::getSceneManager()
89  {
90    if(!scene_)
91    {
92      scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager");
93      COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl;
94    }
95    return scene_;
96  }
97
98  bool GraphicsEngine::load(std::string dataPath)
99  {
100    // temporary overwrite of dataPath, change ini file for permanent change
101    if( dataPath != "" )
102      dataPath_ = dataPath;
103    loadRessourceLocations(this->dataPath_);
104    if (!root_->restoreConfig() && !root_->showConfigDialog())
105      return false;
106    return true;
107  }
108
109  void GraphicsEngine::startRender()
110  {
111    root_->initialise(true, "OrxonoxV2");
112    TextureManager::getSingleton().setDefaultNumMipmaps(5);
113    //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
114    ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
115  }
116
117  void GraphicsEngine::loadRessourceLocations(std::string dataPath)
118  {
119    //TODO: Specify layout of data file and maybe use xml-loader
120    //TODO: Work with ressource groups (should be generated by a special loader)
121    // Load resource paths from data file using configfile ressource type
122    ConfigFile cf;
123    cf.load(dataPath + "resources.cfg");
124
125    // Go through all sections & settings in the file
126    ConfigFile::SectionIterator seci = cf.getSectionIterator();
127
128    std::string secName, typeName, archName;
129    while (seci.hasMoreElements())
130    {
131      secName = seci.peekNextKey();
132      ConfigFile::SettingsMultiMap *settings = seci.getNext();
133      ConfigFile::SettingsMultiMap::iterator i;
134      for (i = settings->begin(); i != settings->end(); ++i)
135      {
136        typeName = i->first; // for instance "FileSystem" or "Zip"
137        archName = i->second; // name (and location) of archive
138
139        ResourceGroupManager::getSingleton().addResourceLocation(
140                                           std::string(dataPath + archName),
141                                           typeName, secName);
142      }
143    }
144  }
145
146
147}
Note: See TracBrowser for help on using the repository browser.