Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/multi_player_world.cc @ 6358

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

network: major changes in the world files

File size: 4.4 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#include "multi_player_world.h"
18
19#include "state.h"
20#include "class_list.h"
21
22#include "load_param.h"
23#include "fast_factory.h"
24#include "factory.h"
25
26
27
28
29SHELL_COMMAND(speed, MultiPlayerWorld, setSpeed);
30SHELL_COMMAND(togglePNodeVisibility, MultiPlayerWorld, togglePNodeVisibility);
31SHELL_COMMAND(toggleBVVisibility, MultiPlayerWorld, toggleBVVisibility);
32
33using namespace std;
34
35//! This creates a Factory to fabricate a MultiPlayerWorld
36CREATE_FACTORY(MultiPlayerWorld, CL_WORLD);
37
38MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root)
39{
40  this->constuctorInit("", -1);
41  this->path = NULL;
42
43  this->loadParams(root);
44}
45
46/**
47 *  remove the MultiPlayerWorld from memory
48 *
49 *  delete everything explicitly, that isn't contained in the parenting tree!
50 *  things contained in the tree are deleted automaticaly
51 */
52MultiPlayerWorld::~MultiPlayerWorld ()
53{
54  delete this->shell;
55  PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n");
56
57  delete this->localPlayer;
58
59  // delete all the initialized Engines.
60  FastFactory::flushAll(true);
61  delete LightManager::getInstance();
62  delete ParticleEngine::getInstance();
63  delete AnimationPlayer::getInstance();
64  delete PhysicsEngine::getInstance();
65
66  // external engines initialized by the orxonox-class get deleted
67  SoundEngine::getInstance()->flushAllBuffers();
68  SoundEngine::getInstance()->flushAllSources();
69
70  if (State::getObjectManager() == &this->objectManager)
71    State::setObjectManager(NULL);
72  // erease everything that is left.
73  delete PNode::getNullParent();
74
75  //secondary cleanup of PNodes;
76  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
77  if (nodeList != NULL)
78    while (!nodeList->empty())
79      delete nodeList->front();
80
81  Shader::suspendShader();
82
83  // unload the resources !!
84  ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
85}
86
87/**
88 * initializes the world.
89 * @param name the name of the world
90 * @param worldID the ID of this world
91 *
92 * set all stuff here that is world generic and does not use to much memory
93 * because the real init() function StoryEntity::init() will be called
94 * shortly before start of the game.
95 * since all worlds are initiated/referenced before they will be started.
96 * NO LEVEL LOADING HERE - NEVER!
97*/
98void MultiPlayerWorld::constuctorInit(const char* name, int worldID)
99{
100  this->setClassID(CL_WORLD, "MultiPlayerWorld");
101  PRINTF(0)("START\n");
102
103  this->setName(name);
104  this->gameTime = 0.0f;
105  this->setSpeed(1.0);
106  this->music = NULL;
107  this->shell = NULL;
108  this->localPlayer = NULL;
109  this->localCamera = NULL;
110
111  this->showPNodes = false;
112  this->showBV = false;
113}
114
115
116/**
117 * loads the parameters of a MultiPlayerWorld from an XML-element
118 * @param root the XML-element to load from
119 */
120void MultiPlayerWorld::loadParams(const TiXmlElement* root)
121{
122  static_cast<GameWorld*>(this)->loadParams(root);
123
124  PRINTF(4)("Creating a MultiPlayerWorld\n");
125}
126
127
128
129/**
130 * this is executed just before load
131 *
132 * since the load function sometimes needs data, that has been initialized
133 * before the load and after the proceeding storyentity has finished
134 */
135ErrorMessage GameWorld::preLoad()
136{
137  static_cast<GameWorld*>(this)->preLoad();
138
139  /* the the single player specific stuff */
140}
141
142
143/**
144 *  loads the GameWorld by initializing all resources, and set their default values.
145 */
146ErrorMessage GameWorld::load()
147{
148  static_cast<GameWorld*>(this)->load();
149
150  /* the the single player specific stuff here */
151
152  /* some static world entities */
153  for(int i = 0; i < 100; i++)
154  {
155    WorldEntity* tmp = new NPCTest1();
156    char npcChar[10];
157    sprintf (npcChar, "NPC_%d", i);
158    tmp->setName(npcChar);
159    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
160    this->spawn(tmp);
161  }
162}
163
164
165/**
166 *  post loads the GameWorld by initializing all resources, and set their default values.
167 */
168ErrorMessage GameWorld::postLoad()
169{
170  static_cast<GameWorld*>(this)->postLoad();
171
172  /* the single player specific stuff here */
173}
174
Note: See TracBrowser for help on using the repository browser.