Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (20 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

Location:
orxonox/branches/levelloader/src/story_entities
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/story_entities/campaign.cc

    r3557 r3746  
    1818
    1919#include "campaign.h"
     20
     21#include "story_entity.h"
     22
    2023#include "world.h"
    2124#include "camera.h"
    22 #include "story_entity.h"
    2325#include "factory.h"
    2426#include "game_loader.h"
    2527
     28#include "list.h"
     29
    2630using namespace std;
    2731
     
    3034Campaign::Campaign ()
    3135{
    32   this->entities = new ListTemplate<StoryEntity>();
     36  this->entities = new tList<StoryEntity>();
    3337  this->isInit = false;
    3438}
     39
    3540
    3641Campaign::~Campaign () {}
     
    4752        GameLoader* loader = GameLoader::getInstance();
    4853       
    49   this->entities = new ListTemplate<StoryEntity>();
     54  this->entities = new tList<StoryEntity>();
    5055  this->isInit = false;
    5156 
     
    106111    {
    107112      se->displayLoadScreen();
     113      se->preLoad();
    108114      se->load();
    109115      se->init();
     
    232238  if( storyID == WORLD_ID_GAMEEND)
    233239    return NULL;
    234   ListTemplate<StoryEntity>* l;
     240
     241  /*
     242  tList<StoryEntity>* l;
    235243  StoryEntity* entity = NULL;
    236244  l = this->entities->getNext(); 
     
    239247      entity = l->getObject();
    240248      l = l->getNext();
     249
    241250      int id = entity->getStoryID();
    242251      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
     
    246255          return entity;
    247256        }
    248     }
     257
     258    }
     259  */
     260
     261
     262
     263  StoryEntity* entity = this->entities->enumerate();
     264  while( entity != NULL)
     265    {
     266      int id = entity->getStoryID();
     267      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
     268      if(id == storyID)
     269        {
     270          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
     271          return entity;
     272        }
     273      entity = this->entities->nextElement();
     274    }
     275
     276
     277
    249278  return NULL;
    250279}
  • orxonox/branches/levelloader/src/story_entities/campaign.h

    r3605 r3746  
    88
    99class World;
     10template<class T> class tList;
    1011
    1112class Campaign : public StoryEntity {
     
    3435
    3536 private:
    36   ListTemplate<StoryEntity>* entities;
     37  //ListTemplate<StoryEntity>* entities;
     38  tList<StoryEntity>* entities;
    3739  bool running;
    3840
  • orxonox/branches/levelloader/src/story_entities/story_entity.cc

    r3499 r3746  
    7272
    7373
     74/**
     75   \brief stuff that will have to be initialized before load
     76
     77   this gives all storyentities the possibility to init stuff before the
     78   load function, where all the stuff is been made ready for start
     79*/
     80ErrorMessage StoryEntity::preLoad()
     81{}
     82
     83/**
     84    \brief loads the current entity
     85
     86    this is here to enable you loading maps into the entities. for all other actions you
     87    should take the init() function.
     88    load() is exec before init()
     89*/
     90ErrorMessage StoryEntity::load()
     91{}
     92
     93
    7494/**
    7595    \brief initialize the entity before use.
     
    7898    After execution of this function, the Entity is ready to be played/executed,
    7999    this shifts the initialisation work before the execution - very important...
     100    init() is exec shortly before start()
    80101*/
    81102ErrorMessage StoryEntity::init()
    82103{}
    83104
    84 
    85 /**
    86     \brief loads the current entity
    87 
    88     this is here to enable you loading maps into the entities. for all other actions you
    89     should take the init() function.
    90 */
    91 ErrorMessage StoryEntity::load()
    92 {}
    93105
    94106/**
  • orxonox/branches/levelloader/src/story_entities/story_entity.h

    r3525 r3746  
    88#define _STORY_ENTITY_H
    99
    10 #include "stdincl.h"
     10#include "base_object.h"
    1111
    1212#include "story_def.h"
     13#include "error.h"
     14
    1315
    1416//! A class that represents something to play in orxonox. it is a container for worlds, movies, mission briefings, etc...
     
    2325  bool isPaused; //! is true if the entity is paused
    2426
     27  virtual ErrorMessage preLoad();
    2528  virtual ErrorMessage load();
    2629  virtual ErrorMessage init();
  • orxonox/branches/levelloader/src/story_entities/world.cc

    r3606 r3746  
    1818
    1919#include "world.h"
    20 #include "world_entity.h"
    21 #include "track_manager.h"
    22 #include "player.h"
    23 #include "command_node.h"
    24 #include "camera.h"
    25 #include "environment.h"
    26 #include "primitive.h"
     20
     21#include "orxonox.h"
     22
    2723#include "p_node.h"
    2824#include "null_parent.h"
    2925#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 "terrain.h"
     33#include "light.h"
     34
     35#include "track_manager.h"
     36#include "garbage_collector.h"
     37#include "simple_animation.h"
     38
     39#include "command_node.h"
    3040#include "glmenu_imagescreen.h"
    31 #include "skysphere.h"
    32 #include "light.h"
    3341#include "fontset.h"
     42#include "list.h"
    3443#include "factory.h"
    3544#include "game_loader.h"
     
    3746#include "terrain.h"
    3847
     48
     49
    3950using namespace std;
    4051
    4152CREATE_FACTORY(World);
     53
     54WorldInterface* WorldInterface::singletonRef = 0;
     55
     56
     57/**
     58   \brief private constructor because of singleton
     59*/
     60WorldInterface::WorldInterface()
     61{
     62  this->worldIsInitialized = false;
     63  this->worldReference = NULL;
     64}
     65
     66/**
     67   \brief public deconstructor
     68*/
     69WorldInterface::~WorldInterface()
     70{
     71  this->singletonRef = NULL;
     72  this->worldIsInitialized = false;
     73  this->worldReference = NULL;
     74}
     75
     76/**
     77   \brief gets the singleton instance
     78   \returns singleton instance
     79*/
     80WorldInterface* WorldInterface::getInstance()
     81{
     82  if( singletonRef == NULL)
     83    singletonRef = new WorldInterface();
     84  return singletonRef;
     85}
     86
     87
     88/**
     89   \brief initializes the interface
     90   \param reference to the world
     91
     92   if the worldinterface is not initilizes, there wont be any
     93   useable interface
     94*/
     95void WorldInterface::init(World* world)
     96{
     97  this->worldReference = world;
     98  if( world != NULL)
     99    {
     100      this->worldIsInitialized = true;
     101      PRINTF(3)("WorldInterface up and running\n");
     102    }
     103}
     104
     105
     106/**
     107   \brief gets the entity list from the world
     108   \return entity list
     109*/
     110tList<WorldEntity>* WorldInterface::getEntityList()
     111{
     112  if( this->worldIsInitialized)
     113    return this->worldReference->getEntities();
     114  PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
     115  return NULL;
     116}
     117
     118
    42119
    43120World::World( TiXmlElement* root)
     
    110187  cn->reset();
    111188
     189  ResourceManager::getInstance()->debug();
     190  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
     191  ResourceManager::getInstance()->debug();
     192
     193  delete WorldInterface::getInstance();
     194
    112195  delete this->nullParent;
    113196  delete this->entities;
     
    116199  if( this->worldName) delete this->worldName;
    117200  if( this->path) delete this->path;
    118 }
    119 
    120 /**
    121    \brief initializes a new World
     201
     202  //delete garbagecollecor
     203  //delete animator
     204}
     205
     206/**
     207   \brief initializes the world.
     208
     209   set all stuff here that is world generic and does not use to much memory
     210   because the real init() function StoryEntity::init() will be called
     211   shortly before start of the game. 
     212   since all worlds are initiated/referenced before they will be started.
     213   NO LEVEL LOADING HERE - NEVER!
    122214*/
    123215void World::init(char* name, int worldID)
     
    128220  this->debugWorldNr = worldID;
    129221  this->entities = new tList<WorldEntity>();
    130 
    131   // Enable default GL stuff
    132   glEnable(GL_DEPTH_TEST);
    133 
     222}
     223
     224
     225/**
     226   \brief this is executed before load
     227
     228   since the load function sometimes needs data, that has been init before
     229   the load and after the proceeding storyentity has finished
     230*/
     231ErrorMessage World::preLoad()
     232{
     233  /* init the world interface */
     234  WorldInterface* wi = WorldInterface::getInstance();
     235  wi->init(this);
     236  this->garbageCollector = GarbageCollector::getInstance();
     237  this->simpleAnimation = SimpleAnimation::getInstance();
    134238}
    135239
     
    153257        // load the campaign document
    154258        if( !XMLDoc->LoadFile())
     259      this->glmis->step();
    155260
    156261        {
     
    257362   
    258363        // bind camera
    259     this->localCamera = new Camera(this);
     364    this->localCamera = new Camera();
    260365    this->localCamera->setName ("camera");
    261     this->localCamera->bind (localPlayer);
     366    //this->localCamera->bind (localPlayer);
    262367    this->localPlayer->addChild (this->localCamera);
    263368
     
    267372      /*monitor progress*/
    268373  //  this->glmis->step();
     374
     375      // LIGHT initialisation
     376      lightMan = LightManager::getInstance();
     377      lightMan->setAmbientColor(.1,.1,.1);
     378      lightMan->addLight();
     379      //      lightMan->setAttenuation(1.0, .01, 0.0);
     380      //      lightMan->setDiffuseColor(1,1,1);
     381      //  lightMan->addLight(1);
     382      //  lightMan->setPosition(20, 10, -20);
     383      //  lightMan->setDiffuseColor(0,0,0);
     384      lightMan->debug();
     385            lightMan->setPosition(-5.0, 10.0, -40.0);
     386
    269387
    270388            // Create SkySphere
     
    274392            this->skySphere->setMode(PNODE_MOVEMENT);
    275393
    276             /*monitor progress*/
    277           //  this->glmis->step();
    278          
    279           //  trackManager->setBindSlave(env);
     394
     395            //      trackManager->setBindSlave(env);
     396            PNode* tn = trackManager->getTrackNode();
     397            tn->addChild(this->localPlayer);
     398
     399            //localCamera->setParent(TrackNode::getInstance());
     400            tn->addChild(this->localCamera);
     401            //      localCamera->lookAt(tn);
     402            this->localPlayer->setMode(PNODE_ALL);
     403            //Vector* cameraOffset = new Vector (0, 5, -10);
     404            //trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    280405
    281406  // initialize debug coord system
     
    290415  terrain->setRelCoor(new Vector(0,-10,0));
    291416  this->spawn(terrain);
    292 
    293 }
    294 
    295 /**
    296    \brief initializes a new World
     417}
     418
     419
     420/**
     421   \brief initializes a new World shortly before start
     422
     423   this is the function, that will be loaded shortly before the world is
     424   started
    297425*/
    298426ErrorMessage World::init()
     
    302430  cn->addToWorld(this);
    303431  cn->enable(true);
    304 
    305432PRINTF0("> Done Loading world: '%s'\n", getPath());
    306433}
     
    363490  this->glmis = GLMenuImageScreen::getInstance();
    364491  this->glmis->init();
    365   this->glmis->setMaximum(10);
     492  this->glmis->setMaximum(8);
    366493  this->glmis->draw();
    367494 
     
    378505  PRINTF(3)("World::releaseLoadScreen - start\n");
    379506  this->glmis->setValue(this->glmis->getMaximum());
    380   SDL_Delay(500);
     507  //SDL_Delay(500);
    381508  PRINTF(3)("World::releaseLoadScreen - end\n");
     509}
     510
     511
     512/**
     513   \brief gets the list of entities from the world
     514   \returns entity list
     515*/
     516tList<WorldEntity>* World::getEntities()
     517{
     518  return this->entities;
     519}
     520
     521
     522/**
     523   \brief this returns the current game time
     524   \returns elapsed game time
     525*/
     526double World::getGameTime()
     527{
     528  return this->gameTime;
    382529}
    383530
     
    435582  glLoadIdentity();
    436583
    437   entity = this->entities->enumerate();
     584  //entity = this->entities->enumerate();
     585  tIterator<WorldEntity>* iterator = this->entities->getIterator();
     586  entity = iterator->nextElement();
    438587  while( entity != NULL )
    439588    {
    440589      if( entity->bDraw ) entity->draw();
    441       entity = this->entities->nextElement();
    442     }
     590      //entity = this->entities->nextElement();
     591      entity = iterator->nextElement();
     592    }
     593  delete iterator;
    443594 
    444595  glCallList (objectList);
     
    477628  p4->debug ();
    478629 
    479   p1->update ();
     630  p1->update (0);
    480631
    481632  printf ("World::debug() - update\n");
     
    486637
    487638  p2->shiftCoor (new Vector(-1, -1, -1));
    488   p1->update ();
     639  p1->update (0);
    489640
    490641  p1->debug ();
     
    496647
    497648
    498  p1->update ();
     649 p1->update (0);
    499650
    500651  p1->debug ();
     
    593744  if(!this->bPause)
    594745    {
    595       Uint32 dt = currentFrame - this->lastFrame;
     746      this->dt = currentFrame - this->lastFrame;
    596747     
    597       if(dt > 0)
     748      if( this->dt > 0)
    598749        {
    599750          float fps = 1000/dt;
     
    607758          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
    608759          SDL_Delay(10);
    609           dt = 10;
     760          this->dt = 10;
    610761        }
    611762      //this->timeSlice (dt);
    612763     
    613764      /* function to let all entities tick (iterate through list) */
    614       WorldEntity* entity;
    615       float seconds = dt / 1000.0; 
    616       assert( this->nullParent != NULL);
    617       entity = entities->enumerate();
     765      float seconds = this->dt / 1000.0;     
     766      this->gameTime += seconds;
     767      //entity = entities->enumerate();
     768      tIterator<WorldEntity>* iterator = this->entities->getIterator();
     769      WorldEntity* entity = iterator->nextElement();
    618770      while( entity != NULL)
    619771        {
    620772          entity->tick (seconds);
    621           entity = entities->nextElement();
    622         }
     773          entity = iterator->nextElement();
     774        }
     775      delete iterator;
     776      //skySphere->updatePosition(localCamera->absCoordinate);
     777     
    623778      /* update tick the rest */
     779      this->trackManager->tick(this->dt);
    624780      assert( this->localCamera != NULL);
    625781      assert( this->trackManager != NULL);
    626       this->localCamera->tick(dt);
    627 
    628       this->trackManager->tick(dt);
     782      this->localCamera->tick(this->dt);
     783      this->garbageCollector->tick(seconds);
     784      this->simpleAnimation->tick(seconds);
    629785    }
    630786  this->lastFrame = currentFrame;
     
    640796void World::update()
    641797{
    642   this->nullParent->update ();
     798  this->garbageCollector->update();
     799  this->nullParent->update (dt);
    643800}
    644801
     
    728885bool World::command(Command* cmd)
    729886{
     887  if( !strcmp( cmd->cmd, "view0")) this->localCamera->setViewMode(VIEW_NORMAL);
     888  else if( !strcmp( cmd->cmd, "view1")) this->localCamera->setViewMode(VIEW_BEHIND);
     889  else if( !strcmp( cmd->cmd, "view2")) this->localCamera->setViewMode(VIEW_FRONT);
     890  else if( !strcmp( cmd->cmd, "view3")) this->localCamera->setViewMode(VIEW_LEFT);
     891  else if( !strcmp( cmd->cmd, "view4")) this->localCamera->setViewMode(VIEW_RIGHT);
     892  else if( !strcmp( cmd->cmd, "view5")) this->localCamera->setViewMode(VIEW_TOP);
     893 
    730894  return false;
    731895}
  • orxonox/branches/levelloader/src/story_entities/world.h

    r3605 r3746  
    88
    99#include "stdincl.h"
    10 
     10#include "comincl.h"
    1111#include "story_entity.h"
    1212#include "p_node.h"
    1313
     14
     15class World;
     16class WorldEntity;
    1417class TrackManager;
    15 class WorldEntity;
    1618class Camera;
    1719class PNode;
     
    2123class FontSet;
    2224class Terrain;
     25class GarbageCollector;
     26class SimpleAnimation;
    2327
     28//! The game world Interface
     29/**
     30   this is a singleton interface, that enables world_entities to access the
     31   world. for those objects, there is no easier way than over this interface!
     32*/
     33class WorldInterface : BaseObject {
     34
     35 public:
     36  ~WorldInterface();
     37  static WorldInterface* getInstance();
     38  void init(World* world);
     39  tList<WorldEntity>* getEntityList();
     40
     41 private:
     42  WorldInterface();
     43  static WorldInterface* singletonRef;    //!< singleton reference to this object
     44  bool worldIsInitialized;                //!< true if the world has been initialized
     45  World* worldReference;                  //!< this is a reference to the running world
     46
     47};
    2448
    2549//! The game world
     
    3963  virtual ~World ();
    4064
     65  double getGameTime();
    4166
    4267  /* classes from story-entity */
     68  virtual ErrorMessage preLoad();
    4369  virtual ErrorMessage load ();
    4470  virtual ErrorMessage init ();
     
    5581  bool command (Command* cmd);
    5682
     83  tList<WorldEntity>* getEntities();
     84
    5785  /* interface to world */
    5886  void spawn (WorldEntity* entity);
     
    6896  void init(char* name, int worldID);
    6997
    70   Uint32 lastFrame;             //!< last time of frame
    71   bool bQuitOrxonox;            //!< quit this application
    72   bool bQuitCurrentGame;        //!< quit only the current game and return to menu
    73   bool bPause;                  //!< pause mode
     98  Uint32 lastFrame;                   //!< last time of frame
     99  Uint32 dt;                          //!< time needed to calculate this frame
     100  double gameTime;                    //!< this is where the game time is saved
     101  bool bQuitOrxonox;                  //!< quit this application
     102  bool bQuitCurrentGame;              //!< quit only the current game and return to menu
     103  bool bPause;                        //!< pause mode
    74104
    75   FontSet* testFont;            //!< A test Font. \todo fix this, so it is for real.
    76   GLMenuImageScreen* glmis;     //!< The Level-Loader Display
     105  FontSet* testFont;                  //!< A test Font. \todo fix this, so it is for real.
     106  GLMenuImageScreen* glmis;           //!< The Level-Loader Display
    77107
    78108  char* worldName;              //!< The name of this World
     
    80110  int debugWorldNr;             //!< The Debug Nr. needed, if something goes wrong
    81111
    82   PNode* nullParent;            //!< The zero-point, that everything has as its parent.
    83   TrackManager* trackManager;   //!< The reference of the TrackManager that handles the course through the Level.
    84   Camera* localCamera;          //!< The current Camera
    85   Skysphere* skySphere;         //!< The Environmental Heaven of orxonox \todo insert this to environment insted
    86   LightManager* lightMan;       //!< The Lights of the Level
    87   Terrain* terrain;             //!< The Terrain of the World.
     112  PNode* nullParent;                  //!< The zero-point, that everything has as its parent.
     113  TrackManager* trackManager;         //!< The reference of the TrackManager that handles the course through the Level.
     114  Camera* localCamera;                //!< The current Camera
     115  Skysphere* skySphere;               //!< The Environmental Heaven of orxonox \todo insert this to environment insted
     116  LightManager* lightMan;             //!< The Lights of the Level
     117  Terrain* terrain;                   //!< The Terrain of the World.
    88118
    89   GLuint objectList;            //!< temporary: \todo this will be ereased soon
    90   tList<WorldEntity>* entities;//!< A template List of all entities. Every moving thing should be included here, and world automatically updates them.
    91   WorldEntity* localPlayer;     //!< The Player, you fly through the level.
     119  GLuint objectList;                  //!< temporary: \todo this will be ereased soon
     120  tList<WorldEntity>* entities;       //!< A template List of all entities. Every moving thing should be included here, and world automatically updates them.
     121  WorldEntity* localPlayer;           //!< The Player, you fly through the level.
     122
     123  GarbageCollector* garbageCollector; //!< reference to the garbage  collector
     124
     125  SimpleAnimation* simpleAnimation;   //!< reference to the SimpleAnimation object
    92126 
    93127  /* function for main-loop */
Note: See TracChangeset for help on using the changeset viewer.