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