Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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