diff engine/core/model/structures/layer.cpp @ 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 90005975cdbb
children e7b55b2b398f
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()) {