[1853] | 1 | |
---|
[4010] | 2 | |
---|
[1853] | 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
[1855] | 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[2190] | 15 | co-programmer: Christian Meyer |
---|
[1853] | 16 | */ |
---|
| 17 | |
---|
[3590] | 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
| 19 | |
---|
[2190] | 20 | #include "world.h" |
---|
[3608] | 21 | |
---|
| 22 | #include "orxonox.h" |
---|
[3620] | 23 | |
---|
[3608] | 24 | #include "p_node.h" |
---|
| 25 | #include "null_parent.h" |
---|
| 26 | #include "helper_parent.h" |
---|
| 27 | #include "track_node.h" |
---|
[2190] | 28 | #include "world_entity.h" |
---|
[2036] | 29 | #include "player.h" |
---|
[2190] | 30 | #include "camera.h" |
---|
[2816] | 31 | #include "environment.h" |
---|
[3419] | 32 | #include "skysphere.h" |
---|
[3803] | 33 | #include "skybox.h" |
---|
[3750] | 34 | #include "satellite.h" |
---|
[3608] | 35 | #include "terrain.h" |
---|
[3436] | 36 | #include "light.h" |
---|
[3790] | 37 | #include "text_engine.h" |
---|
[3620] | 38 | |
---|
[3646] | 39 | #include "track_manager.h" |
---|
| 40 | #include "garbage_collector.h" |
---|
[3812] | 41 | #include "animation_player.h" |
---|
[3646] | 42 | |
---|
[3608] | 43 | #include "command_node.h" |
---|
| 44 | #include "glmenu_imagescreen.h" |
---|
| 45 | #include "list.h" |
---|
[4010] | 46 | #include "game_loader.h" |
---|
[2036] | 47 | |
---|
[3964] | 48 | #include "animation3d.h" |
---|
[3608] | 49 | |
---|
[4010] | 50 | #include "substring.h" |
---|
[3608] | 51 | |
---|
[1856] | 52 | using namespace std; |
---|
[1853] | 53 | |
---|
[3620] | 54 | WorldInterface* WorldInterface::singletonRef = 0; |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | \brief private constructor because of singleton |
---|
| 59 | */ |
---|
| 60 | WorldInterface::WorldInterface() |
---|
| 61 | { |
---|
| 62 | this->worldIsInitialized = false; |
---|
| 63 | this->worldReference = NULL; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | \brief public deconstructor |
---|
| 68 | */ |
---|
| 69 | WorldInterface::~WorldInterface() |
---|
| 70 | { |
---|
| 71 | this->singletonRef = NULL; |
---|
| 72 | this->worldIsInitialized = false; |
---|
| 73 | this->worldReference = NULL; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | \brief gets the singleton instance |
---|
| 78 | \returns singleton instance |
---|
| 79 | */ |
---|
| 80 | WorldInterface* WorldInterface::getInstance() |
---|
| 81 | { |
---|
| 82 | if( singletonRef == NULL) |
---|
| 83 | singletonRef = new WorldInterface(); |
---|
| 84 | return singletonRef; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | \brief initializes the interface |
---|
| 90 | \param reference to the world |
---|
| 91 | |
---|
| 92 | if the worldinterface is not initilizes, there wont be any |
---|
| 93 | useable interface |
---|
| 94 | */ |
---|
| 95 | void WorldInterface::init(World* world) |
---|
| 96 | { |
---|
| 97 | this->worldReference = world; |
---|
[3629] | 98 | if( world != NULL) |
---|
[3620] | 99 | { |
---|
| 100 | this->worldIsInitialized = true; |
---|
| 101 | PRINTF(3)("WorldInterface up and running\n"); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | \brief gets the entity list from the world |
---|
| 108 | \return entity list |
---|
| 109 | */ |
---|
| 110 | tList<WorldEntity>* WorldInterface::getEntityList() |
---|
| 111 | { |
---|
| 112 | if( this->worldIsInitialized) |
---|
| 113 | return this->worldReference->getEntities(); |
---|
| 114 | PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n"); |
---|
| 115 | return NULL; |
---|
| 116 | } |
---|
| 117 | |
---|
[4010] | 118 | CREATE_FACTORY(World); |
---|
[3620] | 119 | |
---|
[4010] | 120 | World::World( TiXmlElement* root) |
---|
| 121 | { |
---|
| 122 | this->constuctorInit("", -1); |
---|
[4094] | 123 | this->path = NULL; |
---|
[4010] | 124 | const char *string; |
---|
| 125 | char *name; |
---|
| 126 | int id; |
---|
| 127 | |
---|
| 128 | PRINTF0("Creating a World\n"); |
---|
| 129 | |
---|
| 130 | // identifier |
---|
| 131 | string = grabParameter( root, "identifier"); |
---|
| 132 | if( string == NULL || sscanf(string, "%d", &id) != 1) |
---|
| 133 | { |
---|
| 134 | PRINTF0("World is missing a proper 'identifier'\n"); |
---|
| 135 | this->setStoryID( -1); |
---|
| 136 | } |
---|
| 137 | else setStoryID( id); |
---|
| 138 | |
---|
| 139 | // next id |
---|
| 140 | string = grabParameter( root, "nextid"); |
---|
| 141 | if( string == NULL || sscanf(string, "%d", &id) != 1) |
---|
| 142 | { |
---|
| 143 | PRINTF0("World is missing a proper 'nextid'\n"); |
---|
| 144 | this->setStoryID( -1); |
---|
| 145 | } |
---|
| 146 | else setNextStoryID( id); |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | // path |
---|
| 150 | string = grabParameter( root, "path"); |
---|
| 151 | if( string == NULL) |
---|
| 152 | { |
---|
| 153 | PRINTF0("World is missing a proper 'path'\n"); |
---|
| 154 | this->setPath( NULL); |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | name = new char[strlen(string + 2)]; |
---|
| 159 | strcpy( name, string); |
---|
| 160 | this->setPath( name); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
[1858] | 164 | /** |
---|
[2551] | 165 | \brief create a new World |
---|
| 166 | |
---|
| 167 | This creates a new empty world! |
---|
[1858] | 168 | */ |
---|
[2636] | 169 | World::World (char* name) |
---|
[1855] | 170 | { |
---|
[4094] | 171 | this->path = NULL; |
---|
[4010] | 172 | this->constuctorInit(name, -1); |
---|
[3573] | 173 | //NullParent* np = NullParent::getInstance(); |
---|
[1855] | 174 | } |
---|
| 175 | |
---|
[3449] | 176 | /** |
---|
| 177 | \brief creates a new World... |
---|
| 178 | \param worldID with this ID |
---|
| 179 | */ |
---|
[2636] | 180 | World::World (int worldID) |
---|
| 181 | { |
---|
[4094] | 182 | this->path = NULL; |
---|
[4010] | 183 | this->constuctorInit(NULL, worldID); |
---|
[2636] | 184 | } |
---|
| 185 | |
---|
[1858] | 186 | /** |
---|
[2551] | 187 | \brief remove the World from memory |
---|
[3365] | 188 | |
---|
| 189 | delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 190 | things contained in the tree are deleted automaticaly |
---|
[1858] | 191 | */ |
---|
[2190] | 192 | World::~World () |
---|
[1872] | 193 | { |
---|
[3546] | 194 | PRINTF(3)("World::~World() - deleting current world\n"); |
---|
[3226] | 195 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3220] | 196 | cn->unbind(this->localPlayer); |
---|
| 197 | cn->reset(); |
---|
[3677] | 198 | |
---|
[3676] | 199 | ResourceManager::getInstance()->debug(); |
---|
[3672] | 200 | ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); |
---|
[3677] | 201 | ResourceManager::getInstance()->debug(); |
---|
[3660] | 202 | |
---|
[3620] | 203 | delete WorldInterface::getInstance(); |
---|
| 204 | |
---|
[3529] | 205 | delete this->nullParent; |
---|
[3553] | 206 | delete this->entities; |
---|
[3597] | 207 | delete this->lightMan; |
---|
[3566] | 208 | delete this->trackManager; |
---|
[3790] | 209 | TextEngine::getInstance()->flush(); |
---|
[3729] | 210 | |
---|
[3816] | 211 | AnimationPlayer::getInstance()->debug(); |
---|
[3812] | 212 | delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence. |
---|
[3729] | 213 | //delete garbagecollecor |
---|
| 214 | //delete animator |
---|
[3790] | 215 | |
---|
| 216 | |
---|
[1872] | 217 | } |
---|
[1858] | 218 | |
---|
[3526] | 219 | /** |
---|
[3629] | 220 | \brief initializes the world. |
---|
| 221 | |
---|
| 222 | set all stuff here that is world generic and does not use to much memory |
---|
| 223 | because the real init() function StoryEntity::init() will be called |
---|
| 224 | shortly before start of the game. |
---|
| 225 | since all worlds are initiated/referenced before they will be started. |
---|
| 226 | NO LEVEL LOADING HERE - NEVER! |
---|
[3526] | 227 | */ |
---|
[4010] | 228 | void World::constuctorInit(char* name, int worldID) |
---|
[3526] | 229 | { |
---|
| 230 | this->setClassName ("World"); |
---|
[2636] | 231 | |
---|
[4010] | 232 | //this->worldName = name; |
---|
| 233 | //this->worldName = new char[strlen(name)+1]; |
---|
| 234 | //strcpy(this->worldName, name); |
---|
[3526] | 235 | this->debugWorldNr = worldID; |
---|
| 236 | this->entities = new tList<WorldEntity>(); |
---|
[3629] | 237 | } |
---|
[3526] | 238 | |
---|
[3629] | 239 | |
---|
| 240 | /** |
---|
| 241 | \brief this is executed before load |
---|
| 242 | |
---|
| 243 | since the load function sometimes needs data, that has been init before |
---|
| 244 | the load and after the proceeding storyentity has finished |
---|
| 245 | */ |
---|
| 246 | ErrorMessage World::preLoad() |
---|
| 247 | { |
---|
[3620] | 248 | /* init the world interface */ |
---|
| 249 | WorldInterface* wi = WorldInterface::getInstance(); |
---|
| 250 | wi->init(this); |
---|
[3646] | 251 | this->garbageCollector = GarbageCollector::getInstance(); |
---|
[4010] | 252 | |
---|
[3993] | 253 | this->trackManager = TrackManager::getInstance(); |
---|
| 254 | this->lightMan = LightManager::getInstance(); |
---|
| 255 | this->nullParent = NullParent::getInstance (); |
---|
| 256 | this->nullParent->setName ("NullParent"); |
---|
| 257 | |
---|
[4010] | 258 | AnimationPlayer::getInstance(); // initializes the animationPlayer |
---|
| 259 | |
---|
[4015] | 260 | this->localCamera = new Camera(); |
---|
| 261 | this->localCamera->setName ("camera"); |
---|
[3526] | 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
[3449] | 265 | /** |
---|
| 266 | \brief loads the World by initializing all resources, and set their default values. |
---|
| 267 | */ |
---|
[3459] | 268 | ErrorMessage World::load() |
---|
[4010] | 269 | { |
---|
[4104] | 270 | PRINTF(3)("> Loading world: '%s'\n", getPath()); |
---|
| 271 | TiXmlElement* element; |
---|
[4010] | 272 | GameLoader* loader = GameLoader::getInstance(); |
---|
| 273 | |
---|
| 274 | if( getPath() == NULL) |
---|
[2636] | 275 | { |
---|
[4104] | 276 | PRINTF(1)("World has no path specified for loading"); |
---|
[4010] | 277 | return (ErrorMessage){213,"Path not specified","World::load()"}; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | TiXmlDocument* XMLDoc = new TiXmlDocument( path); |
---|
| 281 | // load the campaign document |
---|
[4104] | 282 | if( !XMLDoc->LoadFile()) |
---|
[4010] | 283 | { |
---|
| 284 | // report an error |
---|
[4104] | 285 | PRINTF(1)("loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); |
---|
[4010] | 286 | delete XMLDoc; |
---|
| 287 | return (ErrorMessage){213,"XML File parsing error","World::load()"}; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | // check basic validity |
---|
| 291 | TiXmlElement* root = XMLDoc->RootElement(); |
---|
| 292 | assert( root != NULL); |
---|
| 293 | |
---|
| 294 | if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile")) |
---|
| 295 | { |
---|
| 296 | // report an error |
---|
[4104] | 297 | PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n"); |
---|
[4010] | 298 | delete XMLDoc; |
---|
| 299 | return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"}; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | // load the parameters |
---|
| 303 | // name |
---|
| 304 | char* temp; |
---|
| 305 | const char* string = grabParameter( root, "name"); |
---|
| 306 | if( string == NULL) |
---|
| 307 | { |
---|
[4104] | 308 | PRINTF(2)("World is missing a proper 'name'\n"); |
---|
[4010] | 309 | string = "Unknown"; |
---|
| 310 | temp = new char[strlen(string + 2)]; |
---|
| 311 | strcpy( temp, string); |
---|
| 312 | this->worldName = temp; |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | { |
---|
| 316 | temp = new char[strlen(string + 2)]; |
---|
| 317 | strcpy( temp, string); |
---|
| 318 | this->worldName = temp; |
---|
| 319 | } |
---|
[4104] | 320 | //////////////// |
---|
| 321 | // LOADSCREEN // |
---|
| 322 | //////////////// |
---|
| 323 | element = root->FirstChildElement("LoadScreen"); |
---|
| 324 | if (element == NULL) |
---|
| 325 | { |
---|
| 326 | PRINTF(2)("no LoadScreen specified, loading default\n"); |
---|
| 327 | |
---|
| 328 | glmis->setBackgroundImage("pictures/load_screen.jpg"); |
---|
| 329 | this->glmis->setMaximum(8); |
---|
| 330 | this->glmis->draw(); |
---|
| 331 | } |
---|
| 332 | else |
---|
| 333 | { |
---|
| 334 | this->glmis->load(element); |
---|
| 335 | this->glmis->draw(); |
---|
| 336 | } |
---|
| 337 | this->glmis->draw(); |
---|
[4010] | 338 | // find WorldEntities |
---|
[4104] | 339 | element = root->FirstChildElement("WorldEntities"); |
---|
[4010] | 340 | |
---|
| 341 | if( element == NULL) |
---|
| 342 | { |
---|
[4104] | 343 | PRINTF(1)("World is missing 'WorldEntities'\n"); |
---|
[4010] | 344 | } |
---|
| 345 | else |
---|
| 346 | { |
---|
| 347 | element = element->FirstChildElement(); |
---|
| 348 | // load Players/Objects/Whatever |
---|
[4104] | 349 | PRINTF(4)("Loading WorldEntities\n"); |
---|
[4010] | 350 | while( element != NULL) |
---|
| 351 | { |
---|
| 352 | WorldEntity* created = (WorldEntity*) loader->fabricate( element); |
---|
| 353 | if( created != NULL) this->spawn( created); |
---|
| 354 | // if we load a 'Player' we use it as localPlayer |
---|
| 355 | //todo do this more elegant |
---|
| 356 | if( element->Value() != NULL && !strcmp( element->Value(), "Player")) localPlayer = (Player*) created; |
---|
[4015] | 357 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; |
---|
[4010] | 358 | element = element->NextSiblingElement(); |
---|
[4099] | 359 | glmis->step(); //! \todo temporary |
---|
[4010] | 360 | } |
---|
[4104] | 361 | PRINTF(4)("Done loading WorldEntities\n"); |
---|
[4010] | 362 | } |
---|
| 363 | |
---|
| 364 | // find Track |
---|
| 365 | /*element = root->FirstChildElement( "Track"); |
---|
| 366 | if( element == NULL) |
---|
| 367 | { |
---|
| 368 | PRINTF0("============>>>>>>>>>>>>>>>>>World is missing a 'Track'\n"); |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | //load track |
---|
| 373 | PRINTF0("============>>>>>>>>>>>>>>>>Loading Track\n"); |
---|
| 374 | |
---|
| 375 | trackManager->loadTrack( element); |
---|
| 376 | trackManager->finalize(); |
---|
| 377 | PRINTF0("============>>>>>>>>>>>>>>>>Done loading Track\n"); |
---|
| 378 | }*/ |
---|
| 379 | |
---|
| 380 | // free the XML data |
---|
[4015] | 381 | |
---|
[4010] | 382 | delete XMLDoc; |
---|
[4015] | 383 | /* GENERIC LOADING PROCESS FINISHED */ |
---|
[4010] | 384 | |
---|
| 385 | // bind input |
---|
| 386 | Orxonox *orx = Orxonox::getInstance (); |
---|
| 387 | orx->getLocalInput()->bind (localPlayer); |
---|
| 388 | |
---|
| 389 | // bind camera |
---|
| 390 | //this->localCamera->bind (localPlayer); |
---|
| 391 | this->localPlayer->addChild (this->localCamera); |
---|
| 392 | |
---|
| 393 | |
---|
| 394 | // stuff beyond this point remains to be loaded properly |
---|
| 395 | |
---|
[3455] | 396 | // initializing the TrackManager |
---|
[4010] | 397 | this->trackManager = TrackManager::getInstance(); |
---|
[3686] | 398 | //trackManager->addPoint(Vector(0,0,0)); |
---|
| 399 | trackManager->addPoint(Vector(150, -35, 5)); |
---|
| 400 | trackManager->addPoint(Vector(200,-35, 5)); |
---|
| 401 | trackManager->addPoint(Vector(250, -35, 5)); |
---|
[3567] | 402 | trackManager->addPoint(Vector(320,-33,-.55)); |
---|
[3686] | 403 | trackManager->setDuration(2); |
---|
[3567] | 404 | trackManager->setSavePoint(); |
---|
[3686] | 405 | |
---|
[3567] | 406 | trackManager->addPoint(Vector(410, 0, 0)); |
---|
| 407 | trackManager->addPoint(Vector(510, 20, -10)); |
---|
| 408 | trackManager->addPoint(Vector(550, 20, -10)); |
---|
| 409 | trackManager->addPoint(Vector(570, 20, -10)); |
---|
[3634] | 410 | trackManager->setDuration(5); |
---|
[3567] | 411 | |
---|
| 412 | int fork11, fork12; |
---|
| 413 | trackManager->fork(2, &fork11, &fork12); |
---|
| 414 | trackManager->workOn(fork11); |
---|
| 415 | trackManager->addPoint(Vector(640, 25, -30)); |
---|
| 416 | trackManager->addPoint(Vector(700, 40, -120)); |
---|
| 417 | trackManager->addPoint(Vector(800, 50, -150)); |
---|
| 418 | trackManager->addPoint(Vector(900, 60, -100)); |
---|
| 419 | trackManager->addPoint(Vector(900, 60, -70)); |
---|
| 420 | trackManager->addPoint(Vector(990, 65, -15)); |
---|
| 421 | trackManager->addPoint(Vector(1050, 65, -10)); |
---|
| 422 | trackManager->addPoint(Vector(1100, 65, -20)); |
---|
[3634] | 423 | trackManager->setDuration(10); |
---|
[3567] | 424 | |
---|
[3365] | 425 | trackManager->workOn(fork12); |
---|
[3567] | 426 | trackManager->addPoint(Vector(640, 25, 20)); |
---|
| 427 | trackManager->addPoint(Vector(670, 50, 120)); |
---|
| 428 | trackManager->addPoint(Vector(700, 70, 80)); |
---|
| 429 | trackManager->addPoint(Vector(800, 70, 65)); |
---|
| 430 | trackManager->addPoint(Vector(850, 65, 65)); |
---|
| 431 | trackManager->addPoint(Vector(920, 35, 40)); |
---|
| 432 | trackManager->addPoint(Vector(945, 40, 40)); |
---|
| 433 | trackManager->addPoint(Vector(970, 24, 40)); |
---|
| 434 | trackManager->addPoint(Vector(1000, 40, -7)); |
---|
[3634] | 435 | trackManager->setDuration(10); |
---|
[3567] | 436 | |
---|
[3522] | 437 | |
---|
[3567] | 438 | trackManager->join(2, fork11, fork12); |
---|
| 439 | |
---|
[3522] | 440 | trackManager->workOn(5); |
---|
[3567] | 441 | trackManager->addPoint(Vector(1200, 60, -50)); |
---|
| 442 | trackManager->addPoint(Vector(1300, 50, -50)); |
---|
| 443 | trackManager->addPoint(Vector(1400, 40, -50)); |
---|
| 444 | trackManager->addPoint(Vector(1500, 40, -60)); |
---|
| 445 | trackManager->addPoint(Vector(1600, 35, -55)); |
---|
| 446 | trackManager->addPoint(Vector(1700, 45, -40)); |
---|
| 447 | trackManager->addPoint(Vector(1750, 60, -40)); |
---|
| 448 | trackManager->addPoint(Vector(1770, 80, -40)); |
---|
| 449 | trackManager->addPoint(Vector(1800, 100, -40)); |
---|
[3634] | 450 | trackManager->setDuration(10); |
---|
[3522] | 451 | |
---|
[3433] | 452 | trackManager->finalize(); |
---|
[3522] | 453 | |
---|
[3433] | 454 | |
---|
[4010] | 455 | lightMan->setAmbientColor(.1,.1,.1); |
---|
| 456 | lightMan->addLight(); |
---|
| 457 | // lightMan->setAttenuation(1.0, .01, 0.0); |
---|
| 458 | // lightMan->setDiffuseColor(1,1,1); |
---|
| 459 | // lightMan->addLight(1); |
---|
| 460 | // lightMan->setPosition(20, 10, -20); |
---|
| 461 | // lightMan->setDiffuseColor(0,0,0); |
---|
| 462 | lightMan->debug(); |
---|
| 463 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
| 464 | |
---|
| 465 | // trackManager->setBindSlave(env); |
---|
| 466 | PNode* tn = trackManager->getTrackNode(); |
---|
| 467 | tn->addChild(this->localPlayer); |
---|
| 468 | |
---|
| 469 | //localCamera->setParent(TrackNode::getInstance()); |
---|
| 470 | tn->addChild(this->localCamera); |
---|
| 471 | localCamera->lookAt(tn); |
---|
[4105] | 472 | localCamera->setMode(PNODE_MOVEMENT); |
---|
[4010] | 473 | this->localPlayer->setMode(PNODE_ALL); |
---|
| 474 | Vector* cameraOffset = new Vector (0, 5, -10); |
---|
| 475 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
| 476 | |
---|
[4015] | 477 | this->sky->setParent(this->localCamera); |
---|
[3368] | 478 | |
---|
[4010] | 479 | // initialize debug coord system |
---|
| 480 | objectList = glGenLists(1); |
---|
| 481 | glNewList (objectList, GL_COMPILE); |
---|
| 482 | |
---|
| 483 | // trackManager->drawGraph(.01); |
---|
| 484 | trackManager->debug(2); |
---|
| 485 | glEndList(); |
---|
[3993] | 486 | |
---|
[4094] | 487 | terrain = new Terrain("worlds/newGround.obj"); |
---|
[4010] | 488 | terrain->setRelCoor(Vector(0,-10,0)); |
---|
| 489 | this->spawn(terrain); |
---|
[3602] | 490 | |
---|
[4010] | 491 | } |
---|
[3365] | 492 | |
---|
[4010] | 493 | void World::loadDebugWorld(int worldID) |
---|
| 494 | { |
---|
| 495 | /*monitor progress*/ |
---|
| 496 | this->glmis->step(); |
---|
[3194] | 497 | |
---|
[4010] | 498 | // LIGHT initialisation |
---|
[3365] | 499 | |
---|
[4010] | 500 | lightMan->setAmbientColor(.1,.1,.1); |
---|
| 501 | lightMan->addLight(); |
---|
| 502 | // lightMan->setAttenuation(1.0, .01, 0.0); |
---|
| 503 | // lightMan->setDiffuseColor(1,1,1); |
---|
| 504 | // lightMan->addLight(1); |
---|
| 505 | // lightMan->setPosition(20, 10, -20); |
---|
| 506 | // lightMan->setDiffuseColor(0,0,0); |
---|
| 507 | lightMan->debug(); |
---|
[3368] | 508 | |
---|
[4010] | 509 | switch(this->debugWorldNr) |
---|
| 510 | { |
---|
| 511 | /* |
---|
| 512 | this loads the hard-coded debug world. this only for simplicity and will be |
---|
| 513 | removed by a reald world-loader, which interprets a world-file. |
---|
| 514 | if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and |
---|
| 515 | make whatever you want... |
---|
| 516 | */ |
---|
| 517 | case DEBUG_WORLD_0: |
---|
| 518 | { |
---|
| 519 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
| 520 | |
---|
| 521 | // !\todo old track-system has to be removed |
---|
| 522 | |
---|
| 523 | //create helper for player |
---|
| 524 | //HelperParent* hp = new HelperParent (); |
---|
| 525 | /* the player has to be added to this helper */ |
---|
| 526 | |
---|
| 527 | // create a player |
---|
| 528 | this->localPlayer = new Player (); |
---|
| 529 | this->localPlayer->setName ("player"); |
---|
| 530 | this->spawn (this->localPlayer); |
---|
| 531 | /*monitor progress*/ |
---|
| 532 | //this->glmis->step(); |
---|
| 533 | this->glmis->step(); |
---|
| 534 | |
---|
| 535 | // bind input |
---|
| 536 | Orxonox *orx = Orxonox::getInstance (); |
---|
| 537 | orx->getLocalInput()->bind (this->localPlayer); |
---|
[2636] | 538 | |
---|
[4010] | 539 | // bind camera |
---|
| 540 | this->localCamera = new Camera(); |
---|
| 541 | this->localCamera->setName ("camera"); |
---|
[3637] | 542 | |
---|
[4010] | 543 | /*monitor progress*/ |
---|
| 544 | this->glmis->step(); |
---|
[2816] | 545 | |
---|
[4015] | 546 | sky = new SkyBox(); |
---|
| 547 | // (SkyBox*)(sky)->setTexture("pictures/sky/skybox", "jpg"); |
---|
| 548 | sky->setParent(localCamera); |
---|
| 549 | this->spawn(sky); |
---|
[3419] | 550 | |
---|
[4010] | 551 | /*monitor progress*/ |
---|
| 552 | this->glmis->step(); |
---|
[3368] | 553 | |
---|
[3521] | 554 | |
---|
[4010] | 555 | WorldEntity* env = new Environment(); |
---|
| 556 | env->setName ("env"); |
---|
| 557 | this->spawn(env); |
---|
[3521] | 558 | |
---|
[3586] | 559 | |
---|
[4010] | 560 | /* |
---|
| 561 | Vector* es = new Vector (10, 5, 0); |
---|
| 562 | Quaternion* qs = new Quaternion (); |
---|
| 563 | WorldEntity* pr = new Primitive(P_CYLINDER); |
---|
| 564 | pr->setName("primitive"); |
---|
| 565 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
---|
| 566 | */ |
---|
[3521] | 567 | |
---|
[4010] | 568 | /*monitor progress*/ |
---|
| 569 | this->glmis->step(); |
---|
[2816] | 570 | |
---|
[4010] | 571 | // trackManager->setBindSlave(env); |
---|
| 572 | PNode* tn = trackManager->getTrackNode(); |
---|
| 573 | tn->addChild(this->localPlayer); |
---|
| 574 | this->localCamera->lookAt(tn); |
---|
[3539] | 575 | |
---|
[4010] | 576 | //localCamera->setParent(TrackNode::getInstance()); |
---|
| 577 | tn->addChild(this->localCamera); |
---|
| 578 | // localCamera->lookAt(tn); |
---|
| 579 | this->localPlayer->setMode(PNODE_ALL); |
---|
| 580 | //Vector* cameraOffset = new Vector (0, 5, -10); |
---|
| 581 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
| 582 | this->glmis->step(); |
---|
| 583 | break; |
---|
| 584 | } |
---|
| 585 | case DEBUG_WORLD_1: |
---|
| 586 | { |
---|
| 587 | lightMan->setPosition(.0, .0, .0); |
---|
| 588 | lightMan->setAttenuation(1.0, .01, 0.0); |
---|
| 589 | lightMan->setSpecularColor(1,0,0); |
---|
| 590 | this->nullParent = NullParent::getInstance (); |
---|
| 591 | this->nullParent->setName ("NullParent"); |
---|
[3365] | 592 | |
---|
[4010] | 593 | // create a player |
---|
| 594 | WorldEntity* myPlayer = new Player(); |
---|
| 595 | myPlayer->setName ("player"); |
---|
| 596 | this->spawn(myPlayer); |
---|
| 597 | this->localPlayer = myPlayer; |
---|
[2636] | 598 | |
---|
[4010] | 599 | // bind input |
---|
| 600 | Orxonox *orx = Orxonox::getInstance(); |
---|
| 601 | orx->getLocalInput()->bind (myPlayer); |
---|
[2636] | 602 | |
---|
[4010] | 603 | // bind camera |
---|
| 604 | this->localCamera = new Camera (); |
---|
| 605 | this->localCamera->setName ("camera"); |
---|
| 606 | this->localCamera->lookAt(LightManager::getInstance()->getLight(0)); |
---|
| 607 | this->localCamera->setParent(this->localPlayer); |
---|
[3429] | 608 | |
---|
[4010] | 609 | // Create SkySphere |
---|
[4094] | 610 | sky = new Skysphere("pictures/sky-replace.jpg"); |
---|
[4015] | 611 | this->localPlayer->addChild(this->sky); |
---|
| 612 | this->spawn(this->sky); |
---|
[4010] | 613 | Vector* es = new Vector (20, 0, 0); |
---|
| 614 | Quaternion* qs = new Quaternion (); |
---|
[3586] | 615 | |
---|
[4010] | 616 | lightMan->getLight(0)->setParent(trackManager->getTrackNode()); |
---|
| 617 | break; |
---|
| 618 | } |
---|
| 619 | case DEBUG_WORLD_2: |
---|
| 620 | { |
---|
| 621 | lightMan->setAmbientColor(.1,.1,.1); |
---|
| 622 | lightMan->addLight(); |
---|
| 623 | lightMan->setPosition(-5.0, 10.0, -40.0); |
---|
| 624 | this->nullParent = NullParent::getInstance (); |
---|
| 625 | this->nullParent->setName ("NullParent"); |
---|
[3727] | 626 | |
---|
[4010] | 627 | // !\todo old track-system has to be removed |
---|
[3727] | 628 | |
---|
[4010] | 629 | //create helper for player |
---|
| 630 | //HelperParent* hp = new HelperParent (); |
---|
| 631 | /* the player has to be added to this helper */ |
---|
[3727] | 632 | |
---|
[4010] | 633 | // create a player |
---|
| 634 | this->localPlayer = new Player (); |
---|
| 635 | this->localPlayer->setName ("player"); |
---|
| 636 | this->spawn (this->localPlayer); |
---|
| 637 | /*monitor progress*/ |
---|
| 638 | //this->glmis->step(); |
---|
| 639 | this->glmis->step(); |
---|
[3727] | 640 | |
---|
[4010] | 641 | // bind input |
---|
| 642 | Orxonox *orx = Orxonox::getInstance (); |
---|
| 643 | orx->getLocalInput()->bind (this->localPlayer); |
---|
[3727] | 644 | |
---|
[4010] | 645 | // bind camera |
---|
| 646 | this->localCamera = new Camera(); |
---|
| 647 | this->localCamera->setName ("camera"); |
---|
| 648 | this->localCamera->lookAt(this->localPlayer); |
---|
| 649 | this->localCamera->setParent(this->localPlayer); |
---|
[3727] | 650 | |
---|
[4010] | 651 | /*monitor progress*/ |
---|
| 652 | this->glmis->step(); |
---|
[3727] | 653 | |
---|
[4010] | 654 | // Create SkySphere |
---|
[4094] | 655 | this->sky = new Skysphere("pictures/sky-replace.jpg"); |
---|
[4015] | 656 | this->sky->setName("SkySphere"); |
---|
| 657 | this->spawn(this->sky); |
---|
| 658 | this->localCamera->addChild(this->sky); |
---|
| 659 | this->sky->setMode(PNODE_MOVEMENT); |
---|
[4010] | 660 | /*monitor progress*/ |
---|
| 661 | this->glmis->step(); |
---|
[3727] | 662 | |
---|
| 663 | |
---|
[4010] | 664 | WorldEntity* baseNode = new Satellite(Vector(1,0,1), 1.2); |
---|
| 665 | this->localPlayer->addChild(baseNode); |
---|
| 666 | baseNode->setRelCoor(Vector(10.0, 2.0, 1.0)); |
---|
| 667 | this->spawn(baseNode); |
---|
[3730] | 668 | |
---|
[4010] | 669 | WorldEntity* secondNode = new Satellite(Vector(0,0,1), 2.0); |
---|
| 670 | baseNode->addChild(secondNode); |
---|
| 671 | secondNode->setRelCoor(Vector(0.0, 0.0, 3.0)); |
---|
| 672 | this->spawn(secondNode); |
---|
[3729] | 673 | |
---|
[3750] | 674 | |
---|
[4010] | 675 | WorldEntity* thirdNode = new Satellite(Vector(0,0,1), 1.0); |
---|
| 676 | secondNode->addChild(thirdNode); |
---|
| 677 | thirdNode->setRelCoor(Vector(2.0, 0.0, 0.0)); |
---|
| 678 | this->spawn(thirdNode); |
---|
[3750] | 679 | |
---|
[3752] | 680 | |
---|
[3964] | 681 | |
---|
[4010] | 682 | WorldEntity* c = new Environment(); |
---|
| 683 | this->localPlayer->addChild(c); |
---|
| 684 | c->setRelCoor(Vector(10.0, 2.0, -1.0)); |
---|
| 685 | this->spawn(c); |
---|
[3967] | 686 | |
---|
| 687 | |
---|
[3745] | 688 | |
---|
[4010] | 689 | Animation3D* animation = new Animation3D(c); |
---|
| 690 | animation->setInfinity(ANIM_INF_REPLAY); |
---|
[3972] | 691 | |
---|
[3964] | 692 | |
---|
[4010] | 693 | animation->addKeyFrame(Vector(0, 0, 0), Quaternion(0, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
| 694 | animation->addKeyFrame(Vector(0, 2, 0), Quaternion(M_PI, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
| 695 | animation->addKeyFrame(Vector(0, 0, 0), Quaternion(0, Vector(0,1,0)), 1.0, ANIM_NEG_EXP, ANIM_LINEAR); |
---|
[3964] | 696 | |
---|
[3967] | 697 | |
---|
| 698 | |
---|
| 699 | |
---|
[3984] | 700 | |
---|
| 701 | |
---|
[4010] | 702 | /* |
---|
| 703 | KeyFrame* f1 = new KeyFrame; |
---|
| 704 | f1->position = new Vector(-1.1, 0.0, 2.6); |
---|
| 705 | f1->direction = new Quaternion(); |
---|
| 706 | f1->time = 1.0; |
---|
| 707 | f1->mode = NEG_EXP; |
---|
[3848] | 708 | |
---|
| 709 | |
---|
[4010] | 710 | KeyFrame* f2 = new KeyFrame; |
---|
| 711 | f2->position = new Vector(-2.1, 0.0, 2.6); |
---|
| 712 | f2->direction = new Quaternion(); |
---|
| 713 | f2->time = 0.1; |
---|
| 714 | f2->mode = NEG_EXP; |
---|
[3848] | 715 | |
---|
[4010] | 716 | KeyFrame* f3 = new KeyFrame; |
---|
| 717 | f3->position = new Vector(10.0, 2.0, -1.0); |
---|
| 718 | f3->direction = new Quaternion(); |
---|
| 719 | f3->time = 0.2; |
---|
| 720 | f3->mode = NEG_EXP; |
---|
[3848] | 721 | |
---|
[4010] | 722 | KeyFrame* f4 = new KeyFrame; |
---|
| 723 | f4->position = new Vector(10.0, 5.0, -1.0); |
---|
| 724 | f4->direction = new Quaternion(); |
---|
| 725 | f4->time = 1.0; |
---|
| 726 | f4->mode = NEG_EXP; |
---|
[3848] | 727 | |
---|
| 728 | |
---|
| 729 | |
---|
[4010] | 730 | this->simpleAnimation->animatorBegin(); |
---|
| 731 | this->simpleAnimation->selectObject(b); |
---|
| 732 | this->simpleAnimation->setAnimationMode(SINGLE); |
---|
| 733 | this->simpleAnimation->addKeyFrame(f1); |
---|
| 734 | this->simpleAnimation->addKeyFrame(f2); |
---|
| 735 | this->simpleAnimation->start(); |
---|
| 736 | this->simpleAnimation->selectObject(c); |
---|
| 737 | this->simpleAnimation->addKeyFrame(f3); |
---|
| 738 | this->simpleAnimation->addKeyFrame(f4); |
---|
| 739 | this->simpleAnimation->start(); |
---|
| 740 | this->simpleAnimation->animatorEnd(); |
---|
| 741 | */ |
---|
[3729] | 742 | |
---|
[4010] | 743 | /* |
---|
| 744 | Vector* es = new Vector (10, 5, 0); |
---|
| 745 | Quaternion* qs = new Quaternion (); |
---|
| 746 | WorldEntity* pr = new Primitive(P_CYLINDER); |
---|
| 747 | pr->setName("primitive"); |
---|
| 748 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
---|
| 749 | */ |
---|
[3727] | 750 | |
---|
[4010] | 751 | /*monitor progress*/ |
---|
| 752 | this->glmis->step(); |
---|
[3727] | 753 | |
---|
[4010] | 754 | // trackManager->setBindSlave(env); |
---|
| 755 | PNode* tn = trackManager->getTrackNode(); |
---|
| 756 | tn->addChild(this->localPlayer); |
---|
[3727] | 757 | |
---|
[4010] | 758 | //localCamera->setParent(TrackNode::getInstance()); |
---|
| 759 | tn->addChild(this->localCamera); |
---|
| 760 | // localCamera->lookAt(tn); |
---|
| 761 | this->localPlayer->setMode(PNODE_ALL); |
---|
| 762 | //Vector* cameraOffset = new Vector (0, 5, -10); |
---|
| 763 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
---|
| 764 | this->glmis->step(); |
---|
[3727] | 765 | |
---|
[4010] | 766 | break; |
---|
| 767 | } |
---|
| 768 | default: |
---|
| 769 | printf("World::load() - no world with ID %i found", this->debugWorldNr ); |
---|
[2636] | 770 | } |
---|
[4010] | 771 | } |
---|
[2636] | 772 | |
---|
[2731] | 773 | |
---|
[3526] | 774 | |
---|
[3459] | 775 | /** |
---|
[3629] | 776 | \brief initializes a new World shortly before start |
---|
| 777 | |
---|
| 778 | this is the function, that will be loaded shortly before the world is |
---|
| 779 | started |
---|
[3459] | 780 | */ |
---|
| 781 | ErrorMessage World::init() |
---|
| 782 | { |
---|
| 783 | this->bPause = false; |
---|
| 784 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
| 785 | cn->addToWorld(this); |
---|
| 786 | cn->enable(true); |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | |
---|
| 790 | /** |
---|
| 791 | \brief starts the World |
---|
| 792 | */ |
---|
| 793 | ErrorMessage World::start() |
---|
| 794 | { |
---|
[3546] | 795 | PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
---|
[3459] | 796 | this->bQuitOrxonox = false; |
---|
| 797 | this->bQuitCurrentGame = false; |
---|
| 798 | this->mainLoop(); |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | /** |
---|
| 802 | \brief stops the world. |
---|
| 803 | |
---|
| 804 | This happens, when the player decides to end the Level. |
---|
| 805 | */ |
---|
| 806 | ErrorMessage World::stop() |
---|
| 807 | { |
---|
[3546] | 808 | PRINTF(3)("World::stop() - got stop signal\n"); |
---|
[3459] | 809 | this->bQuitCurrentGame = true; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | /** |
---|
| 813 | \brief pauses the Game |
---|
| 814 | */ |
---|
| 815 | ErrorMessage World::pause() |
---|
| 816 | { |
---|
| 817 | this->isPaused = true; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | /** |
---|
| 821 | \brief ends the pause Phase |
---|
| 822 | */ |
---|
| 823 | ErrorMessage World::resume() |
---|
| 824 | { |
---|
| 825 | this->isPaused = false; |
---|
| 826 | } |
---|
| 827 | |
---|
| 828 | /** |
---|
| 829 | \brief destroys the World |
---|
| 830 | */ |
---|
| 831 | ErrorMessage World::destroy() |
---|
| 832 | { |
---|
[3566] | 833 | |
---|
[3459] | 834 | } |
---|
| 835 | |
---|
| 836 | /** |
---|
| 837 | \brief shows the loading screen |
---|
| 838 | */ |
---|
| 839 | void World::displayLoadScreen () |
---|
| 840 | { |
---|
[3546] | 841 | PRINTF(3)("World::displayLoadScreen - start\n"); |
---|
[3459] | 842 | |
---|
| 843 | //GLMenuImageScreen* |
---|
[4099] | 844 | this->glmis = new GLMenuImageScreen(); |
---|
[3459] | 845 | this->glmis->init(); |
---|
[4099] | 846 | glmis->setBackgroundImage("pictures/load_screen.jpg"); |
---|
[3675] | 847 | this->glmis->setMaximum(8); |
---|
[4104] | 848 | // this->glmis->draw(); |
---|
[3459] | 849 | |
---|
[3546] | 850 | PRINTF(3)("World::displayLoadScreen - end\n"); |
---|
[3459] | 851 | } |
---|
| 852 | |
---|
| 853 | /** |
---|
| 854 | \brief removes the loadscreen, and changes over to the game |
---|
| 855 | |
---|
| 856 | \todo take out the delay |
---|
| 857 | */ |
---|
| 858 | void World::releaseLoadScreen () |
---|
| 859 | { |
---|
[3546] | 860 | PRINTF(3)("World::releaseLoadScreen - start\n"); |
---|
[3459] | 861 | this->glmis->setValue(this->glmis->getMaximum()); |
---|
[3546] | 862 | PRINTF(3)("World::releaseLoadScreen - end\n"); |
---|
[4099] | 863 | delete this->glmis; |
---|
[3459] | 864 | } |
---|
| 865 | |
---|
| 866 | |
---|
[3620] | 867 | /** |
---|
| 868 | \brief gets the list of entities from the world |
---|
| 869 | \returns entity list |
---|
| 870 | */ |
---|
| 871 | tList<WorldEntity>* World::getEntities() |
---|
| 872 | { |
---|
| 873 | return this->entities; |
---|
| 874 | } |
---|
| 875 | |
---|
| 876 | |
---|
[3646] | 877 | /** |
---|
| 878 | \brief this returns the current game time |
---|
| 879 | \returns elapsed game time |
---|
| 880 | */ |
---|
| 881 | double World::getGameTime() |
---|
| 882 | { |
---|
| 883 | return this->gameTime; |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | |
---|
[2636] | 887 | /** |
---|
[2551] | 888 | \brief checks for collisions |
---|
| 889 | |
---|
| 890 | This method runs through all WorldEntities known to the world and checks for collisions |
---|
| 891 | between them. In case of collisions the collide() method of the corresponding entities |
---|
| 892 | is called. |
---|
[1858] | 893 | */ |
---|
[2190] | 894 | void World::collide () |
---|
[1858] | 895 | { |
---|
[2816] | 896 | /* |
---|
| 897 | List *a, *b; |
---|
[2551] | 898 | WorldEntity *aobj, *bobj; |
---|
[2816] | 899 | |
---|
| 900 | a = entities; |
---|
[2551] | 901 | |
---|
| 902 | while( a != NULL) |
---|
| 903 | { |
---|
[2816] | 904 | aobj = a->nextElement(); |
---|
[2551] | 905 | if( aobj->bCollide && aobj->collisioncluster != NULL) |
---|
[2190] | 906 | { |
---|
[2816] | 907 | b = a->nextElement(); |
---|
[2551] | 908 | while( b != NULL ) |
---|
| 909 | { |
---|
[2816] | 910 | bobj = b->nextElement(); |
---|
[2551] | 911 | if( bobj->bCollide && bobj->collisioncluster != NULL ) |
---|
[2190] | 912 | { |
---|
[2551] | 913 | unsigned long ahitflg, bhitflg; |
---|
| 914 | if( check_collision ( &aobj->place, aobj->collisioncluster, |
---|
| 915 | &ahitflg, &bobj->place, bobj->collisioncluster, |
---|
| 916 | &bhitflg) ); |
---|
| 917 | { |
---|
| 918 | aobj->collide (bobj, ahitflg, bhitflg); |
---|
| 919 | bobj->collide (aobj, bhitflg, ahitflg); |
---|
| 920 | } |
---|
[2190] | 921 | } |
---|
[2816] | 922 | b = b->nextElement(); |
---|
[2551] | 923 | } |
---|
[2190] | 924 | } |
---|
[2816] | 925 | a = a->enumerate(); |
---|
[2551] | 926 | } |
---|
[2816] | 927 | */ |
---|
[1858] | 928 | } |
---|
| 929 | |
---|
| 930 | /** |
---|
[2551] | 931 | \brief runs through all entities calling their draw() methods |
---|
[1931] | 932 | */ |
---|
[2190] | 933 | void World::draw () |
---|
[2077] | 934 | { |
---|
[3462] | 935 | /* draw entities */ |
---|
[2551] | 936 | WorldEntity* entity; |
---|
[3526] | 937 | glLoadIdentity(); |
---|
| 938 | |
---|
[3653] | 939 | //entity = this->entities->enumerate(); |
---|
| 940 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
| 941 | entity = iterator->nextElement(); |
---|
[2816] | 942 | while( entity != NULL ) |
---|
[2551] | 943 | { |
---|
[2822] | 944 | if( entity->bDraw ) entity->draw(); |
---|
[3653] | 945 | //entity = this->entities->nextElement(); |
---|
| 946 | entity = iterator->nextElement(); |
---|
| 947 | } |
---|
| 948 | delete iterator; |
---|
[2551] | 949 | |
---|
[2731] | 950 | glCallList (objectList); |
---|
[3419] | 951 | |
---|
[3790] | 952 | TextEngine::getInstance()->draw(); |
---|
[3602] | 953 | lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes // |
---|
[1931] | 954 | } |
---|
| 955 | |
---|
[2816] | 956 | |
---|
[2190] | 957 | /** |
---|
[3225] | 958 | \brief function to put your own debug stuff into it. it can display informations about |
---|
| 959 | the current class/procedure |
---|
| 960 | */ |
---|
[2640] | 961 | void World::debug() |
---|
| 962 | { |
---|
[3546] | 963 | PRINTF(2)("debug() - starting debug\n"); |
---|
[3365] | 964 | PNode* p1 = NullParent::getInstance (); |
---|
[3809] | 965 | PNode* p2 = new PNode (Vector(2, 2, 2), p1); |
---|
| 966 | PNode* p3 = new PNode (Vector(4, 4, 4), p1); |
---|
| 967 | PNode* p4 = new PNode (Vector(6, 6, 6), p2); |
---|
[3365] | 968 | |
---|
| 969 | p1->debug (); |
---|
| 970 | p2->debug (); |
---|
| 971 | p3->debug (); |
---|
| 972 | p4->debug (); |
---|
| 973 | |
---|
[3809] | 974 | p1->shiftCoor (Vector(-1, -1, -1)); |
---|
[3365] | 975 | |
---|
| 976 | printf("World::debug() - shift\n"); |
---|
| 977 | p1->debug (); |
---|
| 978 | p2->debug (); |
---|
| 979 | p3->debug (); |
---|
| 980 | p4->debug (); |
---|
| 981 | |
---|
[3644] | 982 | p1->update (0); |
---|
[3365] | 983 | |
---|
| 984 | printf ("World::debug() - update\n"); |
---|
| 985 | p1->debug (); |
---|
| 986 | p2->debug (); |
---|
| 987 | p3->debug (); |
---|
| 988 | p4->debug (); |
---|
| 989 | |
---|
[3809] | 990 | p2->shiftCoor (Vector(-1, -1, -1)); |
---|
[3644] | 991 | p1->update (0); |
---|
[3365] | 992 | |
---|
| 993 | p1->debug (); |
---|
| 994 | p2->debug (); |
---|
| 995 | p3->debug (); |
---|
| 996 | p4->debug (); |
---|
| 997 | |
---|
[3809] | 998 | p2->setAbsCoor (Vector(1,2,3)); |
---|
[3365] | 999 | |
---|
| 1000 | |
---|
[3644] | 1001 | p1->update (0); |
---|
[3365] | 1002 | |
---|
| 1003 | p1->debug (); |
---|
| 1004 | p2->debug (); |
---|
| 1005 | p3->debug (); |
---|
| 1006 | p4->debug (); |
---|
| 1007 | |
---|
[3544] | 1008 | delete p1; |
---|
[3365] | 1009 | |
---|
| 1010 | |
---|
| 1011 | /* |
---|
[2640] | 1012 | WorldEntity* entity; |
---|
| 1013 | printf("counting all entities\n"); |
---|
[2816] | 1014 | printf("World::debug() - enumerate()\n"); |
---|
| 1015 | entity = entities->enumerate(); |
---|
| 1016 | while( entity != NULL ) |
---|
[2640] | 1017 | { |
---|
| 1018 | if( entity->bDraw ) printf("got an entity\n"); |
---|
[2816] | 1019 | entity = entities->nextElement(); |
---|
[2640] | 1020 | } |
---|
[3365] | 1021 | */ |
---|
[2640] | 1022 | } |
---|
[2636] | 1023 | |
---|
[2640] | 1024 | |
---|
[3449] | 1025 | /** |
---|
[3225] | 1026 | \brief main loop of the world: executing all world relevant function |
---|
| 1027 | |
---|
| 1028 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
---|
| 1029 | all other member-entities of the world (tick to player, enemies etc.), checking for |
---|
| 1030 | collisions drawing everything to the screen. |
---|
| 1031 | */ |
---|
[2636] | 1032 | void World::mainLoop() |
---|
| 1033 | { |
---|
[3365] | 1034 | this->lastFrame = SDL_GetTicks (); |
---|
[3546] | 1035 | PRINTF(3)("World::mainLoop() - Entering main loop\n"); |
---|
[3215] | 1036 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ |
---|
[2551] | 1037 | { |
---|
[3546] | 1038 | PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize()); |
---|
[2636] | 1039 | // Network |
---|
[3365] | 1040 | this->synchronize (); |
---|
[2636] | 1041 | // Process input |
---|
[3365] | 1042 | this->handleInput (); |
---|
[3215] | 1043 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
---|
| 1044 | break; |
---|
[2636] | 1045 | // Process time |
---|
[3551] | 1046 | this->tick (); |
---|
| 1047 | // Update the state |
---|
[4010] | 1048 | this->update (); |
---|
[2636] | 1049 | // Process collision |
---|
[3459] | 1050 | this->collide (); |
---|
[2636] | 1051 | // Draw |
---|
[3365] | 1052 | this->display (); |
---|
[3548] | 1053 | |
---|
[3565] | 1054 | // for( int i = 0; i < 5000000; i++) {} |
---|
[3365] | 1055 | /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
---|
[2551] | 1056 | } |
---|
[3546] | 1057 | PRINTF(3)("World::mainLoop() - Exiting the main loop\n"); |
---|
[1899] | 1058 | } |
---|
| 1059 | |
---|
[3459] | 1060 | |
---|
[2190] | 1061 | /** |
---|
[2636] | 1062 | \brief synchronize local data with remote data |
---|
[1855] | 1063 | */ |
---|
[2636] | 1064 | void World::synchronize () |
---|
[1855] | 1065 | { |
---|
[2636] | 1066 | // Get remote input |
---|
| 1067 | // Update synchronizables |
---|
[1855] | 1068 | } |
---|
[2636] | 1069 | |
---|
[3459] | 1070 | |
---|
[2636] | 1071 | /** |
---|
| 1072 | \brief run all input processing |
---|
[3225] | 1073 | |
---|
| 1074 | the command node is the central input event dispatcher. the node uses the even-queue from |
---|
| 1075 | sdl and has its own event-passing-queue. |
---|
[2636] | 1076 | */ |
---|
[3225] | 1077 | void World::handleInput () |
---|
[2636] | 1078 | { |
---|
| 1079 | // localinput |
---|
[3225] | 1080 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
---|
[3216] | 1081 | cn->process(); |
---|
[2636] | 1082 | // remoteinput |
---|
| 1083 | } |
---|
| 1084 | |
---|
[3459] | 1085 | |
---|
[2636] | 1086 | /** |
---|
| 1087 | \brief advance the timeline |
---|
[3225] | 1088 | |
---|
| 1089 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
---|
| 1090 | the time is mesured in ms and passed to all world-entities and other classes that need |
---|
| 1091 | a heart-beat. |
---|
[2636] | 1092 | */ |
---|
[3551] | 1093 | void World::tick () |
---|
[2636] | 1094 | { |
---|
| 1095 | Uint32 currentFrame = SDL_GetTicks(); |
---|
| 1096 | if(!this->bPause) |
---|
| 1097 | { |
---|
[3644] | 1098 | this->dt = currentFrame - this->lastFrame; |
---|
[2816] | 1099 | |
---|
[3646] | 1100 | if( this->dt > 0) |
---|
[2636] | 1101 | { |
---|
| 1102 | float fps = 1000/dt; |
---|
[3790] | 1103 | |
---|
| 1104 | // temporary, only for showing how fast the text-engine is |
---|
| 1105 | char tmpChar[20]; |
---|
| 1106 | sprintf(tmpChar, "fps: %4.0f", fps); |
---|
[2636] | 1107 | } |
---|
| 1108 | else |
---|
| 1109 | { |
---|
[3225] | 1110 | /* the frame-rate is limited to 100 frames per second, all other things are for |
---|
| 1111 | nothing. |
---|
| 1112 | */ |
---|
[3546] | 1113 | PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); |
---|
[3194] | 1114 | SDL_Delay(10); |
---|
[3646] | 1115 | this->dt = 10; |
---|
[2636] | 1116 | } |
---|
[3459] | 1117 | //this->timeSlice (dt); |
---|
| 1118 | |
---|
| 1119 | /* function to let all entities tick (iterate through list) */ |
---|
[3646] | 1120 | float seconds = this->dt / 1000.0; |
---|
| 1121 | this->gameTime += seconds; |
---|
[3654] | 1122 | //entity = entities->enumerate(); |
---|
| 1123 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
---|
| 1124 | WorldEntity* entity = iterator->nextElement(); |
---|
[3459] | 1125 | while( entity != NULL) |
---|
| 1126 | { |
---|
| 1127 | entity->tick (seconds); |
---|
[3654] | 1128 | entity = iterator->nextElement(); |
---|
[3459] | 1129 | } |
---|
[3654] | 1130 | delete iterator; |
---|
[4010] | 1131 | |
---|
[3459] | 1132 | /* update tick the rest */ |
---|
[3646] | 1133 | this->trackManager->tick(this->dt); |
---|
| 1134 | this->localCamera->tick(this->dt); |
---|
| 1135 | this->garbageCollector->tick(seconds); |
---|
[3851] | 1136 | |
---|
[3812] | 1137 | AnimationPlayer::getInstance()->tick(seconds); |
---|
[2636] | 1138 | } |
---|
| 1139 | this->lastFrame = currentFrame; |
---|
| 1140 | } |
---|
| 1141 | |
---|
[3216] | 1142 | |
---|
[2636] | 1143 | /** |
---|
[3551] | 1144 | \brief this function gives the world a consistant state |
---|
| 1145 | |
---|
| 1146 | after ticking (updating the world state) this will give a constistant |
---|
| 1147 | state to the whole system. |
---|
| 1148 | */ |
---|
| 1149 | void World::update() |
---|
| 1150 | { |
---|
[3646] | 1151 | this->garbageCollector->update(); |
---|
[3644] | 1152 | this->nullParent->update (dt); |
---|
[3551] | 1153 | } |
---|
| 1154 | |
---|
| 1155 | |
---|
| 1156 | /** |
---|
[3225] | 1157 | \brief render the current frame |
---|
| 1158 | |
---|
| 1159 | clear all buffers and draw the world |
---|
[2636] | 1160 | */ |
---|
| 1161 | void World::display () |
---|
| 1162 | { |
---|
| 1163 | // clear buffer |
---|
| 1164 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 1165 | // set camera |
---|
| 1166 | this->localCamera->apply (); |
---|
| 1167 | // draw world |
---|
| 1168 | this->draw(); |
---|
| 1169 | // draw HUD |
---|
[3365] | 1170 | /* \todo draw HUD */ |
---|
[2636] | 1171 | // flip buffers |
---|
| 1172 | SDL_GL_SwapBuffers(); |
---|
[3365] | 1173 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
---|
| 1174 | //SDL_Flip (screen); |
---|
[2636] | 1175 | } |
---|
| 1176 | |
---|
[2644] | 1177 | |
---|
[3225] | 1178 | /** |
---|
| 1179 | \brief add and spawn a new entity to this world |
---|
| 1180 | \param entity to be added |
---|
| 1181 | */ |
---|
[2644] | 1182 | void World::spawn(WorldEntity* entity) |
---|
| 1183 | { |
---|
[3365] | 1184 | this->entities->add (entity); |
---|
[3233] | 1185 | entity->postSpawn (); |
---|
[2816] | 1186 | } |
---|
| 1187 | |
---|
| 1188 | |
---|
[3225] | 1189 | /** |
---|
| 1190 | \brief add and spawn a new entity to this world |
---|
| 1191 | \param entity to be added |
---|
[3449] | 1192 | \param absCoor At what coordinates to add this entity. |
---|
| 1193 | \param absDir In which direction should it look. |
---|
[3225] | 1194 | */ |
---|
[3365] | 1195 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
---|
[2816] | 1196 | { |
---|
[3529] | 1197 | this->entities->add (entity); |
---|
| 1198 | |
---|
[3809] | 1199 | entity->setAbsCoor (*absCoor); |
---|
| 1200 | entity->setAbsDir (*absDir); |
---|
[3365] | 1201 | |
---|
[3233] | 1202 | entity->postSpawn (); |
---|
[2644] | 1203 | } |
---|
[2816] | 1204 | |
---|
| 1205 | |
---|
[3521] | 1206 | /** |
---|
| 1207 | \brief add and spawn a new entity to this world |
---|
| 1208 | \param entity to be added |
---|
| 1209 | \param entity to be added to (PNode) |
---|
| 1210 | \param At what relative coordinates to add this entity. |
---|
| 1211 | \param In which relative direction should it look. |
---|
| 1212 | */ |
---|
| 1213 | void World::spawn(WorldEntity* entity, PNode* parentNode, |
---|
| 1214 | Vector* relCoor, Quaternion* relDir, |
---|
[3565] | 1215 | int parentingMode) |
---|
[3521] | 1216 | { |
---|
[3551] | 1217 | this->nullParent = NullParent::getInstance(); |
---|
[3529] | 1218 | if( parentNode != NULL) |
---|
[3521] | 1219 | { |
---|
| 1220 | parentNode->addChild (entity); |
---|
| 1221 | |
---|
[3809] | 1222 | entity->setRelCoor (*relCoor); |
---|
| 1223 | entity->setRelDir (*relDir); |
---|
[3586] | 1224 | entity->setMode(parentingMode); |
---|
[3521] | 1225 | |
---|
| 1226 | this->entities->add (entity); |
---|
| 1227 | |
---|
| 1228 | entity->postSpawn (); |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | |
---|
| 1233 | |
---|
[3449] | 1234 | /** |
---|
[3225] | 1235 | \brief commands that the world must catch |
---|
| 1236 | \returns false if not used by the world |
---|
| 1237 | */ |
---|
[3216] | 1238 | bool World::command(Command* cmd) |
---|
| 1239 | { |
---|
[4091] | 1240 | if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW0)) this->localCamera->setViewMode(VIEW_NORMAL); |
---|
| 1241 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW1)) this->localCamera->setViewMode(VIEW_BEHIND); |
---|
| 1242 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW2)) this->localCamera->setViewMode(VIEW_FRONT); |
---|
| 1243 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW3)) this->localCamera->setViewMode(VIEW_LEFT); |
---|
| 1244 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT); |
---|
| 1245 | else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP); |
---|
[3798] | 1246 | |
---|
[3216] | 1247 | return false; |
---|
| 1248 | } |
---|
[3365] | 1249 | |
---|
[4010] | 1250 | void World::setPath( const char* name) |
---|
| 1251 | { |
---|
[4094] | 1252 | if (this->path) |
---|
| 1253 | delete this->path; |
---|
| 1254 | if (ResourceManager::isFile(name)) |
---|
| 1255 | { |
---|
| 1256 | this->path = new char[strlen(name)+1]; |
---|
| 1257 | strcpy(this->path, name); |
---|
| 1258 | } |
---|
| 1259 | else |
---|
| 1260 | { |
---|
| 1261 | this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1]; |
---|
| 1262 | sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name); |
---|
| 1263 | } |
---|
[4010] | 1264 | } |
---|
| 1265 | |
---|
| 1266 | const char* World::getPath( void) |
---|
| 1267 | { |
---|
| 1268 | return path; |
---|
| 1269 | } |
---|