Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/story_entities/multi_player_world_data.cc @ 9536

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

still tracing ghosts

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