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