Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 496 was 496, checked in by landauf, 16 years ago

added files from objecthierarchy, changed includes

File size: 5.2 KB
RevLine 
[164]1#include <string.h>
2#include <iostream>
3
4#include "LevelLoader.h"
[471]5#include "tinyxml/tinyxml.h"
[496]6#include "orxonox/core/CoreIncludes.h"
[480]7#include "orxonox/core/Error.h"
8#include "orxonox/objects/BaseObject.h"
[164]9
10using namespace std;
11
12namespace loader
13{
14
[480]15LevelLoader::LevelLoader(string file, string path)
[164]16{
[480]17        valid_ = false;
18       
[164]19        // Load XML level file
[480]20        path.append("/");
21        path.append(file);     
[471]22       
[474]23        // Open xml file
[480]24        doc.LoadFile(path);
[474]25
26        // Check if file was loaded
27        if (doc.LoadFile())
[471]28        {
[474]29                TiXmlHandle hDoc(&doc);
[480]30                TiXmlHandle hRoot(0);           
[474]31                TiXmlElement* pElem;
32
33                // Check for root element
34                pElem = hDoc.FirstChildElement("orxonoxworld").Element();
35                if (pElem)
36                {
37                        // Set root element
38                        hRoot = TiXmlHandle(pElem);
[480]39                        rootElement = hRoot.Element();
[474]40
41                        // Set level description
42                        pElem = hRoot.FirstChild("description").Element();
43                        if (pElem)
44                        {
45                                description_ = pElem->GetText();       
46                        }
47                       
48                        // Set level name
[480]49                        name_ = rootElement->Attribute("name");
50                        image_ = rootElement->Attribute("image");
[474]51                       
[480]52                        valid_ = true;
53                }
54                else
55                {
56                        orxonox::Error("Level file has no valid root node");
57                }       
58        }
59        else
60        {
61                orxonox::Error("Could not load level file ");
62        }       
63}
64
65        void LevelLoader::loadLevel()
66        {
67                if (valid_)
68                {
69                        TiXmlElement* loadElem;
70                        TiXmlElement* worldElem;
71                        TiXmlElement* tElem;
72                        TiXmlNode* tNode;
73                       
74                       
[474]75                        // Set loading screen
[480]76                        loadElem = rootElement->FirstChildElement("loading");
77                        if (loadElem)
[474]78                        {
79                                // Set background
[480]80                                tElem = loadElem->FirstChildElement("background");
81                                if (tElem)
[474]82                                {
[480]83                                        loadingBackgroundColor_ = tElem->Attribute("color");
84                                        loadingBackgroundImage_ = tElem->Attribute("image");
[474]85                                }
86                                // Set bar
[480]87                                tElem = loadElem->FirstChildElement("bar");
88                                if (tElem)
[474]89                                {
[480]90                                        loadingBarImage_ = tElem->Attribute("image");;
91                                        loadingBarTop_ = tElem->Attribute("top");
92                                        loadingBarLeft_ = tElem->Attribute("left");
93                                        loadingBarWidth_ = tElem->Attribute("width");
94                                        loadingBarHeight_ = tElem->Attribute("height");
[474]95                                }
[480]96                                showLoadingScreen();
[474]97                        }
98                       
[480]99                        // Load audio
100                        // TODO
101                       
102                        // Load scripts
103                        // TODO
104                       
105                        // Load world
106                        worldElem = rootElement->FirstChildElement("world");
107                        if (worldElem)
108                        {       
109                                tNode = 0;
110                                while( tNode = worldElem->IterateChildren( tNode ) )
111                                {
112                                        tElem = tNode->ToElement();
[496]113                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
[480]114                                        obj->loadParams(tElem);
115                                }                       
116                        }
117                       
118                        std::cout << "Loading finished!\n\n\n\n\n";                                             
[474]119                }
[471]120        }
[480]121       
122        void LevelLoader::showLoadingScreen()
[471]123        {
[480]124                std::cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";
125                std::cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";
126                std::cout << "Backgroundcolor: " << loadingBackgroundColor_ << "\nBackgroundimage:" << loadingBackgroundImage_ << "\n\n\n";
127        }
[471]128       
[474]129       
130        //orxonox::BaseObject* bla = orxonox::ID("classname")->fabricate();
131        //bla->loadParams();
132       
133       
[471]134        /*
[469]135        rootNode = XMLNode::openFileHelper(dir.c_str(),"orxonoxworld");
[164]136        // TODO: Error handling
137
138        // Assing general level infos to class variables
[470]139       
140        this->name_ = rootNode.getAttribute("name");
141        this->image_ = rootNode.getAttribute("image");
142        this->description_ = rootNode.getChildNode("description").getText();
[164]143 
[470]144        loadingScreenNode = rootNode.getChildNode("loading");
145        if (!loadingScreenNode.isEmpty())
146        {
147                this->showLoadingScreen();
148        }
[471]149
150        worldNode = rootNode.getChildNode("world");
151        if (!worldNode.isEmpty())
152        {
153               
154        }
155        */
156
[470]157 
158  /*
[164]159  // Assign sub-nodes
[347]160  if (rootNode.nChildNode("LightManager")==1)
[164]161  {
162        // Init Luightmanager...
[470]163  }*/
[164]164 
165  /*
166 
167        worldNode = rootNode.getChildNode("WorldEntities");
168        scriptNode = rootNode.getChildNode("ScriptManager");
169        cameraNode = rootNode.getChildNode("CameraMan");
170        lightNode = rootNode.getChildNode("LightManager");
171*/
172
173
[480]174
[164]175LevelLoader::~LevelLoader()
176{
177
178
179}
180
181
182string LevelLoader::name()
183{
184        return this->name_;
185}
186
187string LevelLoader::description()
188{
189        return this->description_;
190}
191
192string LevelLoader::image()
193{
194        return this->image_;
195}
196
197
198/*
199
200
201void LevelLoader::loadWorld(WorldManager* wm)
202{
203        if (!worldNode.getChildNode("lights").isEmpty())
204        {
205               
206               
207        }
208}
209
210
211void LevelLoader::loadLights(LightManager* lm)
212{
213        if (!lightNode.getChildNode("lights").isEmpty())
214        {
215                int nLights = lightNode.getChildNode("lights").nChildNode("light");
216                for (int i=0; i<nLights;i++)
217                {
218                        XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i);
219                        const char* diffuse = t.getAttribute("diffuse-color");
220                        const char* coor = t.getAttribute("abs-coor");
221                        lm->addLight(diffuse,coor);     
222                }
223        }
224        lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color"));       
225}
226
227void LevelLoader::loadCameras(CameraManager* cm)
228{
229        if (!cameraNode.getChildNode("cameras").isEmpty())
230        {
231                int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera");
232                for (int i=0; i<nCameras;i++)
233                {
234                        XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i);
235                       
236                       
237                        cm->addCamera();
238                }
239        }
240}
241
242
243void LevelLoader::loadScripts(ScriptManager* sm)
244{
245        if (!scriptNode.getChildNode("scripts").isEmpty())
246        {
247                int nScripts = scriptNode.getChildNode("scripts").nChildNode("script");
248                for (int i=0; i<nScripts;i++)
249                {
250                        XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i);
251                        sm->addScript(t.getAttribute("file"));
252                }
253       
254        }
255}
256*/
257
258
259}
260
Note: See TracBrowser for help on using the repository browser.