Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

applied some old changes (compiles, but may fail running)

File size: 4.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
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    //if(this->bOverwritePath_)
66      ResetConfigValue(dataPath_);
67
68  }
69
70  void GraphicsEngine::setup()
71  {
72    //TODO: Check if file exists (maybe not here)
73/*#ifndef OGRE_STATIC_LIB
74    root_ = new Root(configPath_ + "plugins.cfg", configPath_ + "ogre.cfg",
75                     configPath_ + "Ogre.log");
76#else
77    root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
78#endif*/
79#if defined(_DEBUG) && defined(WIN32)
80    std::string plugin_filename = "plugins_d.cfg";
81#else
82    std::string plugin_filename = "plugins.cfg";
83#endif
84    root_ = new Root(plugin_filename);
85  }
86
87  /**
88   * @return scene manager
89   */
90  SceneManager* GraphicsEngine::getSceneManager()
91  {
92    if(!scene_)
93    {
94      scene_ = root_->createSceneManager(ST_GENERIC, "Default SceneManager");
95      COUT(3) << "Info: Created SceneMan: " << scene_ << std::endl;
96    }
97    return scene_;
98  }
99
100  bool GraphicsEngine::load(std::string dataPath)
101  {
102    if( dataPath != "" ) {
103      dataPath_ = dataPath;
104      bOverwritePath_ = true;
105      setConfigValues();
106    }
107    loadRessourceLocations(this->dataPath_);
108    if (!root_->restoreConfig() && !root_->showConfigDialog())
109      return false;
110    return true;
111  }
112
113  void GraphicsEngine::startRender()
114  {
115    root_->initialise(true, "OrxonoxV2");
116    TextureManager::getSingleton().setDefaultNumMipmaps(5);
117    ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
118  }
119
120  void GraphicsEngine::loadRessourceLocations(std::string dataPath)
121  {
122    //TODO: Specify layout of data file and maybe use xml-loader
123    //TODO: Work with ressource groups (should be generated by a special loader)
124    // Load resource paths from data file using configfile ressource type
125    ConfigFile cf;
126    /*dataPath = "/home/piranha/orxonox/trunk/";
127    //dataPath += "resources.cfg";
128    std::cout << "*******************" << std::endl;
129    std::cout << dataPath << std::endl;
130    std::cout << "*******************" << std::endl;*/
131    cf.load(dataPath + "resources.cfg");
132
133    // Go through all sections & settings in the file
134    ConfigFile::SectionIterator seci = cf.getSectionIterator();
135
136    std::string secName, typeName, archName;
137    while (seci.hasMoreElements())
138    {
139      secName = seci.peekNextKey();
140      ConfigFile::SettingsMultiMap *settings = seci.getNext();
141      ConfigFile::SettingsMultiMap::iterator i;
142      for (i = settings->begin(); i != settings->end(); ++i)
143      {
144        typeName = i->first; // for instance "FileSystem" or "Zip"
145        archName = i->second; // name (and location) of archive
146
147        ResourceGroupManager::getSingleton().addResourceLocation(
148                                           std::string(dataPath + archName),
149                                           typeName, secName);
150      }
151    }
152  }
153
154
155}
Note: See TracBrowser for help on using the repository browser.