| 1 | |
|---|
| 2 | /* |
|---|
| 3 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 4 | |
|---|
| 5 | Copyright (C) 2004 orx |
|---|
| 6 | |
|---|
| 7 | This program is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 10 | any later version. |
|---|
| 11 | |
|---|
| 12 | ### File Specific: |
|---|
| 13 | main-programmer: Patrick Boenzli |
|---|
| 14 | co-programmer: Christian Meyer |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
|---|
| 18 | |
|---|
| 19 | #include "world.h" |
|---|
| 20 | |
|---|
| 21 | #include "orxonox.h" |
|---|
| 22 | |
|---|
| 23 | #include "p_node.h" |
|---|
| 24 | #include "null_parent.h" |
|---|
| 25 | #include "helper_parent.h" |
|---|
| 26 | #include "track_node.h" |
|---|
| 27 | #include "world_entity.h" |
|---|
| 28 | #include "player.h" |
|---|
| 29 | #include "camera.h" |
|---|
| 30 | #include "environment.h" |
|---|
| 31 | #include "skysphere.h" |
|---|
| 32 | #include "skybox.h" |
|---|
| 33 | #include "satellite.h" |
|---|
| 34 | #include "terrain.h" |
|---|
| 35 | #include "light.h" |
|---|
| 36 | #include "text_engine.h" |
|---|
| 37 | |
|---|
| 38 | #include "track_manager.h" |
|---|
| 39 | #include "garbage_collector.h" |
|---|
| 40 | #include "animation_player.h" |
|---|
| 41 | |
|---|
| 42 | #include "command_node.h" |
|---|
| 43 | #include "glmenu_imagescreen.h" |
|---|
| 44 | #include "list.h" |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | using namespace std; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | WorldInterface* WorldInterface::singletonRef = 0; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | \brief private constructor because of singleton |
|---|
| 56 | */ |
|---|
| 57 | WorldInterface::WorldInterface() |
|---|
| 58 | { |
|---|
| 59 | this->worldIsInitialized = false; |
|---|
| 60 | this->worldReference = NULL; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | \brief public deconstructor |
|---|
| 65 | */ |
|---|
| 66 | WorldInterface::~WorldInterface() |
|---|
| 67 | { |
|---|
| 68 | this->singletonRef = NULL; |
|---|
| 69 | this->worldIsInitialized = false; |
|---|
| 70 | this->worldReference = NULL; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | \brief gets the singleton instance |
|---|
| 75 | \returns singleton instance |
|---|
| 76 | */ |
|---|
| 77 | WorldInterface* WorldInterface::getInstance() |
|---|
| 78 | { |
|---|
| 79 | if( singletonRef == NULL) |
|---|
| 80 | singletonRef = new WorldInterface(); |
|---|
| 81 | return singletonRef; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | \brief initializes the interface |
|---|
| 87 | \param reference to the world |
|---|
| 88 | |
|---|
| 89 | if the worldinterface is not initilizes, there wont be any |
|---|
| 90 | useable interface |
|---|
| 91 | */ |
|---|
| 92 | void WorldInterface::init(World* world) |
|---|
| 93 | { |
|---|
| 94 | this->worldReference = world; |
|---|
| 95 | if( world != NULL) |
|---|
| 96 | { |
|---|
| 97 | this->worldIsInitialized = true; |
|---|
| 98 | PRINTF(3)("WorldInterface up and running\n"); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | \brief gets the entity list from the world |
|---|
| 105 | \return entity list |
|---|
| 106 | */ |
|---|
| 107 | tList<WorldEntity>* WorldInterface::getEntityList() |
|---|
| 108 | { |
|---|
| 109 | if( this->worldIsInitialized) |
|---|
| 110 | return this->worldReference->getEntities(); |
|---|
| 111 | PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n"); |
|---|
| 112 | return NULL; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | \brief create a new World |
|---|
| 119 | |
|---|
| 120 | This creates a new empty world! |
|---|
| 121 | */ |
|---|
| 122 | World::World (char* name) |
|---|
| 123 | { |
|---|
| 124 | this->init(name, -1); |
|---|
| 125 | //NullParent* np = NullParent::getInstance(); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | \brief creates a new World... |
|---|
| 130 | \param worldID with this ID |
|---|
| 131 | */ |
|---|
| 132 | World::World (int worldID) |
|---|
| 133 | { |
|---|
| 134 | this->init(NULL, worldID); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /** |
|---|
| 138 | \brief remove the World from memory |
|---|
| 139 | |
|---|
| 140 | delete everything explicitly, that isn't contained in the parenting tree! |
|---|
| 141 | things contained in the tree are deleted automaticaly |
|---|
| 142 | */ |
|---|
| 143 | World::~World () |
|---|
| 144 | { |
|---|
| 145 | PRINTF(3)("World::~World() - deleting current world\n"); |
|---|
| 146 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
|---|
| 147 | cn->unbind(this->localPlayer); |
|---|
| 148 | cn->reset(); |
|---|
| 149 | |
|---|
| 150 | ResourceManager::getInstance()->debug(); |
|---|
| 151 | ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); |
|---|
| 152 | ResourceManager::getInstance()->debug(); |
|---|
| 153 | |
|---|
| 154 | delete WorldInterface::getInstance(); |
|---|
| 155 | |
|---|
| 156 | delete this->nullParent; |
|---|
| 157 | delete this->entities; |
|---|
| 158 | delete this->lightMan; |
|---|
| 159 | delete this->trackManager; |
|---|
| 160 | TextEngine::getInstance()->flush(); |
|---|
| 161 | |
|---|
| 162 | AnimationPlayer::getInstance()->debug(); |
|---|
| 163 | delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence. |
|---|
| 164 | //delete garbagecollecor |
|---|
| 165 | //delete animator |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | \brief initializes the world. |
|---|
| 172 | |
|---|
| 173 | set all stuff here that is world generic and does not use to much memory |
|---|
| 174 | because the real init() function StoryEntity::init() will be called |
|---|
| 175 | shortly before start of the game. |
|---|
| 176 | since all worlds are initiated/referenced before they will be started. |
|---|
| 177 | NO LEVEL LOADING HERE - NEVER! |
|---|
| 178 | */ |
|---|
| 179 | void World::init(char* name, int worldID) |
|---|
| 180 | { |
|---|
| 181 | this->setClassName ("World"); |
|---|
| 182 | |
|---|
| 183 | this->worldName = name; |
|---|
| 184 | this->debugWorldNr = worldID; |
|---|
| 185 | this->entities = new tList<WorldEntity>(); |
|---|
| 186 | AnimationPlayer::getInstance(); // initializes the animationPlayer |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | /** |
|---|
| 191 | \brief this is executed before load |
|---|
| 192 | |
|---|
| 193 | since the load function sometimes needs data, that has been init before |
|---|
| 194 | the load and after the proceeding storyentity has finished |
|---|
| 195 | */ |
|---|
| 196 | ErrorMessage World::preLoad() |
|---|
| 197 | { |
|---|
| 198 | /* init the world interface */ |
|---|
| 199 | WorldInterface* wi = WorldInterface::getInstance(); |
|---|
| 200 | wi->init(this); |
|---|
| 201 | this->garbageCollector = GarbageCollector::getInstance(); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | /** |
|---|
| 206 | \brief loads the World by initializing all resources, and set their default values. |
|---|
| 207 | */ |
|---|
| 208 | ErrorMessage World::load() |
|---|
| 209 | { |
|---|
| 210 | // BezierCurve* tmpCurve = new BezierCurve(); |
|---|
| 211 | if(this->debugWorldNr != -1) |
|---|
| 212 | { |
|---|
| 213 | // initializing Font |
|---|
| 214 | this->glmis->step(); |
|---|
| 215 | // initializing the TrackManager |
|---|
| 216 | trackManager = TrackManager::getInstance(); |
|---|
| 217 | //trackManager->addPoint(Vector(0,0,0)); |
|---|
| 218 | trackManager->addPoint(Vector(150, -35, 5)); |
|---|
| 219 | trackManager->addPoint(Vector(200,-35, 5)); |
|---|
| 220 | trackManager->addPoint(Vector(250, -35, 5)); |
|---|
| 221 | trackManager->addPoint(Vector(320,-33,-.55)); |
|---|
| 222 | trackManager->setDuration(2); |
|---|
| 223 | trackManager->setSavePoint(); |
|---|
| 224 | |
|---|
| 225 | trackManager->addPoint(Vector(410, 0, 0)); |
|---|
| 226 | trackManager->addPoint(Vector(510, 20, -10)); |
|---|
| 227 | trackManager->addPoint(Vector(550, 20, -10)); |
|---|
| 228 | trackManager->addPoint(Vector(570, 20, -10)); |
|---|
| 229 | trackManager->setDuration(5); |
|---|
| 230 | |
|---|
| 231 | int fork11, fork12; |
|---|
| 232 | trackManager->fork(2, &fork11, &fork12); |
|---|
| 233 | trackManager->workOn(fork11); |
|---|
| 234 | trackManager->addPoint(Vector(640, 25, -30)); |
|---|
| 235 | trackManager->addPoint(Vector(700, 40, -120)); |
|---|
| 236 | trackManager->addPoint(Vector(800, 50, -150)); |
|---|
| 237 | trackManager->addPoint(Vector(900, 60, -100)); |
|---|
| 238 | trackManager->addPoint(Vector(900, 60, -70)); |
|---|
| 239 | trackManager->addPoint(Vector(990, 65, -15)); |
|---|
| 240 | trackManager->addPoint(Vector(1050, 65, -10)); |
|---|
| 241 | trackManager->addPoint(Vector(1100, 65, -20)); |
|---|
| 242 | trackManager->setDuration(10); |
|---|
| 243 | |
|---|
| 244 | trackManager->workOn(fork12); |
|---|
| 245 | trackManager->addPoint(Vector(640, 25, 20)); |
|---|
| 246 | trackManager->addPoint(Vector(670, 50, 120)); |
|---|
| 247 | trackManager->addPoint(Vector(700, 70, 80)); |
|---|
| 248 | trackManager->addPoint(Vector(800, 70, 65)); |
|---|
| 249 | trackManager->addPoint(Vector(850, 65, 65)); |
|---|
| 250 | trackManager->addPoint(Vector(920, 35, 40)); |
|---|
| 251 | trackManager->addPoint(Vector(945, 40, 40)); |
|---|
| 252 | trackManager->addPoint(Vector(970, 24, 40)); |
|---|
| 253 | trackManager->addPoint(Vector(1000, 40, -7)); |
|---|
| 254 | trackManager->setDuration(10); |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | trackManager->join(2, fork11, fork12); |
|---|
| 258 | |
|---|
| 259 | trackManager->workOn(5); |
|---|
| 260 | trackManager->addPoint(Vector(1200, 60, -50)); |
|---|
| 261 | trackManager->addPoint(Vector(1300, 50, -50)); |
|---|
| 262 | trackManager->addPoint(Vector(1400, 40, -50)); |
|---|
| 263 | trackManager->addPoint(Vector(1500, 40, -60)); |
|---|
| 264 | trackManager->addPoint(Vector(1600, 35, -55)); |
|---|
| 265 | trackManager->addPoint(Vector(1700, 45, -40)); |
|---|
| 266 | trackManager->addPoint(Vector(1750, 60, -40)); |
|---|
| 267 | trackManager->addPoint(Vector(1770, 80, -40)); |
|---|
| 268 | trackManager->addPoint(Vector(1800, 100, -40)); |
|---|
| 269 | trackManager->setDuration(10); |
|---|
| 270 | |
|---|
| 271 | trackManager->finalize(); |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | /*monitor progress*/ |
|---|
| 275 | this->glmis->step(); |
|---|
| 276 | |
|---|
| 277 | // LIGHT initialisation |
|---|
| 278 | lightMan = LightManager::getInstance(); |
|---|
| 279 | lightMan->setAmbientColor(.1,.1,.1); |
|---|
| 280 | lightMan->addLight(); |
|---|
| 281 | // lightMan->setAttenuation(1.0, .01, 0.0); |
|---|
| 282 | // lightMan->setDiffuseColor(1,1,1); |
|---|
| 283 | // lightMan->addLight(1); |
|---|
| 284 | // lightMan->setPosition(20, 10, -20); |
|---|
| 285 | // lightMan->setDiffuseColor(0,0,0); |
|---|
| 286 | lightMan->debug(); |
|---|
| 287 | |
|---|
| 288 | switch(this->debugWorldNr) |
|---|
| 289 | { |
|---|
| 290 | /* |
|---|
| 291 | this loads the hard-coded debug world. this only for simplicity and will be |
|---|
| 292 | removed by a reald world-loader, which interprets a world-file. |
|---|
| 293 | if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and |
|---|
| 294 | make whatever you want... |
|---|
| 295 | */ |
|---|
| 296 | case DEBUG_WORLD_0: |
|---|
| 297 | { |
|---|
| 298 | lightMan->setPosition(-5.0, 10.0, -40.0); |
|---|
| 299 | this->nullParent = NullParent::getInstance (); |
|---|
| 300 | this->nullParent->setName ("NullParent"); |
|---|
| 301 | |
|---|
| 302 | // !\todo old track-system has to be removed |
|---|
| 303 | |
|---|
| 304 | //create helper for player |
|---|
| 305 | //HelperParent* hp = new HelperParent (); |
|---|
| 306 | /* the player has to be added to this helper */ |
|---|
| 307 | |
|---|
| 308 | // create a player |
|---|
| 309 | this->localPlayer = new Player (); |
|---|
| 310 | this->localPlayer->setName ("player"); |
|---|
| 311 | this->spawn (this->localPlayer); |
|---|
| 312 | /*monitor progress*/ |
|---|
| 313 | //this->glmis->step(); |
|---|
| 314 | this->glmis->step(); |
|---|
| 315 | |
|---|
| 316 | // bind input |
|---|
| 317 | Orxonox *orx = Orxonox::getInstance (); |
|---|
| 318 | orx->getLocalInput()->bind (this->localPlayer); |
|---|
| 319 | |
|---|
| 320 | // bind camera |
|---|
| 321 | this->localCamera = new Camera(); |
|---|
| 322 | this->localCamera->setName ("camera"); |
|---|
| 323 | this->localCamera->lookAt(this->localPlayer); |
|---|
| 324 | this->localCamera->setParent(this->localPlayer); |
|---|
| 325 | |
|---|
| 326 | /*monitor progress*/ |
|---|
| 327 | this->glmis->step(); |
|---|
| 328 | |
|---|
| 329 | // Create SkySphere |
|---|
| 330 | // this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg"); |
|---|
| 331 | // this->skySphere->setName("SkySphere"); |
|---|
| 332 | // this->localCamera->addChild(this->skySphere); |
|---|
| 333 | // this->spawn(this->skySphere); |
|---|
| 334 | skyBox = new SkyBox(); |
|---|
| 335 | skyBox->setTexture("pictures/sky/skybox", "jpg"); |
|---|
| 336 | skyBox->setParent(localCamera); |
|---|
| 337 | this->spawn(skyBox); |
|---|
| 338 | |
|---|
| 339 | /*monitor progress*/ |
|---|
| 340 | this->glmis->step(); |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | WorldEntity* env = new Environment(); |
|---|
| 344 | env->setName ("env"); |
|---|
| 345 | this->spawn(env); |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | /* |
|---|
| 349 | Vector* es = new Vector (10, 5, 0); |
|---|
| 350 | Quaternion* qs = new Quaternion (); |
|---|
| 351 | WorldEntity* pr = new Primitive(P_CYLINDER); |
|---|
| 352 | pr->setName("primitive"); |
|---|
| 353 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
|---|
| 354 | */ |
|---|
| 355 | |
|---|
| 356 | /*monitor progress*/ |
|---|
| 357 | this->glmis->step(); |
|---|
| 358 | |
|---|
| 359 | // trackManager->setBindSlave(env); |
|---|
| 360 | PNode* tn = trackManager->getTrackNode(); |
|---|
| 361 | tn->addChild(this->localPlayer); |
|---|
| 362 | |
|---|
| 363 | //localCamera->setParent(TrackNode::getInstance()); |
|---|
| 364 | tn->addChild(this->localCamera); |
|---|
| 365 | // localCamera->lookAt(tn); |
|---|
| 366 | this->localPlayer->setMode(PNODE_ALL); |
|---|
| 367 | //Vector* cameraOffset = new Vector (0, 5, -10); |
|---|
| 368 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
|---|
| 369 | this->glmis->step(); |
|---|
| 370 | |
|---|
| 371 | break; |
|---|
| 372 | } |
|---|
| 373 | case DEBUG_WORLD_1: |
|---|
| 374 | { |
|---|
| 375 | lightMan->setPosition(.0, .0, .0); |
|---|
| 376 | lightMan->setAttenuation(1.0, .01, 0.0); |
|---|
| 377 | lightMan->setSpecularColor(1,0,0); |
|---|
| 378 | this->nullParent = NullParent::getInstance (); |
|---|
| 379 | this->nullParent->setName ("NullParent"); |
|---|
| 380 | |
|---|
| 381 | // create a player |
|---|
| 382 | WorldEntity* myPlayer = new Player(); |
|---|
| 383 | myPlayer->setName ("player"); |
|---|
| 384 | this->spawn(myPlayer); |
|---|
| 385 | this->localPlayer = myPlayer; |
|---|
| 386 | |
|---|
| 387 | // bind input |
|---|
| 388 | Orxonox *orx = Orxonox::getInstance(); |
|---|
| 389 | orx->getLocalInput()->bind (myPlayer); |
|---|
| 390 | |
|---|
| 391 | // bind camera |
|---|
| 392 | this->localCamera = new Camera (); |
|---|
| 393 | this->localCamera->setName ("camera"); |
|---|
| 394 | this->localCamera->lookAt(LightManager::getInstance()->getLight(0)); |
|---|
| 395 | this->localCamera->setParent(this->localPlayer); |
|---|
| 396 | |
|---|
| 397 | // Create SkySphere |
|---|
| 398 | skySphere = new Skysphere("../data/pictures/sky-replace.jpg"); |
|---|
| 399 | this->localPlayer->addChild(this->skySphere); |
|---|
| 400 | this->spawn(this->skySphere); |
|---|
| 401 | Vector* es = new Vector (20, 0, 0); |
|---|
| 402 | Quaternion* qs = new Quaternion (); |
|---|
| 403 | |
|---|
| 404 | lightMan->getLight(0)->setParent(trackManager->getTrackNode()); |
|---|
| 405 | break; |
|---|
| 406 | } |
|---|
| 407 | case DEBUG_WORLD_2: |
|---|
| 408 | { |
|---|
| 409 | lightMan->setAmbientColor(.1,.1,.1); |
|---|
| 410 | lightMan->addLight(); |
|---|
| 411 | lightMan->setPosition(-5.0, 10.0, -40.0); |
|---|
| 412 | this->nullParent = NullParent::getInstance (); |
|---|
| 413 | this->nullParent->setName ("NullParent"); |
|---|
| 414 | |
|---|
| 415 | // !\todo old track-system has to be removed |
|---|
| 416 | |
|---|
| 417 | //create helper for player |
|---|
| 418 | //HelperParent* hp = new HelperParent (); |
|---|
| 419 | /* the player has to be added to this helper */ |
|---|
| 420 | |
|---|
| 421 | // create a player |
|---|
| 422 | this->localPlayer = new Player (); |
|---|
| 423 | this->localPlayer->setName ("player"); |
|---|
| 424 | this->spawn (this->localPlayer); |
|---|
| 425 | /*monitor progress*/ |
|---|
| 426 | //this->glmis->step(); |
|---|
| 427 | this->glmis->step(); |
|---|
| 428 | |
|---|
| 429 | // bind input |
|---|
| 430 | Orxonox *orx = Orxonox::getInstance (); |
|---|
| 431 | orx->getLocalInput()->bind (this->localPlayer); |
|---|
| 432 | |
|---|
| 433 | // bind camera |
|---|
| 434 | this->localCamera = new Camera(); |
|---|
| 435 | this->localCamera->setName ("camera"); |
|---|
| 436 | this->localCamera->lookAt(this->localPlayer); |
|---|
| 437 | this->localCamera->setParent(this->localPlayer); |
|---|
| 438 | |
|---|
| 439 | /*monitor progress*/ |
|---|
| 440 | this->glmis->step(); |
|---|
| 441 | |
|---|
| 442 | // Create SkySphere |
|---|
| 443 | this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg"); |
|---|
| 444 | this->skySphere->setName("SkySphere"); |
|---|
| 445 | this->spawn(this->skySphere); |
|---|
| 446 | this->localCamera->addChild(this->skySphere); |
|---|
| 447 | this->skySphere->setMode(PNODE_MOVEMENT); |
|---|
| 448 | /*monitor progress*/ |
|---|
| 449 | this->glmis->step(); |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | WorldEntity* baseNode = new Satellite(Vector(1,0,1), 1.2); |
|---|
| 453 | this->localPlayer->addChild(baseNode); |
|---|
| 454 | baseNode->setRelCoor(Vector(10.0, 2.0, 1.0)); |
|---|
| 455 | this->spawn(baseNode); |
|---|
| 456 | |
|---|
| 457 | WorldEntity* secondNode = new Satellite(Vector(0,0,1), 2.0); |
|---|
| 458 | baseNode->addChild(secondNode); |
|---|
| 459 | secondNode->setRelCoor(Vector(0.0, 0.0, 3.0)); |
|---|
| 460 | this->spawn(secondNode); |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | WorldEntity* thirdNode = new Satellite(Vector(0,0,1), 1.0); |
|---|
| 464 | secondNode->addChild(thirdNode); |
|---|
| 465 | thirdNode->setRelCoor(Vector(2.0, 0.0, 0.0)); |
|---|
| 466 | this->spawn(thirdNode); |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | WorldEntity* b = new Environment(); |
|---|
| 472 | this->localPlayer->addChild(b); |
|---|
| 473 | b->setRelCoor(Vector(10.0, 1.0, 1.0)); |
|---|
| 474 | this->spawn(b); |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | WorldEntity* c = new Environment(); |
|---|
| 478 | this->localPlayer->addChild(c); |
|---|
| 479 | c->setRelCoor(Vector(10.0, 2.0, -1.0)); |
|---|
| 480 | this->spawn(c); |
|---|
| 481 | |
|---|
| 482 | /* |
|---|
| 483 | KeyFrame* f1 = new KeyFrame; |
|---|
| 484 | f1->position = new Vector(-1.1, 0.0, 2.6); |
|---|
| 485 | f1->direction = new Quaternion(); |
|---|
| 486 | f1->time = 1.0; |
|---|
| 487 | f1->mode = NEG_EXP; |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | KeyFrame* f2 = new KeyFrame; |
|---|
| 491 | f2->position = new Vector(-2.1, 0.0, 2.6); |
|---|
| 492 | f2->direction = new Quaternion(); |
|---|
| 493 | f2->time = 0.1; |
|---|
| 494 | f2->mode = NEG_EXP; |
|---|
| 495 | |
|---|
| 496 | KeyFrame* f3 = new KeyFrame; |
|---|
| 497 | f3->position = new Vector(10.0, 2.0, -1.0); |
|---|
| 498 | f3->direction = new Quaternion(); |
|---|
| 499 | f3->time = 0.2; |
|---|
| 500 | f3->mode = NEG_EXP; |
|---|
| 501 | |
|---|
| 502 | KeyFrame* f4 = new KeyFrame; |
|---|
| 503 | f4->position = new Vector(10.0, 5.0, -1.0); |
|---|
| 504 | f4->direction = new Quaternion(); |
|---|
| 505 | f4->time = 1.0; |
|---|
| 506 | f4->mode = NEG_EXP; |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | this->simpleAnimation->animatorBegin(); |
|---|
| 511 | this->simpleAnimation->selectObject(b); |
|---|
| 512 | this->simpleAnimation->setAnimationMode(SINGLE); |
|---|
| 513 | this->simpleAnimation->addKeyFrame(f1); |
|---|
| 514 | this->simpleAnimation->addKeyFrame(f2); |
|---|
| 515 | this->simpleAnimation->start(); |
|---|
| 516 | this->simpleAnimation->selectObject(c); |
|---|
| 517 | this->simpleAnimation->addKeyFrame(f3); |
|---|
| 518 | this->simpleAnimation->addKeyFrame(f4); |
|---|
| 519 | this->simpleAnimation->start(); |
|---|
| 520 | this->simpleAnimation->animatorEnd(); |
|---|
| 521 | */ |
|---|
| 522 | |
|---|
| 523 | /* |
|---|
| 524 | Vector* es = new Vector (10, 5, 0); |
|---|
| 525 | Quaternion* qs = new Quaternion (); |
|---|
| 526 | WorldEntity* pr = new Primitive(P_CYLINDER); |
|---|
| 527 | pr->setName("primitive"); |
|---|
| 528 | this->spawn(pr, this->localPlayer, es, qs, PNODE_MOVEMENT); |
|---|
| 529 | */ |
|---|
| 530 | |
|---|
| 531 | /*monitor progress*/ |
|---|
| 532 | this->glmis->step(); |
|---|
| 533 | |
|---|
| 534 | // trackManager->setBindSlave(env); |
|---|
| 535 | PNode* tn = trackManager->getTrackNode(); |
|---|
| 536 | tn->addChild(this->localPlayer); |
|---|
| 537 | |
|---|
| 538 | //localCamera->setParent(TrackNode::getInstance()); |
|---|
| 539 | tn->addChild(this->localCamera); |
|---|
| 540 | // localCamera->lookAt(tn); |
|---|
| 541 | this->localPlayer->setMode(PNODE_ALL); |
|---|
| 542 | //Vector* cameraOffset = new Vector (0, 5, -10); |
|---|
| 543 | trackManager->condition(2, LEFTRIGHT, this->localPlayer); |
|---|
| 544 | this->glmis->step(); |
|---|
| 545 | |
|---|
| 546 | break; |
|---|
| 547 | } |
|---|
| 548 | default: |
|---|
| 549 | printf("World::load() - no world with ID %i found", this->debugWorldNr ); |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | else if(this->worldName != NULL) |
|---|
| 553 | { |
|---|
| 554 | |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | // initialize debug coord system |
|---|
| 558 | objectList = glGenLists(1); |
|---|
| 559 | glNewList (objectList, GL_COMPILE); |
|---|
| 560 | |
|---|
| 561 | // trackManager->drawGraph(.01); |
|---|
| 562 | trackManager->debug(2); |
|---|
| 563 | glEndList(); |
|---|
| 564 | |
|---|
| 565 | terrain = new Terrain("../data/worlds/newGround.obj"); |
|---|
| 566 | terrain->setRelCoor(Vector(0,-10,0)); |
|---|
| 567 | this->spawn(terrain); |
|---|
| 568 | |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | /** |
|---|
| 573 | \brief initializes a new World shortly before start |
|---|
| 574 | |
|---|
| 575 | this is the function, that will be loaded shortly before the world is |
|---|
| 576 | started |
|---|
| 577 | */ |
|---|
| 578 | ErrorMessage World::init() |
|---|
| 579 | { |
|---|
| 580 | this->bPause = false; |
|---|
| 581 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
|---|
| 582 | cn->addToWorld(this); |
|---|
| 583 | cn->enable(true); |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | /** |
|---|
| 588 | \brief starts the World |
|---|
| 589 | */ |
|---|
| 590 | ErrorMessage World::start() |
|---|
| 591 | { |
|---|
| 592 | PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr); |
|---|
| 593 | this->bQuitOrxonox = false; |
|---|
| 594 | this->bQuitCurrentGame = false; |
|---|
| 595 | this->mainLoop(); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | /** |
|---|
| 599 | \brief stops the world. |
|---|
| 600 | |
|---|
| 601 | This happens, when the player decides to end the Level. |
|---|
| 602 | */ |
|---|
| 603 | ErrorMessage World::stop() |
|---|
| 604 | { |
|---|
| 605 | PRINTF(3)("World::stop() - got stop signal\n"); |
|---|
| 606 | this->bQuitCurrentGame = true; |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | /** |
|---|
| 610 | \brief pauses the Game |
|---|
| 611 | */ |
|---|
| 612 | ErrorMessage World::pause() |
|---|
| 613 | { |
|---|
| 614 | this->isPaused = true; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | /** |
|---|
| 618 | \brief ends the pause Phase |
|---|
| 619 | */ |
|---|
| 620 | ErrorMessage World::resume() |
|---|
| 621 | { |
|---|
| 622 | this->isPaused = false; |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | /** |
|---|
| 626 | \brief destroys the World |
|---|
| 627 | */ |
|---|
| 628 | ErrorMessage World::destroy() |
|---|
| 629 | { |
|---|
| 630 | |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | /** |
|---|
| 634 | \brief shows the loading screen |
|---|
| 635 | */ |
|---|
| 636 | void World::displayLoadScreen () |
|---|
| 637 | { |
|---|
| 638 | PRINTF(3)("World::displayLoadScreen - start\n"); |
|---|
| 639 | |
|---|
| 640 | //GLMenuImageScreen* |
|---|
| 641 | this->glmis = GLMenuImageScreen::getInstance(); |
|---|
| 642 | this->glmis->init(); |
|---|
| 643 | this->glmis->setMaximum(8); |
|---|
| 644 | this->glmis->draw(); |
|---|
| 645 | |
|---|
| 646 | PRINTF(3)("World::displayLoadScreen - end\n"); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | /** |
|---|
| 650 | \brief removes the loadscreen, and changes over to the game |
|---|
| 651 | |
|---|
| 652 | \todo take out the delay |
|---|
| 653 | */ |
|---|
| 654 | void World::releaseLoadScreen () |
|---|
| 655 | { |
|---|
| 656 | PRINTF(3)("World::releaseLoadScreen - start\n"); |
|---|
| 657 | this->glmis->setValue(this->glmis->getMaximum()); |
|---|
| 658 | //SDL_Delay(500); |
|---|
| 659 | PRINTF(3)("World::releaseLoadScreen - end\n"); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | /** |
|---|
| 664 | \brief gets the list of entities from the world |
|---|
| 665 | \returns entity list |
|---|
| 666 | */ |
|---|
| 667 | tList<WorldEntity>* World::getEntities() |
|---|
| 668 | { |
|---|
| 669 | return this->entities; |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | /** |
|---|
| 674 | \brief this returns the current game time |
|---|
| 675 | \returns elapsed game time |
|---|
| 676 | */ |
|---|
| 677 | double World::getGameTime() |
|---|
| 678 | { |
|---|
| 679 | return this->gameTime; |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | /** |
|---|
| 684 | \brief checks for collisions |
|---|
| 685 | |
|---|
| 686 | This method runs through all WorldEntities known to the world and checks for collisions |
|---|
| 687 | between them. In case of collisions the collide() method of the corresponding entities |
|---|
| 688 | is called. |
|---|
| 689 | */ |
|---|
| 690 | void World::collide () |
|---|
| 691 | { |
|---|
| 692 | /* |
|---|
| 693 | List *a, *b; |
|---|
| 694 | WorldEntity *aobj, *bobj; |
|---|
| 695 | |
|---|
| 696 | a = entities; |
|---|
| 697 | |
|---|
| 698 | while( a != NULL) |
|---|
| 699 | { |
|---|
| 700 | aobj = a->nextElement(); |
|---|
| 701 | if( aobj->bCollide && aobj->collisioncluster != NULL) |
|---|
| 702 | { |
|---|
| 703 | b = a->nextElement(); |
|---|
| 704 | while( b != NULL ) |
|---|
| 705 | { |
|---|
| 706 | bobj = b->nextElement(); |
|---|
| 707 | if( bobj->bCollide && bobj->collisioncluster != NULL ) |
|---|
| 708 | { |
|---|
| 709 | unsigned long ahitflg, bhitflg; |
|---|
| 710 | if( check_collision ( &aobj->place, aobj->collisioncluster, |
|---|
| 711 | &ahitflg, &bobj->place, bobj->collisioncluster, |
|---|
| 712 | &bhitflg) ); |
|---|
| 713 | { |
|---|
| 714 | aobj->collide (bobj, ahitflg, bhitflg); |
|---|
| 715 | bobj->collide (aobj, bhitflg, ahitflg); |
|---|
| 716 | } |
|---|
| 717 | } |
|---|
| 718 | b = b->nextElement(); |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | a = a->enumerate(); |
|---|
| 722 | } |
|---|
| 723 | */ |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | /** |
|---|
| 727 | \brief runs through all entities calling their draw() methods |
|---|
| 728 | */ |
|---|
| 729 | void World::draw () |
|---|
| 730 | { |
|---|
| 731 | /* draw entities */ |
|---|
| 732 | WorldEntity* entity; |
|---|
| 733 | glLoadIdentity(); |
|---|
| 734 | |
|---|
| 735 | //entity = this->entities->enumerate(); |
|---|
| 736 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
|---|
| 737 | entity = iterator->nextElement(); |
|---|
| 738 | while( entity != NULL ) |
|---|
| 739 | { |
|---|
| 740 | if( entity->bDraw ) entity->draw(); |
|---|
| 741 | //entity = this->entities->nextElement(); |
|---|
| 742 | entity = iterator->nextElement(); |
|---|
| 743 | } |
|---|
| 744 | delete iterator; |
|---|
| 745 | |
|---|
| 746 | glCallList (objectList); |
|---|
| 747 | |
|---|
| 748 | TextEngine::getInstance()->draw(); |
|---|
| 749 | lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes // |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | /** |
|---|
| 754 | \brief function to put your own debug stuff into it. it can display informations about |
|---|
| 755 | the current class/procedure |
|---|
| 756 | */ |
|---|
| 757 | void World::debug() |
|---|
| 758 | { |
|---|
| 759 | PRINTF(2)("debug() - starting debug\n"); |
|---|
| 760 | PNode* p1 = NullParent::getInstance (); |
|---|
| 761 | PNode* p2 = new PNode (Vector(2, 2, 2), p1); |
|---|
| 762 | PNode* p3 = new PNode (Vector(4, 4, 4), p1); |
|---|
| 763 | PNode* p4 = new PNode (Vector(6, 6, 6), p2); |
|---|
| 764 | |
|---|
| 765 | p1->debug (); |
|---|
| 766 | p2->debug (); |
|---|
| 767 | p3->debug (); |
|---|
| 768 | p4->debug (); |
|---|
| 769 | |
|---|
| 770 | p1->shiftCoor (Vector(-1, -1, -1)); |
|---|
| 771 | |
|---|
| 772 | printf("World::debug() - shift\n"); |
|---|
| 773 | p1->debug (); |
|---|
| 774 | p2->debug (); |
|---|
| 775 | p3->debug (); |
|---|
| 776 | p4->debug (); |
|---|
| 777 | |
|---|
| 778 | p1->update (0); |
|---|
| 779 | |
|---|
| 780 | printf ("World::debug() - update\n"); |
|---|
| 781 | p1->debug (); |
|---|
| 782 | p2->debug (); |
|---|
| 783 | p3->debug (); |
|---|
| 784 | p4->debug (); |
|---|
| 785 | |
|---|
| 786 | p2->shiftCoor (Vector(-1, -1, -1)); |
|---|
| 787 | p1->update (0); |
|---|
| 788 | |
|---|
| 789 | p1->debug (); |
|---|
| 790 | p2->debug (); |
|---|
| 791 | p3->debug (); |
|---|
| 792 | p4->debug (); |
|---|
| 793 | |
|---|
| 794 | p2->setAbsCoor (Vector(1,2,3)); |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | p1->update (0); |
|---|
| 798 | |
|---|
| 799 | p1->debug (); |
|---|
| 800 | p2->debug (); |
|---|
| 801 | p3->debug (); |
|---|
| 802 | p4->debug (); |
|---|
| 803 | |
|---|
| 804 | delete p1; |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | /* |
|---|
| 808 | WorldEntity* entity; |
|---|
| 809 | printf("counting all entities\n"); |
|---|
| 810 | printf("World::debug() - enumerate()\n"); |
|---|
| 811 | entity = entities->enumerate(); |
|---|
| 812 | while( entity != NULL ) |
|---|
| 813 | { |
|---|
| 814 | if( entity->bDraw ) printf("got an entity\n"); |
|---|
| 815 | entity = entities->nextElement(); |
|---|
| 816 | } |
|---|
| 817 | */ |
|---|
| 818 | } |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | /** |
|---|
| 822 | \brief main loop of the world: executing all world relevant function |
|---|
| 823 | |
|---|
| 824 | in this loop we synchronize (if networked), handle input events, give the heart-beat to |
|---|
| 825 | all other member-entities of the world (tick to player, enemies etc.), checking for |
|---|
| 826 | collisions drawing everything to the screen. |
|---|
| 827 | */ |
|---|
| 828 | void World::mainLoop() |
|---|
| 829 | { |
|---|
| 830 | this->lastFrame = SDL_GetTicks (); |
|---|
| 831 | PRINTF(3)("World::mainLoop() - Entering main loop\n"); |
|---|
| 832 | while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */ |
|---|
| 833 | { |
|---|
| 834 | PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize()); |
|---|
| 835 | // Network |
|---|
| 836 | this->synchronize (); |
|---|
| 837 | // Process input |
|---|
| 838 | this->handleInput (); |
|---|
| 839 | if( this->bQuitCurrentGame || this->bQuitOrxonox) |
|---|
| 840 | break; |
|---|
| 841 | // Process time |
|---|
| 842 | this->tick (); |
|---|
| 843 | // Update the state |
|---|
| 844 | this->update (); |
|---|
| 845 | // Process collision |
|---|
| 846 | this->collide (); |
|---|
| 847 | // Draw |
|---|
| 848 | this->display (); |
|---|
| 849 | |
|---|
| 850 | // for( int i = 0; i < 5000000; i++) {} |
|---|
| 851 | /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/ |
|---|
| 852 | } |
|---|
| 853 | PRINTF(3)("World::mainLoop() - Exiting the main loop\n"); |
|---|
| 854 | } |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | /** |
|---|
| 858 | \brief synchronize local data with remote data |
|---|
| 859 | */ |
|---|
| 860 | void World::synchronize () |
|---|
| 861 | { |
|---|
| 862 | // Get remote input |
|---|
| 863 | // Update synchronizables |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | /** |
|---|
| 868 | \brief run all input processing |
|---|
| 869 | |
|---|
| 870 | the command node is the central input event dispatcher. the node uses the even-queue from |
|---|
| 871 | sdl and has its own event-passing-queue. |
|---|
| 872 | */ |
|---|
| 873 | void World::handleInput () |
|---|
| 874 | { |
|---|
| 875 | // localinput |
|---|
| 876 | CommandNode* cn = Orxonox::getInstance()->getLocalInput(); |
|---|
| 877 | cn->process(); |
|---|
| 878 | // remoteinput |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | /** |
|---|
| 883 | \brief advance the timeline |
|---|
| 884 | |
|---|
| 885 | this calculates the time used to process one frame (with all input handling, drawing, etc) |
|---|
| 886 | the time is mesured in ms and passed to all world-entities and other classes that need |
|---|
| 887 | a heart-beat. |
|---|
| 888 | */ |
|---|
| 889 | void World::tick () |
|---|
| 890 | { |
|---|
| 891 | Uint32 currentFrame = SDL_GetTicks(); |
|---|
| 892 | if(!this->bPause) |
|---|
| 893 | { |
|---|
| 894 | this->dt = currentFrame - this->lastFrame; |
|---|
| 895 | |
|---|
| 896 | if( this->dt > 0) |
|---|
| 897 | { |
|---|
| 898 | float fps = 1000/dt; |
|---|
| 899 | |
|---|
| 900 | // temporary, only for showing how fast the text-engine is |
|---|
| 901 | char tmpChar[20]; |
|---|
| 902 | sprintf(tmpChar, "fps: %4.0f", fps); |
|---|
| 903 | } |
|---|
| 904 | else |
|---|
| 905 | { |
|---|
| 906 | /* the frame-rate is limited to 100 frames per second, all other things are for |
|---|
| 907 | nothing. |
|---|
| 908 | */ |
|---|
| 909 | PRINTF(2)("fps = 1000 - frame rate is adjusted\n"); |
|---|
| 910 | SDL_Delay(10); |
|---|
| 911 | this->dt = 10; |
|---|
| 912 | } |
|---|
| 913 | //this->timeSlice (dt); |
|---|
| 914 | |
|---|
| 915 | /* function to let all entities tick (iterate through list) */ |
|---|
| 916 | float seconds = this->dt / 1000.0; |
|---|
| 917 | this->gameTime += seconds; |
|---|
| 918 | //entity = entities->enumerate(); |
|---|
| 919 | tIterator<WorldEntity>* iterator = this->entities->getIterator(); |
|---|
| 920 | WorldEntity* entity = iterator->nextElement(); |
|---|
| 921 | while( entity != NULL) |
|---|
| 922 | { |
|---|
| 923 | entity->tick (seconds); |
|---|
| 924 | entity = iterator->nextElement(); |
|---|
| 925 | } |
|---|
| 926 | delete iterator; |
|---|
| 927 | //skySphere->updatePosition(localCamera->absCoordinate); |
|---|
| 928 | |
|---|
| 929 | /* update tick the rest */ |
|---|
| 930 | this->trackManager->tick(this->dt); |
|---|
| 931 | this->localCamera->tick(this->dt); |
|---|
| 932 | this->garbageCollector->tick(seconds); |
|---|
| 933 | |
|---|
| 934 | AnimationPlayer::getInstance()->tick(seconds); |
|---|
| 935 | } |
|---|
| 936 | this->lastFrame = currentFrame; |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | /** |
|---|
| 941 | \brief this function gives the world a consistant state |
|---|
| 942 | |
|---|
| 943 | after ticking (updating the world state) this will give a constistant |
|---|
| 944 | state to the whole system. |
|---|
| 945 | */ |
|---|
| 946 | void World::update() |
|---|
| 947 | { |
|---|
| 948 | this->garbageCollector->update(); |
|---|
| 949 | this->nullParent->update (dt); |
|---|
| 950 | } |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | /** |
|---|
| 954 | \brief render the current frame |
|---|
| 955 | |
|---|
| 956 | clear all buffers and draw the world |
|---|
| 957 | */ |
|---|
| 958 | void World::display () |
|---|
| 959 | { |
|---|
| 960 | // clear buffer |
|---|
| 961 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
|---|
| 962 | // set camera |
|---|
| 963 | this->localCamera->apply (); |
|---|
| 964 | // draw world |
|---|
| 965 | this->draw(); |
|---|
| 966 | // draw HUD |
|---|
| 967 | /* \todo draw HUD */ |
|---|
| 968 | // flip buffers |
|---|
| 969 | SDL_GL_SwapBuffers(); |
|---|
| 970 | //SDL_Surface* screen = Orxonox::getInstance()->getScreen (); |
|---|
| 971 | //SDL_Flip (screen); |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | |
|---|
| 975 | /** |
|---|
| 976 | \brief add and spawn a new entity to this world |
|---|
| 977 | \param entity to be added |
|---|
| 978 | */ |
|---|
| 979 | void World::spawn(WorldEntity* entity) |
|---|
| 980 | { |
|---|
| 981 | this->entities->add (entity); |
|---|
| 982 | entity->postSpawn (); |
|---|
| 983 | } |
|---|
| 984 | |
|---|
| 985 | |
|---|
| 986 | /** |
|---|
| 987 | \brief add and spawn a new entity to this world |
|---|
| 988 | \param entity to be added |
|---|
| 989 | \param absCoor At what coordinates to add this entity. |
|---|
| 990 | \param absDir In which direction should it look. |
|---|
| 991 | */ |
|---|
| 992 | void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir) |
|---|
| 993 | { |
|---|
| 994 | this->entities->add (entity); |
|---|
| 995 | |
|---|
| 996 | entity->setAbsCoor (*absCoor); |
|---|
| 997 | entity->setAbsDir (*absDir); |
|---|
| 998 | |
|---|
| 999 | entity->postSpawn (); |
|---|
| 1000 | } |
|---|
| 1001 | |
|---|
| 1002 | |
|---|
| 1003 | /** |
|---|
| 1004 | \brief add and spawn a new entity to this world |
|---|
| 1005 | \param entity to be added |
|---|
| 1006 | \param entity to be added to (PNode) |
|---|
| 1007 | \param At what relative coordinates to add this entity. |
|---|
| 1008 | \param In which relative direction should it look. |
|---|
| 1009 | */ |
|---|
| 1010 | void World::spawn(WorldEntity* entity, PNode* parentNode, |
|---|
| 1011 | Vector* relCoor, Quaternion* relDir, |
|---|
| 1012 | int parentingMode) |
|---|
| 1013 | { |
|---|
| 1014 | this->nullParent = NullParent::getInstance(); |
|---|
| 1015 | if( parentNode != NULL) |
|---|
| 1016 | { |
|---|
| 1017 | parentNode->addChild (entity); |
|---|
| 1018 | |
|---|
| 1019 | entity->setRelCoor (*relCoor); |
|---|
| 1020 | entity->setRelDir (*relDir); |
|---|
| 1021 | entity->setMode(parentingMode); |
|---|
| 1022 | |
|---|
| 1023 | this->entities->add (entity); |
|---|
| 1024 | |
|---|
| 1025 | entity->postSpawn (); |
|---|
| 1026 | } |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | |
|---|
| 1030 | |
|---|
| 1031 | /** |
|---|
| 1032 | \brief commands that the world must catch |
|---|
| 1033 | \returns false if not used by the world |
|---|
| 1034 | */ |
|---|
| 1035 | bool World::command(Command* cmd) |
|---|
| 1036 | { |
|---|
| 1037 | if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL); |
|---|
| 1038 | else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND); |
|---|
| 1039 | else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT); |
|---|
| 1040 | else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT); |
|---|
| 1041 | else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT); |
|---|
| 1042 | else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP); |
|---|
| 1043 | |
|---|
| 1044 | return false; |
|---|
| 1045 | } |
|---|
| 1046 | |
|---|