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