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