Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6358 in orxonox.OLD


Ignore:
Timestamp:
Dec 30, 2005, 10:49:00 PM (18 years ago)
Author:
patrick
Message:

network: major changes in the world files

Location:
branches/network/src
Files:
6 edited

Legend:

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

    r6341 r6358  
    147147  // StoryEntities (range from 0x00000100 to 0x000001ff)
    148148  CL_CAMPAIGN                   =    0x00000101,
    149   CL_WORLD                      =    0x00000102,
    150 
     149  CL_GAME_WORLD                 =    0x00000102,
     150  CL_SINGLE_PLAYER_WORLD        =    0x00000103,
     151  CL_MULTI_PLAYER_WORLD         =    0x00000104,
    151152
    152153  // WorldEntities (range from 0x00000200 to 0x000004ff)
  • branches/network/src/story_entities/game_world.cc

    r6352 r6358  
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
    1818
    19 #include "world.h"
     19#include "game_world.h"
    2020
    2121#include "shell_command.h"
     
    7070
    7171
    72 SHELL_COMMAND(speed, World, setSpeed);
    73 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);
    74 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);
     72SHELL_COMMAND(speed, GameWorld, setSpeed);
     73SHELL_COMMAND(togglePNodeVisibility, GameWorld, togglePNodeVisibility);
     74SHELL_COMMAND(toggleBVVisibility, GameWorld, toggleBVVisibility);
    7575
    7676using namespace std;
    7777
    78 //! This creates a Factory to fabricate a World
    79 CREATE_FACTORY(World, CL_WORLD);
    80 
    81 World::World(const TiXmlElement* root)
     78//! This creates a Factory to fabricate a GameWorld
     79CREATE_FACTORY(GameWorld, CL_GAME_WORLD);
     80
     81
     82
     83GameWorld::GameWorld(const TiXmlElement* root)
    8284{
    8385  this->constuctorInit("", -1);
     
    8890
    8991/**
    90  *  remove the World from memory
     92 *  remove the GameWorld from memory
    9193 *
    9294 *  delete everything explicitly, that isn't contained in the parenting tree!
    9395 *  things contained in the tree are deleted automaticaly
    9496 */
    95 World::~World ()
     97GameWorld::~GameWorld ()
    9698{
    9799  delete this->shell;
    98   PRINTF(3)("World::~World() - deleting current world\n");
     100  PRINTF(3)("GameWorld::~GameWorld() - deleting current world\n");
    99101
    100102  delete this->localPlayer;
     
    129131
    130132/**
    131  * initializes the world.
     133 *  initializes the world.
    132134 * @param name the name of the world
    133135 * @param worldID the ID of this world
     
    139141 * NO LEVEL LOADING HERE - NEVER!
    140142*/
    141 void World::constuctorInit(const char* name, int worldID)
    142 {
    143   this->setClassID(CL_WORLD, "World");
     143void GameWorld::constuctorInit(const char* name, int worldID)
     144{
     145  this->setClassID(CL_GAME_WORLD, "GameWorld");
    144146
    145147  this->setName(name);
     
    156158
    157159/**
    158  * loads the parameters of a World from an XML-element
     160 * loads the parameters of a GameWorld from an XML-element
    159161 * @param root the XML-element to load from
    160162 */
    161 void World::loadParams(const TiXmlElement* root)
    162 {
    163   PRINTF(4)("Creating a World\n");
    164 
    165   LoadParam(root, "identifier", this, World, setStoryID)
     163void GameWorld::loadParams(const TiXmlElement* root)
     164{
     165  PRINTF(4)("Creating a GameWorld\n");
     166
     167  LoadParam(root, "identifier", this, GameWorld, setStoryID)
    166168    .describe("Sets the StoryID of this world");
    167169
    168   LoadParam(root, "nextid", this, World, setNextStoryID)
     170  LoadParam(root, "nextid", this, GameWorld, setNextStoryID)
    169171    .describe("Sets the ID of the next world");
    170172
    171   LoadParam(root, "path", this, World, setPath)
    172     .describe("The Filename of this World (relative from the data-dir)");
     173  LoadParam(root, "path", this, GameWorld, setPath)
     174    .describe("The Filename of this GameWorld (relative from the data-dir)");
    173175}
    174176
     
    179181 * before the load and after the proceeding storyentity has finished
    180182*/
    181 ErrorMessage World::preLoad()
     183ErrorMessage GameWorld::preLoad()
    182184{
    183185  State::setObjectManager(&this->objectManager);
     
    195197
    196198  this->localCamera = new Camera();
    197   this->localCamera->setName ("World-Camera");
     199  this->localCamera->setName ("GameWorld-Camera");
    198200
    199201  State::setCamera(this->localCamera, this->localCamera->getTarget());
     
    205207
    206208/**
    207  *  loads the World by initializing all resources, and set their default values.
     209 *  loads the GameWorld by initializing all resources, and set their default values.
    208210 */
    209 ErrorMessage World::load()
     211ErrorMessage GameWorld::load()
    210212{
    211213  PRINTF(3)("> Loading world: '%s'\n", getPath());
     
    215217  if( getPath() == NULL)
    216218    {
    217       PRINTF(1)("World has no path specified for loading");
    218       return (ErrorMessage){213,"Path not specified","World::load()"};
     219      PRINTF(1)("GameWorld has no path specified for loading");
     220      return (ErrorMessage){213,"Path not specified","GameWorld::load()"};
    219221    }
    220222
     
    226228    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    227229    delete XMLDoc;
    228     return (ErrorMessage){213,"XML File parsing error","World::load()"};
     230    return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"};
    229231  }
    230232
     
    238240      PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    239241      delete XMLDoc;
    240       return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
     242      return (ErrorMessage){213,"Path not a WorldDataFile","GameWorld::load()"};
    241243    }
    242244
     
    246248  if( string == NULL)
    247249    {
    248       PRINTF(2)("World is missing a proper 'name'\n");
     250      PRINTF(2)("GameWorld is missing a proper 'name'\n");
    249251      this->setName("Unknown");
    250252    }
     
    281283  if( element == NULL)
    282284    {
    283       PRINTF(1)("World is missing 'WorldEntities'\n");
     285      PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
    284286    }
    285287  else
     
    353355  SoundEngine::getInstance()->setListener(this->localCamera);
    354356
    355 
    356 
    357   ////////////
    358   // STATIC //
    359   ////////////
    360 
    361 
    362 //   TestEntity* testEntity = new TestEntity();
    363 //   testEntity->setRelCoor(Vector(570, 10, -15));
    364 //   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    365 //   this->spawn(testEntity);
    366 
    367   for(int i = 0; i < 100; i++)
    368   {
    369     WorldEntity* tmp = new NPCTest1();
    370     char npcChar[10];
    371     sprintf (npcChar, "NPC_%d", i);
    372         tmp->setName(npcChar);
    373     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    374     this->spawn(tmp);
    375   }
     357  /* some static stuff*/
    376358
    377359  this->music = NULL;
     
    380362}
    381363
    382 ErrorMessage World::postLoad()
     364ErrorMessage GameWorld::postLoad()
    383365{
    384366  this->releaseLoadScreen();
     
    387369
    388370/**
    389  *  initializes a new World shortly before start
     371 *  initializes a new GameWorld shortly before start
    390372 *
    391373 * this is the function, that will be loaded shortly before the world is
    392374 * started
    393375*/
    394 ErrorMessage World::preStart()
     376ErrorMessage GameWorld::preStart()
    395377{
    396378  this->bPause = false;
     
    403385
    404386/**
    405  *  starts the World
     387 *  starts the GameWorld
    406388 */
    407 ErrorMessage World::start()
     389ErrorMessage GameWorld::start()
    408390{
    409391  this->bQuitWorld = false;
     
    416398   This happens, when the player decides to end the Level.
    417399*/
    418 ErrorMessage World::stop()
    419 {
    420   PRINTF(3)("World::stop() - got stop signal\n");
     400ErrorMessage GameWorld::stop()
     401{
     402  PRINTF(3)("GameWorld::stop() - got stop signal\n");
    421403  this->bQuitWorld= true;
    422404}
     
    425407 *  pauses the Game
    426408*/
    427 ErrorMessage World::pause()
     409ErrorMessage GameWorld::pause()
    428410{
    429411  this->isPaused = true;
     
    433415 *  ends the pause Phase
    434416*/
    435 ErrorMessage World::resume()
     417ErrorMessage GameWorld::resume()
    436418{
    437419  this->isPaused = false;
     
    439421
    440422/**
    441  *  destroys the World
    442 */
    443 ErrorMessage World::destroy()
     423 *  destroys the GameWorld
     424*/
     425ErrorMessage GameWorld::destroy()
    444426{
    445427
     
    449431 *  shows the loading screen
    450432*/
    451 void World::displayLoadScreen ()
    452 {
    453   PRINTF(3)("World::displayLoadScreen - start\n");
     433void GameWorld::displayLoadScreen ()
     434{
     435  PRINTF(3)("GameWorld::displayLoadScreen - start\n");
    454436
    455437  //GLMenuImageScreen*
     
    457439  this->glmis->setMaximum(8);
    458440
    459   PRINTF(3)("World::displayLoadScreen - end\n");
     441  PRINTF(3)("GameWorld::displayLoadScreen - end\n");
    460442}
    461443
     
    465447 * @todo take out the delay
    466448*/
    467 void World::releaseLoadScreen ()
    468 {
    469   PRINTF(3)("World::releaseLoadScreen - start\n");
     449void GameWorld::releaseLoadScreen ()
     450{
     451  PRINTF(3)("GameWorld::releaseLoadScreen - start\n");
    470452  this->glmis->setValue(this->glmis->getMaximum());
    471   PRINTF(3)("World::releaseLoadScreen - end\n");
     453  PRINTF(3)("GameWorld::releaseLoadScreen - end\n");
    472454  delete this->glmis;
    473455}
     
    478460 * @returns elapsed game time
    479461*/
    480 double World::getGameTime()
     462double GameWorld::getGameTime()
    481463{
    482464  return this->gameTime;
     
    488470 *  synchronize local data with remote data
    489471*/
    490 void World::synchronize ()
     472void GameWorld::synchronize ()
    491473{
    492474  // Get remote input
     
    502484   sdl and has its own event-passing-queue.
    503485*/
    504 void World::handleInput ()
     486void GameWorld::handleInput ()
    505487{
    506488  EventHandler::getInstance()->process();
     
    509491}
    510492
    511 void World::tick(std::list<WorldEntity*> entityList, float dt)
     493void GameWorld::tick(std::list<WorldEntity*> entityList, float dt)
    512494{
    513495  std::list<WorldEntity*>::iterator entity;
     
    524506   a heart-beat.
    525507*/
    526 void World::tick ()
     508void GameWorld::tick ()
    527509{
    528510  Uint32 currentFrame = SDL_GetTicks();
     
    588570   state to the whole system.
    589571*/
    590 void World::update()
     572void GameWorld::update()
    591573{
    592574  GraphicsEngine::getInstance()->update(this->dtS);
     
    597579
    598580
    599 void World::collide()
     581void GameWorld::collide()
    600582{
    601583  CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
     
    610592   clear all buffers and draw the world
    611593*/
    612 void World::display ()
     594void GameWorld::display ()
    613595{
    614596  // clear buffer
     
    630612 *  runs through all entities calling their draw() methods
    631613 */
    632 void World::draw ()
     614void GameWorld::draw ()
    633615{
    634616  GraphicsEngine* engine = GraphicsEngine::getInstance();
     
    674656 * collisions drawing everything to the screen.
    675657 */
    676 void World::mainLoop()
     658void GameWorld::mainLoop()
    677659{
    678660  this->lastFrame = SDL_GetTicks ();
    679   PRINTF(3)("World::mainLoop() - Entering main loop\n");
     661  PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
    680662
    681663  while(!this->bQuitWorld) /* @todo implement pause */
     
    698680  }
    699681
    700   PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
     682  PRINTF(3)("GameWorld::mainLoop() - Exiting the main loop\n");
    701683}
    702684
     
    707689 * @param entity to be added
    708690*/
    709 void World::spawn(WorldEntity* entity)
     691void GameWorld::spawn(WorldEntity* entity)
    710692{
    711693//   this->entities->add (entity);
     
    713695}
    714696
    715 void World::setPath( const char* name)
     697void GameWorld::setPath( const char* name)
    716698{
    717699  if (this->path)
     
    729711}
    730712
    731 const char* World::getPath( void)
     713const char* GameWorld::getPath( void)
    732714{
    733715  return path;
  • branches/network/src/story_entities/game_world.h

    r6352 r6358  
    3838
    3939    /* classes from story-entity */
    40     virtual ErrorMessage preLoad();
    41     virtual ErrorMessage load ();
    42     virtual ErrorMessage postLoad();
     40    ErrorMessage preLoad();
     41    ErrorMessage load ();
     42    ErrorMessage postLoad();
    4343
    4444    virtual ErrorMessage preStart();
     
    9292    bool showBV;                        //!< if the Bounding Volumes should be visible.
    9393
     94    GLMenuImageScreen* glmis;           //!< The Level-Loader Display
     95
    9496    /* world timing */
    9597    Uint32 lastFrame;                   //!< last time of frame
     
    103105    ObjectManager objectManager;        //!< The ObjectManager of this GameWorld.
    104106
     107    /* external modules interfaces */
     108    Shell*     shell;
     109    OggPlayer* music;
    105110
    106111    /* important entities */
  • branches/network/src/story_entities/multi_player_world.cc

    r6355 r6358  
    1111   ### 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 "multi_player_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"
    60 
    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"
    7126
    7227
    73 SHELL_COMMAND(speed, NetworkWorld, setSpeed);
    74 SHELL_COMMAND(togglePNodeVisibility, NetworkWorld, togglePNodeVisibility);
    75 SHELL_COMMAND(toggleBVVisibility, NetworkWorld, toggleBVVisibility);
     28
     29SHELL_COMMAND(speed, MultiPlayerWorld, setSpeed);
     30SHELL_COMMAND(togglePNodeVisibility, MultiPlayerWorld, togglePNodeVisibility);
     31SHELL_COMMAND(toggleBVVisibility, MultiPlayerWorld, toggleBVVisibility);
    7632
    7733using namespace std;
    7834
    79 //! This creates a Factory to fabricate a NetworkWorld
    80 CREATE_FACTORY(NetworkWorld, CL_WORLD);
     35//! This creates a Factory to fabricate a MultiPlayerWorld
     36CREATE_FACTORY(MultiPlayerWorld, CL_WORLD);
    8137
    82 NetworkWorld::NetworkWorld(const TiXmlElement* root)
     38MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root)
    8339{
    8440  this->constuctorInit("", -1);
     
    8945
    9046/**
    91  *  remove the NetworkWorld from memory
     47 *  remove the MultiPlayerWorld from memory
    9248 *
    9349 *  delete everything explicitly, that isn't contained in the parenting tree!
    9450 *  things contained in the tree are deleted automaticaly
    9551 */
    96 NetworkWorld::~NetworkWorld ()
     52MultiPlayerWorld::~MultiPlayerWorld ()
    9753{
    9854  delete this->shell;
    99   PRINTF(3)("NetworkWorld::~NetworkWorld() - deleting current world\n");
     55  PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n");
    10056
    10157  delete this->localPlayer;
     
    14096 * NO LEVEL LOADING HERE - NEVER!
    14197*/
    142 void NetworkWorld::constuctorInit(const char* name, int worldID)
     98void MultiPlayerWorld::constuctorInit(const char* name, int worldID)
    14399{
    144   this->setClassID(CL_WORLD, "NetworkWorld");
     100  this->setClassID(CL_WORLD, "MultiPlayerWorld");
    145101  PRINTF(0)("START\n");
    146102
     
    157113}
    158114
     115
    159116/**
    160  * loads the parameters of a NetworkWorld from an XML-element
     117 * loads the parameters of a MultiPlayerWorld from an XML-element
    161118 * @param root the XML-element to load from
    162119 */
    163 void NetworkWorld::loadParams(const TiXmlElement* root)
     120void MultiPlayerWorld::loadParams(const TiXmlElement* root)
    164121{
    165   PRINTF(4)("Creating a NetworkWorld\n");
     122  static_cast<GameWorld*>(this)->loadParams(root);
    166123
    167   LoadParam(root, "identifier", this, NetworkWorld, setStoryID)
    168     .describe("Sets the StoryID of this world");
     124  PRINTF(4)("Creating a MultiPlayerWorld\n");
     125}
    169126
    170   LoadParam(root, "nextid", this, NetworkWorld, setNextStoryID)
    171     .describe("Sets the ID of the next world");
    172127
    173   LoadParam(root, "path", this, NetworkWorld, setPath)
    174     .describe("The Filename of this NetworkWorld (relative from the data-dir)");
    175 }
    176128
    177129/**
     
    180132 * since the load function sometimes needs data, that has been initialized
    181133 * before the load and after the proceeding storyentity has finished
    182 */
    183 ErrorMessage NetworkWorld::preLoad()
     134 */
     135ErrorMessage GameWorld::preLoad()
    184136{
    185   State::setObjectManager(&this->objectManager);
    186   this->cycle = 0;
     137  static_cast<GameWorld*>(this)->preLoad();
    187138
    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();
     139  /* the the single player specific stuff */
    205140}
    206141
    207142
    208143/**
    209  *  loads the NetworkWorld by initializing all resources, and set their default values.
     144 *  loads the GameWorld by initializing all resources, and set their default values.
    210145 */
    211 ErrorMessage NetworkWorld::load()
     146ErrorMessage GameWorld::load()
    212147{
    213   PRINTF(3)("> Loading world: '%s'\n", getPath());
    214   TiXmlElement* element;
    215   GameLoader* loader = GameLoader::getInstance();
     148  static_cast<GameWorld*>(this)->load();
    216149
    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     }
     150  /* the the single player specific stuff here */
    222151
    223   TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    224   // load the campaign document
    225   if( !XMLDoc->LoadFile())
     152  /* some static world entities */
     153  for(int i = 0; i < 100; i++)
    226154  {
    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()"};
     155    WorldEntity* tmp = new NPCTest1();
     156    char npcChar[10];
     157    sprintf (npcChar, "NPC_%d", i);
     158    tmp->setName(npcChar);
     159    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
     160    this->spawn(tmp);
    231161  }
    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();
    448 }
    449 
    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();
    462162}
    463163
    464164
    465165/**
    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()
     166 *  post loads the GameWorld by initializing all resources, and set their default values.
     167 */
     168ErrorMessage GameWorld::postLoad()
    472169{
    473   this->bPause = false;
     170  static_cast<GameWorld*>(this)->postLoad();
    474171
    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);
     172  /* the single player specific stuff here */
    478173}
    479174
    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/single_player_world.cc

    r6354 r6358  
    1111   ### 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 "world.h"
     17#include "single_player_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"
    6026
    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 "playable.h"
    70 
    71 
    72 SHELL_COMMAND(speed, World, setSpeed);
    73 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);
    74 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);
    7527
    7628using namespace std;
    7729
    78 //! This creates a Factory to fabricate a World
    79 CREATE_FACTORY(World, CL_WORLD);
     30//! This creates a Factory to fabricate a SinglePlayerWorld
     31CREATE_FACTORY(SinglePlayerSinglePlayerWorld, CL_SINGLE_PLAYER_WORLD);
    8032
    81 World::World(const TiXmlElement* root)
     33
     34
     35SinglePlayerWorld::SinglePlayerWorld(const TiXmlElement* root)
     36  : GameWorld(root)
    8237{
    83   this->constuctorInit("", -1);
    84   this->path = NULL;
    85 
    8638  this->loadParams(root);
    8739}
    8840
     41
    8942/**
    90  *  remove the World from memory
     43 *  remove the SinglePlayerWorld from memory
    9144 *
    9245 *  delete everything explicitly, that isn't contained in the parenting tree!
    9346 *  things contained in the tree are deleted automaticaly
    9447 */
    95 World::~World ()
     48SinglePlayerWorld::~SinglePlayerWorld ()
    9649{
    97   delete this->shell;
    98   PRINTF(3)("World::~World() - deleting current world\n");
     50  PRINTF(3)("SinglePlayerWorld::~SinglePlayerWorld() - deleting current world\n");
     51}
    9952
    100   delete this->localPlayer;
    101 
    102   // delete all the initialized Engines.
    103   FastFactory::flushAll(true);
    104   delete LightManager::getInstance();
    105   delete ParticleEngine::getInstance();
    106   delete AnimationPlayer::getInstance();
    107   delete PhysicsEngine::getInstance();
    108 
    109   // external engines initialized by the orxonox-class get deleted
    110   SoundEngine::getInstance()->flushAllBuffers();
    111   SoundEngine::getInstance()->flushAllSources();
    112 
    113   if (State::getObjectManager() == &this->objectManager)
    114     State::setObjectManager(NULL);
    115   // erease everything that is left.
    116   delete PNode::getNullParent();
    117 
    118   //secondary cleanup of PNodes;
    119   const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
    120   if (nodeList != NULL)
    121     while (!nodeList->empty())
    122       delete nodeList->front();
    123 
    124   Shader::suspendShader();
    125 
    126   // unload the resources !!
    127   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
    128 }
    12953
    13054/**
     
    13963 * NO LEVEL LOADING HERE - NEVER!
    14064*/
    141 void World::constuctorInit(const char* name, int worldID)
     65void SinglePlayerWorld::constuctorInit(const char* name, int worldID)
    14266{
    143   this->setClassID(CL_WORLD, "World");
     67  this->setClassID(CL_SINGLE_PLAYER_WORLD, "SinglePlayerSinglePlayerWorld");
     68  this->setName(name);
    14469
    145   this->setName(name);
    14670  this->gameTime = 0.0f;
    14771  this->setSpeed(1.0);
     
    15579}
    15680
     81
    15782/**
    158  * loads the parameters of a World from an XML-element
     83 * loads the parameters of a SinglePlayerWorld from an XML-element
    15984 * @param root the XML-element to load from
    16085 */
    161 void World::loadParams(const TiXmlElement* root)
     86void SinglePlayerWorld::loadParams(const TiXmlElement* root)
    16287{
    163   PRINTF(4)("Creating a World\n");
     88  static_cast<GameWorld*>(this)->loadParams(root);
    16489
    165   LoadParam(root, "identifier", this, World, setStoryID)
    166     .describe("Sets the StoryID of this world");
     90  PRINTF(4)("Creating a SinglePlayerWorld\n");
     91}
    16792
    168   LoadParam(root, "nextid", this, World, setNextStoryID)
    169     .describe("Sets the ID of the next world");
    17093
    171   LoadParam(root, "path", this, World, setPath)
    172     .describe("The Filename of this World (relative from the data-dir)");
    173 }
    17494
    17595/**
     
    17898 * since the load function sometimes needs data, that has been initialized
    17999 * before the load and after the proceeding storyentity has finished
    180 */
    181 ErrorMessage World::preLoad()
     100 */
     101ErrorMessage GameWorld::preLoad()
    182102{
    183   State::setObjectManager(&this->objectManager);
    184   this->cycle = 0;
     103  static_cast<GameWorld*>(this)->preLoad();
    185104
    186   /* init the world interface */
    187   this->shell = new Shell();
    188 
    189   LightManager::getInstance();
    190   PNode::getNullParent();
    191 
    192   AnimationPlayer::getInstance(); // initializes the animationPlayer
    193   ParticleEngine::getInstance();
    194   PhysicsEngine::getInstance();
    195 
    196   this->localCamera = new Camera();
    197   this->localCamera->setName ("World-Camera");
    198 
    199   State::setCamera(this->localCamera, this->localCamera->getTarget());
    200 
    201   GraphicsEngine::getInstance()->displayFPS(true);
    202   this->displayLoadScreen();
     105  /* the the single player specific stuff */
    203106}
    204107
    205108
    206109/**
    207  *  loads the World by initializing all resources, and set their default values.
     110 *  loads the GameWorld by initializing all resources, and set their default values.
    208111 */
    209 ErrorMessage World::load()
     112ErrorMessage GameWorld::load()
    210113{
    211   PRINTF(3)("> Loading world: '%s'\n", getPath());
    212   TiXmlElement* element;
    213   GameLoader* loader = GameLoader::getInstance();
     114  static_cast<GameWorld*>(this)->load();
    214115
    215   if( getPath() == NULL)
    216     {
    217       PRINTF(1)("World has no path specified for loading");
    218       return (ErrorMessage){213,"Path not specified","World::load()"};
    219     }
     116  /* the the single player specific stuff here */
    220117
    221   TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());
    222   // load the campaign document
    223   if( !XMLDoc->LoadFile())
    224   {
    225     // report an error
    226     PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    227     delete XMLDoc;
    228     return (ErrorMessage){213,"XML File parsing error","World::load()"};
    229   }
    230 
    231   // check basic validity
    232   TiXmlElement* root = XMLDoc->RootElement();
    233   assert( root != NULL);
    234 
    235   if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))
    236     {
    237       // report an error
    238       PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");
    239       delete XMLDoc;
    240       return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};
    241     }
    242 
    243   // load the parameters
    244   // name
    245   const char* string = grabParameter( root, "name");
    246   if( string == NULL)
    247     {
    248       PRINTF(2)("World is missing a proper 'name'\n");
    249       this->setName("Unknown");
    250     }
    251   else
    252     {
    253       this->setName(string);
    254     }
    255 
    256   ////////////////
    257   // LOADSCREEN //
    258   ////////////////
    259   element = root->FirstChildElement("LoadScreen");
    260   if (element == NULL)
    261     {
    262       PRINTF(2)("no LoadScreen specified, loading default\n");
    263 
    264       glmis->setBackgroundImage("pictures/load_screen.jpg");
    265       this->glmis->setMaximum(8);
    266       this->glmis->draw();
    267     }
    268   else
    269     {
    270       this->glmis->loadParams(element);
    271       this->glmis->draw();
    272     }
    273   this->glmis->draw();
    274 
    275   ////////////////////////
    276   // find WorldEntities //
    277   ////////////////////////
    278 
    279   element = root->FirstChildElement("WorldEntities");
    280 
    281   if( element == NULL)
    282     {
    283       PRINTF(1)("World is missing 'WorldEntities'\n");
    284     }
    285   else
    286     {
    287       element = element->FirstChildElement();
    288       // load Players/Objects/Whatever
    289       PRINTF(4)("Loading WorldEntities\n");
    290       while( element != NULL)
    291         {
    292           BaseObject* created = Factory::fabricate(element);
    293           if( created != NULL )
    294           {
    295             if(created->isA(CL_WORLD_ENTITY))
    296               this->spawn(dynamic_cast<WorldEntity*>(created));
    297             printf("Created a %s: %s\n", created->getClassName(), created->getName());
    298           }
    299 
    300           // if we load a 'Player' we use it as localPlayer
    301 
    302 
    303           //todo do this more elegant
    304           if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
    305             this->sky = dynamic_cast<WorldEntity*>(created);
    306           if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
    307           {
    308             terrain = dynamic_cast<Terrain*>(created);
    309             CDEngine::getInstance()->setTerrain(terrain);
    310           }
    311           element = element->NextSiblingElement();
    312           glmis->step(); //! @todo temporary
    313         }
    314       PRINTF(4)("Done loading WorldEntities\n");
    315     }
    316 
    317     //////////////////////////////
    318     // LOADING ADDITIONAL STUFF //
    319     //////////////////////////////
    320 
    321     LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
    322 
    323    LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
    324 //   LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
    325 
    326   // free the XML data
    327 
    328   delete XMLDoc;
    329   /* GENERIC LOADING PROCESS FINISHED */
    330 
    331 
    332   // Create a Player
    333   this->localPlayer = new Player();
    334 
    335   Playable* playable;
    336   const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    337   if (playableList != NULL)
    338   {
    339     playable = dynamic_cast<Playable*>(playableList->front());
    340     this->localPlayer->setControllable(playable);
    341   }
    342 
    343 
    344 //   //localCamera->setParent(TrackNode::getInstance());
    345 //  tn->addChild(this->localCamera);
    346   localCamera->setClipRegion(1, 10000.0);
    347 //  localCamera->lookAt(playable);
    348 //  this->localPlayer->setParentMode(PNODE_ALL);
    349   if (this->sky != NULL)
    350   {
    351     this->localCamera->addChild(sky);
    352   }
    353   SoundEngine::getInstance()->setListener(this->localCamera);
    354 
    355 
    356 
    357   ////////////
    358   // STATIC //
    359   ////////////
    360 
    361 
    362 //   TestEntity* testEntity = new TestEntity();
    363 //   testEntity->setRelCoor(Vector(570, 10, -15));
    364 //   testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));
    365 //   this->spawn(testEntity);
    366 
     118  /* some static world entities */
    367119  for(int i = 0; i < 100; i++)
    368120  {
     
    370122    char npcChar[10];
    371123    sprintf (npcChar, "NPC_%d", i);
    372         tmp->setName(npcChar);
     124    tmp->setName(npcChar);
    373125    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
    374126    this->spawn(tmp);
    375127  }
    376 
    377   this->music = NULL;
    378   //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
    379   //music->playback();
    380 }
    381 
    382 ErrorMessage World::postLoad()
    383 {
    384   this->releaseLoadScreen();
    385128}
    386129
    387130
    388131/**
    389  *  initializes a new World shortly before start
    390  *
    391  * this is the function, that will be loaded shortly before the world is
    392  * started
    393 */
    394 ErrorMessage World::preStart()
     132 *  post loads the GameWorld by initializing all resources, and set their default values.
     133 */
     134ErrorMessage GameWorld::postLoad()
    395135{
    396   this->bPause = false;
     136  static_cast<GameWorld*>(this)->postLoad();
    397137
    398   /* update the object position before game start - so there are no wrong coordinates used in the first processing */
    399   PNode::getNullParent()->updateNode (0.001f);
    400   PNode::getNullParent()->updateNode (0.001f);
     138  /* the single player specific stuff here */
    401139}
    402 
    403 
    404 /**
    405  *  starts the World
    406  */
    407 ErrorMessage World::start()
    408 {
    409   this->bQuitWorld = false;
    410   this->mainLoop();
    411 }
    412 
    413 /**
    414  *  stops the world.
    415 
    416    This happens, when the player decides to end the Level.
    417 */
    418 ErrorMessage World::stop()
    419 {
    420   PRINTF(3)("World::stop() - got stop signal\n");
    421   this->bQuitWorld= true;
    422 }
    423 
    424 /**
    425  *  pauses the Game
    426 */
    427 ErrorMessage World::pause()
    428 {
    429   this->isPaused = true;
    430 }
    431 
    432 /**
    433  *  ends the pause Phase
    434 */
    435 ErrorMessage World::resume()
    436 {
    437   this->isPaused = false;
    438 }
    439 
    440 /**
    441  *  destroys the World
    442 */
    443 ErrorMessage World::destroy()
    444 {
    445 
    446 }
    447 
    448 /**
    449  *  shows the loading screen
    450 */
    451 void World::displayLoadScreen ()
    452 {
    453   PRINTF(3)("World::displayLoadScreen - start\n");
    454 
    455   //GLMenuImageScreen*
    456   this->glmis = new GLMenuImageScreen();
    457   this->glmis->setMaximum(8);
    458 
    459   PRINTF(3)("World::displayLoadScreen - end\n");
    460 }
    461 
    462 /**
    463  * @brief removes the loadscreen, and changes over to the game
    464  *
    465  * @todo take out the delay
    466 */
    467 void World::releaseLoadScreen ()
    468 {
    469   PRINTF(3)("World::releaseLoadScreen - start\n");
    470   this->glmis->setValue(this->glmis->getMaximum());
    471   PRINTF(3)("World::releaseLoadScreen - end\n");
    472   delete this->glmis;
    473 }
    474 
    475 
    476 /**
    477  *  this returns the current game time
    478  * @returns elapsed game time
    479 */
    480 double World::getGameTime()
    481 {
    482   return this->gameTime;
    483 }
    484 
    485 
    486 
    487 /**
    488  *  synchronize local data with remote data
    489 */
    490 void World::synchronize ()
    491 {
    492   // Get remote input
    493   // Update synchronizables
    494 /*  NetworkManager::getInstance()->synchronize();*/
    495 }
    496 
    497 
    498 /**
    499  *  run all input processing
    500 
    501    the command node is the central input event dispatcher. the node uses the even-queue from
    502    sdl and has its own event-passing-queue.
    503 */
    504 void World::handleInput ()
    505 {
    506   EventHandler::getInstance()->process();
    507 
    508   // remoteinput
    509 }
    510 
    511 void World::tick(std::list<WorldEntity*> entityList, float dt)
    512 {
    513   std::list<WorldEntity*>::iterator entity;
    514   for (entity = entityList.begin(); entity != entityList.end(); entity++)
    515     (*entity)->tick(dt);
    516 
    517 }
    518 
    519 /**
    520  *  advance the timeline
    521 
    522    this calculates the time used to process one frame (with all input handling, drawing, etc)
    523    the time is mesured in ms and passed to all world-entities and other classes that need
    524    a heart-beat.
    525 */
    526 void World::tick ()
    527 {
    528   Uint32 currentFrame = SDL_GetTicks();
    529   if(!this->bPause)
    530     {
    531       this->dt = currentFrame - this->lastFrame;
    532 
    533       if( this->dt > 10)
    534         {
    535           float fps = 1000/dt;
    536 
    537           // temporary, only for showing how fast the text-engine is
    538           char tmpChar[20];
    539           sprintf(tmpChar, "fps: %4.0f", fps);
    540         }
    541       else
    542         {
    543           /* the frame-rate is limited to 100 frames per second, all other things are for
    544              nothing.
    545           */
    546           PRINTF(3)("fps = 1000 - frame rate is adjusted\n");
    547           SDL_Delay(10-dt);
    548           this->dt = 10;
    549         }
    550 
    551       this->dtS = (float)this->dt / 1000.0 * this->speed;
    552       this->gameTime += this->dtS;
    553 
    554       this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);
    555       this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);
    556       this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);
    557       this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);
    558       this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);
    559 
    560       /* update tick the rest */
    561       this->localCamera->tick(this->dtS);
    562       // tick the engines
    563       AnimationPlayer::getInstance()->tick(this->dtS);
    564 //      if (this->cycle > 5)
    565         PhysicsEngine::getInstance()->tick(this->dtS);
    566 
    567       ParticleEngine::getInstance()->tick(this->dtS);
    568 
    569 
    570       /** actualy the Graphics Engine should tick the world not the other way around...
    571          but since we like the things not too complicated we got it this way around
    572          until there is need or time to do it the other way around.
    573          @todo: GraphicsEngine ticks world: separation of processes and data...
    574 
    575         bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,
    576          beceause graphics have nothing(or at least not much) to do with Motion.
    577       */
    578       GraphicsEngine::getInstance()->tick(this->dtS);
    579     }
    580   this->lastFrame = currentFrame;
    581 }
    582 
    583 
    584 /**
    585  *  this function gives the world a consistant state
    586 
    587    after ticking (updating the world state) this will give a constistant
    588    state to the whole system.
    589 */
    590 void World::update()
    591 {
    592   GraphicsEngine::getInstance()->update(this->dtS);
    593   PNode::getNullParent()->updateNode (this->dtS);
    594   SoundEngine::getInstance()->update();
    595   //music->update();
    596 }
    597 
    598 
    599 void World::collide()
    600 {
    601   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),
    602                                             this->objectManager.getObjectList(OM_GROUP_01_PROJ));
    603   CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),
    604                                             this->objectManager.getObjectList(OM_COMMON));
    605 }
    606 
    607 /**
    608  *  render the current frame
    609 
    610    clear all buffers and draw the world
    611 */
    612 void World::display ()
    613 {
    614   // clear buffer
    615   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    616   // set camera
    617   this->localCamera->apply ();
    618   // draw world
    619   this->draw();
    620   // draw HUD
    621   /** @todo draw HUD */
    622   // flip buffers
    623   GraphicsEngine::swapBuffers();
    624   //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
    625   //SDL_Flip (screen);
    626 }
    627 
    628 
    629 /**
    630  *  runs through all entities calling their draw() methods
    631  */
    632 void World::draw ()
    633 {
    634   GraphicsEngine* engine = GraphicsEngine::getInstance();
    635   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    636   engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));
    637   engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));
    638   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));
    639   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));
    640   engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    641 
    642    if( unlikely( this->showBV))  // to draw the bounding boxes of the objects at level 2 for debug purp
    643    {
    644      CDEngine* engine = CDEngine::getInstance();
    645      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));
    646      engine->drawBV(State::getObjectManager()->getObjectList(OM_ENVIRON));
    647      engine->drawBV(State::getObjectManager()->getObjectList(OM_COMMON));
    648      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_00));
    649      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01));
    650      engine->drawBV(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));
    651    }
    652 
    653 //   {
    654 //     if( entity->isVisible() ) entity->draw();
    655   //FIXME
    656 //     entity = iterator->nextElement();
    657 //   }
    658 
    659   ParticleEngine::getInstance()->draw();
    660 
    661   if (unlikely(this->showPNodes))
    662     PNode::getNullParent()->debugDraw(0);
    663 
    664   engine->draw();
    665   //TextEngine::getInstance()->draw();
    666 }
    667 
    668 
    669 /**
    670  * \brief main loop of the world: executing all world relevant function
    671  *
    672  * in this loop we synchronize (if networked), handle input events, give the heart-beat to
    673  * all other member-entities of the world (tick to player, enemies etc.), checking for
    674  * collisions drawing everything to the screen.
    675  */
    676 void World::mainLoop()
    677 {
    678   this->lastFrame = SDL_GetTicks ();
    679   PRINTF(3)("World::mainLoop() - Entering main loop\n");
    680 
    681   while(!this->bQuitWorld) /* @todo implement pause */
    682   {
    683     ++this->cycle;
    684       // Network
    685     this->synchronize ();
    686       // Process input
    687     this->handleInput ();
    688     if( this->bQuitWorld)
    689       break;
    690       // Process time
    691     this->tick ();
    692       // Process collision
    693     this->collide ();
    694       // Update the state
    695     this->update ();
    696       // Draw
    697     this->display ();
    698   }
    699 
    700   PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
    701 }
    702 
    703 
    704 
    705 /**
    706  *  add and spawn a new entity to this world
    707  * @param entity to be added
    708 */
    709 void World::spawn(WorldEntity* entity)
    710 {
    711 //   this->entities->add (entity);
    712   entity->postSpawn ();
    713 }
    714 
    715 void World::setPath( const char* name)
    716 {
    717   if (this->path)
    718     delete this->path;
    719   if (ResourceManager::isFile(name))
    720   {
    721     this->path = new char[strlen(name)+1];
    722     strcpy(this->path, name);
    723   }
    724   else
    725     {
    726       this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];
    727       sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);
    728     }
    729 }
    730 
    731 const char* World::getPath( void)
    732 {
    733   return path;
    734 }
  • branches/network/src/story_entities/single_player_world.h

    r6355 r6358  
    3333    void loadParams(const TiXmlElement* root);
    3434
    35 
    36     /* classes from story-entity */
    37     virtual ErrorMessage preLoad();
    38     virtual ErrorMessage load ();
    39     virtual ErrorMessage postLoad();
    40 
    41     virtual ErrorMessage preStart();
    42     virtual ErrorMessage start ();
    43     virtual ErrorMessage stop ();
    44     virtual ErrorMessage pause ();
    45     virtual ErrorMessage resume ();
    46     virtual ErrorMessage destroy ();
    47 
    48     virtual void displayLoadScreen();
    49     virtual void releaseLoadScreen();
    50 
    51     /* interface to world */
    52     virtual void spawn (WorldEntity* entity);
    53 
    54 
    55   protected:
    56     virtual void constuctorInit(const char* name, int worldID);
    57 
    58     /* world - running functions */
    59     virtual void mainLoop ();
    60 
    61     virtual void synchronize ();
    62     virtual void handleInput ();
    63     virtual void tick (std::list<WorldEntity*> worldEntity, float dt);
    64     virtual void tick ();
    65     virtual void update ();
    66     virtual void collide ();
    67     virtual void draw ();
    68     virtual void display ();
    69 
    70     virtual void debug ();
    71 
    72 
    73   private:
    74     /* external modules interfaces */
    75     Shell*     shell;
    76     OggPlayer* music;
    77 
    78     GLMenuImageScreen* glmis;           //!< The Level-Loader Display
     35    ErrorMessage preLoad();
     36    ErrorMessage load ();
     37    ErrorMessage postLoad();
    7938
    8039};
Note: See TracChangeset for help on using the changeset viewer.