Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6402 in orxonox.OLD


Ignore:
Timestamp:
Jan 3, 2006, 11:04:50 PM (18 years ago)
Author:
patrick
Message:

network: more modularity for the GameWorld: data and process are now totaly separated from each other, as it should be. Now I will do some magic on the MultiPlayerWorld, see if it works :D

Location:
branches/network/src
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/Makefile.am

    r6363 r6402  
    4848                  story_entities/story_entity.cc \
    4949                  story_entities/campaign.cc \
     50                  story_entities/campaign_data.cc \
    5051                  story_entities/game_world.cc \
     52                  story_entities/game_world_data.cc \
    5153                  story_entities/single_player_world.cc \
    5254                  story_entities/multi_player_world.cc \
     
    9799                 story_entities/story_def.h \
    98100                 story_entities/campaign.h \
     101                 story_entities/campaign_data.h \
    99102                 story_entities/game_world.h \
     103                 story_entities/game_world_data.h \
    100104                 story_entities/single_player_world.h \
    101105                 story_entities/multi_player_world.h \
  • branches/network/src/defs/class_id.h

    r6386 r6402  
    149149  CL_CAMPAIGN_DATA              =    0x00000102,
    150150  CL_GAME_WORLD                 =    0x00000103,
    151   CL_SINGLE_PLAYER_WORLD        =    0x00000104,
    152   CL_MULTI_PLAYER_WORLD         =    0x00000105,
     151  CL_GAME_WORLD_DATA            =    0x00000104,
     152  CL_SINGLE_PLAYER_WORLD        =    0x00000105,
     153  CL_SINGLE_PLAYER_WORLD_DATA   =    0x00000106,
     154  CL_MULTI_PLAYER_WORLD         =    0x00000107,
     155  CL_MULTI_PLAYER_WORLD_DATA    =    0x00000108,
    153156
    154157  // WorldEntities (range from 0x00000200 to 0x000004ff)
  • branches/network/src/lib/coord/p_node.cc

    r6341 r6402  
    152152  }
    153153}
     154
     155
     156/**
     157 *  init the pnode to a well definied state
     158 *
     159 * this function actualy only updates the PNode tree
     160 */
     161void PNode::init()
     162{
     163  /* just update all aboslute positions via timestep 0.001ms */
     164  this->updateNode(0.001f);
     165  this->updateNode(0.001f);
     166}
     167
    154168
    155169/**
  • branches/network/src/lib/coord/p_node.h

    r6341 r6402  
    7878
    7979  void loadParams(const TiXmlElement* root);
     80
     81  void init();
    8082
    8183  // ACTIVATION //
  • branches/network/src/story_entities/campaign.cc

    r6389 r6402  
    2121#include "load_param.h"
    2222
     23#include "campaign_data.h"
    2324
    2425using namespace std;
     
    6364
    6465  PRINTF(4)("Loaded Campaign specific stuff\n");
    65 
    6666}
    6767
     
    147147
    148148
    149 
    150 /* ==========================================================================================================
    151    CampaignData
    152    ==========================================================================================================
    153 */
    154 
    155 /**
    156  * constructor for CampaignData
    157  */
    158 CampaignData::CampaignData(const TiXmlElement* root)
    159 {
    160   this->setClassID(CL_CAMPAIGN_DATA, "CampaignData");
    161   this->currentEntity = NULL;
    162 
    163   this->loadParams(root);
    164 }
    165 
    166 
    167 /**
    168  * destructor for CampaignData
    169  */
    170 CampaignData::~CampaignData()
    171 {
    172   PRINTF(0)("Deleting CampaignData\n");
    173   while( !this->storyEntities.empty())
    174   {
    175     StoryEntity* bo = this->storyEntities.back();
    176     this->storyEntities.pop_back();
    177     PRINTF(0)("CampaignData is been deleted: nr %i\n", bo->getStoryID());
    178     delete bo;
    179   }
    180 }
    181 
    182 
    183 
    184 /**
    185  *  loads the Parameters of a Campaign
    186  * @param root: The XML-element to load from
    187  */
    188 void CampaignData::loadParams(const TiXmlElement* root)
    189 {
    190   LoadParamXML(root, "WorldList", this, CampaignData, loadParamsWorldList)
    191       .describe("A List of Worlds to be loaded in this Campaign");
    192 
    193 }
    194 
    195 
    196 /**
    197  *  loads a WorldList
    198  * @param root: the XML-element to load from
    199  */
    200 void CampaignData::loadParamsWorldList(const TiXmlElement* root)
    201 {
    202   if( root == NULL)
    203     return;
    204 
    205   LOAD_PARAM_START_CYCLE(root, element);
    206   {
    207     StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
    208     if( created != NULL)
    209       this->addStoryEntity(created);
    210   }
    211   LOAD_PARAM_END_CYCLE(element);
    212 }
    213 
    214 
    215 /**
    216  *  add the StoryEntity to the campaign data tank
    217  * @param se the StoryEntity to add
    218  */
    219 void CampaignData::addStoryEntity(StoryEntity* se)
    220 {
    221   this->storyEntities.push_back(se);
    222 }
    223 
    224 
    225 /**
    226  *  switch to the next level in the list and return it
    227  */
    228 StoryEntity* CampaignData::getFirstLevel()
    229 {
    230   int                            nextStoryID;
    231   int                            storyID;
    232   list<StoryEntity*>::iterator   it;
    233 
    234   nextStoryID = 0;
    235   this->currentEntity = NULL;
    236   for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
    237   {
    238     storyID = (*it)->getStoryID();
    239     if( storyID == nextStoryID)
    240       this->currentEntity = (*it);
    241   }
    242   return this->currentEntity;
    243 }
    244 
    245 
    246 /**
    247  *  switch to the next level in the list and return it
    248  */
    249 StoryEntity* CampaignData::getNextLevel()
    250 {
    251   int                            nextStoryID;
    252   int                            storyID;
    253   list<StoryEntity*>::iterator   it;
    254 
    255   nextStoryID = this->currentEntity->getNextStoryID();
    256   this->currentEntity = NULL;
    257   for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
    258   {
    259     storyID = (*it)->getStoryID();
    260     if( storyID == nextStoryID)
    261       this->currentEntity = (*it);
    262   }
    263   return this->currentEntity;
    264 }
    265 
    266 
    267 
    268 
    269 
  • branches/network/src/story_entities/campaign.h

    r6387 r6402  
    99
    1010#include "story_entity.h"
    11 #include <list>
    1211
    1312
     
    4039};
    4140
    42 
    43 
    44 //! A class that contains the data of the Campaign object
    45 class CampaignData : public BaseObject
    46 {
    47 
    48   public:
    49     CampaignData(const TiXmlElement* root);
    50     virtual ~CampaignData();
    51 
    52     void loadParams(const TiXmlElement* root);
    53 
    54     void addStoryEntity(StoryEntity* se);
    55 
    56     StoryEntity* getFirstLevel();
    57     StoryEntity* getNextLevel();
    58 
    59 
    60   private:
    61     void loadParamsWorldList(const TiXmlElement* root);
    62 
    63 
    64   private:
    65     StoryEntity*                  currentEntity;                //!< reference to the currently used StoryEntity
    66     std::list<StoryEntity*>       storyEntities;                //!< list of story entities
    67 };
    68 
    6941#endif /* _CAMPAIGN_H */
  • branches/network/src/story_entities/game_world.cc

    r6387 r6402  
    1818
    1919#include "game_world.h"
     20#include "game_world_data.h"
    2021
    2122#include "shell_command.h"
     
    8283
    8384GameWorld::GameWorld(const TiXmlElement* root)
    84   : StoryEntity()
     85    : StoryEntity()
    8586{
    8687  this->setClassID(CL_GAME_WORLD, "GameWorld");
     
    8990  this->gameTime = 0.0f;
    9091  this->setSpeed(1.0f);
    91   this->music = NULL;
    9292  this->shell = NULL;
    9393
     
    110110  if( this->gameWorldData)
    111111    delete this->gameWorldData;
     112
     113  PRINTF(0)("Deleted GameWorld\n");
    112114}
    113115
     
    123125
    124126  LoadParam(root, "path", this, GameWorld, setPath)
    125     .describe("The Filename of this GameWorld (relative from the data-dir)");
     127  .describe("The Filename of this GameWorld (relative from the data-dir)");
    126128
    127129  PRINTF(4)("Loaded GameWorld specific stuff\n");
     
    137139ErrorMessage GameWorld::init()
    138140{
    139   State::setObjectManager(&this->objectManager);
    140141  this->cycle = 0;
    141 
    142142  /* init the world interface */
    143143  this->shell = new Shell();
    144144
    145   LightManager::getInstance();
    146   PNode::getNullParent();
    147 
    148   AnimationPlayer::getInstance(); // initializes the animationPlayer
    149   ParticleEngine::getInstance();
    150   PhysicsEngine::getInstance();
    151 
    152   this->gameWorldData->localCamera = new Camera();
    153   this->gameWorldData->localCamera->setName ("GameWorld-Camera");
    154 
    155   State::setCamera(this->gameWorldData->localCamera, this->gameWorldData->localCamera->getTarget());
    156 
    157   GraphicsEngine::getInstance()->displayFPS(true);
     145  this->gameWorldData->init();
    158146}
    159147
     
    171159
    172160  if( getPath() == NULL)
    173     {
    174       PRINTF(1)("GameWorld has no path specified for loading");
    175       return (ErrorMessage){213,"Path not specified","GameWorld::load()"};
    176     }
     161  {
     162    PRINTF(1)("GameWorld has no path specified for loading");
     163    return (ErrorMessage){213,"Path not specified","GameWorld::load()"};
     164  }
    177165
    178166  TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    179   // load the campaign document
     167  // load the xml world file for further loading
    180168  if( !XMLDoc->LoadFile())
    181169  {
    182     // report an error
    183170    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    184171    delete XMLDoc;
    185172    return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"};
    186173  }
    187 
    188174  // check basic validity
    189175  TiXmlElement* root = XMLDoc->RootElement();
    190176  assert( root != NULL);
    191 
    192177  if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    193     {
    194       // report an error
    195       PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    196       delete XMLDoc;
    197       return (ErrorMessage){213,"Path not a WorldDataFile","GameWorld::load()"};
    198     }
    199 
    200   // load the parameters
    201   // name
    202   const char* string = grabParameter( root, "name");
    203   if( string == NULL)
    204     {
    205       PRINTF(2)("GameWorld is missing a proper 'name'\n");
    206       this->setName("Unknown");
    207     }
    208   else
    209     {
    210       this->setName(string);
    211     }
    212 
    213 
    214 
    215     this->gameWorldData->loadGUI(root);
    216 
    217 
    218     this->gameWorldData->loadWorldEntities(root);
    219 
    220     //////////////////////////////
    221     // LOADING ADDITIONAL STUFF //
    222     //////////////////////////////
    223 
    224     LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
    225 
    226    LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
    227 //   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    228 
    229   // free the XML data
     178  {
     179    // report an error
     180    PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
     181    delete XMLDoc;
     182    return (ErrorMessage){213,"Path not a WorldDataFile","GameWorld::load()"};
     183  }
     184  /* the whole loading process for the GameWorld */
     185  this->gameWorldData->loadData(root);
    230186
    231187  delete XMLDoc;
    232   /* GENERIC LOADING PROCESS FINISHED */
    233 
    234 
    235 
    236 
    237 
    238 //   //localCamera->setParent(TrackNode::getInstance());
    239 //  tn->addChild(this->localCamera);
    240   this->gameWorldData->localCamera->setClipRegion(1, 10000.0);
    241 //  localCamera->lookAt(playable);
    242 //  this->localPlayer->setParentMode(PNODE_ALL);
    243   if (this->gameWorldData->sky != NULL)
    244   {
    245     this->gameWorldData->localCamera->addChild(this->gameWorldData->sky);
    246   }
    247   SoundEngine::getInstance()->setListener(this->gameWorldData->localCamera);
    248 
    249   /* some static stuff*/
    250 
    251   this->music = NULL;
    252   //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
    253   //music->playback();
    254 
    255   /* update the object position before game start - so there are no wrong coordinates used in the first processing */
    256   PNode::getNullParent()->updateNode (0.001f);
    257   PNode::getNullParent()->updateNode (0.001f);
    258 
    259188  this->releaseLoadScreen();
    260189}
     
    269198  PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n");
    270199
    271   // delete all the initialized Engines.
    272   FastFactory::flushAll(true);
    273   delete LightManager::getInstance();
    274   delete ParticleEngine::getInstance();
    275   delete AnimationPlayer::getInstance();
    276   delete PhysicsEngine::getInstance();
    277 
    278   // external engines initialized by the orxonox-class get deleted
    279   SoundEngine::getInstance()->flushAllBuffers();
    280   SoundEngine::getInstance()->flushAllSources();
    281 
    282   if (State::getObjectManager() == &this->objectManager)
    283     State::setObjectManager(NULL);
    284   // erease everything that is left.
    285   delete PNode::getNullParent();
    286 
    287   //secondary cleanup of PNodes;
    288   const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
    289   if (nodeList != NULL)
    290     while (!nodeList->empty())
    291       delete nodeList->front();
    292 
    293   Shader::suspendShader();
    294 
    295   // unload the resources !!
    296   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
     200  this->gameWorldData->unloadData();
    297201}
    298202
     
    309213}
    310214
     215
    311216/**
    312217 *  stops the world.
    313 
    314    This happens, when the player decides to end the Level.
    315 */
     218 */
    316219bool GameWorld::stop()
    317220{
     
    320223}
    321224
    322 /**
    323  *  pauses the Game
    324 */
     225
     226/**
     227 *  pauses the game
     228 */
    325229bool GameWorld::pause()
    326230{
    327231  this->isPaused = true;
    328232}
     233
    329234
    330235/**
     
    338243
    339244/**
    340  *  shows the loading screen
    341 */
    342 void GameWorld::displayLoadScreen ()
    343 {
    344   PRINTF(3)("GameWorld::displayLoadScreen - start\n");
    345   this->gameWorldData->glmis = new GLMenuImageScreen();
    346   this->gameWorldData->glmis->setMaximum(8);
    347   PRINTF(3)("GameWorld::displayLoadScreen - end\n");
    348 }
    349 
    350 
    351 /**
    352  * @brief removes the loadscreen, and changes over to the game
    353  *
    354  * @todo take out the delay
    355 */
    356 void GameWorld::releaseLoadScreen ()
    357 {
    358   PRINTF(3)("GameWorld::releaseLoadScreen - start\n");
    359   this->gameWorldData->glmis->setValue(this->gameWorldData->glmis->getMaximum());
    360   PRINTF(3)("GameWorld::releaseLoadScreen - end\n");
    361   delete this->gameWorldData->glmis;
     245 *  main loop of the world: executing all world relevant function
     246 *
     247 * in this loop we synchronize (if networked), handle input events, give the heart-beat to
     248 * all other member-entities of the world (tick to player, enemies etc.), checking for
     249 * collisions drawing everything to the screen.
     250 */
     251void GameWorld::run()
     252{
     253  this->lastFrame = SDL_GetTicks ();
     254  PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
     255
     256  while( this->isRunning) /* @todo implement pause */
     257  {
     258    ++this->cycle;
     259    /* process intput */
     260    this->handleInput ();
     261    if( !this->isRunning)
     262      break;
     263
     264    /* network synchronisation */
     265    this->synchronize ();
     266    /* process time */
     267    this->tick ();
     268    /* process collision */
     269    this->collide ();
     270    /* update the state */
     271    this->update ();
     272    /* draw everything */
     273    this->display ();
     274  }
     275
     276  PRINTF(3)("GameWorld::mainLoop() - Exiting the main loop\n");
    362277}
    363278
     
    367282*/
    368283void GameWorld::synchronize ()
    369 {
    370   // Get remote input
    371   // Update synchronizables
    372 /*  NetworkManager::getInstance()->synchronize();*/
    373 }
     284{}
    374285
    375286
     
    383294{
    384295  EventHandler::getInstance()->process();
    385 
    386   // remoteinput
    387 }
    388 
     296}
     297
     298
     299/**
     300 *  ticks a WorldEntity list
     301 * @param entityList list of the WorldEntities
     302 * @param dt time passed since last frame
     303 */
    389304void GameWorld::tick(std::list<WorldEntity*> entityList, float dt)
    390305{
     
    397312/**
    398313 *  advance the timeline
    399 
    400    this calculates the time used to process one frame (with all input handling, drawing, etc)
    401    the time is mesured in ms and passed to all world-entities and other classes that need
    402    a heart-beat.
    403 */
     314 *
     315 * this calculates the time used to process one frame (with all input handling, drawing, etc)
     316 * the time is mesured in ms and passed to all world-entities and other classes that need
     317 * a heart-beat.
     318 */
    404319void GameWorld::tick ()
    405320{
    406321  Uint32 currentFrame = SDL_GetTicks();
     322
    407323  if( !this->isPaused)
     324  {
     325    this->dt = currentFrame - this->lastFrame;
     326
     327    /* limit the the frame rate to 100 frames per second (fps) */
     328    if( this->dt < 10)
    408329    {
    409       this->dt = currentFrame - this->lastFrame;
    410 
    411       if( this->dt > 10)
    412         {
    413           float fps = 1000/dt;
    414 
    415           // temporary, only for showing how fast the text-engine is
    416           char tmpChar[20];
    417           sprintf(tmpChar, "fps: %4.0f", fps);
    418         }
    419       else
    420         {
    421           /* the frame-rate is limited to 100 frames per second, all other things are for
    422              nothing.
    423           */
    424           PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
    425           SDL_Delay(10-dt);
    426           this->dt = 10;
    427         }
    428 
    429       this->dtS = (float)this->dt / 1000.0 * this->speed;
    430       this->gameTime += this->dtS;
    431 
    432       this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
    433       this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
    434       this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);
    435       this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
    436       this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
    437 
    438       /* update tick the rest */
    439       this->gameWorldData->localCamera->tick(this->dtS);
    440       // tick the engines
    441       AnimationPlayer::getInstance()->tick(this->dtS);
    442 //      if (this->cycle > 5)
    443         PhysicsEngine::getInstance()->tick(this->dtS);
    444 
    445       ParticleEngine::getInstance()->tick(this->dtS);
    446 
    447 
    448       /** actualy the Graphics Engine should tick the world not the other way around...
    449          but since we like the things not too complicated we got it this way around
    450          until there is need or time to do it the other way around.
    451          @todo: GraphicsEngine ticks world: separation of processes and data...
    452 
    453         bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
    454          beceause graphics have nothing(or at least not much) to do with Motion.
    455       */
    456       GraphicsEngine::getInstance()->tick(this->dtS);
     330      /* the frame-rate is limited to 100 frames per second, all other things are for nothing. */
     331      PRINTF(0)("fps = 1000 - frame rate is adjusted\n");
     332      SDL_Delay(10 - dt);
     333      this->dt = 10;
    457334    }
     335
     336    this->dtS = (float)this->dt / 1000.0f * this->speed;
     337    this->gameTime += this->dtS;
     338
     339    this->tick(this->gameWorldData->objectManager->getObjectList(OM_DEAD_TICK), this->dtS);
     340    this->tick(this->gameWorldData->objectManager->getObjectList(OM_COMMON), this->dtS);
     341    this->tick(this->gameWorldData->objectManager->getObjectList(OM_GROUP_00), this->dtS);
     342    this->tick(this->gameWorldData->objectManager->getObjectList(OM_GROUP_01), this->dtS);
     343    this->tick(this->gameWorldData->objectManager->getObjectList(OM_GROUP_01_PROJ), this->dtS);
     344
     345    /* update tick the rest */
     346    this->gameWorldData->localCamera->tick(this->dtS);
     347    AnimationPlayer::getInstance()->tick(this->dtS);
     348    ParticleEngine::getInstance()->tick(this->dtS);
     349    PhysicsEngine::getInstance()->tick(this->dtS);
     350
     351    GraphicsEngine::getInstance()->tick(this->dtS);
     352  }
    458353  this->lastFrame = currentFrame;
    459354}
     
    462357/**
    463358 *  this function gives the world a consistant state
    464 
    465    after ticking (updating the world state) this will give a constistant
    466    state to the whole system.
    467 */
     359 *
     360 * after ticking (updating the world state) this will give a constistant
     361 * state to the whole system.
     362 */
    468363void GameWorld::update()
    469364{
     
    475370
    476371
     372/**
     373 * kicks the CDEngine to detect the collisions between the object groups in the world
     374 */
    477375void GameWorld::collide()
    478376{
    479   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
    480                                             this->objectManager.getObjectList(OM_GROUP_01_PROJ));
    481   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),
    482                                             this->objectManager.getObjectList(OM_COMMON));
     377  CDEngine::getInstance()->checkCollisions(this->gameWorldData->objectManager->getObjectList(OM_GROUP_00),
     378      this->gameWorldData->objectManager->getObjectList(OM_GROUP_01_PROJ));
     379  CDEngine::getInstance()->checkCollisions(this->gameWorldData->objectManager->getObjectList(OM_GROUP_01),
     380      this->gameWorldData->objectManager->getObjectList(OM_COMMON));
    483381}
    484382
    485383/**
    486384 *  render the current frame
    487 
    488    clear all buffers and draw the world
    489 */
     385 *
     386 * clear all buffers and draw the world
     387 */
    490388void GameWorld::display ()
    491389{
     
    496394  // draw world
    497395  this->draw();
    498   // draw HUD
    499   /** @todo draw HUD */
    500396  // flip buffers
    501397  GraphicsEngine::swapBuffers();
    502   //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
    503   //SDL_Flip (screen);
    504398}
    505399
     
    511405{
    512406  GraphicsEngine* engine = GraphicsEngine::getInstance();
     407
     408   /* to draw the bounding boxes of the objects at level 2 for debug purp */
     409  if( unlikely( this->showBV))
     410  {
     411    CDEngine* engine = CDEngine::getInstance();
     412    engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
     413    engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));
     414    engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));
     415    engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));
     416    engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));
     417    engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
     418  }
     419  /* debug draw the PNodes */
     420  if( unlikely(this->showPNodes))
     421    PNode::getNullParent()->debugDraw(0);
     422
     423  /* draw all WorldEntiy groups */
    513424  engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    514425  engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));
     
    517428  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));
    518429  engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    519 
    520    if( unlikely( this->showBV))  // to draw the bounding boxes of the objects at level 2 for debug purp
    521    {
    522      CDEngine* engine = CDEngine::getInstance();
    523      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    524      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));
    525      engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));
    526      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));
    527      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));
    528      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    529    }
    530 
    531 //   {
    532 //     if( entity->isVisible() ) entity->draw();
    533   //FIXME
    534 //     entity = iterator->nextElement();
    535 //   }
    536 
     430  /* draws the particles */
    537431  ParticleEngine::getInstance()->draw();
    538432
    539   if (unlikely(this->showPNodes))
    540     PNode::getNullParent()->debugDraw(0);
    541 
     433  /* final draw command */
    542434  engine->draw();
    543   //TextEngine::getInstance()->draw();
    544 }
    545 
    546 
    547 /**
    548  * \brief main loop of the world: executing all world relevant function
    549  *
    550  * in this loop we synchronize (if networked), handle input events, give the heart-beat to
    551  * all other member-entities of the world (tick to player, enemies etc.), checking for
    552  * collisions drawing everything to the screen.
    553  */
    554 void GameWorld::run()
    555 {
    556   this->lastFrame = SDL_GetTicks ();
    557   PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
    558 
    559   while( this->isRunning) /* @todo implement pause */
    560   {
    561     ++this->cycle;
    562       // Network
    563     this->synchronize ();
    564       // Process input
    565     this->handleInput ();
    566     if( !this->isRunning)
    567       break;
    568       // Process time
    569     this->tick ();
    570       // Process collision
    571     this->collide ();
    572       // Update the state
    573     this->update ();
    574       // Draw
    575     this->display ();
    576   }
    577 
    578   PRINTF(3)("GameWorld::mainLoop() - Exiting the main loop\n");
    579 }
    580 
    581 
    582 
    583 /**
    584  *  add and spawn a new entity to this world
    585  * @param entity to be added
    586 */
    587 // void GameWorld::spawn(WorldEntity* entity)
    588 // {
    589 // //   this->entities->add (entity);
    590 //   entity->postSpawn ();
    591 // }
     435}
     436
    592437
    593438/**
     
    605450  }
    606451  else
    607     {
    608       this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
    609       sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
    610     }
    611 }
    612 
    613 
    614 
    615 
    616 
    617 
    618 
    619 GameWorldData::GameWorldData()
    620 {
    621   this->localPlayer = NULL;
    622   this->localCamera = NULL;
    623 
    624   this->glmis = NULL;
    625 
    626   this->localCamera = NULL;
    627   this->localPlayer = NULL;
    628   this->sky = NULL;
    629   this->terrain = NULL;
    630 
    631 }
    632 
    633 
    634 GameWorldData::~GameWorldData()
    635 {
    636   if( this->localPlayer)
    637     delete this->localPlayer;
    638 }
    639 
    640 
    641 
    642 ErrorMessage GameWorldData::loadData(TiXmlElement* root)
    643 {}
    644 
    645 
    646 
    647 
    648 ErrorMessage GameWorldData::loadGUI(TiXmlElement* root)
    649 {
    650   ////////////////
    651   // LOADSCREEN //
    652   ////////////////
    653   TiXmlElement* element = root->FirstChildElement("LoadScreen");
    654   if( element == NULL)
    655   {
    656     PRINTF(2)("no LoadScreen specified, loading default\n");
    657 
    658     glmis->setBackgroundImage("pictures/load_screen.jpg");
    659     this->glmis->setMaximum(8);
    660     this->glmis->draw();
    661   }
    662   else
    663   {
    664     this->glmis->loadParams(element);
    665     this->glmis->draw();
    666   }
    667   this->glmis->draw();
    668 
    669 }
    670 
    671 
    672 ErrorMessage GameWorldData::loadWorldEntities(TiXmlElement* root)
    673 {
    674   ////////////////////////
    675   // find WorldEntities //
    676   ////////////////////////
    677 
    678   TiXmlElement* element = root->FirstChildElement("WorldEntities");
    679 
    680   if( element == NULL)
    681   {
    682     PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
    683   }
    684   else
    685   {
    686     element = element->FirstChildElement();
    687       // load Players/Objects/Whatever
    688     PRINTF(4)("Loading WorldEntities\n");
    689     while( element != NULL)
    690     {
    691       BaseObject* created = Factory::fabricate(element);
    692       if( created != NULL )
    693         printf("Created a %s: %s\n", created->getClassName(), created->getName());
    694 
    695 
    696           //todo do this more elegant
    697       if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    698         this->sky = dynamic_cast<WorldEntity*>(created);
    699       if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    700       {
    701         this->terrain = dynamic_cast<Terrain*>(created);
    702         CDEngine::getInstance()->setTerrain(terrain);
    703       }
    704       element = element->NextSiblingElement();
    705       this->glmis->step(); //! @todo temporary
    706     }
    707     PRINTF(4)("Done loading WorldEntities\n");
    708   }
    709 
    710     // Create a Player
    711   this->localPlayer = new Player();
    712 
    713   Playable* playable;
    714   const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    715   if (playableList != NULL)
    716   {
    717     playable = dynamic_cast<Playable*>(playableList->front());
    718     this->localPlayer->setControllable(playable);
    719   }
    720 }
    721 
    722 
    723 ErrorMessage GameWorldData::loadScene(TiXmlElement* root)
    724 {}
    725 
     452  {
     453    this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
     454    sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
     455  }
     456}
     457
     458
     459/**
     460 *  shows the loading screen
     461 */
     462void GameWorld::displayLoadScreen ()
     463{
     464  PRINTF(3)("GameWorld::displayLoadScreen - start\n");
     465  this->gameWorldData->glmis = new GLMenuImageScreen();
     466  this->gameWorldData->glmis->setMaximum(8);
     467  PRINTF(3)("GameWorld::displayLoadScreen - end\n");
     468}
     469
     470
     471/**
     472 *  removes the loadscreen, and changes over to the game
     473 */
     474void GameWorld::releaseLoadScreen ()
     475{
     476  PRINTF(3)("GameWorld::releaseLoadScreen - start\n");
     477  this->gameWorldData->glmis->setValue(this->gameWorldData->glmis->getMaximum());
     478  PRINTF(3)("GameWorld::releaseLoadScreen - end\n");
     479}
     480
  • branches/network/src/story_entities/game_world.h

    r6387 r6402  
    77#define _GAME_WORLD_H
    88
    9 #include "sdlincl.h"
     9
    1010#include "story_entity.h"
    11 #include "object_manager.h"
    1211
     12
     13class TiXmlElement;
     14class Shell;
    1315class WorldEntity;
    14 class Camera;
    15 class Player;
    16 class GLMenuImageScreen;
    17 class Terrain;
    18 class TiXmlElement;
     16class GameWorldData;
    1917
    20 class Shell;
    21 class OggPlayer;
    22 class GameWorldData;
    2318
    2419//! The game world
     
    8681
    8782    /* world timing */
    88     Uint32              lastFrame;                   //!< last time of frame
    89     Uint32              cycle;                       //!< The cycle we are in (starts with 0 and rises with every frame)
    90     Uint32              dt;                          //!< time needed to calculate this frame (in milliSeconds)
    91     float               dtS;                         //!< The time needed for caluculations in seconds
    92     float               speed;                       //!< how fast the game flows
    93     double              gameTime;                    //!< this is where the game time is saved
    94 
    95     /* external modules interfaces */
    96     ObjectManager objectManager;                     //!< The ObjectManager of this GameWorld.
     83    Uint32              lastFrame;                    //!< last time of frame
     84    Uint32              cycle;                        //!< The cycle we are in (starts with 0 and rises with every frame)
     85    Uint32              dt;                           //!< time needed to calculate this frame (in milliSeconds)
     86    float               dtS;                          //!< The time needed for caluculations in seconds
     87    float               speed;                        //!< how fast the game flows
     88    double              gameTime;                     //!< this is where the game time is saved
    9789
    9890    /* external modules interfaces */
    9991    Shell*              shell;
    100     OggPlayer*          music;
    101 
    102     /* important entities */
    103 };
    104 
    105 
    106 class GameWorldData : public BaseObject
    107 {
    108 
    109   public:
    110     GameWorldData();
    111     ~GameWorldData();
    112     /* world loading functions */
    113     virtual ErrorMessage loadData(TiXmlElement* root);
    114 
    115     virtual ErrorMessage loadGUI(TiXmlElement* root);
    116     virtual ErrorMessage loadWorldEntities(TiXmlElement* root);
    117     virtual ErrorMessage loadScene(TiXmlElement* root);
    118 
    119   public:
    120     GLMenuImageScreen*  glmis;                        //!< The Level-Loader Display
    121 
    122     Camera*             localCamera;                 //!< The current Camera
    123     Player*             localPlayer;                 //!< The Player, you fly through the level.
    124     WorldEntity*        sky;                         //!< The Environmental Heaven of orxonox @todo insert this to environment insted
    125     Terrain*            terrain;                     //!< The Terrain of the GameWorld.
    126 
    12792};
    12893
  • branches/network/src/story_entities/multi_player_world.cc

    r6387 r6402  
    5151  : GameWorld(root)
    5252{
    53   this->constuctorInit("", -1);
     53  this->setClassID(CL_MULTI_PLAYER_WORLD, "MultiPlayerWorld");
     54
    5455  this->path = NULL;
    5556
     
    8384void MultiPlayerWorld::constuctorInit(const char* name, int worldID)
    8485{
    85   this->setClassID(CL_MULTI_PLAYER_WORLD, "MultiPlayerWorld");
    86   this->setName(name);
    87 
    8886  this->gameTime = 0.0f;
    8987  this->setSpeed(1.0);
    90   this->music = NULL;
    9188  this->shell = NULL;
    9289
  • branches/network/src/story_entities/single_player_world.cc

    r6376 r6402  
    3838  : GameWorld(root)
    3939{
    40   this->setClassID(CL_SINGLE_PLAYER_WORLD, "SinglePlayerSinglePlayerWorld");
     40  this->setClassID(CL_SINGLE_PLAYER_WORLD, "SinglePlayerWorld");
    4141  this->setName("SinglePlayerWorld uninitialized");
    4242
Note: See TracChangeset for help on using the changeset viewer.