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