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