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