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