Mercurial > fife-parpg
comparison engine/core/model/structures/layer.cpp @ 99:64e7fe3d4288
- added possibility to change instance ids
- speedup instances by removing uniqueness check for ids, that means the client has to provide unique ids or live with on unique ids
- added possibility to list all instances with a given id
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 22 Jul 2008 10:04:16 +0000 |
parents | 746df66978da |
children | 56ac89189bc4 |
comparison
equal
deleted
inserted
replaced
98:214e3eb81eb2 | 99:64e7fe3d4288 |
---|---|
69 Instance* Layer::createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id) { | 69 Instance* Layer::createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id) { |
70 Location l; | 70 Location l; |
71 l.setLayer(this); | 71 l.setLayer(this); |
72 l.setExactLayerCoordinates(p); | 72 l.setExactLayerCoordinates(p); |
73 | 73 |
74 if(id != "") { | |
75 std::vector<Instance*>::iterator it = m_instances.begin(); | |
76 for(; it != m_instances.end(); ++it) { | |
77 if((*it)->getId() == id) | |
78 throw NameClash(id); | |
79 } | |
80 } | |
81 | |
82 Instance* instance = new Instance(object, l, id); | 74 Instance* instance = new Instance(object, l, id); |
83 m_instances.push_back(instance); | 75 m_instances.push_back(instance); |
84 m_instanceTree->addInstance(instance); | 76 m_instanceTree->addInstance(instance); |
85 | 77 |
86 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); | 78 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); |
99 } | 91 } |
100 | 92 |
101 Location l; | 93 Location l; |
102 l.setLayer(this); | 94 l.setLayer(this); |
103 l.setExactLayerCoordinates(p); | 95 l.setExactLayerCoordinates(p); |
104 std::string id = instance->getId(); | |
105 | |
106 if(id != "") { | |
107 std::vector<Instance*>::iterator it = m_instances.begin(); | |
108 for(; it != m_instances.end(); ++it) { | |
109 if((*it)->getId() == id) | |
110 throw NameClash(id); | |
111 } | |
112 } | |
113 | 96 |
114 m_instances.push_back(instance); | 97 m_instances.push_back(instance); |
115 m_instanceTree->addInstance(instance); | 98 m_instanceTree->addInstance(instance); |
116 | 99 |
117 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); | 100 std::vector<LayerChangeListener*>::iterator i = m_changelisteners.begin(); |
148 if((*it)->getId() == id) | 131 if((*it)->getId() == id) |
149 return *it; | 132 return *it; |
150 } | 133 } |
151 | 134 |
152 throw NotFound(id); | 135 throw NotFound(id); |
136 } | |
137 | |
138 std::vector<Instance*> Layer::getInstances(const std::string& id) { | |
139 std::vector<Instance*> matching_instances; | |
140 std::vector<Instance*>::iterator it = m_instances.begin(); | |
141 for(; it != m_instances.end(); ++it) { | |
142 if((*it)->getId() == id) | |
143 matching_instances.push_back(*it); | |
144 } | |
145 return matching_instances; | |
153 } | 146 } |
154 | 147 |
155 void Layer::getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer) const { | 148 void Layer::getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer) const { |
156 if (!layer) { | 149 if (!layer) { |
157 layer = this; | 150 layer = this; |