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