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