Mercurial > fife-parpg
changeset 90:9855464762c1
Layer::addInstance for moving instances around layers. Useful when we have multi-level buildings.
author | Sleek@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 19 Jul 2008 12:06:14 +0000 |
parents | fa33cda75471 |
children | e7b55b2b398f |
files | engine/core/model/structures/layer.cpp engine/core/model/structures/layer.h |
diffstat | 2 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/model/structures/layer.cpp Sat Jul 19 11:38:52 2008 +0000 +++ b/engine/core/model/structures/layer.cpp Sat Jul 19 12:06:14 2008 +0000 @@ -89,6 +89,34 @@ return instance; } + bool Layer::addInstance(Instance* instance, const ExactModelCoordinate& p){ + if( !instance ) + FL_ERR(_log, "Tried to add an instance to layer, but given instance is invalid"); + Location l; + l.setLayer(this); + l.setExactLayerCoordinates(p); + std::string id = instance->getId(); + + if(id != "") { + std::vector<Instance*>::iterator it = m_instances.begin(); + for(; it != m_instances.end(); ++it) { + if((*it)->getId() == id) + throw NameClash(id); + } + } + + m_instances.push_back(instance); + m_instanceTree->addInstance(instance); + + std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); + while (i != m_changelisteners.end()) { + (*i)->onInstanceCreate(this, instance); + ++i; + } + m_changed = true; + return instance; + } + void Layer::deleteInstance(Instance* instance) { std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); while (i != m_changelisteners.end()) {
--- a/engine/core/model/structures/layer.h Sat Jul 19 11:38:52 2008 +0000 +++ b/engine/core/model/structures/layer.h Sat Jul 19 12:06:14 2008 +0000 @@ -131,6 +131,11 @@ /** Add an instance of an object at a specific position */ Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id=""); + + /** Add a valid instance at a specific position. This is temporary. It will be moved to a higher level + later so that we can ensure that each Instance only lives in one layer. + */ + Instance* Layer::addInstance(Instance* instance, const ExactModelCoordinate& p); /** Remove an instance from the layer */