1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: Christian Meyer |
---|
16 | */ |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
19 | |
---|
20 | #include "world.h" |
---|
21 | |
---|
22 | #include "orxonox.h" |
---|
23 | |
---|
24 | #include "p_node.h" |
---|
25 | #include "null_parent.h" |
---|
26 | #include "helper_parent.h" |
---|
27 | #include "track_node.h" |
---|
28 | #include "world_entity.h" |
---|
29 | #include "player.h" |
---|
30 | #include "camera.h" |
---|
31 | #include "environment.h" |
---|
32 | #include "skysphere.h" |
---|
33 | #include "skybox.h" |
---|
34 | #include "satellite.h" |
---|
35 | #include "terrain.h" |
---|
36 | #include "light.h" |
---|
37 | #include "text_engine.h" |
---|
38 | |
---|
39 | #include "track_manager.h" |
---|
40 | #include "garbage_collector.h" |
---|
41 | #include "animation_player.h" |
---|
42 | |
---|
43 | #include "command_node.h" |
---|
44 | #include "glmenu_imagescreen.h" |
---|
45 | #include "list.h" |
---|
46 | #include "game_loader.h" |
---|
47 | |
---|
48 | #include "animation3d.h" |
---|
49 | |
---|
50 | #include "substring.h" |
---|
51 | |
---|
52 | using namespace std; |
---|
53 | |
---|
54 | WorldInterface* WorldInterface::singletonRef = 0; |
---|
55 | |
---|
56 | |
---|
57 | /** |
---|
58 | \brief private constructor because of singleton |
---|
59 | */ |
---|
60 | WorldInterface::WorldInterface() |
---|
61 | { |
---|
62 | this->worldIsInitialized = false; |
---|
63 | this->worldReference = NULL; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | \brief public deconstructor |
---|
68 | */ |
---|
69 | WorldInterface::~WorldInterface() |
---|
70 | { |
---|
71 | this->singletonRef = NULL; |
---|
72 | this->worldIsInitialized = false; |
---|
73 | this->worldReference = NULL; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | \brief gets the singleton instance |
---|
78 | \returns singleton instance |
---|
79 | */ |
---|
80 | WorldInterface* WorldInterface::getInstance() |
---|
81 | { |
---|
82 | if( singletonRef == NULL) |
---|
83 | singletonRef = new WorldInterface(); |
---|
84 | return singletonRef; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | /** |
---|
89 | \brief initializes the interface |
---|
90 | \param reference to the world |
---|
91 | |
---|
92 | if the worldinterface is not initilizes, there wont be any |
---|
93 | useable interface |
---|
94 | */ |
---|
95 | void WorldInterface::init(World* world) |
---|
96 | { |
---|
97 | this->worldReference = world; |
---|
98 | if( world != NULL) |
---|
99 | { |
---|
100 | this->worldIsInitialized = true; |
---|
101 | PRINTF(3)("WorldInterface up and running\n"); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | /** |
---|
107 | \brief gets the entity list from the world |
---|
108 | \return entity list |
---|
109 | */ |
---|
110 | tList<WorldEntity>* WorldInterface::getEntityList() |
---|
111 | { |
---|
112 | if( this->worldIsInitialized) |
---|
113 | return this->worldReference->getEntities(); |
---|
114 | PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n"); |
---|
115 | return NULL; |
---|
116 | } |
---|
117 | |
---|
118 | CREATE_FACTORY(World); |
---|
119 | |
---|
120 | World::World( TiXmlElement* root) |
---|
121 | { |
---|
122 | this->constuctorInit("", -1); |
---|
123 | this->path = NULL; |
---|
124 | const char *string; |
---|
125 | char *name; |
---|
126 | int id; |
---|
127 | |
---|
128 | PRINTF0("Creating a World\n"); |
---|
129 | |
---|
130 | // identifier |
---|
131 | string = grabParameter( root, "identifier"); |
---|
132 | if( string == NULL || sscanf(string, "%d", &id) != 1) |
---|
133 | { |
---|
134 | PRINTF0("World is missing a proper 'identifier'\n"); |
---|
135 | this->setStoryID( -1); |
---|
136 | } |
---|
137 | else setStoryID( id); |
---|
138 | |
---|
139 | // next id |
---|
140 | string = grabParameter( root, "nextid"); |
---|
141 | if( string == NULL || sscanf(string, "%d", &id) != 1) |
---|
142 | { |
---|
143 | PRINTF0("World is missing a proper 'nextid'\n"); |
---|
144 | this->setStoryID( -1); |
---|
145 | } |
---|
146 | else setNextStoryID( id); |
---|
147 | |
---|
148 | |
---|
149 | // path |
---|
150 | string = grabParameter( root, "path"); |
---|
151 | if( string == NULL) |
---|
152 | { |
---|
153 | PRINTF0("World is missing a proper 'path'\n"); |
---|
154 | this->setPath( NULL); |
---|
155 | } |
---|
156 | else |
---|
157 | { |
---|
158 | name = new char[strlen(string + 2)]; |
---|
159 | strcpy( name, string); |
---|
160 | this->setPath( name); |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | /** |
---|
165 | \brief create a new World |
---|
166 | |
---|
167 | This creates a new empty world! |
---|
168 | */ |
---|
169 | World::World (char* name) |
---|
170 | { |
---|
171 | this->path = NULL; |
---|
172 | this->constuctorInit(name, -1); |
---|
173 | //NullParent* np = NullParent::getInstance(); |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | \brief creates a new World... |
---|
178 | \param worldID with this ID |
---|
179 | */ |
---|
180 | World::World (int worldID) |
---|
181 | { |
---|
182 | this->path = NULL; |
---|
183 | this->constuctorInit(NULL, worldID); |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | \brief remove the World from memory |
---|
188 | |
---|
189 | delete everything explicitly, that isn't contained in the parenting tree! |
---|
190 | things contained in the tree are deleted automaticaly |
---|
191 | */ |
---|
192 | World::~World () |
---|
193 | { |
---|
194 | PRINTF(3)("World::~World() - deleting current world\n"); |
---|
195 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
196 | cn->unbind(this->localPlayer); |
---|
197 | cn->reset(); |
---|
198 | |
---|
199 | ResourceManager::getInstance()->debug(); |
---|
200 | ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); |
---|
201 | ResourceManager::getInstance()->debug(); |
---|
202 | |
---|
203 | delete WorldInterface::getInstance(); |
---|
204 | |
---|
205 | delete this->nullParent; |
---|
206 | delete this->entities; |
---|
207 | delete this->lightMan; |
---|
208 | delete this->trackManager; |
---|
209 | TextEngine::getInstance()->flush(); |
---|
210 | |
---|
211 | AnimationPlayer::getInstance()->debug(); |
---|
212 | delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence. |
---|
213 | //delete garbagecollecor |
---|
214 | //delete animator |
---|
215 | |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | \brief initializes the world. |
---|
221 | |
---|
222 | set all stuff here that is world generic and does not use to much memory |
---|
223 | because the real init() function StoryEntity::init() will be called |
---|
224 | shortly before start of the game. |
---|
225 | since all worlds are initiated/referenced before they will be started. |
---|
226 | NO LEVEL LOADING HERE - NEVER! |
---|
227 | */ |
---|
228 | void World::constuctorInit(char* name, int worldID) |
---|
229 | { |
---|
230 | this->setClassName ("World"); |
---|
231 | |
---|
232 | //this->worldName = name; |
---|
233 | //this->worldName = new char[strlen(name)+1]; |
---|
234 | //strcpy(this->worldName, name); |
---|
235 | this->debugWorldNr = worldID; |
---|
236 | this->entities = new tList<WorldEntity>(); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | /** |
---|
241 | \brief this is executed before load |
---|
242 | |
---|
243 | since the load function sometimes needs data, that has been init before |
---|
244 | the load and after the proceeding storyentity has finished |
---|
245 | */ |
---|
246 | ErrorMessage World::preLoad() |
---|
247 | { |
---|
248 | /* init the world interface */ |
---|
249 | WorldInterface* wi = WorldInterface::getInstance(); |
---|
250 | wi->init(this); |
---|
251 | this->garbageCollector = GarbageCollector::getInstance(); |
---|
252 | |
---|
253 | this->trackManager = TrackManager::getInstance(); |
---|
254 | this->lightMan = LightManager::getInstance(); |
---|
255 | this->nullParent = NullParent::getInstance (); |
---|
256 | this->nullParent->setName ("NullParent"); |
---|
257 | |
---|
258 | AnimationPlayer::getInstance(); // initializes the animationPlayer |
---|
259 | |
---|
260 | this->localCamera = new Camera(); |
---|
261 | this->localCamera->setName ("camera"); |
---|
262 | } |
---|
263 | |
---|
264 | |
---|
265 | /** |
---|
266 | \brief loads the World by initializing all resources, and set their default values. |
---|
267 | */ |
---|
268 | ErrorMessage World::load() |
---|
269 | { |
---|
270 | PRINTF(0)("> Loading world: '%s'\n", getPath()); |
---|
271 | |
---|
272 | GameLoader* loader = GameLoader::getInstance(); |
---|
273 | |
---|
274 | if( getPath() == NULL) |
---|
275 | { |
---|
276 | PRINTF0("World has no path specified for loading"); |
---|
277 | return (ErrorMessage){213,"Path not specified","World::load()"}; |
---|
278 | } |
---|
279 | |
---|
280 | TiXmlDocument* XMLDoc = new TiXmlDocument( path); |
---|
281 | // load the campaign document |
---|
282 | if( !XMLDoc->LoadFile()) |
---|
283 | //this->glmis->step(); |
---|
284 | |
---|
285 | { |
---|
286 | // report an error |
---|
287 | PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); |
---|
288 | delete XMLDoc; |
---|
289 | return (ErrorMessage){213,"XML File parsing error","World::load()"}; |
---|
290 | } |
---|
291 | |
---|
292 | // check basic validity |
---|
293 | TiXmlElement* root = XMLDoc->RootElement(); |
---|
294 | assert( root != NULL); |
---|
295 | |
---|
296 | if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) |
---|
297 | { |
---|
298 | // report an error |
---|
299 | PRINTF0("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); |
---|
300 | delete XMLDoc; |
---|
301 | return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; |
---|
302 | } |
---|
303 | |
---|
304 | // load the parameters |
---|
305 | // name |
---|
306 | char* temp; |
---|
307 | const char* string = grabParameter( root, "name"); |
---|
308 | if( string == NULL) |
---|
309 | { |
---|
310 | PRINTF0("World is missing a proper 'name'\n"); |
---|
311 | string = "Unknown"; |
---|
312 | temp = new char[strlen(string + 2)]; |
---|
313 | strcpy( temp, string); |
---|
314 | this->worldName = temp; |
---|
315 | } |
---|
316 | else |
---|
317 | { |
---|
318 | temp = new char[strlen(string + 2)]; |
---|
319 | strcpy( temp, string); |
---|
320 | this->worldName = temp; |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | // find WorldEntities |
---|
325 | TiXmlElement* element = root->FirstChildElement( "WorldEntities"); |
---|
326 | |
---|
327 | if( element == NULL) |
---|
328 | { |
---|
329 | PRINTF0("World is missing 'WorldEntities'\n"); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | element = element->FirstChildElement(); |
---|
334 | // load Players/Objects/Whatever |
---|
335 | PRINTF0("Loading WorldEntities\n"); |
---|
336 | while( element != NULL) |
---|
337 | { |
---|
338 | WorldEntity* created = (WorldEntity*) loader->fabricate( element); |
---|
339 | if( created != NULL) this->spawn( created); |
---|
340 | // if we load a 'Player' we use it as localPlayer |
---|
341 | //todo do this more elegant |
---|
342 | if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created; |
---|
343 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; |
---|
344 | element = element->NextSiblingElement(); |
---|
345 | } |
---|
346 | PRINTF0("Done loading WorldEntities\n"); |
---|
347 | } |
---|
348 | |
---|
349 | // find Track |
---|
350 | /*element = root->FirstChildElement( "Track"); |
---|
351 | if( element == NULL) |
---|
352 | { |
---|
353 | PRINTF0("============>>>>>>>>>>>>>>>>>World is missing a 'Track'\n"); |
---|
354 | } |
---|
355 | else |
---|
356 | { |
---|
357 | //load track |
---|
358 | PRINTF0("============>>>>>>>>>>>>>>>>Loading Track\n"); |
---|
359 | |
---|
360 | trackManager->loadTrack( element); |
---|
361 | trackManager->finalize(); |
---|
362 | PRINTF0("============>>>>>>>>>>>>>>>>Done loading Track\n"); |
---|
363 | }*/ |
---|
364 | |
---|
365 | // free the XML data |
---|
366 | |
---|
367 | delete XMLDoc; |
---|
368 | /* GENERIC LOADING PROCESS FINISHED */ |
---|
369 | |
---|
370 | // bind input |
---|
371 | Orxonox *orx = Orxonox::getInstance (); |
---|
372 | orx->getLocalInput()->bind (localPlayer); |
---|
373 | |
---|
374 | // bind camera |
---|
375 | //this->localCamera->bind (localPlayer); |
---|
376 | this->localPlayer->addChild (this->localCamera); |
---|
377 | |
---|
378 | |
---|
379 | // stuff beyond this point remains to be loaded properly |
---|
380 | |
---|
381 | // initializing the TrackManager |
---|
382 | this->trackManager = TrackManager::getInstance(); |
---|
383 | //trackManager->addPoint(Vector(0,0,0)); |
---|
384 | trackManager->addPoint(Vector(150, -35, 5)); |
---|
385 | trackManager->addPoint(Vector(200,-35, 5)); |
---|
386 | trackManager->addPoint(Vector(250, -35, 5)); |
---|
387 | trackManager->addPoint(Vector(320,-33,-.55)); |
---|
388 | trackManager->setDuration(2); |
---|
389 | trackManager->setSavePoint(); |
---|
390 | |
---|
391 | trackManager->addPoint(Vector(410, 0, 0)); |
---|
392 | trackManager->addPoint(Vector(510, 20, -10)); |
---|
393 | trackManager->addPoint(Vector(550, 20, -10)); |
---|
394 | trackManager->addPoint(Vector(570, 20, -10)); |
---|
395 | trackManager->setDuration(5); |
---|
396 | |
---|
397 | int fork11, fork12; |
---|
398 | trackManager->fork(2, &fork11, &fork12); |
---|
399 | trackManager->workOn(fork11); |
---|
400 | trackManager->addPoint(Vector(640, 25, -30)); |
---|
401 | trackManager->addPoint(Vector(700, 40, -120)); |
---|
402 | trackManager->addPoint(Vector(800, 50, -150)); |
---|
403 | trackManager->addPoint(Vector(900, 60, -100)); |
---|
404 | trackManager->addPoint(Vector(900, 60, -70)); |
---|
405 | trackManager->addPoint(Vector(990, 65, -15)); |
---|
406 | trackManager->addPoint(Vector(1050, 65, -10)); |
---|
407 | trackManager->addPoint(Vector(1100, 65, -20)); |
---|
408 | trackManager->setDuration(10); |
---|
409 | |
---|
410 | trackManager->workOn(fork12); |
---|
411 | trackManager->addPoint(Vector(640, 25, 20)); |
---|
412 | trackManager->addPoint(Vector(670, 50, 120)); |
---|
413 | trackManager->addPoint(Vector(700, 70, 80)); |
---|
414 | trackManager->addPoint(Vector(800, 70, 65)); |
---|
415 | trackManager->addPoint(Vector(850, 65, 65)); |
---|
416 | trackManager->addPoint(Vector(920, 35, 40)); |
---|
417 | trackManager->addPoint(Vector(945, 40, 40)); |
---|
418 | trackManager->addPoint(Vector(970, 24, 40)); |
---|
419 | trackManager->addPoint(Vector(1000, 40, -7)); |
---|
420 | trackManager->setDuration(10); |
---|
421 | |
---|
422 | |
---|
423 | trackManager->join(2, fork11, fork12); |
---|
424 | |
---|
425 | trackManager->workOn(5); |
---|
426 | trackManager->addPoint(Vector(1200, 60, -50)); |
---|
427 | trackManager->addPoint(Vector(1300, 50, -50)); |
---|
428 | trackManager->addPoint(Vector(1400, 40, -50)); |
---|
429 | trackManager->addPoint(Vector(1500, 40, -60)); |
---|
430 | trackManager->addPoint(Vector(1600, 35, -55)); |
---|
431 | trackManager->addPoint(Vector(1700, 45, -40)); |
---|
432 | trackManager->addPoint(Vector(1750, 60, -40)); |
---|
433 | trackManager->addPoint(Vector(1770, 80, -40)); |
---|
434 | trackManager->addPoint(Vector(1800, 100, -40)); |
---|
435 | trackManager->setDuration(10); |
---|
436 | |
---|
437 | trackManager->finalize(); |
---|
438 | |
---|
439 | |
---|
440 | lightMan->setAmbientColor(.1,.1,.1); |
---|
441 | lightMan->addLight(); |
---|
442 | // lightMan->setAttenuation(1.0, .01, 0.0); |
---|
443 | // lightMan->setDiffuseColor(1,1,1); |
---|
444 | // lightMan->addLight(1); |
---|
445 | // lightMan->setPosition(20, 10, -20); |
---|
446 | // lightMan->setDiffuseColor(0,0,0); |
---|
447 | lightMan->debug(); |
---|
448 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
449 | |
---|
450 | // trackManager->setBindSlave(env); |
---|
451 | PNode* tn = trackManager->getTrackNode(); |
---|
452 | tn->addChild(this->localPlayer); |
---|
453 | |
---|
454 | //localCamera->setParent(TrackNode::getInstance()); |
---|
455 | tn->addChild(this->localCamera); |
---|
456 | localCamera->lookAt(tn); |
---|
457 | this->localPlayer->setMode(PNODE_ALL); |
---|
458 | Vector* cameraOffset = new Vector (0, 5, -10); |
---|
459 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
460 | |
---|
461 | this->sky->setParent(this->localCamera); |
---|
462 | |
---|
463 | // initialize debug coord system |
---|
464 | objectList = glGenLists(1); |
---|
465 | glNewList (objectList, GL_COMPILE); |
---|
466 | |
---|
467 | // trackManager->drawGraph(.01); |
---|
468 | trackManager->debug(2); |
---|
469 | glEndList(); |
---|
470 | |
---|
471 | terrain = new Terrain("worlds/newGround.obj"); |
---|
472 | terrain->setRelCoor(Vector(0,-10,0)); |
---|
473 | this->spawn(terrain); |
---|
474 | |
---|
475 | } |
---|
476 | |
---|
477 | void World::loadDebugWorld(int worldID) |
---|
478 | { |
---|
479 | /*monitor progress*/ |
---|
480 | this->glmis->step(); |
---|
481 | |
---|
482 | // LIGHT initialisation |
---|
483 | |
---|
484 | lightMan->setAmbientColor(.1,.1,.1); |
---|
485 | lightMan->addLight(); |
---|
486 | // lightMan->setAttenuation(1.0, .01, 0.0); |
---|
487 | // lightMan->setDiffuseColor(1,1,1); |
---|
488 | // lightMan->addLight(1); |
---|
489 | // lightMan->setPosition(20, 10, -20); |
---|
490 | // lightMan->setDiffuseColor(0,0,0); |
---|
491 | lightMan->debug(); |
---|
492 | |
---|
493 | switch(this->debugWorldNr) |
---|
494 | { |
---|
495 | /* |
---|
496 | this loads the hard-coded debug world. this only for simplicity and will be |
---|
497 | removed by a reald world-loader, which interprets a world-file. |
---|
498 | if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and |
---|
499 | make whatever you want... |
---|
500 | */ |
---|
501 | case DEBUG_WORLD_0: |
---|
502 | { |
---|
503 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
504 | |
---|
505 | // !\todo old track-system has to be removed |
---|
506 | |
---|
507 | //create helper for player |
---|
508 | //HelperParent* hp = new HelperParent (); |
---|
509 | /* the player has to be added to this helper */ |
---|
510 | |
---|
511 | // create a player |
---|
512 | this->localPlayer = new Player (); |
---|
513 | this->localPlayer->setName ("player"); |
---|
514 | this->spawn (this->localPlayer); |
---|
515 | /*monitor progress*/ |
---|
516 | //this->glmis->step(); |
---|
517 | this->glmis->step(); |
---|
518 | |
---|
519 | // bind input |
---|
520 | Orxonox *orx = Orxonox::getInstance (); |
---|
521 | orx->getLocalInput()->bind (this->localPlayer); |
---|
522 | |
---|
523 | // bind camera |
---|
524 | this->localCamera = new Camera(); |
---|
525 | this->localCamera->setName ("camera"); |
---|
526 | |
---|
527 | /*monitor progress*/ |
---|
528 | this->glmis->step(); |
---|
529 | |
---|
530 | sky = new SkyBox(); |
---|
531 | // (SkyBox*)(sky)->setTexture("pictures/sky/skybox", "jpg"); |
---|
532 | sky->setParent(localCamera); |
---|
533 | this->spawn(sky); |
---|
534 | |
---|
535 | /*monitor progress*/ |
---|
536 | this->glmis->step(); |
---|
537 | |
---|
538 | |
---|
539 | WorldEntity* env = new Environment(); |
---|
540 | env->setName ("env"); |
---|
541 | this->spawn(env); |
---|
542 | |
---|
543 | |
---|
544 | /* |
---|
545 | Vector* es = new Vector (10, 5, 0); |
---|
546 | Quaternion* qs = new Quaternion (); |
---|
547 | WorldEntity* pr = new Primitive(P_CYLINDER); |
---|
548 | pr->setName("primitive"); |
---|
549 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
---|
550 | */ |
---|
551 | |
---|
552 | /*monitor progress*/ |
---|
553 | this->glmis->step(); |
---|
554 | |
---|
555 | // trackManager->setBindSlave(env); |
---|
556 | PNode* tn = trackManager->getTrackNode(); |
---|
557 | tn->addChild(this->localPlayer); |
---|
558 | this->localCamera->lookAt(tn); |
---|
559 | |
---|
560 | //localCamera->setParent(TrackNode::getInstance()); |
---|
561 | tn->addChild(this->localCamera); |
---|
562 | // localCamera->lookAt(tn); |
---|
563 | this->localPlayer->setMode(PNODE_ALL); |
---|
564 | //Vector* cameraOffset = new Vector (0, 5, -10); |
---|
565 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
566 | this->glmis->step(); |
---|
567 | break; |
---|
568 | } |
---|
569 | case DEBUG_WORLD_1: |
---|
570 | { |
---|
571 | lightMan->setPosition(.0, .0, .0); |
---|
572 | lightMan->setAttenuation(1.0, .01, 0.0); |
---|
573 | lightMan->setSpecularColor(1,0,0); |
---|
574 | this->nullParent = NullParent::getInstance (); |
---|
575 | this->nullParent->setName ("NullParent"); |
---|
576 | |
---|
577 | // create a player |
---|
578 | WorldEntity* myPlayer = new Player(); |
---|
579 | myPlayer->setName ("player"); |
---|
580 | this->spawn(myPlayer); |
---|
581 | this->localPlayer = myPlayer; |
---|
582 | |
---|
583 | // bind input |
---|
584 | Orxonox *orx = Orxonox::getInstance(); |
---|
585 | orx->getLocalInput()->bind (myPlayer); |
---|
586 | |
---|
587 | // bind camera |
---|
588 | this->localCamera = new Camera (); |
---|
589 | this->localCamera->setName ("camera"); |
---|
590 | this->localCamera->lookAt(LightManager::getInstance()->getLight(0)); |
---|
591 | this->localCamera->setParent(this->localPlayer); |
---|
592 | |
---|
593 | // Create SkySphere |
---|
594 | sky = new Skysphere("pictures/sky-replace.jpg"); |
---|
595 | this->localPlayer->addChild(this->sky); |
---|
596 | this->spawn(this->sky); |
---|
597 | Vector* es = new Vector (20, 0, 0); |
---|
598 | Quaternion* qs = new Quaternion (); |
---|
599 | |
---|
600 | lightMan->getLight(0)->setParent(trackManager->getTrackNode()); |
---|
601 | break; |
---|
602 | } |
---|
603 | case DEBUG_WORLD_2: |
---|
604 | { |
---|
605 | lightMan->setAmbientColor(.1,.1,.1); |
---|
606 | lightMan->addLight(); |
---|
607 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
608 | this->nullParent = NullParent::getInstance (); |
---|
609 | this->nullParent->setName ("NullParent"); |
---|
610 | |
---|
611 | // !\todo old track-system has to be removed |
---|
612 | |
---|
613 | //create helper for player |
---|
614 | //HelperParent* hp = new HelperParent (); |
---|
615 | /* the player has to be added to this helper */ |
---|
616 | |
---|
617 | // create a player |
---|
618 | this->localPlayer = new Player (); |
---|
619 | this->localPlayer->setName ("player"); |
---|
620 | this->spawn (this->localPlayer); |
---|
621 | /*monitor progress*/ |
---|
622 | //this->glmis->step(); |
---|
623 | this->glmis->step(); |
---|
624 | |
---|
625 | // bind input |
---|
626 | Orxonox *orx = Orxonox::getInstance (); |
---|
627 | orx->getLocalInput()->bind (this->localPlayer); |
---|
628 | |
---|
629 | // bind camera |
---|
630 | this->localCamera = new Camera(); |
---|
631 | this->localCamera->setName ("camera"); |
---|
632 | this->localCamera->lookAt(this->localPlayer); |
---|
633 | this->localCamera->setParent(this->localPlayer); |
---|
634 | |
---|
635 | /*monitor progress*/ |
---|
636 | this->glmis->step(); |
---|
637 | |
---|
638 | // Create SkySphere |
---|
639 | this->sky = new Skysphere("pictures/sky-replace.jpg"); |
---|
640 | this->sky->setName("SkySphere"); |
---|
641 | this->spawn(this->sky); |
---|
642 | this->localCamera->addChild(this->sky); |
---|
643 | this->sky->setMode(PNODE_MOVEMENT); |
---|
644 | /*monitor progress*/ |
---|
645 | this->glmis->step(); |
---|
646 | |
---|
647 | |
---|
648 | WorldEntity* baseNode = new Satellite(Vector(1,0,1), 1.2); |
---|
649 | this->localPlayer->addChild(baseNode); |
---|
650 | baseNode->setRelCoor(Vector(10.0, 2.0, 1.0)); |
---|
651 | this->spawn(baseNode); |
---|
652 | |
---|
653 | WorldEntity* secondNode = new Satellite(Vector(0,0,1), 2.0); |
---|
654 | baseNode->addChild(secondNode); |
---|
655 | secondNode->setRelCoor(Vector(0.0, 0.0, 3.0)); |
---|
656 | this->spawn(secondNode); |
---|
657 | |
---|
658 | |
---|
659 | WorldEntity* thirdNode = new Satellite(Vector(0,0,1), 1.0); |
---|
660 | secondNode->addChild(thirdNode); |
---|
661 | thirdNode->setRelCoor(Vector(2.0, 0.0, 0.0)); |
---|
662 | this->spawn(thirdNode); |
---|
663 | |
---|
664 | |
---|
665 | |
---|
666 | WorldEntity* c = new Environment(); |
---|
667 | this->localPlayer->addChild(c); |
---|
668 | c->setRelCoor(Vector(10.0, 2.0, -1.0)); |
---|
669 | this->spawn(c); |
---|
670 | |
---|
671 | |
---|
672 | |
---|
673 | Animation3D* animation = new Animation3D(c); |
---|
674 | animation->setInfinity(ANIM_INF_REPLAY); |
---|
675 | |
---|
676 | |
---|
677 | animation->addKeyFrame(Vector(0, 0, 0), Quaternion(0, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
678 | animation->addKeyFrame(Vector(0, 2, 0), Quaternion(M_PI, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
679 | animation->addKeyFrame(Vector(0, 0, 0), Quaternion(0, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
680 | |
---|
681 | |
---|
682 | |
---|
683 | |
---|
684 | |
---|
685 | |
---|
686 | /* |
---|
687 | KeyFrame* f1 = new KeyFrame; |
---|
688 | f1->position = new Vector(-1.1, 0.0, 2.6); |
---|
689 | f1->direction = new Quaternion(); |
---|
690 | f1->time = 1.0; |
---|
691 | f1->mode = NEG_EXP; |
---|
692 | |
---|
693 | |
---|
694 | KeyFrame* f2 = new KeyFrame; |
---|
695 | f2->position = new Vector(-2.1, 0.0, 2.6); |
---|
696 | f2->direction = new Quaternion(); |
---|
697 | f2->time = 0.1; |
---|
698 | f2->mode = NEG_EXP; |
---|
699 | |
---|
700 | KeyFrame* f3 = new KeyFrame; |
---|
701 | f3->position = new Vector(10.0, 2.0, -1.0); |
---|
702 | f3->direction = new Quaternion(); |
---|
703 | f3->time = 0.2; |
---|
704 | f3->mode = NEG_EXP; |
---|
705 | |
---|
706 | KeyFrame* f4 = new KeyFrame; |
---|
707 | f4->position = new Vector(10.0, 5.0, -1.0); |
---|
708 | f4->direction = new Quaternion(); |
---|
709 | f4->time = 1.0; |
---|
710 | f4->mode = NEG_EXP; |
---|
711 | |
---|
712 | |
---|
713 | |
---|
714 | this->simpleAnimation->animatorBegin(); |
---|
715 | this->simpleAnimation->selectObject(b); |
---|
716 | this->simpleAnimation->setAnimationMode(SINGLE); |
---|
717 | this->simpleAnimation->addKeyFrame(f1); |
---|
718 | this->simpleAnimation->addKeyFrame(f2); |
---|
719 | this->simpleAnimation->start(); |
---|
720 | this->simpleAnimation->selectObject(c); |
---|
721 | this->simpleAnimation->addKeyFrame(f3); |
---|
722 | this->simpleAnimation->addKeyFrame(f4); |
---|
723 | this->simpleAnimation->start(); |
---|
724 | this->simpleAnimation->animatorEnd(); |
---|
725 | */ |
---|
726 | |
---|
727 | /* |
---|
728 | Vector* es = new Vector (10, 5, 0); |
---|
729 | Quaternion* qs = new Quaternion (); |
---|
730 | WorldEntity* pr = new Primitive(P_CYLINDER); |
---|
731 | pr->setName("primitive"); |
---|
732 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
---|
733 | */ |
---|
734 | |
---|
735 | /*monitor progress*/ |
---|
736 | this->glmis->step(); |
---|
737 | |
---|
738 | // trackManager->setBindSlave(env); |
---|
739 | PNode* tn = trackManager->getTrackNode(); |
---|
740 | tn->addChild(this->localPlayer); |
---|
741 | |
---|
742 | //localCamera->setParent(TrackNode::getInstance()); |
---|
743 | tn->addChild(this->localCamera); |
---|
744 | // localCamera->lookAt(tn); |
---|
745 | this->localPlayer->setMode(PNODE_ALL); |
---|
746 | //Vector* cameraOffset = new Vector (0, 5, -10); |
---|
747 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
748 | this->glmis->step(); |
---|
749 | |
---|
750 | break; |
---|
751 | } |
---|
752 | default: |
---|
753 | printf("World::load() - no world with ID %i found", this->debugWorldNr ); |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | |
---|
758 | |
---|
759 | /** |
---|
760 | \brief initializes a new World shortly before start |
---|
761 | |
---|
762 | this is the function, that will be loaded shortly before the world is |
---|
763 | started |
---|
764 | */ |
---|
765 | ErrorMessage World::init() |
---|
766 | { |
---|
767 | this->bPause = false; |
---|
768 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
769 | cn->addToWorld(this); |
---|
770 | cn->enable(true); |
---|
771 | } |
---|
772 | |
---|
773 | |
---|
774 | /** |
---|
775 | \brief starts the World |
---|
776 | */ |
---|
777 | ErrorMessage World::start() |
---|
778 | { |
---|
779 | PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
---|
780 | this->bQuitOrxonox = false; |
---|
781 | this->bQuitCurrentGame = false; |
---|
782 | this->mainLoop(); |
---|
783 | } |
---|
784 | |
---|
785 | /** |
---|
786 | \brief stops the world. |
---|
787 | |
---|
788 | This happens, when the player decides to end the Level. |
---|
789 | */ |
---|
790 | ErrorMessage World::stop() |
---|
791 | { |
---|
792 | PRINTF(3)("World::stop() - got stop signal\n"); |
---|
793 | this->bQuitCurrentGame = true; |
---|
794 | } |
---|
795 | |
---|
796 | /** |
---|
797 | \brief pauses the Game |
---|
798 | */ |
---|
799 | ErrorMessage World::pause() |
---|
800 | { |
---|
801 | this->isPaused = true; |
---|
802 | } |
---|
803 | |
---|
804 | /** |
---|
805 | \brief ends the pause Phase |
---|
806 | */ |
---|
807 | ErrorMessage World::resume() |
---|
808 | { |
---|
809 | this->isPaused = false; |
---|
810 | } |
---|
811 | |
---|
812 | /** |
---|
813 | \brief destroys the World |
---|
814 | */ |
---|
815 | ErrorMessage World::destroy() |
---|
816 | { |
---|
817 | |
---|
818 | } |
---|
819 | |
---|
820 | /** |
---|
821 | \brief shows the loading screen |
---|
822 | */ |
---|
823 | void World::displayLoadScreen () |
---|
824 | { |
---|
825 | PRINTF(3)("World::displayLoadScreen - start\n"); |
---|
826 | |
---|
827 | //GLMenuImageScreen* |
---|
828 | this->glmis = GLMenuImageScreen::getInstance(); |
---|
829 | this->glmis->init(); |
---|
830 | this->glmis->setMaximum(8); |
---|
831 | this->glmis->draw(); |
---|
832 | |
---|
833 | PRINTF(3)("World::displayLoadScreen - end\n"); |
---|
834 | } |
---|
835 | |
---|
836 | /** |
---|
837 | \brief removes the loadscreen, and changes over to the game |
---|
838 | |
---|
839 | \todo take out the delay |
---|
840 | */ |
---|
841 | void World::releaseLoadScreen () |
---|
842 | { |
---|
843 | PRINTF(3)("World::releaseLoadScreen - start\n"); |
---|
844 | this->glmis->setValue(this->glmis->getMaximum()); |
---|
845 | //SDL_Delay(500); |
---|
846 | PRINTF(3)("World::releaseLoadScreen - end\n"); |
---|
847 | } |
---|
848 | |
---|
849 | |
---|
850 | /** |
---|
851 | \brief gets the list of entities from the world |
---|
852 | \returns entity list |
---|
853 | */ |
---|
854 | tList<WorldEntity>* World::getEntities() |
---|
855 | { |
---|
856 | return this->entities; |
---|
857 | } |
---|
858 | |
---|
859 | |
---|
860 | /** |
---|
861 | \brief this returns the current game time |
---|
862 | \returns elapsed game time |
---|
863 | */ |
---|
864 | double World::getGameTime() |
---|
865 | { |
---|
866 | return this->gameTime; |
---|
867 | } |
---|
868 | |
---|
869 | |
---|
870 | /** |
---|
871 | \brief checks for collisions |
---|
872 | |
---|
873 | This method runs through all WorldEntities known to the world and checks for collisions |
---|
874 | between them. In case of collisions the collide() method of the corresponding entities |
---|
875 | is called. |
---|
876 | */ |
---|
877 | void World::collide () |
---|
878 | { |
---|
879 | /* |
---|
880 | List *a, *b; |
---|
881 | WorldEntity *aobj, *bobj; |
---|
882 | |
---|
883 | a = entities; |
---|
884 | |
---|
885 | while( a != NULL) |
---|
886 | { |
---|
887 | aobj = a->nextElement(); |
---|
888 | if( aobj->bCollide && aobj->collisioncluster != NULL) |
---|
889 | { |
---|
890 | b = a->nextElement(); |
---|
891 | while( b != NULL ) |
---|
892 | { |
---|
893 | bobj = b->nextElement(); |
---|
894 | if( bobj->bCollide && bobj->collisioncluster != NULL ) |
---|
895 | { |
---|
896 | unsigned long ahitflg, bhitflg; |
---|
897 | if( check_collision ( &aobj->place, aobj->collisioncluster, |
---|
898 | &ahitflg, &bobj->place, bobj->collisioncluster, |
---|
899 | &bhitflg) ); |
---|
900 | { |
---|
901 | aobj->collide (bobj, ahitflg, bhitflg); |
---|
902 | bobj->collide (aobj, bhitflg, ahitflg); |
---|
903 | } |
---|
904 | } |
---|
905 | b = b->nextElement(); |
---|
906 | } |
---|
907 | } |
---|
908 | a = a->enumerate(); |
---|
909 | } |
---|
910 | */ |
---|
911 | } |
---|
912 | |
---|
913 | /** |
---|
914 | \brief runs through all entities calling their draw() methods |
---|
915 | */ |
---|
916 | void World::draw () |
---|
917 | { |
---|
918 | /* draw entities */ |
---|
919 | WorldEntity* entity; |
---|
920 | glLoadIdentity(); |
---|
921 | |
---|
922 | //entity = this->entities->enumerate(); |
---|
923 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
924 | entity = iterator->nextElement(); |
---|
925 | while( entity != NULL ) |
---|
926 | { |
---|
927 | if( entity->bDraw ) entity->draw(); |
---|
928 | //entity = this->entities->nextElement(); |
---|
929 | entity = iterator->nextElement(); |
---|
930 | } |
---|
931 | delete iterator; |
---|
932 | |
---|
933 | glCallList (objectList); |
---|
934 | |
---|
935 | TextEngine::getInstance()->draw(); |
---|
936 | lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes // |
---|
937 | } |
---|
938 | |
---|
939 | |
---|
940 | /** |
---|
941 | \brief function to put your own debug stuff into it. it can display informations about |
---|
942 | the current class/procedure |
---|
943 | */ |
---|
944 | void World::debug() |
---|
945 | { |
---|
946 | PRINTF(2)("debug() - starting debug\n"); |
---|
947 | PNode* p1 = NullParent::getInstance (); |
---|
948 | PNode* p2 = new PNode (Vector(2, 2, 2), p1); |
---|
949 | PNode* p3 = new PNode (Vector(4, 4, 4), p1); |
---|
950 | PNode* p4 = new PNode (Vector(6, 6, 6), p2); |
---|
951 | |
---|
952 | p1->debug (); |
---|
953 | p2->debug (); |
---|
954 | p3->debug (); |
---|
955 | p4->debug (); |
---|
956 | |
---|
957 | p1->shiftCoor (Vector(-1, -1, -1)); |
---|
958 | |
---|
959 | printf("World::debug() - shift\n"); |
---|
960 | p1->debug (); |
---|
961 | p2->debug (); |
---|
962 | p3->debug (); |
---|
963 | p4->debug (); |
---|
964 | |
---|
965 | p1->update (0); |
---|
966 | |
---|
967 | printf ("World::debug() - update\n"); |
---|
968 | p1->debug (); |
---|
969 | p2->debug (); |
---|
970 | p3->debug (); |
---|
971 | p4->debug (); |
---|
972 | |
---|
973 | p2->shiftCoor (Vector(-1, -1, -1)); |
---|
974 | p1->update (0); |
---|
975 | |
---|
976 | p1->debug (); |
---|
977 | p2->debug (); |
---|
978 | p3->debug (); |
---|
979 | p4->debug (); |
---|
980 | |
---|
981 | p2->setAbsCoor (Vector(1,2,3)); |
---|
982 | |
---|
983 | |
---|
984 | p1->update (0); |
---|
985 | |
---|
986 | p1->debug (); |
---|
987 | p2->debug (); |
---|
988 | p3->debug (); |
---|
989 | p4->debug (); |
---|
990 | |
---|
991 | delete p1; |
---|
992 | |
---|
993 | |
---|
994 | /* |
---|
995 | WorldEntity* entity; |
---|
996 | printf("counting all entities\n"); |
---|
997 | printf("World::debug() - enumerate()\n"); |
---|
998 | entity = entities->enumerate(); |
---|
999 | while( entity != NULL ) |
---|
1000 | { |
---|
1001 | if( entity->bDraw ) printf("got an entity\n"); |
---|
1002 | entity = entities->nextElement(); |
---|
1003 | } |
---|
1004 | */ |
---|
1005 | } |
---|
1006 | |
---|
1007 | |
---|
1008 | /** |
---|
1009 | \brief main loop of the world: executing all world relevant function |
---|
1010 | |
---|
1011 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
1012 | all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
1013 | collisions drawing everything to the screen. |
---|
1014 | */ |
---|
1015 | void World::mainLoop() |
---|
1016 | { |
---|
1017 | this->lastFrame = SDL_GetTicks (); |
---|
1018 | PRINTF(3)("World::mainLoop() - Entering main loop\n"); |
---|
1019 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ |
---|
1020 | { |
---|
1021 | PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize()); |
---|
1022 | // Network |
---|
1023 | this->synchronize (); |
---|
1024 | // Process input |
---|
1025 | this->handleInput (); |
---|
1026 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
---|
1027 | break; |
---|
1028 | // Process time |
---|
1029 | this->tick (); |
---|
1030 | // Update the state |
---|
1031 | this->update (); |
---|
1032 | // Process collision |
---|
1033 | this->collide (); |
---|
1034 | // Draw |
---|
1035 | this->display (); |
---|
1036 | |
---|
1037 | // for( int i = 0; i < 5000000; i++) {} |
---|
1038 | /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
---|
1039 | } |
---|
1040 | PRINTF(3)("World::mainLoop() - Exiting the main loop\n"); |
---|
1041 | } |
---|
1042 | |
---|
1043 | |
---|
1044 | /** |
---|
1045 | \brief synchronize local data with remote data |
---|
1046 | */ |
---|
1047 | void World::synchronize () |
---|
1048 | { |
---|
1049 | // Get remote input |
---|
1050 | // Update synchronizables |
---|
1051 | } |
---|
1052 | |
---|
1053 | |
---|
1054 | /** |
---|
1055 | \brief run all input processing |
---|
1056 | |
---|
1057 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
1058 | sdl and has its own event-passing-queue. |
---|
1059 | */ |
---|
1060 | void World::handleInput () |
---|
1061 | { |
---|
1062 | // localinput |
---|
1063 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
1064 | cn->process(); |
---|
1065 | // remoteinput |
---|
1066 | } |
---|
1067 | |
---|
1068 | |
---|
1069 | /** |
---|
1070 | \brief advance the timeline |
---|
1071 | |
---|
1072 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
1073 | the time is mesured in ms and passed to all world-entities and other classes that need |
---|
1074 | a heart-beat. |
---|
1075 | */ |
---|
1076 | void World::tick () |
---|
1077 | { |
---|
1078 | Uint32 currentFrame = SDL_GetTicks(); |
---|
1079 | if(!this->bPause) |
---|
1080 | { |
---|
1081 | this->dt = currentFrame - this->lastFrame; |
---|
1082 | |
---|
1083 | if( this->dt > 0) |
---|
1084 | { |
---|
1085 | float fps = 1000/dt; |
---|
1086 | |
---|
1087 | // temporary, only for showing how fast the text-engine is |
---|
1088 | char tmpChar[20]; |
---|
1089 | sprintf(tmpChar, "fps: %4.0f", fps); |
---|
1090 | } |
---|
1091 | else |
---|
1092 | { |
---|
1093 | /* the frame-rate is limited to 100 frames per second, all other things are for |
---|
1094 | nothing. |
---|
1095 | */ |
---|
1096 | PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); |
---|
1097 | SDL_Delay(10); |
---|
1098 | this->dt = 10; |
---|
1099 | } |
---|
1100 | //this->timeSlice (dt); |
---|
1101 | |
---|
1102 | /* function to let all entities tick (iterate through list) */ |
---|
1103 | float seconds = this->dt / 1000.0; |
---|
1104 | this->gameTime += seconds; |
---|
1105 | //entity = entities->enumerate(); |
---|
1106 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
1107 | WorldEntity* entity = iterator->nextElement(); |
---|
1108 | while( entity != NULL) |
---|
1109 | { |
---|
1110 | entity->tick (seconds); |
---|
1111 | entity = iterator->nextElement(); |
---|
1112 | } |
---|
1113 | delete iterator; |
---|
1114 | |
---|
1115 | /* update tick the rest */ |
---|
1116 | this->trackManager->tick(this->dt); |
---|
1117 | this->localCamera->tick(this->dt); |
---|
1118 | this->garbageCollector->tick(seconds); |
---|
1119 | |
---|
1120 | AnimationPlayer::getInstance()->tick(seconds); |
---|
1121 | } |
---|
1122 | this->lastFrame = currentFrame; |
---|
1123 | } |
---|
1124 | |
---|
1125 | |
---|
1126 | /** |
---|
1127 | \brief this function gives the world a consistant state |
---|
1128 | |
---|
1129 | after ticking (updating the world state) this will give a constistant |
---|
1130 | state to the whole system. |
---|
1131 | */ |
---|
1132 | void World::update() |
---|
1133 | { |
---|
1134 | this->garbageCollector->update(); |
---|
1135 | this->nullParent->update (dt); |
---|
1136 | } |
---|
1137 | |
---|
1138 | |
---|
1139 | /** |
---|
1140 | \brief render the current frame |
---|
1141 | |
---|
1142 | clear all buffers and draw the world |
---|
1143 | */ |
---|
1144 | void World::display () |
---|
1145 | { |
---|
1146 | // clear buffer |
---|
1147 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
1148 | // set camera |
---|
1149 | this->localCamera->apply (); |
---|
1150 | // draw world |
---|
1151 | this->draw(); |
---|
1152 | // draw HUD |
---|
1153 | /* \todo draw HUD */ |
---|
1154 | // flip buffers |
---|
1155 | SDL_GL_SwapBuffers(); |
---|
1156 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
---|
1157 | //SDL_Flip (screen); |
---|
1158 | } |
---|
1159 | |
---|
1160 | |
---|
1161 | /** |
---|
1162 | \brief add and spawn a new entity to this world |
---|
1163 | \param entity to be added |
---|
1164 | */ |
---|
1165 | void World::spawn(WorldEntity* entity) |
---|
1166 | { |
---|
1167 | this->entities->add (entity); |
---|
1168 | entity->postSpawn (); |
---|
1169 | } |
---|
1170 | |
---|
1171 | |
---|
1172 | /** |
---|
1173 | \brief add and spawn a new entity to this world |
---|
1174 | \param entity to be added |
---|
1175 | \param absCoor At what coordinates to add this entity. |
---|
1176 | \param absDir In which direction should it look. |
---|
1177 | */ |
---|
1178 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
---|
1179 | { |
---|
1180 | this->entities->add (entity); |
---|
1181 | |
---|
1182 | entity->setAbsCoor (*absCoor); |
---|
1183 | entity->setAbsDir (*absDir); |
---|
1184 | |
---|
1185 | entity->postSpawn (); |
---|
1186 | } |
---|
1187 | |
---|
1188 | |
---|
1189 | /** |
---|
1190 | \brief add and spawn a new entity to this world |
---|
1191 | \param entity to be added |
---|
1192 | \param entity to be added to (PNode) |
---|
1193 | \param At what relative coordinates to add this entity. |
---|
1194 | \param In which relative direction should it look. |
---|
1195 | */ |
---|
1196 | void World::spawn(WorldEntity* entity, PNode* parentNode, |
---|
1197 | Vector* relCoor, Quaternion* relDir, |
---|
1198 | int parentingMode) |
---|
1199 | { |
---|
1200 | this->nullParent = NullParent::getInstance(); |
---|
1201 | if( parentNode != NULL) |
---|
1202 | { |
---|
1203 | parentNode->addChild (entity); |
---|
1204 | |
---|
1205 | entity->setRelCoor (*relCoor); |
---|
1206 | entity->setRelDir (*relDir); |
---|
1207 | entity->setMode(parentingMode); |
---|
1208 | |
---|
1209 | this->entities->add (entity); |
---|
1210 | |
---|
1211 | entity->postSpawn (); |
---|
1212 | } |
---|
1213 | } |
---|
1214 | |
---|
1215 | |
---|
1216 | |
---|
1217 | /** |
---|
1218 | \brief commands that the world must catch |
---|
1219 | \returns false if not used by the world |
---|
1220 | */ |
---|
1221 | bool World::command(Command* cmd) |
---|
1222 | { |
---|
1223 | if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW0)) this->localCamera->setViewMode(VIEW_NORMAL); |
---|
1224 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW1)) this->localCamera->setViewMode(VIEW_BEHIND); |
---|
1225 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW2)) this->localCamera->setViewMode(VIEW_FRONT); |
---|
1226 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW3)) this->localCamera->setViewMode(VIEW_LEFT); |
---|
1227 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT); |
---|
1228 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP); |
---|
1229 | |
---|
1230 | return false; |
---|
1231 | } |
---|
1232 | |
---|
1233 | void World::setPath( const char* name) |
---|
1234 | { |
---|
1235 | if (this->path) |
---|
1236 | delete this->path; |
---|
1237 | if (ResourceManager::isFile(name)) |
---|
1238 | { |
---|
1239 | this->path = new char[strlen(name)+1]; |
---|
1240 | strcpy(this->path, name); |
---|
1241 | } |
---|
1242 | else |
---|
1243 | { |
---|
1244 | this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1]; |
---|
1245 | sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name); |
---|
1246 | } |
---|
1247 | } |
---|
1248 | |
---|
1249 | const char* World::getPath( void) |
---|
1250 | { |
---|
1251 | return path; |
---|
1252 | } |
---|