Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/loader/LevelLoader.cc @ 679

Last change on this file since 679 was 677, checked in by landauf, 17 years ago

changed \n to std::endl

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