Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/story_entities/multi_player_world_data.cc @ 9715

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

renamed newclassid to classid and newobjectlist to objectlist

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