Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/game_world_data.cc @ 6402

Last change on this file since 6402 was 6402, checked in by patrick, 18 years ago

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

File size: 7.0 KB
Line 
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*/
14
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
17
18#include "game_world_data.h"
19
20#include "resource_manager.h"
21#include "state.h"
22#include "class_list.h"
23#include "substring.h"
24
25#include "game_loader.h"
26
27#include "p_node.h"
28#include "world_entity.h"
29#include "player.h"
30#include "camera.h"
31#include "environment.h"
32#include "terrain.h"
33#include "test_entity.h"
34#include "terrain.h"
35#include "md2Model.h"
36#include "weapons/projectile.h"
37#include "npcs/npc_test1.h"
38#include "playable.h"
39
40#include "light.h"
41
42#include "factory.h"
43#include "fast_factory.h"
44#include "load_param.h"
45
46#include "particle_engine.h"
47#include "graphics_engine.h"
48#include "event_handler.h"
49#include "sound_engine.h"
50#include "cd_engine.h"
51#include "network_manager.h"
52#include "physics_engine.h"
53#include "fields.h"
54
55#include "glmenu_imagescreen.h"
56
57#include "animation_player.h"
58#include "animation3d.h"
59
60#include "ogg_player.h"
61#include "shader.h"
62
63
64
65using namespace std;
66
67
68/**
69 * constructor of the GameWorldData
70 */
71GameWorldData::GameWorldData()
72{
73  this->setClassID(CL_GAME_WORLD_DATA, "GameWorldData");
74
75  this->localPlayer = NULL;
76  this->localCamera = NULL;
77
78  this->glmis = NULL;
79
80  this->localCamera = NULL;
81  this->localPlayer = NULL;
82  this->sky = NULL;
83  this->terrain = NULL;
84
85  this->music = NULL;
86  this->objectManager = NULL;
87}
88
89
90/**
91 * destructor for the GameWorldData
92 */
93GameWorldData::~GameWorldData()
94{
95}
96
97
98
99/**
100 *  initialize the GameWorldData
101 */
102ErrorMessage GameWorldData::init()
103{
104  this->objectManager = new ObjectManager();
105  State::setObjectManager(this->objectManager);
106
107  PNode::getNullParent();
108  this->localCamera = new Camera();
109  this->localCamera->setName ("GameWorld-Camera");
110  State::setCamera(this->localCamera, this->localCamera->getTarget());
111
112  LightManager::getInstance();
113
114  GraphicsEngine::getInstance()->displayFPS(true);
115
116  /* initialize some graphics engines and graphical elements */
117  AnimationPlayer::getInstance();
118  ParticleEngine::getInstance();
119  PhysicsEngine::getInstance();
120}
121
122
123/**
124 *  loads the data from the xml file
125 * @param root reference to the xml root element
126 */
127ErrorMessage GameWorldData::loadData(TiXmlElement* root)
128{
129  // load the parameters
130  // name
131  const char* string = grabParameter( root, "name");
132  if( string == NULL)
133  {
134    PRINTF(2)("GameWorld is missing a proper 'name'\n");
135    this->setName("Unknown");
136  }
137  else
138    this->setName(string);
139
140  this->loadGUI(root);
141  this->loadWorldEntities(root);
142  this->loadScene(root);
143}
144
145
146/**
147 *  unloads the data from the xml file
148 */
149ErrorMessage GameWorldData::unloadData()
150{
151  this->unloadGUI();
152  this->unloadWorldEntities();
153  this->unloadScene();
154}
155
156
157/**
158 *  loads the GUI data
159 * @param root reference to the xml root element
160 */
161ErrorMessage GameWorldData::loadGUI(TiXmlElement* root)
162{
163  TiXmlElement* element = root->FirstChildElement("LoadScreen");
164  if( element == NULL)
165  {
166    PRINTF(2)("no LoadScreen specified, loading default\n");
167
168    glmis->setBackgroundImage("pictures/load_screen.jpg");
169    this->glmis->setMaximum(8);
170//     this->glmis->draw();
171  }
172  else
173  {
174    this->glmis->loadParams(element);
175//     this->glmis->draw();
176  }
177  this->glmis->draw();
178}
179
180
181/**
182 *  loads the GUI data
183 */
184ErrorMessage GameWorldData::unloadGUI()
185{
186  delete this->glmis;
187}
188
189
190/**
191 *  loads the world entities from the xml file
192 * @param root reference to the xml root parameter
193 */
194ErrorMessage GameWorldData::loadWorldEntities(TiXmlElement* root)
195{
196  TiXmlElement* element = root->FirstChildElement("WorldEntities");
197
198  if( element == NULL)
199  {
200    PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
201  }
202  else
203  {
204    element = element->FirstChildElement();
205    // load Players/Objects/Whatever
206    PRINTF(4)("Loading WorldEntities\n");
207    while( element != NULL)
208    {
209      BaseObject* created = Factory::fabricate(element);
210      if( created != NULL )
211        printf("Created a %s: %s\n", created->getClassName(), created->getName());
212
213      //todo do this more elegant
214      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
215        this->sky = dynamic_cast<WorldEntity*>(created);
216      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
217      {
218        this->terrain = dynamic_cast<Terrain*>(created);
219        CDEngine::getInstance()->setTerrain(terrain);
220      }
221      element = element->NextSiblingElement();
222      this->glmis->step(); //! @todo temporary
223    }
224    PRINTF(4)("Done loading WorldEntities\n");
225  }
226
227  // Create a Player
228  this->localPlayer = new Player();
229
230  Playable* playable;
231  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
232  if (playableList != NULL)
233  {
234    playable = dynamic_cast<Playable*>(playableList->front());
235    this->localPlayer->setControllable(playable);
236  }
237
238  /* init the pnode tree */
239  PNode::getNullParent()->init();
240}
241
242
243/**
244 *  unloads the world entities from the xml file
245 */
246ErrorMessage GameWorldData::unloadWorldEntities()
247{
248  FastFactory::flushAll(true);
249
250  // erease everything that is left.
251  delete PNode::getNullParent();
252
253  //secondary cleanup of PNodes;
254  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
255  if (nodeList != NULL)
256    while (!nodeList->empty())
257      delete nodeList->front();
258
259  /* remove the player object */
260  if( this->localPlayer)
261    delete this->localPlayer;
262
263  // unload the resources !!
264  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
265
266  if (State::getObjectManager() == this->objectManager)
267  {
268    State::setObjectManager(NULL);
269    delete this->objectManager;
270  }
271}
272
273
274/**
275 *  loads the scene data
276 * @param root reference to the xml root element
277 */
278ErrorMessage GameWorldData::loadScene(TiXmlElement* root)
279{
280  LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
281
282  LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
283  //LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
284
285  this->localCamera->setClipRegion(1, 10000.0);
286  if( this->sky != NULL)
287    this->localCamera->addChild(this->sky);
288
289  /* sound loading */
290  this->music = NULL;
291  //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);
292  //music->playback();
293  SoundEngine::getInstance()->setListener(this->localCamera);
294}
295
296
297/**
298 *  unloads the scene data
299 */
300ErrorMessage GameWorldData::unloadScene()
301{
302  /* delete some garphics and scene eingines */
303  delete LightManager::getInstance();
304  delete ParticleEngine::getInstance();
305  delete AnimationPlayer::getInstance();
306  delete PhysicsEngine::getInstance();
307
308  /* stop the sound eninge */
309  SoundEngine::getInstance()->flushAllBuffers();
310  SoundEngine::getInstance()->flushAllSources();
311
312  /* unload the shaders */
313  Shader::suspendShader();
314}
315
Note: See TracBrowser for help on using the repository browser.