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
Line 
1#include <string.h>
2#include <iostream>
3
4#include "LevelLoader.h"
5#include "tinyxml/tinyxml.h"
6#include "orxonox/core/CoreIncludes.h"
7#include "orxonox/core/Error.h"
8#include "orxonox/objects/BaseObject.h"
9
10using namespace std;
11
12namespace loader
13{
14
15LevelLoader::LevelLoader(string file, string path)
16{
17        valid_ = false;
18       
19        // Load XML level file
20        path.append("/");
21        path.append(file);     
22       
23        // Open xml file
24        doc.LoadFile(path);
25
26        // Check if file was loaded
27        if (doc.LoadFile())
28        {
29                TiXmlHandle hDoc(&doc);
30                TiXmlHandle hRoot(0);           
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);
39                        rootElement = hRoot.Element();
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
49                        name_ = rootElement->Attribute("name");
50                        image_ = rootElement->Attribute("image");
51                       
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                       
75                        // Set loading screen
76                        loadElem = rootElement->FirstChildElement("loading");
77                        if (loadElem)
78                        {
79                                // Set background
80                                tElem = loadElem->FirstChildElement("background");
81                                if (tElem)
82                                {
83                                        loadingBackgroundColor_ = tElem->Attribute("color");
84                                        loadingBackgroundImage_ = tElem->Attribute("image");
85                                }
86                                // Set bar
87                                tElem = loadElem->FirstChildElement("bar");
88                                if (tElem)
89                                {
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");
95                                }
96                                showLoadingScreen();
97                        }
98                       
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();
113                                        orxonox::BaseObject* obj = ID(tElem->Value())->fabricate();
114                                        obj->loadParams(tElem);
115                                }                       
116                        }
117                       
118                        std::cout << "Loading finished!\n\n\n\n\n";                                             
119                }
120        }
121       
122        void LevelLoader::showLoadingScreen()
123        {
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        }
128       
129       
130        //orxonox::BaseObject* bla = orxonox::ID("classname")->fabricate();
131        //bla->loadParams();
132       
133       
134        /*
135        rootNode = XMLNode::openFileHelper(dir.c_str(),"orxonoxworld");
136        // TODO: Error handling
137
138        // Assing general level infos to class variables
139       
140        this->name_ = rootNode.getAttribute("name");
141        this->image_ = rootNode.getAttribute("image");
142        this->description_ = rootNode.getChildNode("description").getText();
143 
144        loadingScreenNode = rootNode.getChildNode("loading");
145        if (!loadingScreenNode.isEmpty())
146        {
147                this->showLoadingScreen();
148        }
149
150        worldNode = rootNode.getChildNode("world");
151        if (!worldNode.isEmpty())
152        {
153               
154        }
155        */
156
157 
158  /*
159  // Assign sub-nodes
160  if (rootNode.nChildNode("LightManager")==1)
161  {
162        // Init Luightmanager...
163  }*/
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
174
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.