Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/core/BaseObject.cc @ 2143

Last change on this file since 2143 was 2019, checked in by landauf, 16 years ago

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
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/**
30    @file
31    @brief Implementation of the BaseObject class.
32*/
33
34#include "BaseObject.h"
35#include "tinyxml/tinyxml.h"
36#include "CoreIncludes.h"
37#include "XMLPort.h"
38#include "XMLFile.h"
39#include "Template.h"
40#include "util/String.h"
41
42namespace orxonox
43{
44    CreateFactory(BaseObject);
45
46    /**
47        @brief Constructor: Registers the object in the BaseObject-list.
48    */
49    BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false)
50    {
51        RegisterRootObject(BaseObject);
52
53        this->bInitialized_ = true;
54
55        this->bActive_ = true;
56        this->bVisible_ = true;
57        this->oldGametype_ = 0;
58
59        this->setCreator(creator);
60        if (this->creator_)
61        {
62            this->setFile(this->creator_->getFile());
63            this->setNamespace(this->creator_->getNamespace());
64            this->setScene(this->creator_->getScene());
65            this->setGametype(this->creator_->getGametype());
66        }
67        else
68        {
69            this->file_ = 0;
70            this->namespace_ = 0;
71            this->scene_ = 0;
72            this->gametype_ = 0;
73        }
74    }
75
76    /**
77        @brief Destructor
78    */
79    BaseObject::~BaseObject()
80    {
81    }
82
83    /**
84        @brief XML loading and saving.
85        @param xmlelement The XML-element
86        @param loading Loading (true) or saving (false)
87        @return The XML-element
88    */
89    void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode)
90    {
91        XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode);
92        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
93        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
94
95        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
96    }
97
98    /**
99        @brief Returns the levelfile that loaded this object.
100        @return The levelfile
101    */
102    const std::string& BaseObject::getFilename() const
103    {
104        if (this->file_)
105            return this->file_->getFilename();
106        else
107            return BLANKSTRING;
108    }
109
110    /**
111        @brief Adds a Template to the object.
112        @param name The name of the Template
113    */
114    void BaseObject::addTemplate(const std::string& name)
115    {
116        Template* temp = Template::getTemplate(name);
117        if (temp)
118            this->addTemplate(temp);
119        else
120            COUT(1) << "Error: \"" << name << "\" is not a valid Template name (in class: " << this->getIdentifier()->getName() << ", name: " << this->getName() << ")." << std::endl;
121    }
122
123    /**
124        @brief Adds a Template to the object.
125        @param temp The Template
126    */
127    void BaseObject::addTemplate(Template* temp)
128    {
129        this->templates_.insert(temp);
130        temp->applyOn(this);
131    }
132
133    /**
134        @brief Returns the Template with the given index.
135        @param index The index
136    */
137    Template* BaseObject::getTemplate(unsigned int index) const
138    {
139        unsigned int i = 0;
140        for (std::set<Template*>::const_iterator it = this->templates_.begin(); it != this->templates_.end(); ++it)
141        {
142            if (i == index)
143                return (*it);
144            i++;
145        }
146        return 0;
147    }
148}
Note: See TracBrowser for help on using the repository browser.