Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 702 was 702, checked in by nicolasc, 16 years ago

removed some deprecated alut stuff - plz test on windows

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