Skip to content

Commit

Permalink
GenericEntityNode now uses observeKey() with auto-disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Dec 12, 2021
1 parent 099252e commit 76addec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
7 changes: 4 additions & 3 deletions radiantcore/entity/AngleKey.h
Expand Up @@ -9,7 +9,8 @@ class Entity;
namespace entity
{

class AngleKey
/// Wrapper for an "angle" spawnarg
class AngleKey: public sigc::trackable
{
private:
std::function<void()> _angleChanged;
Expand All @@ -19,8 +20,8 @@ class AngleKey
public:
static const float IDENTITY;

AngleKey(const std::function<void()>& angleChanged) :
_angleChanged(angleChanged),
AngleKey(const std::function<void()>& angleChanged) :
_angleChanged(angleChanged),
_value(IDENTITY)
{}

Expand Down
31 changes: 8 additions & 23 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Expand Up @@ -37,19 +37,6 @@ GenericEntityNode::GenericEntityNode(const GenericEntityNode& other) :

GenericEntityNode::~GenericEntityNode()
{
if (!_allow3Drotations)
{
// Ordinary rotation (2D around z axis), use angle key observer
removeKeyObserver("angle", _angleObserver);
}
else
{
// Full 3D rotations allowed, observe both keys using the rotation key observer
removeKeyObserver("angle", _angleObserver);
removeKeyObserver("rotation", _rotationObserver);
}

removeKeyObserver("origin", m_originKey);
}

GenericEntityNodePtr GenericEntityNode::Create(const IEntityClassPtr& eclass)
Expand All @@ -71,22 +58,20 @@ void GenericEntityNode::construct()

if (!_allow3Drotations)
{
_angleObserver.setCallback(std::bind(&AngleKey::angleChanged, &m_angleKey, std::placeholders::_1));

// Ordinary rotation (2D around z axis), use angle key observer
addKeyObserver("angle", _angleObserver);
static_assert(std::is_base_of<sigc::trackable, AngleKey>::value);
observeKey("angle", sigc::mem_fun(m_angleKey, &AngleKey::angleChanged));
}
else
{
_angleObserver.setCallback(std::bind(&RotationKey::angleChanged, &m_rotationKey, std::placeholders::_1));
_rotationObserver.setCallback(std::bind(&RotationKey::rotationChanged, &m_rotationKey, std::placeholders::_1));

// Full 3D rotations allowed, observe both keys using the rotation key observer
addKeyObserver("angle", _angleObserver);
addKeyObserver("rotation", _rotationObserver);
}
static_assert(std::is_base_of<sigc::trackable, RotationKey>::value);
observeKey("angle", sigc::mem_fun(m_rotationKey, &RotationKey::angleChanged));
observeKey("rotation", sigc::mem_fun(m_rotationKey, &RotationKey::rotationChanged));
}

addKeyObserver("origin", m_originKey);
static_assert(std::is_base_of<sigc::trackable, OriginKey>::value);
observeKey("origin", sigc::mem_fun(m_originKey, &OriginKey::onKeyValueChanged));
}

void GenericEntityNode::snapto(float snap)
Expand Down
14 changes: 10 additions & 4 deletions radiantcore/entity/generic/GenericEntityNode.h
Expand Up @@ -24,7 +24,16 @@ namespace entity
class GenericEntityNode;
typedef std::shared_ptr<GenericEntityNode> GenericEntityNodePtr;

/// EntityNode subclass for all entity types not handled by a specific class

/**
* @brief EntityNode subclass for all entity types not handled by a specific
* class.
*
* Generic entity nodes represent entities which have no editor-specific
* functionality, beyond simply existing and pointing in a particular direction.
* They are rendered as boxes with an angle/rotation arrow. Common generic
* entities include "info_playerstart" and "info_location".
*/
class GenericEntityNode: public EntityNode, public Snappable
{
OriginKey m_originKey;
Expand Down Expand Up @@ -53,9 +62,6 @@ class GenericEntityNode: public EntityNode, public Snappable
// FALSE if the arrow is caught in the xy plane
bool _allow3Drotations;

KeyObserverDelegate _rotationObserver;
KeyObserverDelegate _angleObserver;

// Whether to draw a solid/shaded box in full material render mode or just the wireframe
enum SolidAAABBRenderMode
{
Expand Down

0 comments on commit 76addec

Please sign in to comment.