Mercurial > fife-parpg
changeset 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 | 214e3eb81eb2 |
children | 69a7d40ccf62 |
files | engine/core/model/structures/instance.cpp engine/core/model/structures/instance.h engine/core/model/structures/instance.i engine/core/model/structures/layer.cpp engine/core/model/structures/layer.h engine/core/model/structures/layer.i |
diffstat | 6 files changed, 26 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/model/structures/instance.cpp Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.cpp Tue Jul 22 10:04:16 2008 +0000 @@ -193,6 +193,10 @@ m_changeinfo |= ICHANGE_ROTATION; } + void Instance::setId(const std::string& identifier) { + m_id = identifier; + } + void Instance::addActionListener(InstanceActionListener* listener) { initializeChanges(); m_activity->m_actionlisteners.push_back(listener);
--- a/engine/core/model/structures/instance.h Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.h Tue Jul 22 10:04:16 2008 +0000 @@ -90,6 +90,10 @@ */ const std::string& getId() { return m_id; } + /** Set the identifier for this instance. + */ + void setId(const std::string& identifier=""); + /** Gets object where this instance is instantiated from */ Object* getObject() { return m_object; }
--- a/engine/core/model/structures/instance.i Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/instance.i Tue Jul 22 10:04:16 2008 +0000 @@ -67,6 +67,7 @@ Instance(Object* object, const Location& location, const std::string& identifier=""); virtual ~Instance(); const std::string& getId(); + void setId(const std::string& identifier=""); Object* getObject(); void setLocation(const Location& loc); Location getLocation() const;
--- a/engine/core/model/structures/layer.cpp Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.cpp Tue Jul 22 10:04:16 2008 +0000 @@ -71,14 +71,6 @@ l.setLayer(this); l.setExactLayerCoordinates(p); - if(id != "") { - std::vector<Instance*>::iterator it = m_instances.begin(); - for(; it != m_instances.end(); ++it) { - if((*it)->getId() == id) - throw NameClash(id); - } - } - Instance* instance = new Instance(object, l, id); m_instances.push_back(instance); m_instanceTree->addInstance(instance); @@ -101,15 +93,6 @@ 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); @@ -152,6 +135,16 @@ throw NotFound(id); } + std::vector<Instance*> Layer::getInstances(const std::string& id) { + std::vector<Instance*> matching_instances; + std::vector<Instance*>::iterator it = m_instances.begin(); + for(; it != m_instances.end(); ++it) { + if((*it)->getId() == id) + matching_instances.push_back(*it); + } + return matching_instances; + } + void Layer::getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer) const { if (!layer) { layer = this;
--- a/engine/core/model/structures/layer.h Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.h Tue Jul 22 10:04:16 2008 +0000 @@ -145,9 +145,13 @@ */ const std::vector<Instance*>& getInstances() const { return m_instances; } - /** Get the instance on this layer with the given identifier. + /** Get the list of instances on this layer with the given identifier. */ - Instance* getInstance(const std::string& id); + std::vector<Instance*> getInstances(const std::string& id); + + /** Get the first instance on this layer with the given identifier. + */ + Instance* getInstance(const std::string& identifier); /** Set object visibility */
--- a/engine/core/model/structures/layer.i Mon Jul 21 13:46:15 2008 +0000 +++ b/engine/core/model/structures/layer.i Tue Jul 22 10:04:16 2008 +0000 @@ -72,6 +72,7 @@ void deleteInstance(Instance* object); const std::vector<Instance*>& getInstances() const; + std::vector<Instance*> getInstances(const std::string& identifier); Instance* getInstance(const std::string& id); void setInstancesVisible(bool vis);