Skip to content

Commit

Permalink
SpeakerNode is now using observeKey()
Browse files Browse the repository at this point in the history
Remove KeyObserverDelegates, use observeKey() with auto-disconnection for all
relevant spawnargs.
  • Loading branch information
Matthew Mott committed Dec 11, 2021
1 parent c198b59 commit d052567
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
21 changes: 7 additions & 14 deletions radiantcore/entity/speaker/SpeakerNode.cpp
Expand Up @@ -24,9 +24,6 @@ SpeakerNode::SpeakerNode(const IEntityClassPtr& eclass) :
m_maxIsSet(false),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_radiusMinObserver(std::bind(&SpeakerNode::sMinChanged, this, std::placeholders::_1)),
_radiusMaxObserver(std::bind(&SpeakerNode::sMaxChanged, this, std::placeholders::_1)),
_shaderObserver(std::bind(&SpeakerNode::sShaderChanged, this, std::placeholders::_1)),
_dragPlanes(std::bind(&SpeakerNode::selectedChangedComponent, this, std::placeholders::_1))
{}

Expand All @@ -41,9 +38,6 @@ SpeakerNode::SpeakerNode(const SpeakerNode& other) :
m_maxIsSet(false),
m_aabb_solid(m_aabb_local),
m_aabb_wire(m_aabb_local),
_radiusMinObserver(std::bind(&SpeakerNode::sMinChanged, this, std::placeholders::_1)),
_radiusMaxObserver(std::bind(&SpeakerNode::sMaxChanged, this, std::placeholders::_1)),
_shaderObserver(std::bind(&SpeakerNode::sShaderChanged, this, std::placeholders::_1)),
_dragPlanes(std::bind(&SpeakerNode::selectedChangedComponent, this, std::placeholders::_1))
{}

Expand All @@ -62,18 +56,17 @@ void SpeakerNode::construct()
m_aabb_local = _spawnArgs.getEntityClass()->getBounds();
m_aabb_border = m_aabb_local;

addKeyObserver("origin", m_originKey);
addKeyObserver(KEY_S_SHADER, _shaderObserver);
addKeyObserver(KEY_S_MINDISTANCE, _radiusMinObserver);
addKeyObserver(KEY_S_MAXDISTANCE, _radiusMaxObserver);
observeKey("origin", sigc::mem_fun(m_originKey, &OriginKey::onKeyValueChanged));

// Observe speaker-related spawnargs
static_assert(std::is_base_of<sigc::trackable, SpeakerNode>::value);
observeKey(KEY_S_SHADER, sigc::mem_fun(this, &SpeakerNode::sShaderChanged));
observeKey(KEY_S_MINDISTANCE, sigc::mem_fun(this, &SpeakerNode::sMinChanged));
observeKey(KEY_S_MAXDISTANCE, sigc::mem_fun(this, &SpeakerNode::sMaxChanged));
}

SpeakerNode::~SpeakerNode()
{
removeKeyObserver("origin", m_originKey);
removeKeyObserver(KEY_S_SHADER, _shaderObserver);
removeKeyObserver(KEY_S_MINDISTANCE, _radiusMinObserver);
removeKeyObserver(KEY_S_MAXDISTANCE, _radiusMaxObserver);
}

void SpeakerNode::originChanged()
Expand Down
6 changes: 1 addition & 5 deletions radiantcore/entity/speaker/SpeakerNode.h
Expand Up @@ -55,10 +55,6 @@ class SpeakerNode :
RenderableSolidAABB m_aabb_solid;
RenderableWireframeAABB m_aabb_wire;

KeyObserverDelegate _radiusMinObserver;
KeyObserverDelegate _radiusMaxObserver;
KeyObserverDelegate _shaderObserver;

// dragplanes for resizing using mousedrag
selection::DragPlanes _dragPlanes;

Expand All @@ -84,7 +80,7 @@ class SpeakerNode :

/// Public construction function
static SpeakerNodePtr create(const IEntityClassPtr& eclass);

~SpeakerNode();

// Snappable implementation
Expand Down

0 comments on commit d052567

Please sign in to comment.