Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/shader/src/asylum/loader/LevelLoader.cc @ 10066

Last change on this file since 10066 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 5.7 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*     Nicolas Perrenoud <nicolape_at_ee.ethz.ch>
23*   Co-authors:
24*      ...
25*
26*/
27
28#include "OrxonoxStableHeaders.h"
29
30#include <OgreOverlay.h>
31#include <OgreOverlayManager.h>
32
33#include "core/Error.h"
34#include "core/Debug.h"
35#include "core/CoreIncludes.h"
36
37#include "audio/AudioManager.h"
38#include "core/BaseObject.h"
39#include "orxonox/Orxonox.h"
40
41#include "LevelLoader.h"
42
43namespace loader
44{
45
46  LevelLoader::LevelLoader(std::string file, std::string path)
47  {
48    valid_ = false;
49
50    // Load XML level file
51    path.append("/");
52    path.append(file);
53
54    // Open xml file
55    doc_.LoadFile(path.c_str());
56
57    // Check if file was loaded
58    if (doc_.LoadFile())
59    {
60      TiXmlHandle hDoc(&doc_);
61      TiXmlHandle hRoot(0);
62      TiXmlElement* pElem;
63
64      // Check for root element
65      pElem = hDoc.FirstChildElement("orxonoxworld").Element();
66      if (pElem)
67      {
68        // Set root element
69        hRoot = TiXmlHandle(pElem);
70        rootElement_ = hRoot.Element();
71
72        // Set level description
73        pElem = hRoot.FirstChild("description").Element();
74        if (pElem)
75        {
76          description_ = pElem->GetText();
77        }
78
79        // Set level name
80        name_ = rootElement_->Attribute("name");
81        image_ = rootElement_->Attribute("image");
82
83        valid_ = true;
84      }
85      else
86      {
87        orxonox::Error("Level file has no valid root node");
88      }
89    }
90    else
91    {
92      orxonox::Error("Could not load level file ");
93    }
94  }
95
96  void LevelLoader::loadLevel()
97  {
98    if (valid_)
99    {
100      TiXmlElement* loadElem;
101      TiXmlElement* audioElem;
102      TiXmlElement* worldElem;
103      TiXmlElement* tElem;
104      TiXmlNode* tNode;
105
106      Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton();
107      Ogre::Overlay* mLoadOverlay; // FIXME: may be uninitialized
108
109      // Set loading screen
110      loadElem = rootElement_->FirstChildElement("loading");
111      if (loadElem)
112      {
113        // Set background
114        tElem = loadElem->FirstChildElement("background");
115        if (tElem)
116        {
117          loadingBackgroundColor_ = tElem->Attribute("color");
118          loadingBackgroundImage_ = tElem->Attribute("image");
119        }
120        // Set bar
121        tElem = loadElem->FirstChildElement("bar");
122        if (tElem)
123        {
124          loadingBarImage_ = tElem->Attribute("image");;
125          loadingBarTop_ = tElem->Attribute("top");
126          loadingBarLeft_ = tElem->Attribute("left");
127          loadingBarWidth_ = tElem->Attribute("width");
128          loadingBarHeight_ = tElem->Attribute("height");
129        }
130
131
132        mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample");
133        mLoadOverlay->show();
134
135        COUT(0) << "This is Orxonox" << std::endl;
136        COUT(0) << "the hottest 3D action shooter ever to exist" << std::endl;
137        COUT(0) << "Level: " << name() << std::endl << "Description:" << description() << std::endl << "Image:" << image() << std::endl;
138        COUT(4) << "Backgroundcolor: " << loadingBackgroundColor_ << std::endl << "Backgroundimage:" << loadingBackgroundImage_ << std::endl;
139
140      }
141
142      // Load audio
143      audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer();
144      audioElem = rootElement_->FirstChildElement("audio");
145
146      if (audioElem)
147      {
148        audioElem = audioElem->FirstChildElement("ambient");
149        if (audioElem)
150        {
151          tNode = 0;
152          //FIXME something is wrong, probably missing ==
153          while( tNode = audioElem->IterateChildren( tNode ) )
154          {
155            if (tNode->Type() == TiXmlNode::ELEMENT)
156            {
157
158              tElem = tNode->ToElement();
159              std::string elemVal = tElem->Value();
160              if (elemVal == "ogg")
161              {
162                COUT(3) << "Adding sound "<< tElem->Attribute("src") << std::endl;
163
164                auMan->ambientAdd(tElem->Attribute("src"));
165              }
166            }
167          }
168          auMan->ambientStart();
169        }
170      }
171
172      // Load world
173      worldElem = rootElement_->FirstChildElement("world");
174      if (worldElem)
175      {
176        tNode = 0;
177        //FIXME something is wrong, probably missing ==
178        while (tNode = worldElem->IterateChildren(tNode))
179        {
180          if (tNode->Type() == TiXmlNode::ELEMENT)
181          {
182            tElem = tNode->ToElement();
183            orxonox::Identifier* id = ID(tElem->Value());
184            if (id)
185            {
186              orxonox::BaseObject* obj = id->fabricate();
187              obj->loadParams(tElem);
188            }
189            else
190            {
191              COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname." << std::endl;
192            }
193          }
194        }
195      }
196
197      if (loadElem)
198      {
199        // FIXME: check for potential initialisation of mLoadOverlay
200        mLoadOverlay->hide();
201      }
202
203
204      COUT(0) << "Loading finished!" << std::endl << std::endl;
205    }
206  }
207
208  LevelLoader::~LevelLoader()
209  {
210
211  }
212
213}
Note: See TracBrowser for help on using the repository browser.