Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: some more menu work. There is no menu visible yet (only for your info)

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 "world_entities/projectiles/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->glmis = NULL;
76
77  this->localCamera = NULL;
78  this->localPlayer = NULL;
79  this->sky = NULL;
80  this->terrain = NULL;
81
82  this->music = NULL;
83  this->objectManager = NULL;
84}
85
86
87/**
88 * destructor for the GameWorldData
89 */
90GameWorldData::~GameWorldData()
91{}
92
93
94
95/**
96 *  initialize the GameWorldData
97 */
98ErrorMessage GameWorldData::init()
99{
100  this->objectManager = new ObjectManager();
101  State::setObjectManager(this->objectManager);
102
103  PNode::getNullParent();
104  this->localCamera = new Camera();
105  this->localCamera->setName ("GameWorld-Camera");
106  State::setCamera(this->localCamera, this->localCamera->getTarget());
107
108  LightManager::getInstance();
109
110  GraphicsEngine::getInstance()->displayFPS(true);
111
112  /* initialize some graphics engines and graphical elements */
113  AnimationPlayer::getInstance();
114  ParticleEngine::getInstance();
115  PhysicsEngine::getInstance();
116}
117
118
119/**
120 *  loads the data from the xml file
121 * @param root reference to the xml root element
122 */
123ErrorMessage GameWorldData::loadData(TiXmlElement* root)
124{
125  // load the parameters
126  // name
127  const char* string = grabParameter( root, "name");
128  if( string == NULL)
129  {
130    PRINTF(2)("GameWorld is missing a proper 'name'\n");
131    this->setName("Unknown");
132  }
133  else
134    this->setName(string);
135
136  this->loadGUI(root);
137  this->loadWorldEntities(root);
138  this->loadScene(root);
139}
140
141
142/**
143 *  unloads the data from the xml file
144 */
145ErrorMessage GameWorldData::unloadData()
146{
147  this->unloadGUI();
148  this->unloadWorldEntities();
149  this->unloadScene();
150}
151
152
153/**
154 *  loads the GUI data
155 * @param root reference to the xml root element
156 */
157ErrorMessage GameWorldData::loadGUI(TiXmlElement* root)
158{
159  TiXmlElement* element = root->FirstChildElement("LoadScreen");
160  if( element == NULL)
161  {
162    PRINTF(2)("no LoadScreen specified, loading default\n");
163
164    glmis->setBackgroundImage("pictures/load_screen.jpg");
165    this->glmis->setMaximum(8);
166//     this->glmis->draw();
167  }
168  else
169  {
170    this->glmis->loadParams(element);
171//     this->glmis->draw();
172  }
173  this->glmis->draw();
174}
175
176
177/**
178 *  unloads the GUI data
179 */
180ErrorMessage GameWorldData::unloadGUI()
181{
182  delete this->glmis;
183}
184
185
186/**
187 *  loads the world entities from the xml file
188 * @param root reference to the xml root parameter
189 */
190ErrorMessage GameWorldData::loadWorldEntities(TiXmlElement* root)
191{
192  TiXmlElement* element = root->FirstChildElement("WorldEntities");
193
194  if( element == NULL)
195  {
196    PRINTF(1)("GameWorld is missing 'WorldEntities'\n");
197  }
198  else
199  {
200    element = element->FirstChildElement();
201    // load Players/Objects/Whatever
202    PRINTF(4)("Loading WorldEntities\n");
203    while( element != NULL)
204    {
205      BaseObject* created = Factory::fabricate(element);
206      if( created != NULL )
207        printf("Created a %s: %s\n", created->getClassName(), created->getName());
208
209      //todo do this more elegant
210      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
211        this->sky = dynamic_cast<WorldEntity*>(created);
212      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
213      {
214        this->terrain = dynamic_cast<Terrain*>(created);
215        CDEngine::getInstance()->setTerrain(terrain);
216      }
217      element = element->NextSiblingElement();
218      this->glmis->step(); //! @todo temporary
219    }
220    PRINTF(4)("Done loading WorldEntities\n");
221  }
222
223  // Create a Player
224  this->localPlayer = new Player();
225
226  Playable* playable;
227  const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
228  if (playableList != NULL)
229  {
230    playable = dynamic_cast<Playable*>(playableList->front());
231    this->localPlayer->setControllable(playable);
232  }
233
234  /* init the pnode tree */
235  PNode::getNullParent()->init();
236}
237
238
239/**
240 *  unloads the world entities
241 */
242ErrorMessage GameWorldData::unloadWorldEntities()
243{
244  FastFactory::flushAll(true);
245
246  // erease everything that is left.
247  delete PNode::getNullParent();
248
249  //secondary cleanup of PNodes;
250  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
251  if (nodeList != NULL)
252    while (!nodeList->empty())
253      delete nodeList->front();
254
255  /* remove the player object */
256  if( this->localPlayer)
257    delete this->localPlayer;
258
259  // unload the resources !!
260  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
261
262  if (State::getObjectManager() == this->objectManager)
263  {
264    State::setObjectManager(NULL);
265    delete this->objectManager;
266  }
267}
268
269
270/**
271 *  loads the scene data
272 * @param root reference to the xml root element
273 */
274ErrorMessage GameWorldData::loadScene(TiXmlElement* root)
275{
276  LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);
277
278  LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);
279  //LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);
280
281  this->localCamera->setClipRegion(1, 10000.0);
282  if( this->sky != NULL)
283    this->localCamera->addChild(this->sky);
284  SoundEngine::getInstance()->setListener(this->localCamera);
285}
286
287
288/**
289 *  unloads the scene data
290 */
291ErrorMessage GameWorldData::unloadScene()
292{
293  /* delete some garphics and scene eingines */
294  delete LightManager::getInstance();
295  delete ParticleEngine::getInstance();
296  delete AnimationPlayer::getInstance();
297  delete PhysicsEngine::getInstance();
298
299  /* stop the sound eninge */
300  SoundEngine::getInstance()->flushAllBuffers();
301  SoundEngine::getInstance()->flushAllSources();
302
303  /* unload the shaders */
304  Shader::suspendShader();
305}
306
307
308void GameWorldData::setSoundTrack(const char* name)
309{
310  PRINTF(3)("Setting Sound Track to %s\n", name);
311  this->music = (OggPlayer*)ResourceManager::getInstance()->load(name, OGG, RP_LEVEL);
312}
313
314
Note: See TracBrowser for help on using the repository browser.