Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
89:fa33cda75471 | 90:9855464762c1 |
---|---|
87 } | 87 } |
88 m_changed = true; | 88 m_changed = true; |
89 return instance; | 89 return instance; |
90 } | 90 } |
91 | 91 |
92 bool Layer::addInstance(Instance* instance, const ExactModelCoordinate& p){ | |
93 if( !instance ) | |
94 FL_ERR(_log, "Tried to add an instance to layer, but given instance is invalid"); | |
95 Location l; | |
96 l.setLayer(this); | |
97 l.setExactLayerCoordinates(p); | |
98 std::string id = instance->getId(); | |
99 | |
100 if(id != "") { | |
101 std::vector<Instance*>::iterator it = m_instances.begin(); | |
102 for(; it != m_instances.end(); ++it) { | |
103 if((*it)->getId() == id) | |
104 throw NameClash(id); | |
105 } | |
106 } | |
107 | |
108 m_instances.push_back(instance); | |
109 m_instanceTree->addInstance(instance); | |
110 | |
111 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); | |
112 while (i != m_changelisteners.end()) { | |
113 (*i)->onInstanceCreate(this, instance); | |
114 ++i; | |
115 } | |
116 m_changed = true; | |
117 return instance; | |
118 } | |
119 | |
92 void Layer::deleteInstance(Instance* instance) { | 120 void Layer::deleteInstance(Instance* instance) { |
93 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); | 121 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); |
94 while (i != m_changelisteners.end()) { | 122 while (i != m_changelisteners.end()) { |
95 (*i)->onInstanceDelete(this, instance); | 123 (*i)->onInstanceDelete(this, instance); |
96 ++i; | 124 ++i; |