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