[6139] | 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 | |
---|
[6358] | 17 | #include "multi_player_world.h" |
---|
[6139] | 18 | |
---|
| 19 | #include "state.h" |
---|
[6358] | 20 | #include "class_list.h" |
---|
[6139] | 21 | |
---|
| 22 | #include "load_param.h" |
---|
| 23 | #include "fast_factory.h" |
---|
| 24 | #include "factory.h" |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
[6358] | 29 | SHELL_COMMAND(speed, MultiPlayerWorld, setSpeed); |
---|
| 30 | SHELL_COMMAND(togglePNodeVisibility, MultiPlayerWorld, togglePNodeVisibility); |
---|
| 31 | SHELL_COMMAND(toggleBVVisibility, MultiPlayerWorld, toggleBVVisibility); |
---|
[6139] | 32 | |
---|
| 33 | using namespace std; |
---|
| 34 | |
---|
[6358] | 35 | //! This creates a Factory to fabricate a MultiPlayerWorld |
---|
| 36 | CREATE_FACTORY(MultiPlayerWorld, CL_WORLD); |
---|
[6139] | 37 | |
---|
[6358] | 38 | MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root) |
---|
[6139] | 39 | { |
---|
| 40 | this->constuctorInit("", -1); |
---|
| 41 | this->path = NULL; |
---|
| 42 | |
---|
| 43 | this->loadParams(root); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
[6358] | 47 | * remove the MultiPlayerWorld from memory |
---|
[6345] | 48 | * |
---|
| 49 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 50 | * things contained in the tree are deleted automaticaly |
---|
[6139] | 51 | */ |
---|
[6358] | 52 | MultiPlayerWorld::~MultiPlayerWorld () |
---|
[6139] | 53 | { |
---|
| 54 | delete this->shell; |
---|
[6358] | 55 | PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n"); |
---|
[6139] | 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 | |
---|
[6142] | 70 | if (State::getObjectManager() == &this->objectManager) |
---|
| 71 | State::setObjectManager(NULL); |
---|
[6139] | 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 | */ |
---|
[6358] | 98 | void MultiPlayerWorld::constuctorInit(const char* name, int worldID) |
---|
[6139] | 99 | { |
---|
[6358] | 100 | this->setClassID(CL_WORLD, "MultiPlayerWorld"); |
---|
[6341] | 101 | PRINTF(0)("START\n"); |
---|
[6139] | 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 | |
---|
[6358] | 115 | |
---|
[6139] | 116 | /** |
---|
[6358] | 117 | * loads the parameters of a MultiPlayerWorld from an XML-element |
---|
[6139] | 118 | * @param root the XML-element to load from |
---|
| 119 | */ |
---|
[6358] | 120 | void MultiPlayerWorld::loadParams(const TiXmlElement* root) |
---|
[6139] | 121 | { |
---|
[6358] | 122 | static_cast<GameWorld*>(this)->loadParams(root); |
---|
[6139] | 123 | |
---|
[6358] | 124 | PRINTF(4)("Creating a MultiPlayerWorld\n"); |
---|
| 125 | } |
---|
[6139] | 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 |
---|
[6345] | 134 | */ |
---|
[6358] | 135 | ErrorMessage GameWorld::preLoad() |
---|
[6139] | 136 | { |
---|
[6358] | 137 | static_cast<GameWorld*>(this)->preLoad(); |
---|
[6139] | 138 | |
---|
[6358] | 139 | /* the the single player specific stuff */ |
---|
[6139] | 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | /** |
---|
[6358] | 144 | * loads the GameWorld by initializing all resources, and set their default values. |
---|
[6345] | 145 | */ |
---|
[6358] | 146 | ErrorMessage GameWorld::load() |
---|
[6139] | 147 | { |
---|
[6358] | 148 | static_cast<GameWorld*>(this)->load(); |
---|
[6139] | 149 | |
---|
[6358] | 150 | /* the the single player specific stuff here */ |
---|
[6139] | 151 | |
---|
[6358] | 152 | /* some static world entities */ |
---|
| 153 | for(int i = 0; i < 100; i++) |
---|
[6345] | 154 | { |
---|
[6358] | 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); |
---|
[6345] | 161 | } |
---|
[6139] | 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | /** |
---|
[6358] | 166 | * post loads the GameWorld by initializing all resources, and set their default values. |
---|
[6139] | 167 | */ |
---|
[6358] | 168 | ErrorMessage GameWorld::postLoad() |
---|
[6139] | 169 | { |
---|
[6358] | 170 | static_cast<GameWorld*>(this)->postLoad(); |
---|
[6139] | 171 | |
---|
[6358] | 172 | /* the single player specific stuff here */ |
---|
[6139] | 173 | } |
---|
| 174 | |
---|