Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5968 in orxonox.OLD for branches/network/src/story_entities/world.cc


Ignore:
Timestamp:
Dec 7, 2005, 4:16:51 PM (18 years ago)
Author:
patrick
Message:

network: merged the trunk into the network with the command svn merge -r5824:HEAD ../trunk network, changes changed… bla bla..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/story_entities/world.cc

    r5829 r5968  
    2626#include "null_parent.h"
    2727#include "pilot_node.h"
    28 #include "track_node.h"
    2928#include "world_entity.h"
    3029#include "player.h"
     
    4039#include "shell.h"
    4140
    42 #include "track_manager.h"
    4341#include "garbage_collector.h"
    4442#include "fast_factory.h"
     
    6361#include "weapons/projectile.h"
    6462#include "event_handler.h"
    65 
    6663#include "sound_engine.h"
    6764#include "ogg_player.h"
     
    7471
    7572#include "network_manager.h"
     73#include "playable.h"
     74
    7675
    7776SHELL_COMMAND(speed, World, setSpeed);
     
    124123  PRINTF(3)("World::~World() - deleting current world\n");
    125124
     125
    126126  // here everything that is alocated by the World is deleted
    127127  delete this->entities;
    128128  State::setWorldEntityList(NULL);
    129129
     130  delete this->localPlayer;
    130131
    131132  // delete all the initialized Engines.
    132133  FastFactory::flushAll(true);
    133134  delete LightManager::getInstance();
    134   delete TrackManager::getInstance();
    135135  delete ParticleEngine::getInstance();
    136136  delete AnimationPlayer::getInstance();
     
    144144  // erease everything that is left.
    145145  delete NullParent::getInstance();
     146
    146147  Shader::suspendShader();
    147148
     
    174175  this->shell = NULL;
    175176  this->entities = NULL;
     177  this->localPlayer = NULL;
     178  this->localCamera = NULL;
    176179
    177180  this->showPNodes = false;
     
    215218
    216219  AnimationPlayer::getInstance(); // initializes the animationPlayer
     220  ParticleEngine::getInstance();
    217221  PhysicsEngine::getInstance();
    218222
     
    244248    }
    245249
    246   TiXmlDocument* XMLDoc = new TiXmlDocument( path);
     250  TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    247251  // load the campaign document
    248252  if( !XMLDoc->LoadFile())
    249253  {
    250254    // report an error
    251     PRINTF(1)("loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     255    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    252256    delete XMLDoc;
    253257    return (ErrorMessage){213,"XML File parsing error","World::load()"};
     
    315319      while( element != NULL)
    316320        {
    317           WorldEntity* created = dynamic_cast<WorldEntity*>( loader->fabricate( element));
    318           if( created != NULL) this->spawn( created);
    319           // if we load a 'Player' we use it as localPlayer
    320           //todo do this more elegant
    321           if( element->Value() != NULL && !strcmp( element->Value(), "Player"))
     321          BaseObject* created = (loader->fabricate(element));
     322          if( created != NULL )
    322323          {
    323             localPlayer = (Player*) created;
    324             CDEngine::getInstance()->setPlayer(localPlayer);
     324            if(created->isA(CL_WORLD_ENTITY))
     325              this->spawn(dynamic_cast<WorldEntity*>(created));
     326            printf("Created a %s: %s\n", created->getClassName(), created->getName());
    325327            NetworkManager::getInstance()->connectSynchronizeable(*(Synchronizeable*)this->localPlayer);
    326328          }
    327           if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created;
     329
     330          // if we load a 'Player' we use it as localPlayer
     331
     332
     333          //todo do this more elegant
     334          if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
     335            sky = dynamic_cast<SkyBox*>(created);
    328336          if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    329337          {
    330             terrain = (Terrain*) created;
     338            terrain = dynamic_cast<Terrain*>(created);
    331339            CDEngine::getInstance()->setTerrain(terrain);
    332340          }
     
    343351    LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
    344352
    345     LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
    346     LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    347 
    348   // find Track
    349   element = root->FirstChildElement( "Track");
    350   if( element == NULL)
    351     {
    352       PRINTF(0)("World is missing a 'Track'\n");
    353     }
    354   else
    355     {
    356       //load track
    357       PRINTF(4)("Loading Track\n");
    358 
    359       TrackManager::getInstance()->loadParams( element);
    360       TrackManager::getInstance()->finalize();
    361     }
     353   LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
     354//   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    362355
    363356  // free the XML data
     
    366359  /* GENERIC LOADING PROCESS FINISHED */
    367360
    368   // bind input
    369   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP);
    370   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_DOWN);
    371   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_LEFT);
    372   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_RIGHT);
    373   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1);
    374   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON);
    375   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON);
    376   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, SDLK_PAGEUP);
    377   EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, SDLK_PAGEDOWN);
     361
     362  // Create a Player
     363  this->localPlayer = new Player();
     364
     365  Playable* playable;
     366  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
     367  if (playableList != NULL)
     368  {
     369    playable = dynamic_cast<Playable*>(playableList->front());
     370    this->localPlayer->setControllable(playable);
     371  }
    378372
    379373  // bind camera
    380   //this->localCamera->bind (localPlayer);
    381  // this->localPlayer->addChild (this->localCamera);
    382 
    383 
    384   //        TrackManager::getInstance()->setBindSlave(env);
    385   PNode* tn = TrackManager::getInstance()->getTrackNode();
    386   tn->addChild(this->localPlayer);
    387 
    388   //localCamera->setParent(TrackNode::getInstance());
    389   tn->addChild(this->localCamera);
    390   localCamera->lookAt(tn);
     374  playable->addChild (this->localCamera);
     375
     376//   //localCamera->setParent(TrackNode::getInstance());
     377//  tn->addChild(this->localCamera);
    391378  localCamera->setClipRegion(1, 10000.0);
    392   this->localPlayer->setParentMode(PNODE_ALL);
    393   TrackManager::getInstance()->condition(1, LEFTRIGHT, this->localPlayer);
    394 
     379  localCamera->lookAt(playable);
     380//  this->localPlayer->setParentMode(PNODE_ALL);
    395381  if (sky != NULL)
    396382  {
     
    403389  glNewList (objectList, GL_COMPILE);
    404390
    405   //TrackManager::getInstance()->drawGraph(.01);
    406   //TrackManager::getInstance()->debug(2);
    407391  glEndList();
    408392
     
    415399  ////////////
    416400
    417   Gravity* test = new Gravity();
    418 
    419   // SYSTEM TRAILING THE PLAYER
    420   // Creating a Test Particle System
    421 
    422   //new PhysicsConnection(system, gravity);
    423   //    new PhysicsConnection(this->localPlayer, gravity);
    424401
    425402//   TestEntity* testEntity = new TestEntity();
     
    427404//   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    428405//   this->spawn(testEntity);
    429 
    430 //   TestEntity* testEntity2 = new TestEntity();
    431 //   testEntity2->setAnim(STAND);
    432 //   testEntity2->setRelCoor(Vector(2400.0, 10.0, -30.0));
    433 //   testEntity2->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    434 //   //testEntity2->setParent(this->localPlayer);
    435 //   this->spawn(testEntity2);
    436 //
    437 //   TestEntity* testEntity3 = new TestEntity();
    438 //   testEntity3->setAnim(BOOM);
    439 //   testEntity3->setRelCoor(Vector(2450.0, 10.0, -40.0));
    440 //   testEntity3->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    441 //   this->spawn(testEntity3);
    442 //
    443 //   TestEntity* testEntity4 = new TestEntity();
    444 //   testEntity4->setAnim(FLIP);
    445 //   testEntity4->setRelCoor(Vector(2500.0, 10.0, -22.0));
    446 //   testEntity4->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    447 //   this->spawn(testEntity4);
    448 //
    449 //   TestEntity* testEntity5 = new TestEntity();
    450 //   testEntity5->setAnim(WAVE);
    451 //   testEntity5->setRelCoor(Vector(2420.0, 10.0, -50.0));
    452 //   testEntity5->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    453 //   this->spawn(testEntity5);
    454 //
    455 //   TestEntity* testEntity6 = new TestEntity();
    456 //   testEntity6->setAnim(WAVE);
    457 //   testEntity6->setRelCoor(Vector(2420.0, 10.0, -20.0));
    458 //   testEntity6->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    459 //   this->spawn(testEntity6);
    460 //
    461 //   TestEntity* testEntity7 = new TestEntity();
    462 //   testEntity7->setAnim(WAVE);
    463 //   testEntity7->setRelCoor(Vector(2500.0, 10.0, -50.0));
    464 //   testEntity7->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    465 //   this->spawn(testEntity7);
    466 
    467 
    468 
    469 //  PhysicsEngine::getInstance()->debug();
    470 
    471 
    472406
    473407  for(int i = 0; i < 100; i++)
     
    479413    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    480414    this->spawn(tmp);
    481 
    482 
    483415  }
    484 
    485 
    486 
    487 //  ClassList::debug();
    488416
    489417  this->music = NULL;//(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
     
    501429  this->glmis->step();
    502430  // stuff beyond this point remains to be loaded properly
    503 
    504   // initializing the TrackManager
    505   TrackManager::getInstance()->addPointV(Vector(150, -35, 5));
    506   TrackManager::getInstance()->addPointV(Vector(200,-35, 5));
    507   TrackManager::getInstance()->addPointV(Vector(250, -35, 5));
    508   TrackManager::getInstance()->addPointV(Vector(320,-33,-.55));
    509   TrackManager::getInstance()->setDuration(1);
    510   TrackManager::getInstance()->setSavePoint();
    511 
    512   TrackManager::getInstance()->addPointV(Vector(410, 0, 0));
    513   TrackManager::getInstance()->addPointV(Vector(510, 20, -10));
    514   TrackManager::getInstance()->addPointV(Vector(550, 20, -10));
    515   TrackManager::getInstance()->addPointV(Vector(570, 20, -10));
    516   TrackManager::getInstance()->setDuration(2);
    517 
    518   TrackManager::getInstance()->forkS("testFork1,testFork2");
    519   TrackManager::getInstance()->workOnS("testFork1");
    520   TrackManager::getInstance()->addPointV(Vector(640, 25, -30));
    521   TrackManager::getInstance()->addPointV(Vector(700, 40, -120));
    522   TrackManager::getInstance()->addPointV(Vector(800, 50, -150));
    523   TrackManager::getInstance()->addPointV(Vector(900, 60, -100));
    524   TrackManager::getInstance()->addPointV(Vector(900, 60, -70));
    525   TrackManager::getInstance()->addPointV(Vector(990, 65, -15));
    526   TrackManager::getInstance()->addPointV(Vector(1050, 65, -10));
    527   TrackManager::getInstance()->addPointV(Vector(1100, 65, -20));
    528   TrackManager::getInstance()->setDuration(4);
    529 
    530   TrackManager::getInstance()->workOnS("testFork2");
    531   TrackManager::getInstance()->addPointV(Vector(640, 25, 20));
    532   TrackManager::getInstance()->addPointV(Vector(670, 50, 120));
    533   TrackManager::getInstance()->addPointV(Vector(700, 70, 80));
    534   TrackManager::getInstance()->addPointV(Vector(800, 70, 65));
    535   TrackManager::getInstance()->addPointV(Vector(850, 65, 65));
    536   TrackManager::getInstance()->addPointV(Vector(920, 35, 40));
    537   TrackManager::getInstance()->addPointV(Vector(945, 40, 40));
    538   TrackManager::getInstance()->addPointV(Vector(970, 24, 40));
    539   TrackManager::getInstance()->addPointV(Vector(1000, 40, -7));
    540 
    541   TrackManager::getInstance()->setDuration(4);
    542 
    543 
    544   TrackManager::getInstance()->joinS("testFork1,testFork2");
    545 
    546   TrackManager::getInstance()->addPointV(Vector(1200, 60, -50));
    547   TrackManager::getInstance()->addPointV(Vector(1300, 50, -50));
    548   TrackManager::getInstance()->addPointV(Vector(1400, 40, -50));
    549   TrackManager::getInstance()->addPointV(Vector(1500, 40, -60));
    550   TrackManager::getInstance()->addPointV(Vector(1600, 35, -55));
    551   TrackManager::getInstance()->addPointV(Vector(1700, 45, -40));
    552   TrackManager::getInstance()->addPointV(Vector(1750, 60, -40));
    553   TrackManager::getInstance()->addPointV(Vector(1770, 80, -40));
    554   TrackManager::getInstance()->addPointV(Vector(1800, 100, -40));
    555   TrackManager::getInstance()->setDuration(10);
    556 
    557   TrackManager::getInstance()->finalize();
    558 
    559431
    560432  // LIGHT initialisation
     
    574446      {
    575447        LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);
    576 
    577 
    578         this->localPlayer = new Player ();
    579         this->localPlayer->setName ("player");
    580         this->spawn (this->localPlayer);
    581         this->localPlayer->setRelCoor(Vector(5,0,0));
    582448        /*monitor progress*/
    583449        this->glmis->step();
    584 
    585 
    586         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1);
    587         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON);
    588         EventHandler::getInstance()->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_PREVIOUS_WEAPON);
    589 
    590         /*
    591         Field* testField = new Gravity();
    592         testField->setMagnitude(10);
    593         new PhysicsConnection(this->localPlayer, testField);
    594         */
    595450
    596451        // bind camera
     
    617472        this->glmis->step();
    618473
    619         this->pilotNode = new PilotNode();
    620         this->spawn(this->pilotNode);
    621         this->pilotNode->setAbsCoor(Vector(150, -35, 5));
    622         this->pilotNode->addChild(this->localPlayer);
    623         this->pilotNode->addChild(this->localCamera);
    624         this->localCamera->lookAt(this->localPlayer);
    625 
    626         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP);
    627         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN);
    628         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT);
    629         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT);
    630         EventHandler::getInstance()->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION);
    631 
    632         /*
    633         PNode* tn = TrackManager::getInstance()->getTrackNode();
    634         tn->addChild(this->localPlayer);
    635         this->localCamera->lookAt(tn);
    636 
    637         tn->addChild(this->localCamera);
    638         this->localPlayer->setParentMode(PNODE_ALL);
    639         TrackManager::getInstance()->condition(2, LEFTRIGHT, this->localPlayer);
    640         */
    641474        this->glmis->step();
    642475        break;
     
    666499{
    667500  this->bPause = false;
    668   this->pilotNode = NULL;
    669501
    670502  /* update the object position before game start - so there are no wrong coordinates used in the first processing */
     
    842674void World::handleInput ()
    843675{
    844   // localinput
    845   //CommandNode* cn = Orxonox::getInstance()->getLocalInput();
    846   //cn->process();
    847 
    848676  EventHandler::getInstance()->process();
    849677
     
    897725
    898726      /* update tick the rest */
    899       TrackManager::getInstance()->tick(this->dtS);
    900727      this->localCamera->tick(this->dtS);
    901728      // tick the engines
Note: See TracChangeset for help on using the changeset viewer.