Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/game_world_data.cc @ 6705

Last change on this file since 6705 was 6634, checked in by bensch, 19 years ago

orxonox/trunk: merged the network-branche back to the trunk

merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6500:HEAD
minor conflicts in texture and one Makefile resolved to the trunk

also made a small patch to texture, so it Modulates with GL_REPEAT

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