Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/multi_player_world_data.cc @ 10618

Last change on this file since 10618 was 10618, checked in by bknecht, 17 years ago

merged cleanup into trunk (only improvements)

File size: 9.2 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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
16
17
18#include "multi_player_world_data.h"
19
20#include "state.h"
21#include "substring.h"
22
23#include "util/loading/game_loader.h"
24#include "cd_engine.h"
25
26#include "p_node.h"
27#include "world_entity.h"
28#include "player.h"
29#include "tools/camera.h"
30#include "environments/environment.h"
31#include "environments/terrain.h"
32#include "world_entities/projectiles/projectile.h"
33#include "npcs/npc_test1.h"
34#include "playable.h"
35
36#include "util/loading/factory.h"
37#include "loading/fast_factory.h"
38#include "util/loading/load_param.h"
39
40#include "network_manager.h"
41#include "network_game_manager.h"
42#include "player_stats.h"
43
44#include "proxy/network_settings.h"
45
46#include "glmenu_imagescreen.h"
47
48
49/**
50 * constructor of the GameWorldDataData
51 */
52MultiPlayerWorldData::MultiPlayerWorldData()
53    : GameWorldData()
54{
55  this->toggle = false;
56}
57
58
59/**
60 * destructor for the GameWorldDataData
61 */
62MultiPlayerWorldData::~MultiPlayerWorldData()
63{}
64
65
66/**
67 *  initialize the GameWorldDataData
68 */
69ErrorMessage MultiPlayerWorldData::init()
70{
71  /* call underlying function */
72  return GameWorldData::init();
73}
74
75
76/**
77 *  loads the GUI data
78 * @param root reference to the xml root element
79 */
80ErrorMessage MultiPlayerWorldData::loadGUI(const TiXmlElement* root)
81{
82  /* call underlying function */
83  return GameWorldData::loadGUI(root);
84}
85
86
87/**
88 *  unloads the GUI data
89 */
90ErrorMessage MultiPlayerWorldData::unloadGUI()
91{
92  /* call underlying function */
93  return GameWorldData::unloadGUI();
94}
95
96
97/**
98 *  overloads the GameWorld::loadWorldEntities(...) class since the network WorldEntity loading is different
99 * @param root reference to the xml root parameter
100 */
101ErrorMessage MultiPlayerWorldData::loadWorldEntities(const TiXmlElement* root)
102{
103  const TiXmlElement* element = NULL;
104
105  if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
106  {
107    /* load the spawning points */
108    element = root->FirstChildElement("SpawningPoints");
109    if( element == NULL)
110    {
111      PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");
112    }
113    else
114    {
115      element = element->FirstChildElement();
116      // load Players/Objects/Whatever
117      PRINTF(4)("Loading Spawning Points\n");
118      while( element != NULL)
119      {
120        BaseObject* created = Factory::fabricate(element);
121        if( created != NULL )
122          printf("Created a Spawning Point %s: %s\n", created->getClassCName(), created->getCName());
123
124        element = element->NextSiblingElement();
125        glmis->step();
126      }
127      PRINTF(4)("Done loading Spawning Points\n");
128    }
129  }
130
131  /* load the WorldEntities */
132  element = root->FirstChildElement("WorldEntities");
133  if( element == NULL)
134  {
135    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
136  }
137  else
138  {
139    element = element->FirstChildElement();
140
141    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
142    {
143      while( element != NULL)
144      {
145        /* pass the entity to the NetworkGameManager to be created */
146        BaseObject* created = Factory::fabricate(element);
147        if( created != NULL )
148          PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), (int)created->getClassID().id(), element->Value());
149        else
150          PRINTF(1)("NetworkWorld: could not create this entity\n");
151
152        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
153          this->sky = dynamic_cast<WorldEntity*>(created);
154        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
155        {
156          this->terrain = dynamic_cast<Terrain*>(created);
157          CDEngine::getInstance()->setTerrain(terrain);
158        }
159
160        element = element->NextSiblingElement();
161
162
163        glmis->step();
164        PRINTF(4)("Done loading NetworkWorldEntities\n");
165      }
166    }
167    else
168    {
169      while( element != NULL)
170      {
171        PRINTF(0)("load: %s\n", element->Value());
172        if( !strcmp(element->Value(), "Terrain") || !strcmp(element->Value(), "Building")  )
173        {
174
175          /* pass the entity to the NetworkGameManager to be created */
176          BaseObject* created = Factory::fabricate(element);
177
178          if( created != NULL )
179            PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), created->getClassID().id(), element->Value());
180          else
181            PRINTF(1)("NetworkWorld: could not create this entity\n");
182
183          if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
184            this->sky = dynamic_cast<WorldEntity*>(created);
185          if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
186          {
187            this->terrain = dynamic_cast<Terrain*>(created);
188            CDEngine::getInstance()->setTerrain(terrain);
189          }
190
191          glmis->step();
192          PRINTF(4)("Done loading NetworkWorldEntities\n");
193        }
194        element = element->NextSiblingElement();
195      }
196    }
197
198
199    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
200    {
201      this->localPlayer = new Player();
202
203#if 0
204      Playable* playable;
205      const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
206      assert( playableList != NULL);
207
208      if (playableList != NULL)
209      {
210        playable = dynamic_cast<Playable*>(playableList->front());
211        this->localPlayer->setPlayable(playable);
212        playable->toList(OM_GROUP_00);
213        playable->setAbsCoor(213.37, 57.71, -47.98);
214        playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0)));
215      }
216#endif
217    }
218    else
219    {
220      /* create a Player */
221      this->localPlayer = new Player();
222    }
223
224
225    /* init the pnode tree */
226    PNode::getNullParent()->init();
227  }
228    // Fill the EntityLists. Tick then Draw:
229  this->tickLists.push_back(OM_DEAD_TICK);
230  this->tickLists.push_back(OM_ENVIRON);
231  this->tickLists.push_back(OM_COMMON);
232  this->tickLists.push_back(OM_PLAYERS);
233  this->tickLists.push_back(OM_PLAYERS_PROJ);
234  this->tickLists.push_back(OM_GROUP_00);
235  this->tickLists.push_back(OM_GROUP_00_PROJ);
236  this->tickLists.push_back(OM_GROUP_01);
237  this->tickLists.push_back(OM_GROUP_01_PROJ);
238
239  this->drawLists.push_back(OM_ENVIRON_NOTICK);
240  this->drawLists.push_back(OM_ENVIRON);
241  this->drawLists.push_back(OM_COMMON);
242  this->drawLists.push_back(OM_PLAYERS);
243  this->drawLists.push_back(OM_PLAYERS_PROJ);
244  this->drawLists.push_back(OM_GROUP_00);
245  this->drawLists.push_back(OM_GROUP_00_PROJ);
246  this->drawLists.push_back(OM_GROUP_01);
247  this->drawLists.push_back(OM_GROUP_01_PROJ);
248
249  State::setPlayer(this->localPlayer);
250
251  return ErrorMessage();
252}
253
254
255/**
256 *  unloads the world entities from the xml file
257 */
258ErrorMessage MultiPlayerWorldData::unloadWorldEntities()
259{
260  /* call underlying function */
261  return GameWorldData::unloadWorldEntities();
262}
263
264
265/**
266 *  loads the scene data
267 * @param root reference to the xml root element
268 */
269ErrorMessage MultiPlayerWorldData::loadScene(const TiXmlElement* root)
270{
271  /* call underlying function */
272  GameWorldData::loadScene(root);
273
274//   LoadParamXML(root, "NetworkSettings", NetworkSettings::getInstance(), NetworkSettings, loadNetworkSettings);
275
276  // create server playable
277  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
278  {
279    NetworkGameManager::getInstance()->signalNewPlayer( 0 );
280    State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() );
281  }
282
283  return ErrorMessage();
284}
285
286
287/**
288 *  unloads the scene data
289 */
290ErrorMessage MultiPlayerWorldData::unloadScene()
291{
292  // delete the proxy settings
293  delete NetworkSettings::getInstance();
294
295  /* call underlying function */
296  return GameWorldData::unloadScene();
297}
298
299
300/**
301 * some debug output
302 */
303void MultiPlayerWorldData::debug()
304{
305  PRINT(0)("==================================================\n");
306
307  Playable* playable;
308
309  for (ObjectList<Playable>::const_iterator entity = Playable::objectList().begin();
310       entity != Playable::objectList().end();
311      ++entity)
312  {
313    Playable* p = *entity;
314    PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassCName(), (*entity)->getCName(), p->getUniqueID());
315  }
316
317
318  if( this->toggle)
319  {
320    playable = Playable::objectList().front();
321    this->localPlayer->setPlayable(playable);
322    this->toggle = !this->toggle;
323  }
324  else
325  {
326    playable = Playable::objectList().back();
327    this->localPlayer->setPlayable(playable);
328    this->toggle = !this->toggle;
329  }
330
331
332  Playable* pl = this->localPlayer->getPlayable();
333  PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID());
334
335
336  PNode* cam = State::getCameraTargetNode();
337  PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassCName(), cam->getCName(), cam->getUniqueID());
338
339  PRINT(0)("==================================================\n");
340
341}
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
Note: See TracBrowser for help on using the repository browser.