Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem3/src/orxonox/objects/Level.cc @ 2706

Last change on this file since 2706 was 2702, checked in by rgrieder, 16 years ago

Completed work on installation:

  • The CMake switch INSTALL_COPYABLE tells whether you will be able to move the installed directory or not. If TRUE then all folders, including log and config directory, will be put into the CMAKE_INSTALL_PREFIX. Furthermore, relative paths are used, which get resolved at run time.
  • If INSTALL_COPYABLE is set to FALSE, the standard operating system directories will be used. That also means on Windows files get written to the Application Data/.orxonox folder instead of Program Files/Orxonox
  • Default configuration is INSTALL_COPYABLE=TRUE for Windows and FALSE for Unix
  • Split OrxonoxConfig.h.in in two to avoid complete recompiles when changing only a path or INSTALL_COPYABLE
  • Added a global constant character: CP_SLASH which stands for cross platform slash, meaning '/' on Unix and '
    ' on Windows
  • Core class now has methods getFooPath(), getFooPathString() and getFooPathPOSIXString() where Foo can be Media, Log or Config
  • getFooPathPOSIXString() will always return a directory formatted with slashes, even on Windows
  • getFooPath() returns a reference to the boost::filesystem::path
  • boost/filesystem.hpp does not get included to Core.h because it has a very large rat tail
  • The platform specific directory stuff gets done in Core::postMainInitialisation()
  • Adjusted all classes using the media path
File size: 4.9 KB
RevLine 
[2072]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Level.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "core/Loader.h"
35#include "core/XMLFile.h"
36#include "core/Template.h"
[2685]37#include "core/Core.h"
[2072]38
39#include "LevelManager.h"
[2169]40#include "objects/infos/PlayerInfo.h"
[2072]41#include "objects/gametypes/Gametype.h"
[2168]42#include "overlays/OverlayGroup.h"
[2072]43
44#include "util/Math.h"
45
46namespace orxonox
47{
48    CreateFactory(Level);
49
[2169]50    Level::Level(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
[2072]51    {
52        RegisterObject(Level);
53
54        this->registerVariables();
55        this->xmlfilename_ = this->getFilename();
56
[2702]57        if (this->xmlfilename_.length() >= Core::getMediaPathString().length())
58            this->xmlfilename_ = this->xmlfilename_.substr(Core::getMediaPathString().length());
[2072]59    }
60
61    Level::~Level()
62    {
63        if (this->isInitialized())
64        {
[2168]65            if (LevelManager::getInstancePtr())
66                LevelManager::getInstance().releaseActivity(this);
[2072]67
68            if (this->xmlfile_)
69                Loader::unload(this->xmlfile_);
70        }
71    }
72
73    void Level::XMLPort(Element& xmlelement, XMLPort::Mode mode)
74    {
75        SUPER(Level, XMLPort, xmlelement, mode);
76
77        XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
78        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
79
80        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
81    }
82
83    void Level::registerVariables()
84    {
[2662]85        registerVariable(this->xmlfilename_, variableDirection::toclient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
86        registerVariable(this->name_,        variableDirection::toclient, new NetworkCallback<Level>(this, &Level::changedName));
87        registerVariable(this->description_, variableDirection::toclient);
[2072]88    }
89
90    void Level::networkcallback_applyXMLFile()
91    {
92        COUT(0) << "Loading level \"" << this->xmlfilename_ << "\"..." << std::endl;
93
94        ClassTreeMask mask;
95        mask.exclude(Class(BaseObject));
96        mask.include(Class(Template));
[2168]97        mask.include(Class(OverlayGroup)); // HACK to include the ChatOverlay
[2072]98
[2702]99        this->xmlfile_ = new XMLFile(Core::getMediaPathString() + this->xmlfilename_, mask);
[2072]100
101        Loader::open(this->xmlfile_);
102    }
103
104    void Level::setGametypeString(const std::string& gametype)
105    {
106        Identifier* identifier = ClassByString(gametype);
107        if (identifier && identifier->isA(Class(Gametype)))
108        {
109            this->gametype_ = gametype;
110
111            Gametype* rootgametype = dynamic_cast<Gametype*>(identifier->fabricate(this));
112            this->setGametype(rootgametype);
113
114            for (std::list<BaseObject*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
115                (*it)->setGametype(rootgametype);
116
[2168]117            if (LevelManager::getInstancePtr())
118                LevelManager::getInstance().requestActivity(this);
[2072]119        }
120    }
121
122
123    void Level::addObject(BaseObject* object)
124    {
125        this->objects_.push_back(object);
126        object->setGametype(this->getGametype());
127    }
128
129    BaseObject* Level::getObject(unsigned int index) const
130    {
131        unsigned int i = 0;
132        for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
133        {
134            if (i == index)
135                return (*it);
136            ++i;
137        }
138        return 0;
139    }
140
141    void Level::playerEntered(PlayerInfo* player)
142    {
[2662]143        COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
[2072]144        player->setGametype(this->getGametype());
145    }
146
147    void Level::playerLeft(PlayerInfo* player)
148    {
[2662]149        COUT(3) << "player left level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
[2072]150        player->setGametype(0);
151    }
152}
Note: See TracBrowser for help on using the repository browser.