Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/proxy: merged the proxy.old back again, and it seems to work.

Merged with command
svn merge -r9247:HEAD https://svn.orxonox.net/orxonox/branches/proxy.old .

no conflicts

File size: 9.2 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
[7193]20#include "util/loading/resource_manager.h"
[6404]21#include "state.h"
22#include "class_list.h"
23#include "substring.h"
24
[7193]25#include "util/loading/game_loader.h"
[6404]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"
[8490]36#include "md2/md2Model.h"
[6434]37#include "world_entities/projectiles/projectile.h"
[6404]38#include "npcs/npc_test1.h"
39#include "playable.h"
40
[7193]41#include "util/loading/factory.h"
[6404]42#include "fast_factory.h"
[7193]43#include "util/loading/load_param.h"
[6404]44
45#include "network_manager.h"
46#include "network_game_manager.h"
[8068]47#include "player_stats.h"
[6404]48
[9347]49#include "proxy/proxy_settings.h"
[6404]50
51#include "glmenu_imagescreen.h"
52
53
[6498]54
[6404]55using namespace std;
56
57
58/**
59 * constructor of the GameWorldDataData
60 */
61MultiPlayerWorldData::MultiPlayerWorldData()
62    : GameWorldData()
[6498]63{
64  this->toggle = false;
65}
[6404]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 */
[8717]81  return GameWorldData::init();
[6404]82}
83
84
85/**
86 *  loads the GUI data
87 * @param root reference to the xml root element
88 */
[7370]89ErrorMessage MultiPlayerWorldData::loadGUI(const TiXmlElement* root)
[6404]90{
91  /* call underlying function */
[8717]92  return GameWorldData::loadGUI(root);
[6404]93}
94
95
96/**
97 *  unloads the GUI data
98 */
99ErrorMessage MultiPlayerWorldData::unloadGUI()
100{
101  /* call underlying function */
[8717]102  return GameWorldData::unloadGUI();
[6404]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 */
[7370]110ErrorMessage MultiPlayerWorldData::loadWorldEntities(const TiXmlElement* root)
[6404]111{
[9235]112  const TiXmlElement* element = NULL;
[9347]113
114  if( NetworkManager::getInstance()->isMasterServer() )
[6404]115  {
[9235]116    /* load the spawning points */
117    element = root->FirstChildElement("SpawningPoints");
118    if( element == NULL)
[6404]119    {
[9235]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->getClassName(), created->getName());
[6404]132
[9235]133        element = element->NextSiblingElement();
134        glmis->step();
135      }
136      PRINTF(4)("Done loading Spawning Points\n");
[6404]137    }
138  }
139
140  /* load the WorldEntities */
141  element = root->FirstChildElement("WorldEntities");
142  if( element == NULL)
[6409]143  {
[6404]144    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
[6409]145  }
[6404]146  else
147  {
148    element = element->FirstChildElement();
149
[9347]150    if( NetworkManager::getInstance()->isMasterServer() )
[6404]151    {
[7071]152      while( element != NULL)
[6404]153      {
154        /* pass the entity to the NetworkGameManager to be created */
[8068]155        BaseObject* created = Factory::fabricate(element);
[6404]156        if( created != NULL )
[6412]157          PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value());
[6404]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        }
[7071]168
169        element = element->NextSiblingElement();
170
171
172        glmis->step();
173        PRINTF(4)("Done loading NetworkWorldEntities\n");
[6404]174      }
[7071]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        {
[6404]183
[7071]184          /* pass the entity to the NetworkGameManager to be created */
185          BaseObject* created = Factory::fabricate(element);
[6498]186
[7071]187          if( created != NULL )
188            PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), 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      }
[6404]205    }
206
[7071]207
[9347]208    if( NetworkManager::getInstance()->isMasterServer())
[6498]209    {
210      this->localPlayer = new Player();
[6404]211
[8068]212#if 0
[6498]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());
[6985]220        this->localPlayer->setPlayable(playable);
[7078]221        playable->toList(OM_GROUP_00);
[7074]222        playable->setAbsCoor(213.37, 57.71, -47.98);
[7346]223        playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0)));
[6498]224      }
[8068]225#endif
[6498]226    }
227    else
[6404]228    {
[6498]229      /* create a Player */
230      this->localPlayer = new Player();
[6404]231    }
232
233
234    /* init the pnode tree */
235    PNode::getNullParent()->init();
236  }
[7954]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);
[9008]241  this->tickLists.push_back(OM_PLAYERS);
242  this->tickLists.push_back(OM_PLAYERS_PROJ);
[7954]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);
[9008]251  this->drawLists.push_back(OM_PLAYERS);
252  this->drawLists.push_back(OM_PLAYERS_PROJ);
[7954]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);
[8717]257
[7082]258  State::setPlayer(this->localPlayer);
[8717]259
260  return ErrorMessage();
[6404]261}
262
263
264/**
265 *  unloads the world entities from the xml file
266 */
267ErrorMessage MultiPlayerWorldData::unloadWorldEntities()
268{
269  /* call underlying function */
[8717]270  return GameWorldData::unloadWorldEntities();
[6404]271}
272
273
274/**
275 *  loads the scene data
276 * @param root reference to the xml root element
277 */
[7370]278ErrorMessage MultiPlayerWorldData::loadScene(const TiXmlElement* root)
[6404]279{
280  /* call underlying function */
281  GameWorldData::loadScene(root);
[8717]282
[9347]283  LoadParamXML(root, "ProxySettings", ProxySettings::getInstance(), ProxySettings, loadProxySettings);
284
[8068]285  // create server playable
[9347]286  if ( NetworkManager::getInstance()->isMasterServer() )
[8068]287  {
288    NetworkGameManager::getInstance()->signalNewPlayer( 0 );
289    State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() );
290  }
[8717]291
292  return ErrorMessage();
[6404]293}
294
295
296/**
297 *  unloads the scene data
298 */
299ErrorMessage MultiPlayerWorldData::unloadScene()
300{
[9347]301  // delete the proxy settings
302  delete ProxySettings::getInstance();
303
[6404]304  /* call underlying function */
[8717]305  return GameWorldData::unloadScene();
[6404]306}
307
[6498]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)->getClassName(), (*entity)->getName(), p->getUniqueID());
326  }
327
328
329  if( this->toggle)
330  {
331    playable = dynamic_cast<Playable*>(playableList->front());
[6985]332    this->localPlayer->setPlayable(playable);
[6498]333    this->toggle = !this->toggle;
334  }
335  else
336  {
337    playable = dynamic_cast<Playable*>(playableList->back());
[6985]338    this->localPlayer->setPlayable(playable);
[6498]339    this->toggle = !this->toggle;
340  }
341
342
[6985]343  Playable* pl = this->localPlayer->getPlayable();
[6634]344  PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID());
[6498]345
[6634]346
[7014]347  PNode* cam = State::getCameraTargetNode();
[6498]348  PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassName(), cam->getName(), 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.