Skip to content

Commit

Permalink
Add EntityNode::onEntityClassChanged() method to be overridden by chi…
Browse files Browse the repository at this point in the history
…ld classes.

Redirect the connected signal to the virtual method which will call KeyObserverMap::refreshObservers() by default.
  • Loading branch information
codereader committed Dec 10, 2017
1 parent 8dc14d2 commit 6f7b858
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugins/entity/EntityNode.cpp
Expand Up @@ -49,9 +49,10 @@ EntityNode::~EntityNode()

void EntityNode::construct()
{
_eclass->changedSignal().connect(
sigc::mem_fun(_keyObservers, &KeyObserverMap::refreshObservers)
);
_eclassChangedConn = _eclass->changedSignal().connect([this]()
{
this->onEntityClassChanged();
});

TargetableNode::construct();

Expand Down Expand Up @@ -80,9 +81,17 @@ void EntityNode::destruct()
removeKeyObserver("_color", _colourKey);
removeKeyObserver("name", _nameKey);

_eclassChangedConn.disconnect();

TargetableNode::destruct();
}

void EntityNode::onEntityClassChanged()
{
// By default, we notify the KeyObservers attached to this entity
_keyObservers.refreshObservers();
}

void EntityNode::addKeyObserver(const std::string& key, KeyObserver& observer)
{
_keyObservers.insert(key, observer);
Expand Down
8 changes: 8 additions & 0 deletions plugins/entity/EntityNode.h
@@ -1,5 +1,6 @@
#pragma once

#include <sigc++/connection.h>
#include "ientity.h"
#include "inamespace.h"
#include "Bounded.h"
Expand Down Expand Up @@ -74,6 +75,8 @@ class EntityNode :
ShaderPtr _fillShader;
ShaderPtr _wireShader;

sigc::connection _eclassChangedConn;

protected:
// The Constructor needs the eclass
EntityNode(const IEntityClassPtr& eclass);
Expand Down Expand Up @@ -151,6 +154,11 @@ class EntityNode :
*/
virtual void construct();

// Signal method to be overridden by subclasses.
// Don't forget to call the base class implementation as this will
// reload the entity key values and notify observers
virtual void onEntityClassChanged();

private:
// Routine used by the destructor, should be non-virtual
void destruct();
Expand Down

0 comments on commit 6f7b858

Please sign in to comment.