Skip to content

Commit

Permalink
EclassModelNode using 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 e0013ab commit b39db31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
17 changes: 7 additions & 10 deletions radiantcore/entity/eclassmodel/EclassModelNode.cpp
Expand Up @@ -29,9 +29,6 @@ EclassModelNode::EclassModelNode(const EclassModelNode& other) :

EclassModelNode::~EclassModelNode()
{
removeKeyObserver("origin", _originKey);
removeKeyObserver("rotation", _rotationObserver);
removeKeyObserver("angle", _angleObserver);
}

EclassModelNodePtr EclassModelNode::Create(const IEntityClassPtr& eclass)
Expand All @@ -46,14 +43,14 @@ void EclassModelNode::construct()
{
EntityNode::construct();

_rotationObserver.setCallback(std::bind(&RotationKey::rotationChanged, &_rotationKey, std::placeholders::_1));
_angleObserver.setCallback(std::bind(&RotationKey::angleChanged, &_rotationKey, std::placeholders::_1));

_rotation.setIdentity();

addKeyObserver("angle", _angleObserver);
addKeyObserver("rotation", _rotationObserver);
addKeyObserver("origin", _originKey);
// Observe position and orientation spawnargs
static_assert(std::is_base_of<sigc::trackable, OriginKey>::value);
static_assert(std::is_base_of<sigc::trackable, RotationKey>::value);
observeKey("angle", sigc::mem_fun(_rotationKey, &RotationKey::angleChanged));
observeKey("rotation", sigc::mem_fun(_rotationKey, &RotationKey::rotationChanged));
observeKey("origin", sigc::mem_fun(_originKey, &OriginKey::onKeyValueChanged));
}

// Snappable implementation
Expand Down Expand Up @@ -109,7 +106,7 @@ void EclassModelNode::translate(const Vector3& translation)
_origin += translation;
}

void EclassModelNode::rotate(const Quaternion& rotation)
void EclassModelNode::rotate(const Quaternion& rotation)
{
_rotation.rotate(rotation);
}
Expand Down
11 changes: 7 additions & 4 deletions radiantcore/entity/eclassmodel/EclassModelNode.h
Expand Up @@ -22,6 +22,12 @@ namespace entity
class EclassModelNode;
typedef std::shared_ptr<EclassModelNode> EclassModelNodePtr;

/**
* @brief Entity node displaying a model defined in an entityDef.
*
* This is used for entities whose model is defined in the entity class, e.g.
* guards, interactable objects etc.
*/
class EclassModelNode :
public EntityNode,
public Snappable
Expand All @@ -40,9 +46,6 @@ class EclassModelNode :

AABB _localAABB;

KeyObserverDelegate _rotationObserver;
KeyObserverDelegate _angleObserver;

private:
// Constructor
EclassModelNode(const IEntityClassPtr& eclass);
Expand All @@ -66,7 +69,7 @@ class EclassModelNode :
void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override;
void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;

// Returns the original "origin" value
const Vector3& getUntransformedOrigin() override;

Expand Down

0 comments on commit b39db31

Please sign in to comment.