# HG changeset patch # User Sleek@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1216469174 0 # Node ID 9855464762c1d9d3992880299d9f48a7f4fdfe6b # Parent fa33cda75471feb3101a1a3103303efe8a7c7995 Layer::addInstance for moving instances around layers. Useful when we have multi-level buildings. diff -r fa33cda75471 -r 9855464762c1 engine/core/model/structures/layer.cpp --- 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::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::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::iterator i = m_changelisteners.begin(); while (i != m_changelisteners.end()) { diff -r fa33cda75471 -r 9855464762c1 engine/core/model/structures/layer.h --- 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 */