Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6386 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
Jan 2, 2006, 1:30:23 AM (19 years ago)
Author:
patrick
Message:

network: many changes in the StoryEntity and Campaign framework: introduced CampaignData as a container for the data of the Campaign and made some changes in the GameWorlds, which are not yet finished

Location:
branches/network/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/class_id.h

    r6358 r6386  
    147147  // StoryEntities (range from 0x00000100 to 0x000001ff)
    148148  CL_CAMPAIGN                   =    0x00000101,
    149   CL_GAME_WORLD                 =    0x00000102,
    150   CL_SINGLE_PLAYER_WORLD        =    0x00000103,
    151   CL_MULTI_PLAYER_WORLD         =    0x00000104,
     149  CL_CAMPAIGN_DATA              =    0x00000102,
     150  CL_GAME_WORLD                 =    0x00000103,
     151  CL_SINGLE_PLAYER_WORLD        =    0x00000104,
     152  CL_MULTI_PLAYER_WORLD         =    0x00000105,
    152153
    153154  // WorldEntities (range from 0x00000200 to 0x000004ff)
  • branches/network/src/story_entities/campaign.cc

    r6376 r6386  
    3434{
    3535  this->setClassID(CL_CAMPAIGN, "Campaign");
    36   this->isInit = false;
    3736
    3837  PRINTF(4)("Loading Campaign...\n");
    3938  assert( root != NULL);
    4039
     40  this->campaignData = new CampaignData();
    4141  this->loadParams(root);
    4242}
     
    5151
    5252/**
    53  *  initializes the class
    54  */
    55 ErrorMessage Campaign::init()
    56 {
    57   this->isInit = true;
    58 }
    59 
    60 
    61 /**
    6253 *  loads the Parameters of a Campaign
    6354 * @param root: The XML-element to load from
     
    8778    StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
    8879    if( created != NULL)
    89       this->addEntity( created);
    90     PRINTF(3)("Campaign: Constructor: adding a world with name \"%s\" and id %i\n",
    91               created->getName(), created->getStoryID());
     80      this->campaignData->addStoryEntity(created);
    9281  }
    9382  LOAD_PARAM_END_CYCLE(element);
     
    9786
    9887/**
    99  *  starts the campaing
    100  */
    101 ErrorMessage Campaign::start()
    102 {
    103   this->start(0);
     88 *  initializes the class
     89 */
     90ErrorMessage Campaign::init()
     91{
     92  this->isInit = true;
    10493}
    10594
     
    10998 * @param storyID the id of the StoryEntity
    11099 */
    111 ErrorMessage Campaign::start(int storyID = 0)
    112 {
    113   ErrorMessage errorCode;
    114   if( !this->isInit) return errorCode;
    115   if( storyID == WORLD_ID_GAMEEND) return errorCode;
    116   this->running = true;
    117   StoryEntity* se = this->getStoryEntity(storyID);
    118   this->currentEntity = se;
    119   while( se != NULL && this->running)
    120   {
    121     PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", se->getStoryID());
    122 
    123     se->init();
    124     se->loadData();
    125 
    126     se->preStart();
    127     se->start();
    128 
    129 
    130     int nextWorldID = se->getNextStoryID();
    131 
    132     this->entities.remove(se);
    133     delete se;
    134 
    135     se = this->getStoryEntity(nextWorldID);
    136     this->currentEntity = se;
    137     if( ( nextWorldID == WORLD_ID_GAMEEND) || ( se == NULL) )
    138     {
    139       PRINTF(4)("Quitting campaing story loop\n");
    140       if(se != NULL)
    141         delete se;
    142       return errorCode;
    143     }
    144   }
    145 
    146   /* clean up all world that have not been loaded and therefore are still in the world list  -
    147      this probably does not belong into the start function. remove this later
    148   */
    149   list<StoryEntity*>::iterator it;
    150   for(it = this->entities.begin(); it != entities.end(); it++)
    151   {
    152     delete (*it);
     100ErrorMessage Campaign::start()
     101{
     102  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
     103
     104  ErrorMessage       errorCode;
     105  int                storyID = WORLD_ID_0;
     106
     107  for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true;
     108       this->currentEntity != NULL && this->isRunning;
     109       this->currentEntity = this->campaignData->getNextLevel())
     110  {
     111    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
     112
     113    this->currentEntity->init();
     114    this->currentEntity->loadData();
     115    this->currentEntity->start();
     116    this->currentEntity->unloadData();
    153117  }
    154118
     
    158122
    159123/**
    160  *  pauses the campaing
     124 *  pauses the campaign
    161125 */
    162126ErrorMessage Campaign::pause()
    163127{
    164   if(this->currentEntity != NULL)
     128  if( this->currentEntity != NULL)
    165129    this->isPaused = true;
    166130}
    167131
    168132
     133/**
     134 *  resumes the campaign after a pause
     135 */
    169136ErrorMessage Campaign::resume()
    170137{
    171   if(this->currentEntity != NULL)
     138  if( this->currentEntity != NULL)
    172139    this->isPaused = false;
    173140}
    174141
    175142
     143/**
     144 *  stops the campaign
     145 */
    176146ErrorMessage Campaign::stop()
    177147{
    178   this->running = false;
    179   if(this->currentEntity != NULL)
     148  this->isRunning = false;
     149  if( this->currentEntity != NULL)
    180150  {
    181151    this->currentEntity->stop();
     
    183153}
    184154
    185 /*
    186 ErrorMessage Campaign::destroy()
    187 {
    188   if(this->currentEntity != NULL)
    189     {
    190       this->currentEntity->destroy();
    191       delete this->currentEntity;
    192       this->currentEntity = NULL;
    193     }
    194 }*/
    195 
    196 
    197 /**
    198   *  adds an game stroy entity to the campaign
    199 
    200   * @param se: The entity
    201   * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
    202 
    203     An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
    204     want to queue up in the campaign.
    205 */
    206 void Campaign::addEntity(StoryEntity* se, int storyID)
    207 {
    208   se->setStoryID(storyID);
    209   this->addEntity(se);
    210 }
    211 
    212 void Campaign::addEntity(StoryEntity* se)
    213 {
    214   this->entities.push_back(se);
    215 }
    216 
    217 
    218 void Campaign::removeEntity(int storyID)
    219 {
    220   this->removeEntity(this->getStoryEntity(storyID));
    221 
    222 }
    223 
    224 
    225 void Campaign::removeEntity(StoryEntity* se)
    226 {
    227   this->entities.remove(se);
    228 }
    229 
    230 
    231 /*
    232   \brief this changes to the next level
    233 */
    234 void Campaign::nextLevel()
     155
     156/**
     157 *  this changes to the next level
     158 */
     159void Campaign::switchToNextLevel()
    235160{
    236161  PRINTF(4)("Campaign:nextLevel()\n");
     
    238163}
    239164
    240 /*
    241   \brief change to the previous level - not implemented
    242 
    243   this propably useless
    244 */
    245 void Campaign::previousLevel()
     165
     166
     167/* CampaignData */
     168
     169/**
     170 * constructor for CampaignData
     171 */
     172CampaignData::CampaignData()
     173{
     174  this->setClassID(CL_CAMPAIGN_DATA, "CampaignData");
     175  this->currentEntity = NULL;
     176}
     177
     178
     179/**
     180 * destructor for CampaignData
     181 */
     182CampaignData::~ CampaignData()
    246183{}
    247184
    248185
    249 /*
    250   \brief lookup a entity with a given id
    251 * @param story id to be lookuped
    252   @returns the entity found or NULL if search ended without match
    253 */
    254 StoryEntity* Campaign::getStoryEntity(int storyID)
    255 {
    256   if( storyID == WORLD_ID_GAMEEND)
    257     return NULL;
    258 
    259   int id;
    260   list<StoryEntity*>::iterator it;
    261   for( it = this->entities.begin(); it != this->entities.end(); it++)
    262   {
    263     id = (*it)->getStoryID();
    264     if( id == storyID)
    265       return (*it);
    266   }
    267 
    268   return NULL;
    269 }
     186/**
     187 *  add the StoryEntity to the campaign data tank
     188 * @param se the StoryEntity to add
     189 */
     190void CampaignData::addStoryEntity(StoryEntity* se)
     191{
     192  this->storyEntities.push_back(se);
     193}
     194
     195
     196/**
     197 *  switch to the next level in the list and return it
     198 */
     199StoryEntity* CampaignData::getFirstLevel()
     200{
     201  int                            nextStoryID;
     202  int                            storyID;
     203  list<StoryEntity*>::iterator   it;
     204
     205  nextStoryID = 0;
     206  this->currentEntity = NULL;
     207  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
     208  {
     209    storyID = (*it)->getStoryID();
     210    if( storyID == nextStoryID)
     211      this->currentEntity = (*it);
     212  }
     213  return this->currentEntity;
     214}
     215
     216
     217/**
     218 *  switch to the next level in the list and return it
     219 */
     220StoryEntity* CampaignData::getNextLevel()
     221{
     222  int                            nextStoryID;
     223  int                            storyID;
     224  list<StoryEntity*>::iterator   it;
     225
     226  nextStoryID = this->currentEntity->getNextStoryID();
     227  this->currentEntity = NULL;
     228  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
     229  {
     230    storyID = (*it)->getStoryID();
     231    if( storyID == nextStoryID)
     232      this->currentEntity = (*it);
     233  }
     234  return this->currentEntity;
     235}
     236
     237
     238
     239
     240
  • branches/network/src/story_entities/campaign.h

    r6374 r6386  
     1/*!
     2 * @file campaign.h
     3 * definition of the campaign
     4 */
    15
    26#ifndef _CAMPAIGN_H
    37#define _CAMPAIGN_H
    48
     9
    510#include "story_entity.h"
    6 
    711#include <list>
    812
    9 class World;
     13
    1014class TiXmlElement;
     15class CampaignData;
    1116
     17
     18//! A class that represents a game Campaign that contains other StoryEntities like GameWorlds, movies, etc.
    1219class Campaign : public StoryEntity
    1320{
     
    2229    virtual ErrorMessage init();
    2330    virtual ErrorMessage start();
    24     virtual ErrorMessage start(int storyID);
    2531    virtual ErrorMessage pause();
    2632    virtual ErrorMessage resume();
    2733    virtual ErrorMessage stop();
    2834
    29     void addEntity(StoryEntity* se, int storyID);
    30     void addEntity(StoryEntity* se);
    31     void removeEntity(int storyID);
    32     void removeEntity(StoryEntity* se);
    33 
    34     void nextLevel();
    35     void previousLevel();
     35    void switchToNextLevel();
    3636
    3737
    3838  private:
    39     StoryEntity* getStoryEntity(int storyID);
    40 
    41 
    42   private:
    43     StoryEntity* currentEntity;
    44     std::list<StoryEntity*> entities;
    45     bool running;
    46 
     39    StoryEntity*                        currentEntity;          //!< reference to the current StoryEntity
     40    CampaignData*                       campaignData;           //!< reference to the CampaignData
    4741};
    4842
    4943
    5044
     45//! A class that contains the data of the Campaign object
    5146class CampaignData : virtual public BaseObject
    5247{
     
    5651    virtual ~CampaignData();
    5752
    58     void addStoryEntity(StoryEntity* se, int storyID = -1);
     53    void addStoryEntity(StoryEntity* se);
    5954
    60     void getNextLevel();
     55    StoryEntity* getFirstLevel();
     56    StoryEntity* getNextLevel();
     57
     58
     59  private:
     60    StoryEntity*                  currentEntity;                //!< reference to the currently used StoryEntity
     61    std::list<StoryEntity*>       storyEntities;                //!< list of story entities
    6162};
    6263
  • branches/network/src/story_entities/debug_world.cc

    r6222 r6386  
    1 /*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
    10 
    11    ### File Specific:
    12    main-programmer: Patrick Boenzli
    13    co-programmer: Christian Meyer
    14    co-programmer: Benjamin Grauer
    15 */
    16 
    17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
    18 
    19 #include "world.h"
    20 
    21 #include "shell_command.h"
    22 
    23 #include "state.h"
    24 
    25 #include "p_node.h"
    26 #include "pilot_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 "test_entity.h"
    35 #include "terrain.h"
    36 #include "light.h"
    37 #include "load_param.h"
    38 #include "shell.h"
    39 
    40 #include "fast_factory.h"
    41 #include "animation_player.h"
    42 #include "particle_engine.h"
    43 #include "graphics_engine.h"
    44 #include "physics_engine.h"
    45 #include "fields.h"
    46 
    47 #include "md2Model.h"
    48 
    49 #include "glmenu_imagescreen.h"
    50 #include "game_loader.h"
    51 
    52 #include "animation3d.h"
    53 
    54 #include "substring.h"
    55 
    56 #include "factory.h"
    57 
    58 #include "weapons/projectile.h"
    59 #include "event_handler.h"
    60 #include "sound_engine.h"
    61 #include "ogg_player.h"
    62 
    63 #include "class_list.h"
    64 
    65 #include "cd_engine.h"
    66 #include "npcs/npc_test1.h"
    67 #include "shader.h"
    68 
    69 #include "playable.h"
    70 #include "network_manager.h"
    71 #include "playable.h"
    72 
    73 
    74 SHELL_COMMAND(speed, World, setSpeed);
    75 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);
    76 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);
    77 
    78 using namespace std;
    79 
    80 //! This creates a Factory to fabricate a World
    81 CREATE_FACTORY(World, CL_WORLD);
    82 
    83 World::World(const TiXmlElement* root)
    84 {
    85   this->constuctorInit("", -1);
    86   this->path = NULL;
    87 
    88   this->loadParams(root);
    89 }
    90 
    91 /**
    92   *  create a new World
    93 
    94     This creates a new empty world!
    95 */
    96 World::World (const char* name)
    97 {
    98   this->path = NULL;
    99   this->constuctorInit(name, -1);
    100 }
    101 
    102 /**
    103  *  creates a new World...
    104  * @param worldID with this ID
    105 */
    106 World::World (int worldID)
    107 {
    108   this->path = NULL;
    109   this->constuctorInit(NULL, worldID);
    110 }
    111 
    112 /**
    113  *  remove the World from memory
    114 
    115     delete everything explicitly, that isn't contained in the parenting tree!
    116     things contained in the tree are deleted automaticaly
    117  */
    118 World::~World ()
    119 {
    120   delete this->shell;
    121   PRINTF(3)("World::~World() - deleting current world\n");
    122 
    123   delete this->localPlayer;
    124 
    125   // delete all the initialized Engines.
    126   FastFactory::flushAll(true);
    127   delete LightManager::getInstance();
    128   delete ParticleEngine::getInstance();
    129   delete AnimationPlayer::getInstance();
    130   delete PhysicsEngine::getInstance();
    131 
    132   // external engines initialized by the orxonox-class get deleted
    133   SoundEngine::getInstance()->flushAllBuffers();
    134   SoundEngine::getInstance()->flushAllSources();
    135 
    136   if (State::getObjectManager() == &this->objectManager)
    137     State::setObjectManager(NULL);
    138   // erease everything that is left.
    139   delete PNode::getNullParent();
    140 
    141   //secondary cleanup of PNodes;
    142   const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
    143   if (nodeList != NULL)
    144     while (!nodeList->empty())
    145       delete nodeList->front();
    146 
    147   Shader::suspendShader();
    148 
    149   // unload the resources !!
    150   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    151 
    152   delete[] this->path;
    153 }
    154 
    155 /**
    156  * initializes the world.
    157  * @param name the name of the world
    158  * @param worldID the ID of this world
    159  *
    160  * set all stuff here that is world generic and does not use to much memory
    161  * because the real init() function StoryEntity::init() will be called
    162  * shortly before start of the game.
    163  * since all worlds are initiated/referenced before they will be started.
    164  * NO LEVEL LOADING HERE - NEVER!
    165 */
    166 void World::constuctorInit(const char* name, int worldID)
    167 {
    168   this->setClassID(CL_WORLD, "World");
    169 
    170   this->setName(name);
    171   this->debugWorldNr = worldID;
    172   this->gameTime = 0.0f;
    173   this->setSpeed(1.0);
    174   this->music = NULL;
    175   this->shell = NULL;
    176   this->localPlayer = NULL;
    177   this->localCamera = NULL;
    178 
    179   this->showPNodes = false;
    180   this->showBV = false;
    181 }
    182 
    183 /**
    184  * loads the parameters of a World from an XML-element
    185  * @param root the XML-element to load from
    186  */
    187 void World::loadParams(const TiXmlElement* root)
    188 {
    189   PRINTF(4)("Creating a World\n");
    190 
    191   LoadParam(root, "identifier", this, World, setStoryID)
    192     .describe("Sets the StoryID of this world");
    193 
    194   LoadParam(root, "nextid", this, World, setNextStoryID)
    195     .describe("Sets the ID of the next world");
    196 
    197   LoadParam(root, "path", this, World, setPath)
    198     .describe("The Filename of this World (relative from the data-dir)");
    199 }
    200 
    201 /**
    202  * this is executed just before load
    203  *
    204  * since the load function sometimes needs data, that has been initialized
    205  * before the load and after the proceeding storyentity has finished
    206 */
    207 ErrorMessage World::preLoad()
    208 {
    209   State::setObjectManager(&this->objectManager);
    210   this->cycle = 0;
    211 
    212   /* init the world interface */
    213   this->shell = new Shell();
    214 
    215   LightManager::getInstance();
    216   PNode::getNullParent();
    217 
    218   AnimationPlayer::getInstance(); // initializes the animationPlayer
    219   ParticleEngine::getInstance();
    220   PhysicsEngine::getInstance();
    221 
    222   this->localCamera = new Camera();
    223   this->localCamera->setName ("World-Camera");
    224 
    225   State::setCamera(this->localCamera, this->localCamera->getTarget());
    226 
    227   GraphicsEngine::getInstance()->displayFPS(true);
    228 }
    229 
    230 
    231 /**
    232  *  loads the World by initializing all resources, and set their default values.
    233 */
    234 ErrorMessage World::load()
    235 {
    236   PRINTF(3)("> Loading world: '%s'\n", getPath());
    237   TiXmlElement* element;
    238   GameLoader* loader = GameLoader::getInstance();
    239 
    240   if( getPath() == NULL)
    241     {
    242       PRINTF(1)("World has no path specified for loading");
    243       this->loadDebugWorld(this->getStoryID());
    244       return (ErrorMessage){213,"Path not specified","World::load()"};
    245     }
    246 
    247   TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    248   // load the campaign document
    249   if( !XMLDoc->LoadFile())
    250   {
    251     // report an error
    252     PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    253     delete XMLDoc;
    254     return (ErrorMessage){213,"XML File parsing error","World::load()"};
    255   }
    256 
    257   // check basic validity
    258   TiXmlElement* root = XMLDoc->RootElement();
    259   assert( root != NULL);
    260 
    261   if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    262     {
    263       // report an error
    264       PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    265       delete XMLDoc;
    266       return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
    267     }
    268 
    269   // load the parameters
    270   // name
    271   const char* string = grabParameter( root, "name");
    272   if( string == NULL)
    273     {
    274       PRINTF(2)("World is missing a proper 'name'\n");
    275       this->setName("Unknown");
    276     }
    277   else
    278     {
    279       this->setName(string);
    280     }
    281 
    282   ////////////////
    283   // LOADSCREEN //
    284   ////////////////
    285   element = root->FirstChildElement("LoadScreen");
    286   if (element == NULL)
    287     {
    288       PRINTF(2)("no LoadScreen specified, loading default\n");
    289 
    290       glmis->setBackgroundImage("pictures/load_screen.jpg");
    291       this->glmis->setMaximum(8);
    292       this->glmis->draw();
    293     }
    294   else
    295     {
    296       this->glmis->loadParams(element);
    297       this->glmis->draw();
    298     }
    299   this->glmis->draw();
    300 
    301   ////////////////////////
    302   // find WorldEntities //
    303   ////////////////////////
    304 
    305   element = root->FirstChildElement("WorldEntities");
    306 
    307   if( element == NULL)
    308     {
    309       PRINTF(1)("World is missing 'WorldEntities'\n");
    310     }
    311   else
    312     {
    313       element = element->FirstChildElement();
    314       // load Players/Objects/Whatever
    315       PRINTF(4)("Loading WorldEntities\n");
    316       while( element != NULL)
    317         {
    318           BaseObject* created = Factory::fabricate(element);
    319           if( created != NULL )
    320           {
    321             if(created->isA(CL_WORLD_ENTITY))
    322               this->spawn(dynamic_cast<WorldEntity*>(created));
    323             printf("Created a %s: %s\n", created->getClassName(), created->getName());
    324           }
    325 
    326           // if we load a 'Player' we use it as localPlayer
    327 
    328 
    329           //todo do this more elegant
    330           if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    331             sky = dynamic_cast<SkyBox*>(created);
    332           if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    333           {
    334             terrain = dynamic_cast<Terrain*>(created);
    335             CDEngine::getInstance()->setTerrain(terrain);
    336           }
    337           element = element->NextSiblingElement();
    338           glmis->step(); //! @todo temporary
    339         }
    340       PRINTF(4)("Done loading WorldEntities\n");
    341     }
    342 
    343     //////////////////////////////
    344     // LOADING ADDITIONAL STUFF //
    345     //////////////////////////////
    346 
    347     LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
    348 
    349    LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
    350 //   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    351 
    352   // free the XML data
    353 
    354   delete XMLDoc;
    355   /* GENERIC LOADING PROCESS FINISHED */
    356 
    357 
    358   // Create a Player
    359   this->localPlayer = new Player();
    360 
    361   Playable* playable;
    362   const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    363   if (playableList != NULL)
    364   {
    365     playable = dynamic_cast<Playable*>(playableList->front());
    366     this->localPlayer->setControllable(playable);
    367   }
    368 
    369   // bind camera
    370   playable->addChild (this->localCamera);
    371 
    372 //   //localCamera->setParent(TrackNode::getInstance());
    373 //  tn->addChild(this->localCamera);
    374   localCamera->setClipRegion(1, 10000.0);
    375   localCamera->lookAt(playable);
    376 //  this->localPlayer->setParentMode(PNODE_ALL);
    377   if (sky != NULL)
    378   {
    379     this->sky->setParent(this->localCamera);
    380     this->sky->setParentMode(PNODE_MOVEMENT);
    381   }
    382 
    383   // initialize debug coord system
    384   objectList = glGenLists(1);
    385   glNewList (objectList, GL_COMPILE);
    386 
    387   glEndList();
    388 
    389   SoundEngine::getInstance()->setListener(this->localCamera);
    390 
    391 
    392 
    393   ////////////
    394   // STATIC //
    395   ////////////
    396 
    397 
    398 //   TestEntity* testEntity = new TestEntity();
    399 //   testEntity->setRelCoor(Vector(570, 10, -15));
    400 //   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    401 //   this->spawn(testEntity);
    402 
    403   for(int i = 0; i < 100; i++)
    404   {
    405     WorldEntity* tmp = new NPCTest1();
    406     char npcChar[10];
    407     sprintf (npcChar, "NPC_%d", i);
    408         tmp->setName(npcChar);
    409     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    410     this->spawn(tmp);
    411   }
    412 
    413   this->music = NULL;
    414   //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
    415   //music->playback();
    416 }
    417 
    418 
    419 
    420 /**
    421  * creates a debug world: only for experimental stuff
    422 */
    423 void World::loadDebugWorld(int worldID)
    424 {
    425   /*monitor progress*/
    426   this->glmis->step();
    427   // stuff beyond this point remains to be loaded properly
    428 
    429   // LIGHT initialisation
    430   LightManager::getInstance()->setAmbientColor(.1,.1,.1);
    431 //  LightManager::getInstance()->addLight();
    432   LightManager::getInstance()->debug();
    433 
    434   switch(this->debugWorldNr)
    435     {
    436       /*
    437         this loads the hard-coded debug world. this only for simplicity and will be
    438         removed by a reald world-loader, which interprets a world-file.
    439         if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
    440         make whatever you want...
    441       */
    442     case DEBUG_WORLD_0:
    443       {
    444         LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);
    445         /*monitor progress*/
    446         this->glmis->step();
    447 
    448         // bind camera
    449         this->localCamera = new Camera();
    450         this->localCamera->setName ("camera");
    451         /*monitor progress*/
    452         this->glmis->step();
    453 
    454 
    455         // Create SkySphere
    456         this->sky = new Skysphere("pictures/sky-replace.jpg");
    457         this->sky->setName("SkySphere");
    458         this->spawn(this->sky);
    459         this->localCamera->addChild(this->sky);
    460         this->sky->setParentMode(PNODE_MOVEMENT);
    461         /*monitor progress*/
    462         this->glmis->step();
    463 
    464 
    465         terrain = new Terrain("worlds/newGround.obj");
    466         terrain->setRelCoor(Vector(0,-10,0));
    467         this->spawn(terrain);
    468         /*monitor progress*/
    469         this->glmis->step();
    470 
    471         this->glmis->step();
    472         break;
    473       }
    474     case DEBUG_WORLD_1:
    475       {
    476 
    477         break;
    478       }
    479     case DEBUG_WORLD_2:
    480       {
    481 
    482         break;
    483       }
    484     default:
    485       break;
    486     }
    487 }
    488 
    489 /**
    490  *  initializes a new World shortly before start
    491  *
    492  * this is the function, that will be loaded shortly before the world is
    493  * started
    494 */
    495 ErrorMessage World::init()
    496 {
    497   this->bPause = false;
    498 
    499   /* update the object position before game start - so there are no wrong coordinates used in the first processing */
    500   PNode::getNullParent()->updateNode (0.001f);
    501   PNode::getNullParent()->updateNode (0.001f);
    502 
    503 }
    504 
    505 
    506 /**
    507  *  starts the World
    508 */
    509 ErrorMessage World::start()
    510 {
    511   PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
    512   this->bQuitOrxonox = false;
    513   this->bQuitCurrentGame = false;
    514   this->mainLoop();
    515 }
    516 
    517 /**
    518  *  stops the world.
    519 
    520    This happens, when the player decides to end the Level.
    521 */
    522 ErrorMessage World::stop()
    523 {
    524   PRINTF(3)("World::stop() - got stop signal\n");
    525   this->bQuitCurrentGame = true;
    526 }
    527 
    528 /**
    529  *  pauses the Game
    530 */
    531 ErrorMessage World::pause()
    532 {
    533   this->isPaused = true;
    534 }
    535 
    536 /**
    537  *  ends the pause Phase
    538 */
    539 ErrorMessage World::resume()
    540 {
    541   this->isPaused = false;
    542 }
    543 
    544 /**
    545  *  destroys the World
    546 */
    547 ErrorMessage World::destroy()
    548 {
    549 
    550 }
    551 
    552 /**
    553  *  shows the loading screen
    554 */
    555 void World::displayLoadScreen ()
    556 {
    557   PRINTF(3)("World::displayLoadScreen - start\n");
    558 
    559   //GLMenuImageScreen*
    560   this->glmis = new GLMenuImageScreen();
    561   this->glmis->setMaximum(8);
    562 
    563   PRINTF(3)("World::displayLoadScreen - end\n");
    564 }
    565 
    566 /**
    567  *  removes the loadscreen, and changes over to the game
    568 
    569    @todo take out the delay
    570 */
    571 void World::releaseLoadScreen ()
    572 {
    573   PRINTF(3)("World::releaseLoadScreen - start\n");
    574   this->glmis->setValue(this->glmis->getMaximum());
    575   PRINTF(3)("World::releaseLoadScreen - end\n");
    576   delete this->glmis;
    577 }
    578 
    579 
    580 /**
    581  *  this returns the current game time
    582  * @returns elapsed game time
    583 */
    584 double World::getGameTime()
    585 {
    586   return this->gameTime;
    587 }
    588 
    589 /**
    590   \brief main loop of the world: executing all world relevant function
    591 
    592   in this loop we synchronize (if networked), handle input events, give the heart-beat to
    593   all other member-entities of the world (tick to player, enemies etc.), checking for
    594   collisions drawing everything to the screen.
    595 */
    596 void World::mainLoop()
    597 {
    598   this->lastFrame = SDL_GetTicks ();
    599   PRINTF(3)("World::mainLoop() - Entering main loop\n");
    600 
    601   while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */
    602     {
    603       ++this->cycle;
    604       // Network
    605       this->synchronize ();
    606       // Process input
    607       this->handleInput ();
    608       if( this->bQuitCurrentGame || this->bQuitOrxonox)
    609           break;
    610       // Process time
    611       this->tick ();
    612       // Process collision
    613       this->collide ();
    614       // Update the state
    615       this->update ();
    616       // Draw
    617       this->display ();
    618     }
    619 
    620   PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
    621 }
    622 
    623 
    624 /**
    625  *  synchronize local data with remote data
    626 */
    627 void World::synchronize ()
    628 {
    629   // Get remote input
    630   // Update synchronizables
    631 /*  NetworkManager::getInstance()->synchronize();*/
    632 }
    633 
    634 
    635 /**
    636  *  run all input processing
    637 
    638    the command node is the central input event dispatcher. the node uses the even-queue from
    639    sdl and has its own event-passing-queue.
    640 */
    641 void World::handleInput ()
    642 {
    643   EventHandler::getInstance()->process();
    644 
    645   // remoteinput
    646 }
    647 
    648 void World::tick(std::list<WorldEntity*> entityList, float dt)
    649 {
    650   std::list<WorldEntity*>::iterator entity;
    651   for (entity = entityList.begin(); entity != entityList.end(); entity++)
    652     (*entity)->tick(dt);
    653 
    654 }
    655 
    656 /**
    657  *  advance the timeline
    658 
    659    this calculates the time used to process one frame (with all input handling, drawing, etc)
    660    the time is mesured in ms and passed to all world-entities and other classes that need
    661    a heart-beat.
    662 */
    663 void World::tick ()
    664 {
    665   Uint32 currentFrame = SDL_GetTicks();
    666   if(!this->bPause)
    667     {
    668       this->dt = currentFrame - this->lastFrame;
    669 
    670       if( this->dt > 10)
    671         {
    672           float fps = 1000/dt;
    673 
    674           // temporary, only for showing how fast the text-engine is
    675           char tmpChar[20];
    676           sprintf(tmpChar, "fps: %4.0f", fps);
    677         }
    678       else
    679         {
    680           /* the frame-rate is limited to 100 frames per second, all other things are for
    681              nothing.
    682           */
    683           PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
    684           SDL_Delay(10-dt);
    685           this->dt = 10;
    686         }
    687 
    688       this->dtS = (float)this->dt / 1000.0 * this->speed;
    689       this->gameTime += this->dtS;
    690 
    691 /*      this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
    692       this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
    693       this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);*/
    694       this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
    695       this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
    696 
    697       /* update tick the rest */
    698       this->localCamera->tick(this->dtS);
    699       // tick the engines
    700       AnimationPlayer::getInstance()->tick(this->dtS);
    701 //      if (this->cycle > 5)
    702         PhysicsEngine::getInstance()->tick(this->dtS);
    703 
    704       ParticleEngine::getInstance()->tick(this->dtS);
    705 
    706 
    707       /** actualy the Graphics Engine should tick the world not the other way around...
    708          but since we like the things not too complicated we got it this way around
    709          until there is need or time to do it the other way around.
    710          @todo: GraphicsEngine ticks world: separation of processes and data...
    711 
    712         bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
    713          beceause graphics have nothing(or at least not much) to do with Motion.
    714       */
    715       GraphicsEngine::getInstance()->tick(this->dtS);
    716     }
    717   this->lastFrame = currentFrame;
    718 }
    719 
    720 
    721 /**
    722  *  this function gives the world a consistant state
    723 
    724    after ticking (updating the world state) this will give a constistant
    725    state to the whole system.
    726 */
    727 void World::update()
    728 {
    729   GraphicsEngine::getInstance()->update(this->dtS);
    730   PNode::getNullParent()->updateNode (this->dtS);
    731 
    732   SoundEngine::getInstance()->update();
    733   //music->update();
    734 }
    735 
    736 
    737 void World::collide()
    738 {
    739   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
    740                                             this->objectManager.getObjectList(OM_GROUP_01_PROJ));
    741   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),
    742                                             this->objectManager.getObjectList(OM_COMMON));
    743 }
    744 
    745 /**
    746  *  render the current frame
    747 
    748    clear all buffers and draw the world
    749 */
    750 void World::display ()
    751 {
    752   // clear buffer
    753   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    754   // set camera
    755   this->localCamera->apply ();
    756   // draw world
    757   this->draw();
    758   // draw HUD
    759   /** @todo draw HUD */
    760   // flip buffers
    761   GraphicsEngine::swapBuffers();
    762   //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
    763   //SDL_Flip (screen);
    764 }
    765 
    766 
    767 /**
    768  *  runs through all entities calling their draw() methods
    769  */
    770 void World::draw ()
    771 {
    772   GraphicsEngine* engine = GraphicsEngine::getInstance();
    773   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    774   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));
    775   engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));
    776   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));
    777   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));
    778   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    779 
    780 //   {
    781 //     if( entity->isVisible() ) entity->draw();
    782   //FIXME
    783 //     if( unlikely( this->showBV)) entity->drawBVTree(3, 226);  // to draw the bounding boxes of the objects at level 2 for debug purp
    784 //     entity = iterator->nextElement();
    785 //   }
    786 
    787   glCallList (objectList);
    788 
    789   ParticleEngine::getInstance()->draw();
    790 
    791   if (unlikely(this->showPNodes))
    792     PNode::getNullParent()->debugDraw(0);
    793 
    794   engine->draw();
    795   //TextEngine::getInstance()->draw();
    796 }
    797 
    798 /**
    799  *  add and spawn a new entity to this world
    800  * @param entity to be added
    801 */
    802 void World::spawn(WorldEntity* entity)
    803 {
    804 //   this->entities->add (entity);
    805   entity->postSpawn ();
    806 }
    807 
    808 
    809 /**
    810  *  add and spawn a new entity to this world
    811  * @param entity to be added
    812  * @param absCoor At what coordinates to add this entity.
    813  * @param absDir In which direction should it look.
    814 */
    815 void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
    816 {
    817 //   this->entities->add (entity);
    818 
    819   entity->setAbsCoor (*absCoor);
    820   entity->setAbsDir (*absDir);
    821 
    822   entity->postSpawn ();
    823 }
    824 
    825 
    826 /**
    827  *  add and spawn a new entity to this world
    828  * @param entity to be added
    829  * @param entity to be added to (PNode)
    830  * @param At what relative  coordinates to add this entity.
    831  * @param In which relative direction should it look.
    832 */
    833 void World::spawn(WorldEntity* entity, PNode* parentNode,
    834                   Vector* relCoor, Quaternion* relDir)
    835 {
    836   if( parentNode != NULL)
    837     {
    838       parentNode->addChild (entity);
    839 
    840       entity->setRelCoor (*relCoor);
    841       entity->setRelDir (*relDir);
    842 
    843 //       this->entities->add (entity);
    844 
    845       entity->postSpawn ();
    846     }
    847 }
    848 
    849 void World::setPath( const char* name)
    850 {
    851   if (this->path)
    852     delete this->path;
    853   if (ResourceManager::isFile(name))
    854   {
    855     this->path = new char[strlen(name)+1];
    856     strcpy(this->path, name);
    857   }
    858   else
    859     {
    860       this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
    861       sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
    862     }
    863 }
    864 
    865 const char* World::getPath( void)
    866 {
    867   return path;
    868 }
  • branches/network/src/story_entities/debug_world.h

    r6150 r6386  
    1 /*!
    2  * @file world.h
    3   *  Holds and manages all game data
    4 */
    5 
    6 #ifndef _WORLD_H
    7 #define _WORLD_H
    8 
    9 #include "stdincl.h"
    10 #include "comincl.h"
    11 #include "story_entity.h"
    12 #include "p_node.h"
    13 #include "object_manager.h"
    14 
    15 
    16 class WorldEntity;
    17 class Camera;
    18 class Player;
    19 class GLMenuImageScreen;
    20 class Terrain;
    21 class TiXmlElement;
    22 
    23 class Shell;
    24 class OggPlayer;
    25 
    26 //! The game world
    27 /**
    28    this class initializes everything that should be displayed inside of the current level.
    29    it is the main driving factor during gameplay.
    30 */
    31 class World : public StoryEntity {
    32 
    33  public:
    34   World (const char* name);
    35   World (int worldID);
    36   World (const TiXmlElement* root = NULL);
    37   virtual ~World ();
    38 
    39   void loadParams(const TiXmlElement* root);
    40 
    41   double getGameTime();
    42 
    43   /* classes from story-entity */
    44   virtual ErrorMessage preLoad();
    45   virtual ErrorMessage load ();
    46   virtual ErrorMessage init ();
    47   virtual ErrorMessage start ();
    48   virtual ErrorMessage stop ();
    49   virtual ErrorMessage pause ();
    50   virtual ErrorMessage resume ();
    51   virtual ErrorMessage destroy ();
    52 
    53   void loadDebugWorld(int worldID);
    54 
    55   virtual void displayLoadScreen();
    56   virtual void releaseLoadScreen();
    57 
    58   /* command node functions */
    59   bool command (Command* cmd);
    60 
    61   /* interface to world */
    62   void spawn (WorldEntity* entity);
    63   void spawn (WorldEntity* entity, Vector* absCoor, Quaternion* absDir);
    64   void spawn(WorldEntity* entity, PNode* parentNode, Vector* relCoor, Quaternion* relDir);
    65 
    66   /** @param speed sets the speed of the Game */
    67   inline void setSpeed(float speed) { this->speed = speed; };
    68   const char* getPath();
    69   void setPath( const char* name);
    70 
    71   inline Camera* getLocalCamera() { return this->localCamera; };
    72 
    73   void togglePNodeVisibility() { this->showPNodes = !this->showPNodes; };
    74   void toggleBVVisibility() { this->showBV = !this->showBV; };
    75 
    76  private:
    77   void constuctorInit(const char* name, int worldID);
    78   /* function for main-loop */
    79   void mainLoop ();
    80   void synchronize ();
    81   void handleInput ();
    82   void tick (std::list<WorldEntity*> worldEntity, float dt);
    83   void tick ();
    84   void update ();
    85   void collide ();
    86   void draw ();
    87   void display ();
    88   void debug ();
    89 
    90   private:
    91     bool   showPNodes;                  //!< if the PNodes should be visible.
    92     bool   showBV;                      //!< if the Bounding Volumes should be visible.
    93     Uint32 lastFrame;                   //!< last time of frame
    94     Uint32 cycle;                       //!< The cycle we are in (starts with 0 and rises with every frame)
    95     Uint32 dt;                          //!< time needed to calculate this frame (in milliSeconds)
    96     float dtS;                          //!< The time needed for caluculations in seconds
    97     float speed;                        //!< how fast the game flows
    98     double gameTime;                    //!< this is where the game time is saved
    99     bool bQuitOrxonox;                  //!< quit this application
    100     bool bQuitCurrentGame;              //!< quit only the current game and return to menu
    101     bool bPause;                        //!< pause mode
    102 
    103     ObjectManager      objectManager;   //!< The ObjectManager of this World.
    104 
    105     GLMenuImageScreen* glmis;           //!< The Level-Loader Display
    106 
    107     int debugWorldNr;                   //!< The Debug Nr. needed, if something goes wrong
    108     char* path;                         //!< The file from which this world is loaded
    109 
    110     Shell*     shell;
    111     OggPlayer* music;
    112 
    113   // IMPORTANT WORLD-ENTITIES
    114     Camera* localCamera;                //!< The current Camera
    115     WorldEntity* sky;                   //!< The Environmental Heaven of orxonox @todo insert this to environment insted
    116     Terrain* terrain;                   //!< The Terrain of the World.
    117 
    118     GLuint objectList;                  //!< temporary: @todo this will be ereased soon
    119 
    120     Player* localPlayer;                //!< The Player, you fly through the level.
    121 };
    122 
    123 #endif /* _WORLD_H */
  • branches/network/src/story_entities/dedicated_server_world.cc

    r6355 r6386  
    99   any later version.
    1010
    11    ### File Specific:
     11### File Specific:
    1212   main-programmer: Patrick Boenzli
    13    co-programmer: Christian Meyer
    14    co-programmer: Benjamin Grauer
    1513*/
    1614
    1715#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
    1816
    19 #include "network_world.h"
     17#include "dedicated_server_world.h"
    2018
    21 #include "shell_command.h"
    22 #include "resource_manager.h"
    2319#include "state.h"
     20#include "class_list.h"
    2421
    25 #include "p_node.h"
    26 #include "world_entity.h"
    27 #include "player.h"
    28 #include "camera.h"
    29 #include "environment.h"
    30 #include "terrain.h"
    31 
    32 #include "test_entity.h"
    33 #include "terrain.h"
    34 #include "light.h"
    3522#include "load_param.h"
    36 #include "shell.h"
    37 
    3823#include "fast_factory.h"
    39 #include "animation_player.h"
    40 #include "particle_engine.h"
    41 #include "graphics_engine.h"
    42 #include "physics_engine.h"
    43 #include "fields.h"
    44 
    45 #include "md2Model.h"
    46 
    47 #include "glmenu_imagescreen.h"
    48 #include "game_loader.h"
    49 
    50 #include "animation3d.h"
    51 
    52 #include "substring.h"
    53 
    5424#include "factory.h"
    5525
    56 #include "weapons/projectile.h"
    57 #include "event_handler.h"
    58 #include "sound_engine.h"
    59 #include "ogg_player.h"
     26#include "world_entity.h"
     27#include "npcs/npc_test1.h"
    6028
    61 #include "class_list.h"
    62 
    63 #include "cd_engine.h"
    64 #include "npcs/npc_test1.h"
    65 #include "shader.h"
    66 
    67 #include "playable.h"
    68 #include "network_manager.h"
    69 #include "network_game_manager.h"
    70 #include "playable.h"
    71 
    72 
    73 SHELL_COMMAND(speed, NetworkWorld, setSpeed);
    74 SHELL_COMMAND(togglePNodeVisibility, NetworkWorld, togglePNodeVisibility);
    75 SHELL_COMMAND(toggleBVVisibility, NetworkWorld, toggleBVVisibility);
    7629
    7730using namespace std;
    7831
    79 //! This creates a Factory to fabricate a NetworkWorld
    80 CREATE_FACTORY(NetworkWorld, CL_WORLD);
     32//! This creates a Factory to fabricate a DedicatedServerWorld
     33CREATE_FACTORY(DedicatedServerWorld, CL_DEDICATED_SERVER_WORLD);
    8134
    82 NetworkWorld::NetworkWorld(const TiXmlElement* root)
     35
     36
     37DedicatedServerWorld::DedicatedServerWorld(const TiXmlElement* root)
     38  : GameWorld(root)
    8339{
    84   this->constuctorInit("", -1);
    85   this->path = NULL;
     40  this->setClassID(CL_DEDICATED_SERVER_WORLD, "DedicatedServerWorld");
     41  this->setName("DedicatedServerWorld uninitialized");
    8642
    8743  this->loadParams(root);
    8844}
    8945
     46
    9047/**
    91  *  remove the NetworkWorld from memory
     48 *  remove the DedicatedServerWorld from memory
    9249 *
    9350 *  delete everything explicitly, that isn't contained in the parenting tree!
    9451 *  things contained in the tree are deleted automaticaly
    9552 */
    96 NetworkWorld::~NetworkWorld ()
     53DedicatedServerWorld::~DedicatedServerWorld ()
    9754{
    98   delete this->shell;
    99   PRINTF(3)("NetworkWorld::~NetworkWorld() - deleting current world\n");
    100 
    101   delete this->localPlayer;
    102 
    103   // delete all the initialized Engines.
    104   FastFactory::flushAll(true);
    105   delete LightManager::getInstance();
    106   delete ParticleEngine::getInstance();
    107   delete AnimationPlayer::getInstance();
    108   delete PhysicsEngine::getInstance();
    109 
    110   // external engines initialized by the orxonox-class get deleted
    111   SoundEngine::getInstance()->flushAllBuffers();
    112   SoundEngine::getInstance()->flushAllSources();
    113 
    114   if (State::getObjectManager() == &this->objectManager)
    115     State::setObjectManager(NULL);
    116   // erease everything that is left.
    117   delete PNode::getNullParent();
    118 
    119   //secondary cleanup of PNodes;
    120   const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
    121   if (nodeList != NULL)
    122     while (!nodeList->empty())
    123       delete nodeList->front();
    124 
    125   Shader::suspendShader();
    126 
    127   // unload the resources !!
    128   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    129 }
    130 
    131 /**
    132  * initializes the world.
    133  * @param name the name of the world
    134  * @param worldID the ID of this world
    135  *
    136  * set all stuff here that is world generic and does not use to much memory
    137  * because the real init() function StoryEntity::init() will be called
    138  * shortly before start of the game.
    139  * since all worlds are initiated/referenced before they will be started.
    140  * NO LEVEL LOADING HERE - NEVER!
    141 */
    142 void NetworkWorld::constuctorInit(const char* name, int worldID)
    143 {
    144   this->setClassID(CL_WORLD, "NetworkWorld");
    145   PRINTF(0)("START\n");
    146 
    147   this->setName(name);
    148   this->gameTime = 0.0f;
    149   this->setSpeed(1.0);
    150   this->music = NULL;
    151   this->shell = NULL;
    152   this->localPlayer = NULL;
    153   this->localCamera = NULL;
    154 
    155   this->showPNodes = false;
    156   this->showBV = false;
    157 }
    158 
    159 /**
    160  * loads the parameters of a NetworkWorld from an XML-element
    161  * @param root the XML-element to load from
    162  */
    163 void NetworkWorld::loadParams(const TiXmlElement* root)
    164 {
    165   PRINTF(4)("Creating a NetworkWorld\n");
    166 
    167   LoadParam(root, "identifier", this, NetworkWorld, setStoryID)
    168     .describe("Sets the StoryID of this world");
    169 
    170   LoadParam(root, "nextid", this, NetworkWorld, setNextStoryID)
    171     .describe("Sets the ID of the next world");
    172 
    173   LoadParam(root, "path", this, NetworkWorld, setPath)
    174     .describe("The Filename of this NetworkWorld (relative from the data-dir)");
    175 }
    176 
    177 /**
    178  * this is executed just before load
    179  *
    180  * since the load function sometimes needs data, that has been initialized
    181  * before the load and after the proceeding storyentity has finished
    182 */
    183 ErrorMessage NetworkWorld::preLoad()
    184 {
    185   State::setObjectManager(&this->objectManager);
    186   this->cycle = 0;
    187 
    188   /* init the world interface */
    189   this->shell = new Shell();
    190 
    191   LightManager::getInstance();
    192   PNode::getNullParent();
    193 
    194   AnimationPlayer::getInstance(); // initializes the animationPlayer
    195   ParticleEngine::getInstance();
    196   PhysicsEngine::getInstance();
    197 
    198   this->localCamera = new Camera();
    199   this->localCamera->setName ("NetworkWorld-Camera");
    200 
    201   State::setCamera(this->localCamera, this->localCamera->getTarget());
    202 
    203   GraphicsEngine::getInstance()->displayFPS(true);
    204   this->displayLoadScreen();
     55  PRINTF(3)("DedicatedServerWorld::~DedicatedServerWorld() - deleting current world\n");
    20556}
    20657
    20758
    20859/**
    209  *  loads the NetworkWorld by initializing all resources, and set their default values.
     60 * loads the parameters of a DedicatedServerWorld from an XML-element
     61 * @param root the XML-element to load from
    21062 */
    211 ErrorMessage NetworkWorld::load()
     63void DedicatedServerWorld::loadParams(const TiXmlElement* root)
    21264{
    213   PRINTF(3)("> Loading world: '%s'\n", getPath());
    214   TiXmlElement* element;
    215   GameLoader* loader = GameLoader::getInstance();
     65  static_cast<GameWorld*>(this)->loadParams(root);
    21666
    217   if( getPath() == NULL)
    218     {
    219       PRINTF(1)("World has no path specified for loading");
    220       return (ErrorMessage){213,"Path not specified","World::load()"};
    221     }
    222 
    223   TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    224   // load the campaign document
    225   if( !XMLDoc->LoadFile())
    226   {
    227     // report an error
    228     PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    229     delete XMLDoc;
    230     return (ErrorMessage){213,"XML File parsing error","NetworkWorld::load()"};
    231   }
    232 
    233   // check basic validity
    234   TiXmlElement* root = XMLDoc->RootElement();
    235   assert( root != NULL);
    236 
    237   if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    238     {
    239       // report an error
    240       PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    241       delete XMLDoc;
    242       return (ErrorMessage){213,"Path not a WorldDataFile","NetworkWorld::load()"};
    243     }
    244 
    245 
    246   // load the parameters
    247   // name
    248   const char* string = grabParameter( root, "name");
    249   if( string == NULL)
    250     {
    251       PRINTF(2)("World is missing a proper 'name'\n");
    252       this->setName("Unknown");
    253     }
    254   else
    255     {
    256       this->setName(string);
    257     }
    258 
    259 
    260   ////////////////
    261   // LOADSCREEN //
    262   ////////////////
    263   element = root->FirstChildElement("LoadScreen");
    264   if (element == NULL)
    265     {
    266       PRINTF(2)("no LoadScreen specified, loading default\n");
    267 
    268       glmis->setBackgroundImage("pictures/load_screen.jpg");
    269       this->glmis->setMaximum(8);
    270       this->glmis->draw();
    271     }
    272   else
    273     {
    274       this->glmis->loadParams(element);
    275       this->glmis->draw();
    276     }
    277   this->glmis->draw();
    278 
    279 
    280 
    281   ////////////////////////////
    282   // Loading Spawning Point //
    283   ////////////////////////////
    284   element = root->FirstChildElement("SpawningPoints");
    285   if( element == NULL)
    286   {
    287     PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");
    288   }
    289   else
    290   {
    291     element = element->FirstChildElement();
    292       // load Players/Objects/Whatever
    293     PRINTF(4)("Loading Spawning Points\n");
    294     while( element != NULL)
    295     {
    296       BaseObject* created = Factory::fabricate(element);
    297       if( created != NULL )
    298       {
    299 //        if(created->isA(CL_SPAWNING_POINT))
    300 //          this->spawn(dynamic_cast<WorldEntity*>(created));
    301         printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());
    302       }
    303 
    304 
    305       element = element->NextSiblingElement();
    306       glmis->step(); //! @todo temporary
    307     }
    308     PRINTF(4)("Done loading NetworkWorldEntities\n");
    309   }
    310 
    311 
    312   ////////////////////////
    313   // find WorldEntities //
    314   ////////////////////////
    315   element = root->FirstChildElement("WorldEntities");
    316   if( element == NULL)
    317   {
    318     PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
    319   }
    320   else
    321   {
    322     element = element->FirstChildElement();
    323       // load Players/Objects/Whatever
    324     PRINTF(4)("Loading NetworkWorldEntities\n");
    325     while( element != NULL)
    326     {
    327       if( NetworkManager::getInstance()->isGameServer())
    328       {
    329 
    330         BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
    331         if( created != NULL )
    332         {
    333 //          if(created->isA(CL_WORLD_ENTITY))
    334 //            this->spawn(dynamic_cast<WorldEntity*>(created));
    335           printf("Created a %s: %s\n", created->getClassName(), created->getName());
    336         }
    337         else
    338           PRINTF(1)("NetworkWorld: could not create this entity\n");
    339 
    340           // if we load a 'Player' we use it as localPlayer
    341 
    342 
    343           //todo do this more elegant
    344         if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    345           sky = dynamic_cast<WorldEntity*>(created);
    346         if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    347         {
    348           terrain = dynamic_cast<Terrain*>(created);
    349           CDEngine::getInstance()->setTerrain(terrain);
    350 
    351         }
    352 
    353       }
    354       else if( /* !strcmp( element->Value(), "SkyBox") || */ /* !strcmp( element->Value(), "Terrain") || */ !strcmp( element->Value(), "SpaceShip"))
    355       {
    356         BaseObject* created = Factory::fabricate(element);
    357         if( created != NULL )
    358         {
    359 //          if(created->isA(CL_WORLD_ENTITY))
    360 //            this->spawn(dynamic_cast<WorldEntity*>(created));
    361           printf("Created a %s: %s\n", created->getClassName(), created->getName());
    362         }
    363         else
    364           PRINTF(1)("NetworkWorld: could not create this entity\n");
    365 
    366           // if we load a 'Player' we use it as localPlayer
    367 
    368 
    369           //todo do this more elegant
    370         if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    371           sky = dynamic_cast<WorldEntity*>(created);
    372         if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    373         {
    374           terrain = dynamic_cast<Terrain*>(created);
    375           CDEngine::getInstance()->setTerrain(terrain);
    376         }
    377       }
    378       element = element->NextSiblingElement();
    379       glmis->step(); //! @todo temporary
    380       PRINTF(4)("Done loading NetworkWorldEntities\n");
    381     }
    382   }
    383 
    384 
    385     //////////////////////////////
    386     // LOADING ADDITIONAL STUFF //
    387     //////////////////////////////
    388 
    389     LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
    390 
    391    LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
    392 //   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    393 
    394   // free the XML data
    395 
    396   delete XMLDoc;
    397   /* GENERIC LOADING PROCESS FINISHED */
    398 
    399 
    400   // Create a Player
    401   this->localPlayer = new Player();
    402 
    403   Playable* playable;
    404   const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    405   if (playableList != NULL)
    406   {
    407     playable = dynamic_cast<Playable*>(playableList->front());
    408     this->localPlayer->setControllable(playable);
    409   }
    410 
    411 
    412 //   //localCamera->setParent(TrackNode::getInstance());
    413 //  tn->addChild(this->localCamera);
    414   localCamera->setClipRegion(1, 10000.0);
    415 //  localCamera->lookAt(playable);
    416 //  this->localPlayer->setParentMode(PNODE_ALL);
    417   if (this->sky != NULL)
    418   {
    419     this->localCamera->addChild(sky);
    420   }
    421   SoundEngine::getInstance()->setListener(this->localCamera);
    422 
    423 
    424 
    425   ////////////
    426   // STATIC //
    427   ////////////
    428 
    429 
    430 //   TestEntity* testEntity = new TestEntity();
    431 //   testEntity->setRelCoor(Vector(570, 10, -15));
    432 //   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    433 //   this->spawn(testEntity);
    434 
    435 //   for(int i = 0; i < 100; i++)
    436 //   {
    437 //     WorldEntity* tmp = NetworkGameManager::;
    438 //     char npcChar[10];
    439 //     sprintf (npcChar, "NPC_%d", i);
    440 //         tmp->setName(npcChar);
    441 //     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    442 //     this->spawn(tmp);
    443 //   }
    444 
    445   this->music = NULL;
    446   //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
    447   //music->playback();
     67  PRINTF(4)("Loaded DedicatedServerWorld specific stuff\n");
    44868}
    44969
    450 ErrorMessage NetworkWorld::postLoad()
    451 {
    452   /*monitor progress*/
    453   this->glmis->step();
    454   // stuff beyond this point remains to be loaded properly
    455 
    456   // LIGHT initialisation
    457   LightManager::getInstance()->setAmbientColor(.1,.1,.1);
    458 //  LightManager::getInstance()->addLight();
    459   LightManager::getInstance()->debug();
    460 
    461   this->releaseLoadScreen();
    462 }
    463 
    464 
    465 /**
    466  *  initializes a new NetworkWorld shortly before start
    467  *
    468  * this is the function, that will be loaded shortly before the world is
    469  * started
    470 */
    471 ErrorMessage NetworkWorld::preStart()
    472 {
    473   this->bPause = false;
    474 
    475   /* update the object position before game start - so there are no wrong coordinates used in the first processing */
    476   PNode::getNullParent()->updateNode (0.001f);
    477   PNode::getNullParent()->updateNode (0.001f);
    478 }
    479 
    480 
    481 /**
    482  *  starts the NetworkWorld
    483  */
    484 ErrorMessage NetworkWorld::start()
    485 {
    486   this->bQuitWorld = false;
    487   this->mainLoop();
    488 }
    489 
    490 /**
    491  *  stops the world.
    492 
    493    This happens, when the player decides to end the Level.
    494 */
    495 ErrorMessage NetworkWorld::stop()
    496 {
    497   PRINTF(3)("NetworkWorld::stop() - got stop signal\n");
    498   this->bQuitWorld= true;
    499 }
    500 
    501 /**
    502  *  pauses the Game
    503 */
    504 ErrorMessage NetworkWorld::pause()
    505 {
    506   this->isPaused = true;
    507 }
    508 
    509 /**
    510  *  ends the pause Phase
    511 */
    512 ErrorMessage NetworkWorld::resume()
    513 {
    514   this->isPaused = false;
    515 }
    516 
    517 /**
    518  *  destroys the NetworkWorld
    519 */
    520 ErrorMessage NetworkWorld::destroy()
    521 {
    522 
    523 }
    524 
    525 /**
    526  *  shows the loading screen
    527 */
    528 void NetworkWorld::displayLoadScreen ()
    529 {
    530   PRINTF(3)("NetworkWorld::displayLoadScreen - start\n");
    531 
    532   //GLMenuImageScreen*
    533   this->glmis = new GLMenuImageScreen();
    534   this->glmis->setMaximum(8);
    535 
    536   PRINTF(3)("NetworkWorld::displayLoadScreen - end\n");
    537 }
    538 
    539 /**
    540  * @brief removes the loadscreen, and changes over to the game
    541  *
    542  * @todo take out the delay
    543 */
    544 void NetworkWorld::releaseLoadScreen ()
    545 {
    546   PRINTF(3)("NetworkWorld::releaseLoadScreen - start\n");
    547   this->glmis->setValue(this->glmis->getMaximum());
    548   PRINTF(3)("NetworkWorld::releaseLoadScreen - end\n");
    549   delete this->glmis;
    550 }
    551 
    552 
    553 /**
    554  *  this returns the current game time
    555  * @returns elapsed game time
    556 */
    557 double NetworkWorld::getGameTime()
    558 {
    559   return this->gameTime;
    560 }
    561 
    562 /**
    563   \brief main loop of the world: executing all world relevant function
    564   in this loop we synchronize (if networked), handle input events, give the heart-beat to
    565   all other member-entities of the world (tick to player, enemies etc.), checking for
    566   collisions drawing everything to the screen.
    567 */
    568 void NetworkWorld::mainLoop()
    569 {
    570   this->lastFrame = SDL_GetTicks ();
    571   PRINTF(3)("World::mainLoop() - Entering main loop\n");
    572 
    573   while(!this->bQuitWorld) /* @todo implement pause */
    574   {
    575     ++this->cycle;
    576       // Network
    577     this->synchronize ();
    578       // Process input
    579     this->handleInput ();
    580     if( this->bQuitWorld)
    581       break;
    582       // Process time
    583     this->tick ();
    584       // Process collision
    585     this->collide ();
    586       // Update the state
    587     this->update ();
    588       // Draw
    589     this->display ();
    590   }
    591 
    592   PRINTF(3)("NetworkWorld::mainLoop() - Exiting the main loop\n");
    593 }
    594 
    595 
    596 /**
    597  *  synchronize local data with remote data
    598 */
    599 void NetworkWorld::synchronize ()
    600 {
    601   // Get remote input
    602   // Update synchronizables
    603   NetworkManager::getInstance()->synchronize();
    604 }
    605 
    606 
    607 /**
    608  *  run all input processing
    609 
    610    the command node is the central input event dispatcher. the node uses the even-queue from
    611    sdl and has its own event-passing-queue.
    612 */
    613 void NetworkWorld::handleInput ()
    614 {
    615   EventHandler::getInstance()->process();
    616 
    617   // remoteinput
    618 }
    619 
    620 void NetworkWorld::tick(std::list<WorldEntity*> entityList, float dt)
    621 {
    622   std::list<WorldEntity*>::iterator entity;
    623   for (entity = entityList.begin(); entity != entityList.end(); entity++)
    624     (*entity)->tick(dt);
    625 
    626 }
    627 
    628 /**
    629  *  advance the timeline
    630 
    631    this calculates the time used to process one frame (with all input handling, drawing, etc)
    632    the time is mesured in ms and passed to all world-entities and other classes that need
    633    a heart-beat.
    634 */
    635 void NetworkWorld::tick ()
    636 {
    637   Uint32 currentFrame = SDL_GetTicks();
    638   if(!this->bPause)
    639     {
    640       this->dt = currentFrame - this->lastFrame;
    641 
    642       if( this->dt > 10)
    643         {
    644           float fps = 1000/dt;
    645 
    646           // temporary, only for showing how fast the text-engine is
    647           char tmpChar[20];
    648           sprintf(tmpChar, "fps: %4.0f", fps);
    649         }
    650       else
    651         {
    652           /* the frame-rate is limited to 100 frames per second, all other things are for
    653              nothing.
    654           */
    655           PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
    656           SDL_Delay(10-dt);
    657           this->dt = 10;
    658         }
    659 
    660       this->dtS = (float)this->dt / 1000.0 * this->speed;
    661       this->gameTime += this->dtS;
    662 
    663       this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
    664       this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
    665       this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);
    666       this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
    667       this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
    668 
    669       /* update tick the rest */
    670       this->localCamera->tick(this->dtS);
    671       // tick the engines
    672       AnimationPlayer::getInstance()->tick(this->dtS);
    673 //      if (this->cycle > 5)
    674         PhysicsEngine::getInstance()->tick(this->dtS);
    675 
    676       ParticleEngine::getInstance()->tick(this->dtS);
    677 
    678 
    679       /** actualy the Graphics Engine should tick the world not the other way around...
    680          but since we like the things not too complicated we got it this way around
    681          until there is need or time to do it the other way around.
    682          @todo: GraphicsEngine ticks world: separation of processes and data...
    683 
    684         bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
    685          beceause graphics have nothing(or at least not much) to do with Motion.
    686       */
    687       GraphicsEngine::getInstance()->tick(this->dtS);
    688     }
    689   this->lastFrame = currentFrame;
    690 }
    691 
    692 
    693 /**
    694  *  this function gives the world a consistant state
    695 
    696    after ticking (updating the world state) this will give a constistant
    697    state to the whole system.
    698 */
    699 void NetworkWorld::update()
    700 {
    701   GraphicsEngine::getInstance()->update(this->dtS);
    702   PNode::getNullParent()->updateNode (this->dtS);
    703   SoundEngine::getInstance()->update();
    704   //music->update();
    705 }
    706 
    707 
    708 void NetworkWorld::collide()
    709 {
    710   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
    711                                             this->objectManager.getObjectList(OM_GROUP_01_PROJ));
    712   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),
    713                                             this->objectManager.getObjectList(OM_COMMON));
    714 }
    715 
    716 /**
    717  *  render the current frame
    718 
    719    clear all buffers and draw the world
    720 */
    721 void NetworkWorld::display ()
    722 {
    723   // clear buffer
    724   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    725   // set camera
    726   this->localCamera->apply ();
    727   // draw world
    728   this->draw();
    729   // draw HUD
    730   /** @todo draw HUD */
    731   // flip buffers
    732   GraphicsEngine::swapBuffers();
    733   //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
    734   //SDL_Flip (screen);
    735 }
    736 
    737 
    738 /**
    739  *  runs through all entities calling their draw() methods
    740  */
    741 void NetworkWorld::draw ()
    742 {
    743   GraphicsEngine* engine = GraphicsEngine::getInstance();
    744   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    745   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));
    746   engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));
    747   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));
    748   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));
    749   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    750 
    751    if( unlikely( this->showBV))  // to draw the bounding boxes of the objects at level 2 for debug purp
    752    {
    753      CDEngine* engine = CDEngine::getInstance();
    754      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    755      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));
    756      engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));
    757      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));
    758      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));
    759      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    760    }
    761 
    762 //   {
    763 //     if( entity->isVisible() ) entity->draw();
    764   //FIXME
    765 //     entity = iterator->nextElement();
    766 //   }
    767 
    768   ParticleEngine::getInstance()->draw();
    769 
    770   if (unlikely(this->showPNodes))
    771     PNode::getNullParent()->debugDraw(0);
    772 
    773   engine->draw();
    774   //TextEngine::getInstance()->draw();
    775 }
    776 
    777 void NetworkWorld::setPath( const char* name)
    778 {
    779   if (this->path)
    780     delete this->path;
    781   if (ResourceManager::isFile(name))
    782   {
    783     this->path = new char[strlen(name)+1];
    784     strcpy(this->path, name);
    785   }
    786   else
    787     {
    788       this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
    789       sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
    790     }
    791 }
    792 
    793 const char* NetworkWorld::getPath( void)
    794 {
    795   return path;
    796 }
  • branches/network/src/story_entities/dedicated_server_world.h

    r6355 r6386  
    11/*!
    2  * @file world.h
    3   *  Holds and manages all game data
    4 */
     2 * @file dedicated_server_world.h
     3 *  Holds and manages all dedicated server data
     4 */
    55
    6 #ifndef _WORLD_H
    7 #define _WORLD_H
     6#ifndef _DEDICATED_SERVER_WORLD_H
     7#define _DEDICATED_SERVER_WORLD_H
    88
    9 #include "sdlincl.h"
    10 #include "story_entity.h"
    11 #include "object_manager.h"
     9#include "game_world.h"
    1210
    13 class NetworkWorld;
    1411
    15 class WorldEntity;
    16 class Camera;
    17 class Player;
    18 class GLMenuImageScreen;
    19 class Terrain;
    2012class TiXmlElement;
    2113
    22 class Shell;
    23 class OggPlayer;
    2414
    2515//! The game world
    2616/**
    27    this class initializes everything that should be displayed inside of the current level.
    28    it is the main driving factor during gameplay.
    29 */
    30 class NetworkWorld : public StoryEntity {
     17 *  this class initializes everything that should be displayed inside of the current level.
     18 *  it is the main driving factor during gameplay.
     19 */
     20class DedicatedServerWorld : public GameWorld
     21{
    3122
    32  public:
    33   NetworkWorld (const TiXmlElement* root = NULL);
    34   virtual ~NetworkWorld ();
     23  public:
     24    DedicatedServerWorld (const TiXmlElement* root = NULL);
     25    virtual ~DedicatedServerWorld ();
    3526
    36   void loadParams(const TiXmlElement* root);
    37 
    38   double getGameTime();
    39 
    40   /* classes from story-entity */
    41   virtual ErrorMessage preLoad();
    42   virtual ErrorMessage load ();
    43   virtual ErrorMessage postLoad();
    44 
    45   virtual ErrorMessage preStart();
    46   virtual ErrorMessage start ();
    47   virtual ErrorMessage stop ();
    48   virtual ErrorMessage pause ();
    49   virtual ErrorMessage resume ();
    50   virtual ErrorMessage destroy ();
    51 
    52   void displayLoadScreen();
    53   void releaseLoadScreen();
    54 
    55   /* interface to world */
    56 //  void spawn (WorldEntity* entity);
    57 
    58   /** @param speed sets the speed of the Game */
    59   inline void setSpeed(float speed) { this->speed = speed; };
    60   const char* getPath();
    61   void setPath( const char* name);
    62 
    63   void togglePNodeVisibility() { this->showPNodes = !this->showPNodes; };
    64   void toggleBVVisibility() { this->showBV = !this->showBV; };
    65 
    66  private:
    67   void constuctorInit(const char* name, int worldID);
    68   /* function for main-loop */
    69   void synchronize ();
    70   void handleInput ();
    71   void tick (std::list<WorldEntity*> worldEntity, float dt);
    72   void tick ();
    73   void update ();
    74   void collide ();
    75   void draw ();
    76   void mainLoop ();
    77 
    78   void display ();
    79   void debug ();
     27    void loadParams(const TiXmlElement* root);
    8028
    8129  private:
    82     char* path;                         //!< The file from which this world is loaded
    8330
    84     // FLAGS //
    85     bool bQuitWorld;                    //!< quit only the current game and return to menu
    86     bool bPause;                        //!< pause mode
    87 
    88     bool showPNodes;                    //!< if the PNodes should be visible.
    89     bool showBV;                        //!< if the Bounding Volumes should be visible.
    90 
    91     // TIMING //
    92     Uint32 lastFrame;                   //!< last time of frame
    93     Uint32 cycle;                       //!< The cycle we are in (starts with 0 and rises with every frame)
    94     Uint32 dt;                          //!< time needed to calculate this frame (in milliSeconds)
    95     float dtS;                          //!< The time needed for caluculations in seconds
    96     float speed;                        //!< how fast the game flows
    97     double gameTime;                    //!< this is where the game time is saved
    98 
    99     // INTERNAL ENGINES
    100     ObjectManager objectManager;        //!< The ObjectManager of this World.
    101     Shell*     shell;
    102     OggPlayer* music;
    103 
    104     GLMenuImageScreen* glmis;           //!< The Level-Loader Display
    105 
    106 
    107     // IMPORTANT ENTITIES
    108     Camera* localCamera;                //!< The current Camera
    109     Player* localPlayer;                //!< The Player, you fly through the level.
    110 
    111     WorldEntity* sky;                   //!< The Environmental Heaven of orxonox @todo insert this to environment insted
    112     Terrain* terrain;                   //!< The Terrain of the NetworkWorld.
    11331};
    11432
    115 #endif /* _WORLD_H */
     33#endif /* _DEDICATED_SERVER_WORLD_H */
  • branches/network/src/story_entities/game_world.cc

    r6377 r6386  
    278278          BaseObject* created = Factory::fabricate(element);
    279279          if( created != NULL )
    280           {
    281             if(created->isA(CL_WORLD_ENTITY))
    282               this->spawn(dynamic_cast<WorldEntity*>(created));
    283280            printf("Created a %s: %s\n", created->getClassName(), created->getName());
    284           }
    285 
    286           // if we load a 'Player' we use it as localPlayer
    287281
    288282
     
    345339  //music->playback();
    346340
    347   this->releaseLoadScreen();
    348 }
    349 
    350 
    351 /**
    352  *  initializes a new GameWorld shortly before start
    353  *
    354  * this is the function, that will be loaded shortly before the world is
    355  * started
    356 */
    357 ErrorMessage GameWorld::preStart()
    358 {
    359   this->bPause = false;
    360 
    361341  /* update the object position before game start - so there are no wrong coordinates used in the first processing */
    362342  PNode::getNullParent()->updateNode (0.001f);
    363343  PNode::getNullParent()->updateNode (0.001f);
     344
     345  this->releaseLoadScreen();
    364346}
    365347
     
    370352ErrorMessage GameWorld::start()
    371353{
    372   this->bQuitWorld = false;
     354  this->isPaused = false;
     355  this->isRunning = true;
    373356  this->mainLoop();
    374357}
     
    382365{
    383366  PRINTF(3)("GameWorld::stop() - got stop signal\n");
    384   this->bQuitWorld= true;
     367  this->isRunning = false;
    385368}
    386369
     
    408391{
    409392  PRINTF(3)("GameWorld::displayLoadScreen - start\n");
    410 
    411   //GLMenuImageScreen*
    412393  this->glmis = new GLMenuImageScreen();
    413394  this->glmis->setMaximum(8);
    414 
    415395  PRINTF(3)("GameWorld::displayLoadScreen - end\n");
    416396}
     397
    417398
    418399/**
     
    472453{
    473454  Uint32 currentFrame = SDL_GetTicks();
    474   if(!this->bPause)
     455  if( !this->isPaused)
    475456    {
    476457      this->dt = currentFrame - this->lastFrame;
     
    624605  PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
    625606
    626   while(!this->bQuitWorld) /* @todo implement pause */
     607  while( this->isRunning) /* @todo implement pause */
    627608  {
    628609    ++this->cycle;
     
    631612      // Process input
    632613    this->handleInput ();
    633     if( this->bQuitWorld)
     614    if( !this->isRunning)
    634615      break;
    635616      // Process time
     
    652633 * @param entity to be added
    653634*/
    654 void GameWorld::spawn(WorldEntity* entity)
    655 {
    656 //   this->entities->add (entity);
    657   entity->postSpawn ();
    658 }
     635// void GameWorld::spawn(WorldEntity* entity)
     636// {
     637// //   this->entities->add (entity);
     638//   entity->postSpawn ();
     639// }
    659640
    660641/**
  • branches/network/src/story_entities/game_world.h

    r6372 r6386  
    3838    virtual ErrorMessage init();
    3939    virtual ErrorMessage loadData();
     40    virtual ErrorMessage unloadData() {}
    4041
    41     virtual ErrorMessage preStart();
    4242    virtual ErrorMessage start();
    4343    virtual ErrorMessage stop();
    4444    virtual ErrorMessage pause();
    4545    virtual ErrorMessage resume();
    46 
    47     virtual void displayLoadScreen();
    48     virtual void releaseLoadScreen();
    49 
    50     /* interface to the game world */
    51     virtual void spawn (WorldEntity* entity);
    5246
    5347
     
    5751    inline void setSpeed(float speed) { this->speed = speed; };
    5852    /**  returns the track path of this world @returns the track path */
    59     const char* getPath() {   return path; }
     53    const char* getPath() { return this->path; }
    6054    void setPath( const char* name);
    6155
     
    6761
    6862  protected:
     63    /* world loading functions */
     64    virtual ErrorMessage loadGUI(TiXmlElement* root) {}
     65    virtual ErrorMessage loadWorldEntities(TiXmlElement* root) {}
     66    virtual ErrorMessage loadScene(TiXmlElement* root) {}
     67
    6968    /* world - running functions */
    7069    virtual void mainLoop ();
    7170
    72     virtual void synchronize ();
    73     virtual void handleInput ();
    74     virtual void tick (std::list<WorldEntity*> worldEntity, float dt);
    75     virtual void tick ();
    76     virtual void update ();
    77     virtual void collide ();
    78     virtual void draw ();
    79     virtual void display ();
     71    virtual void synchronize();
     72    virtual void handleInput();
     73    virtual void tick(std::list<WorldEntity*> worldEntity, float dt);
     74    virtual void tick();
     75    virtual void update();
     76    virtual void collide();
     77    virtual void draw();
     78    virtual void display();
     79
     80
     81  private:
     82    void displayLoadScreen();
     83    void releaseLoadScreen();
    8084
    8185
    8286  protected:
    8387    char* path;                         //!< The file from which this world is loaded
    84 
    85     /* state flags */
    86     bool bQuitWorld;                    //!< quit only the current game and return to menu
    87     bool bPause;                        //!< pause mode
    8888
    8989    bool showPNodes;                    //!< if the PNodes should be visible.
  • branches/network/src/story_entities/story_entity.cc

    r6376 r6386  
    3232
    3333  this->isInit = false;
    34   this->readyToRun = false;
    3534  this->isPaused = false;
    36   this->isSuspended = false;
     35  this->isRunning = false;
    3736
    3837  this->storyID = -1;
  • branches/network/src/story_entities/story_entity.h

    r6377 r6386  
    11/*!
    22 * @file story_entity.h
    3   *  holds the base class of everything that is playable - that is part of the story
    4 */
     3 *  holds the base class of everything that is playable - that is part of the story
     4 */
    55
    66
     
    2424  /** initializes a Story Entity to the needed values */
    2525  virtual ErrorMessage init() {};
    26   /** called to load the data into the story entity */
     26  /** called to load the data into the StoryEntity*/
    2727  virtual ErrorMessage loadData() {};
    28 
     28  /** function that unloads the data from the StoryEntity */
     29  virtual ErrorMessage unloadData() {};
    2930  /* running, stopping and pausing */
    30   /** called shortly before starting the Entity */
    31   virtual ErrorMessage preStart() {};
    3231  /** starts the Entity. Starts the main cycle */
    3332  virtual ErrorMessage start() = 0;
     
    3635  /** resumes the Entity after a stop/pause or suspend. */
    3736  virtual ErrorMessage resume() = 0;
    38   /** suspends the Entity detaches all mayor functions  (optional) */
    39   virtual ErrorMessage suspend() {};
    40   /** rewinds to the beginning/last checkpoint */
    41   virtual ErrorMessage rewind() {};
    42   /** leaves the Entity. Ends it */
    43   virtual ErrorMessage preStop() {};
    4437  /**  Stops the entity. */
    4538  virtual ErrorMessage stop() = 0;
     
    6255  protected:
    6356    bool isInit;         //!< if the entity is initialized, this has to be true.
    64     bool readyToRun;     //!< If the entity is ready to run -> post-check.
     57    bool isRunning;      //!< is true if the entity is running
    6558    bool isPaused;       //!< is true if the entity is paused
    66     bool isSuspended;    //!< if the Entity is suspended.
    6759
    6860
  • branches/network/src/util/loading/game_loader.cc

    r6152 r6386  
    6161}
    6262
    63 
    64 /**
    65  *  this class is a singleton class
    66  * @returns an instance of itself
    67  *
    68  * if you are unsure about singleton classes, check the theory out on the internet :)
    69  */
    70 GameLoader* GameLoader::getInstance()
    71 {
    72   if(singletonRef == NULL)
    73     singletonRef = new GameLoader();
    74   return singletonRef;
    75 }
    7663
    7764/**
     
    124111  if (campaignName)
    125112  {
    126     this->currentCampaign = this->fileToNetworkCampaign(campaignName);
     113    this->currentCampaign = this->fileToCampaign(campaignName);
    127114    delete[] campaignName;
    128115  }
     
    225212
    226213/**
    227  *  release the mem ATTENTION: not implemented
    228  */
    229 ErrorMessage GameLoader::destroy()
    230 {
    231 
    232 }
    233 
    234 
    235 /**
    236214 *  reads a campaign definition file into a campaign class
    237215 * @param fileName to be loaded
     
    285263
    286264
    287 /**
    288  *  reads a campaign definition file into a campaign class
    289  * @param fileName to be loaded
    290  * @returns the loaded campaign
    291  *
    292  *  this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    293  */
    294 Campaign* GameLoader::fileToNetworkCampaign(const char* fileName)
    295 {
    296   /* do not entirely load the campaign. just the current world
    297   before start of each world, it has to be initialized so it
    298   can load everything it needs into memory then.
    299   */
    300 
    301   if( fileName == NULL)
    302   {
    303     PRINTF(2)("No filename specified for loading");
    304     return NULL;
    305   }
    306 
    307   TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
    308   // load the campaign document
    309   if( !XMLDoc->LoadFile())
    310   {
    311       // report an error
    312     PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    313     delete XMLDoc;
    314     return NULL;
    315   }
    316 
    317   // check basic validity
    318   TiXmlElement* root = XMLDoc->RootElement();
    319   assert( root != NULL);
    320 
    321   if( strcmp( root->Value(), "Campaign"))
    322   {
    323       // report an error
    324     PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    325     delete XMLDoc;
    326     return NULL;
    327   }
    328 
    329   // construct campaign
    330   Campaign* c = new Campaign( root);
    331 
    332   // free the XML data
    333   delete XMLDoc;
    334 
    335   return c;
    336 }
    337 
    338265
    339266/**
     
    347274    if( likely(event.bPressed))
    348275    {
    349       this->nextLevel();
    350     }
    351   }
    352   else if( event.type == KeyMapper::PEV_PREVIOUS_WORLD)
    353   {
    354     if( likely(event.bPressed))
    355     {
    356       this->previousLevel();
     276      this->switchToNextLevel();
    357277    }
    358278  }
     
    377297
    378298/**
    379  *  \brief this changes to the next level
    380  */
    381 void GameLoader::nextLevel()
    382 {
    383   if(this->currentCampaign != NULL)
    384     this->currentCampaign->nextLevel();
    385 }
    386 
    387 
    388 /**
    389  *  change to the previous level - not implemented
    390  *
    391  * this propably useless
    392  */
    393 void GameLoader::previousLevel()
    394 {
    395   if(this->currentCampaign != NULL)
    396     this->currentCampaign->previousLevel();
    397 }
     299 *  this changes to the next level
     300 */
     301void GameLoader::switchToNextLevel()
     302{
     303  if(this->currentCampaign != NULL)
     304    this->currentCampaign->switchToNextLevel();
     305}
     306
     307
  • branches/network/src/util/loading/game_loader.h

    r6152 r6386  
    4141 public:
    4242  ~GameLoader ();
     43  /**  this class is a singleton class @returns an instance of itself  */
     44  static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; }
    4345
    44   static GameLoader* getInstance();
     46  ErrorMessage loadCampaign(const char* name);
     47  ErrorMessage loadDebugCampaign(Uint32 campaignID);
     48  ErrorMessage loadNetworkCampaign(const char* fileName);
    4549
    4650  ErrorMessage init();
     
    4953  ErrorMessage pause();
    5054  ErrorMessage resume();
    51   ErrorMessage destroy();
    5255
    53   ErrorMessage loadCampaign(const char* name);
    54   ErrorMessage loadDebugCampaign(Uint32 campaignID);
    55   ErrorMessage loadNetworkCampaign(const char* fileName);
    56 
    57   void nextLevel();
    58   void previousLevel();
     56  void switchToNextLevel();
    5957
    6058  void process(const Event &event);
     
    6563
    6664  Campaign* fileToCampaign(const char* name);
    67   Campaign* fileToNetworkCampaign(const char* fileName);
    6865
    6966
Note: See TracChangeset for help on using the changeset viewer.