mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
In some cases you want to store property data for each instance. Often you'll use member data on the entities themselves for this. But in some cases you don't want to bloat the entity class with data for seldomly used properties. In these cases you can instead use the PropertyInstanceState class, and keep a static instance of this per property.
80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
/*
|
|
Copyright (C) 2014 Erik Ogenvik
|
|
|
|
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 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "DomainProperty.h"
|
|
#include "PhysicalDomain.h"
|
|
#include "VoidDomain.h"
|
|
#include "LocatedEntity.h"
|
|
|
|
PropertyInstanceState<Domain> DomainProperty::sInstanceState;
|
|
|
|
DomainProperty::DomainProperty()
|
|
{
|
|
}
|
|
|
|
DomainProperty::DomainProperty(const DomainProperty& rhs)
|
|
: Property(rhs)
|
|
{
|
|
}
|
|
|
|
void DomainProperty::install(LocatedEntity *entity, const std::string &)
|
|
{
|
|
sInstanceState.addState(entity, nullptr);
|
|
}
|
|
|
|
|
|
void DomainProperty::remove(LocatedEntity * entity, const std::string &)
|
|
{
|
|
sInstanceState.removeState(entity);
|
|
entity->setFlags(~entity_domain);
|
|
}
|
|
|
|
void DomainProperty::apply(LocatedEntity * entity)
|
|
{
|
|
if (m_data != "") {
|
|
Domain* domain = sInstanceState.getState(entity);
|
|
if (!domain) {
|
|
if (m_data == "physical") {
|
|
domain = new PhysicalDomain(*entity);
|
|
sInstanceState.replaceState(entity, domain);
|
|
entity->setFlags(entity_domain);
|
|
} else if (m_data == "void") {
|
|
domain = new VoidDomain(*entity);
|
|
sInstanceState.replaceState(entity, domain);
|
|
entity->setFlags(entity_domain);
|
|
}
|
|
}
|
|
} else {
|
|
sInstanceState.replaceState(entity, nullptr);
|
|
entity->setFlags(~entity_domain);
|
|
}
|
|
}
|
|
|
|
DomainProperty * DomainProperty::copy() const
|
|
{
|
|
return new DomainProperty(*this);
|
|
}
|
|
|
|
Domain* DomainProperty::getDomain(const LocatedEntity *entity) const {
|
|
return sInstanceState.getState(entity);
|
|
}
|
|
|