Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/multi_player_world_data.cc @ 6409

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

network: the network loading now works again, couldn't test it over the network, since my laptop realy is too slow (600MHz and no hw gl). now we can continue working on the network stuff

File size: 5.1 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 "resource_manager.h"
21#include "state.h"
22#include "class_list.h"
23#include "substring.h"
24
25#include "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 "md2Model.h"
37#include "weapons/projectile.h"
38#include "npcs/npc_test1.h"
39#include "playable.h"
40
41#include "factory.h"
42#include "fast_factory.h"
43#include "load_param.h"
44
45#include "network_manager.h"
46#include "network_game_manager.h"
47
48
49#include "glmenu_imagescreen.h"
50
51
52using namespace std;
53
54
55/**
56 * constructor of the GameWorldDataData
57 */
58MultiPlayerWorldData::MultiPlayerWorldData()
59    : GameWorldData()
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  GameWorldData::init();
77}
78
79
80/**
81 *  loads the GUI data
82 * @param root reference to the xml root element
83 */
84ErrorMessage MultiPlayerWorldData::loadGUI(TiXmlElement* root)
85{
86  /* call underlying function */
87  GameWorldData::loadGUI(root);
88}
89
90
91/**
92 *  unloads the GUI data
93 */
94ErrorMessage MultiPlayerWorldData::unloadGUI()
95{
96  /* call underlying function */
97  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(TiXmlElement* root)
106{
107  /* load the spawning points */
108  TiXmlElement* element = root->FirstChildElement("SpawningPoints");
109  if( element == NULL)
110  {
111    PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n");
112  }
113  else
114  {
115    element = element->FirstChildElement();
116    // load Players/Objects/Whatever
117    PRINTF(4)("Loading Spawning Points\n");
118    while( element != NULL)
119    {
120      BaseObject* created = Factory::fabricate(element);
121      if( created != NULL )
122        printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName());
123
124      element = element->NextSiblingElement();
125      glmis->step();
126    }
127    PRINTF(4)("Done loading Spawning Points\n");
128  }
129
130  /* load the WorldEntities */
131  element = root->FirstChildElement("WorldEntities");
132  if( element == NULL)
133  {
134    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
135  }
136  else
137  {
138    element = element->FirstChildElement();
139
140    while( element != NULL)
141    {
142      if( NetworkManager::getInstance()->isGameServer())
143      {
144        /* pass the entity to the NetworkGameManager to be created */
145        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
146        if( created != NULL )
147          PRINTF(1)("Created a %s: %s\n", created->getClassName(), created->getName());
148        else
149          PRINTF(1)("NetworkWorld: could not create this entity\n");
150
151        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
152          this->sky = dynamic_cast<WorldEntity*>(created);
153        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
154        {
155          this->terrain = dynamic_cast<Terrain*>(created);
156          CDEngine::getInstance()->setTerrain(terrain);
157        }
158      }
159      /* clients only spawn the SpaceShip */
160      else if( !strcmp( element->Value(), "SpaceShip"))
161      {
162        BaseObject* created = Factory::fabricate(element);
163        if( created != NULL )
164          PRINTF(1)("Created a %s: %s\n", created->getClassName(), created->getName());
165        else
166          PRINTF(1)("NetworkWorld: could not create this entity\n");
167      }
168      element = element->NextSiblingElement();
169
170      glmis->step();
171      PRINTF(4)("Done loading NetworkWorldEntities\n");
172    }
173
174
175    /* create a Player */
176    this->localPlayer = new Player();
177    Playable* playable;
178    const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
179    if (playableList != NULL)
180    {
181      playable = dynamic_cast<Playable*>(playableList->front());
182      this->localPlayer->setControllable(playable);
183    }
184
185
186    /* init the pnode tree */
187    PNode::getNullParent()->init();
188  }
189}
190
191
192/**
193 *  unloads the world entities from the xml file
194 */
195ErrorMessage MultiPlayerWorldData::unloadWorldEntities()
196{
197  /* call underlying function */
198  GameWorldData::unloadWorldEntities();
199}
200
201
202/**
203 *  loads the scene data
204 * @param root reference to the xml root element
205 */
206ErrorMessage MultiPlayerWorldData::loadScene(TiXmlElement* root)
207{
208  /* call underlying function */
209  GameWorldData::loadScene(root);
210}
211
212
213/**
214 *  unloads the scene data
215 */
216ErrorMessage MultiPlayerWorldData::unloadScene()
217{
218  /* call underlying function */
219  GameWorldData::unloadScene();
220}
221
Note: See TracBrowser for help on using the repository browser.