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