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
RevLine 
[6404]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
[7193]23#include "util/loading/game_loader.h"
[6404]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"
[8490]34#include "md2/md2Model.h"
[6434]35#include "world_entities/projectiles/projectile.h"
[6404]36#include "npcs/npc_test1.h"
37#include "playable.h"
38
[7193]39#include "util/loading/factory.h"
[9869]40#include "loading/fast_factory.h"
[7193]41#include "util/loading/load_param.h"
[6404]42
43#include "network_manager.h"
44#include "network_game_manager.h"
[8068]45#include "player_stats.h"
[6404]46
[9406]47#include "proxy/network_settings.h"
[6404]48
49#include "glmenu_imagescreen.h"
50
51
52/**
53 * constructor of the GameWorldDataData
54 */
55MultiPlayerWorldData::MultiPlayerWorldData()
56    : GameWorldData()
[6498]57{
58  this->toggle = false;
59}
[6404]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 */
[8717]75  return GameWorldData::init();
[6404]76}
77
78
79/**
80 *  loads the GUI data
81 * @param root reference to the xml root element
82 */
[7370]83ErrorMessage MultiPlayerWorldData::loadGUI(const TiXmlElement* root)
[6404]84{
85  /* call underlying function */
[8717]86  return GameWorldData::loadGUI(root);
[6404]87}
88
89
90/**
91 *  unloads the GUI data
92 */
93ErrorMessage MultiPlayerWorldData::unloadGUI()
94{
95  /* call underlying function */
[8717]96  return GameWorldData::unloadGUI();
[6404]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 */
[7370]104ErrorMessage MultiPlayerWorldData::loadWorldEntities(const TiXmlElement* root)
[6404]105{
[9235]106  const TiXmlElement* element = NULL;
[9406]107
[9494]108  if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
[6404]109  {
[9235]110    /* load the spawning points */
111    element = root->FirstChildElement("SpawningPoints");
112    if( element == NULL)
[6404]113    {
[9235]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 )
[9406]125          printf("Created a Spawning Point %s: %s\n", created->getClassCName(), created->getCName());
[6404]126
[9235]127        element = element->NextSiblingElement();
128        glmis->step();
129      }
130      PRINTF(4)("Done loading Spawning Points\n");
[6404]131    }
132  }
133
134  /* load the WorldEntities */
135  element = root->FirstChildElement("WorldEntities");
136  if( element == NULL)
[6409]137  {
[6404]138    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
[6409]139  }
[6404]140  else
141  {
142    element = element->FirstChildElement();
143
[9494]144    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
[6404]145    {
[7071]146      while( element != NULL)
[6404]147      {
148        /* pass the entity to the NetworkGameManager to be created */
[8068]149        BaseObject* created = Factory::fabricate(element);
[6404]150        if( created != NULL )
[9406]151          PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), created->getLeafClassID(), element->Value());
[6404]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        }
[7071]162
163        element = element->NextSiblingElement();
164
165
166        glmis->step();
167        PRINTF(4)("Done loading NetworkWorldEntities\n");
[6404]168      }
[7071]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        {
[6404]177
[7071]178          /* pass the entity to the NetworkGameManager to be created */
179          BaseObject* created = Factory::fabricate(element);
[6498]180
[7071]181          if( created != NULL )
[9406]182            PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), created->getLeafClassID(), element->Value());
[7071]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      }
[6404]199    }
200
[7071]201
[9494]202    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
[6498]203    {
204      this->localPlayer = new Player();
[6404]205
[8068]206#if 0
[6498]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());
[6985]214        this->localPlayer->setPlayable(playable);
[7078]215        playable->toList(OM_GROUP_00);
[7074]216        playable->setAbsCoor(213.37, 57.71, -47.98);
[7346]217        playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0)));
[6498]218      }
[8068]219#endif
[6498]220    }
221    else
[6404]222    {
[6498]223      /* create a Player */
224      this->localPlayer = new Player();
[6404]225    }
226
227
228    /* init the pnode tree */
229    PNode::getNullParent()->init();
230  }
[7954]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);
[9008]235  this->tickLists.push_back(OM_PLAYERS);
236  this->tickLists.push_back(OM_PLAYERS_PROJ);
[7954]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);
[9008]245  this->drawLists.push_back(OM_PLAYERS);
246  this->drawLists.push_back(OM_PLAYERS_PROJ);
[7954]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);
[8717]251
[7082]252  State::setPlayer(this->localPlayer);
[8717]253
254  return ErrorMessage();
[6404]255}
256
257
258/**
259 *  unloads the world entities from the xml file
260 */
261ErrorMessage MultiPlayerWorldData::unloadWorldEntities()
262{
263  /* call underlying function */
[8717]264  return GameWorldData::unloadWorldEntities();
[6404]265}
266
267
268/**
269 *  loads the scene data
270 * @param root reference to the xml root element
271 */
[7370]272ErrorMessage MultiPlayerWorldData::loadScene(const TiXmlElement* root)
[6404]273{
274  /* call underlying function */
275  GameWorldData::loadScene(root);
[8717]276
[9406]277//   LoadParamXML(root, "NetworkSettings", NetworkSettings::getInstance(), NetworkSettings, loadNetworkSettings);
278
[8068]279  // create server playable
[9494]280  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
[8068]281  {
282    NetworkGameManager::getInstance()->signalNewPlayer( 0 );
283    State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() );
284  }
[8717]285
286  return ErrorMessage();
[6404]287}
288
289
290/**
291 *  unloads the scene data
292 */
293ErrorMessage MultiPlayerWorldData::unloadScene()
294{
[9406]295  // delete the proxy settings
296  delete NetworkSettings::getInstance();
297
[6404]298  /* call underlying function */
[8717]299  return GameWorldData::unloadScene();
[6404]300}
301
[6498]302
303/**
304 * some debug output
305 */
306void MultiPlayerWorldData::debug()
307{
308  PRINT(0)("==================================================\n");
[9869]309
[6498]310  Playable* playable;
311
[9869]312  for (ObjectList<Playable>::const_iterator entity = Playable::objectList().begin();
313       entity != Playable::objectList().end();
314      ++entity)
[6498]315  {
[9869]316    Playable* p = *entity;
[9406]317    PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassCName(), (*entity)->getCName(), p->getUniqueID());
[6498]318  }
319
320
321  if( this->toggle)
322  {
[9869]323    playable = Playable::objectList().front();
[6985]324    this->localPlayer->setPlayable(playable);
[6498]325    this->toggle = !this->toggle;
326  }
327  else
328  {
[9869]329    playable = Playable::objectList().back();
[6985]330    this->localPlayer->setPlayable(playable);
[6498]331    this->toggle = !this->toggle;
332  }
333
334
[6985]335  Playable* pl = this->localPlayer->getPlayable();
[6634]336  PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID());
[6498]337
[6634]338
[7014]339  PNode* cam = State::getCameraTargetNode();
[9406]340  PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassCName(), cam->getCName(), cam->getUniqueID());
[6498]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.