/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD #include "multi_player_world.h" #include "state.h" #include "class_list.h" #include "load_param.h" #include "fast_factory.h" #include "factory.h" SHELL_COMMAND(speed, MultiPlayerWorld, setSpeed); SHELL_COMMAND(togglePNodeVisibility, MultiPlayerWorld, togglePNodeVisibility); SHELL_COMMAND(toggleBVVisibility, MultiPlayerWorld, toggleBVVisibility); using namespace std; //! This creates a Factory to fabricate a MultiPlayerWorld CREATE_FACTORY(MultiPlayerWorld, CL_WORLD); MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root) { this->constuctorInit("", -1); this->path = NULL; this->loadParams(root); } /** * remove the MultiPlayerWorld from memory * * delete everything explicitly, that isn't contained in the parenting tree! * things contained in the tree are deleted automaticaly */ MultiPlayerWorld::~MultiPlayerWorld () { delete this->shell; PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n"); delete this->localPlayer; // delete all the initialized Engines. FastFactory::flushAll(true); delete LightManager::getInstance(); delete ParticleEngine::getInstance(); delete AnimationPlayer::getInstance(); delete PhysicsEngine::getInstance(); // external engines initialized by the orxonox-class get deleted SoundEngine::getInstance()->flushAllBuffers(); SoundEngine::getInstance()->flushAllSources(); if (State::getObjectManager() == &this->objectManager) State::setObjectManager(NULL); // erease everything that is left. delete PNode::getNullParent(); //secondary cleanup of PNodes; const std::list* nodeList = ClassList::getList(CL_PARENT_NODE); if (nodeList != NULL) while (!nodeList->empty()) delete nodeList->front(); Shader::suspendShader(); // unload the resources !! ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL); } /** * initializes the world. * @param name the name of the world * @param worldID the ID of this world * * set all stuff here that is world generic and does not use to much memory * because the real init() function StoryEntity::init() will be called * shortly before start of the game. * since all worlds are initiated/referenced before they will be started. * NO LEVEL LOADING HERE - NEVER! */ void MultiPlayerWorld::constuctorInit(const char* name, int worldID) { this->setClassID(CL_WORLD, "MultiPlayerWorld"); PRINTF(0)("START\n"); this->setName(name); this->gameTime = 0.0f; this->setSpeed(1.0); this->music = NULL; this->shell = NULL; this->localPlayer = NULL; this->localCamera = NULL; this->showPNodes = false; this->showBV = false; } /** * loads the parameters of a MultiPlayerWorld from an XML-element * @param root the XML-element to load from */ void MultiPlayerWorld::loadParams(const TiXmlElement* root) { static_cast(this)->loadParams(root); PRINTF(4)("Creating a MultiPlayerWorld\n"); } /** * this is executed just before load * * since the load function sometimes needs data, that has been initialized * before the load and after the proceeding storyentity has finished */ ErrorMessage GameWorld::preLoad() { static_cast(this)->preLoad(); /* the the single player specific stuff */ } /** * loads the GameWorld by initializing all resources, and set their default values. */ ErrorMessage GameWorld::load() { static_cast(this)->load(); /* the the single player specific stuff here */ /* some static world entities */ for(int i = 0; i < 100; i++) { WorldEntity* tmp = new NPCTest1(); char npcChar[10]; sprintf (npcChar, "NPC_%d", i); tmp->setName(npcChar); tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30); this->spawn(tmp); } } /** * post loads the GameWorld by initializing all resources, and set their default values. */ ErrorMessage GameWorld::postLoad() { static_cast(this)->postLoad(); /* the single player specific stuff here */ }