Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/story_entities/multi_player_world_data.cc @ 9417

Last change on this file since 9417 was 9417, checked in by bensch, 18 years ago

Cleanup after merge

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