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