Skip to content

Commit

Permalink
#5622: Implement fingerprinting of entity nodes (layer or grouping in…
Browse files Browse the repository at this point in the history
…formation are disregarded)
  • Loading branch information
codereader committed May 22, 2021
1 parent c33d883 commit ffe86cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -5,6 +5,8 @@
#include "icounter.h"
#include "imodel.h"
#include "itransformable.h"
#include "math/Hash.h"
#include "string/case_conv.h"

#include "EntitySettings.h"

Expand Down Expand Up @@ -202,6 +204,20 @@ const Vector3& EntityNode::getDirection() const
return _direction;
}

std::size_t EntityNode::getFingerprint()
{
std::size_t hash = 0;

// Entities are just a collection of key/value pairs, use them lower case, ignore inherited keys
_spawnArgs.forEachKeyValue([&](const std::string& key, const std::string& value)
{
math::combineHash(hash, std::hash<std::string>()(string::to_lower_copy(key)));
math::combineHash(hash, std::hash<std::string>()(string::to_lower_copy(value)));
}, false);

return hash;
}

void EntityNode::testSelect(Selector& selector, SelectionTest& test)
{
test.BeginMesh(localToWorld());
Expand Down
7 changes: 6 additions & 1 deletion radiantcore/entity/EntityNode.h
Expand Up @@ -3,6 +3,7 @@
#include <sigc++/connection.h>
#include "ientity.h"
#include "inamespace.h"
#include "icomparablenode.h"
#include "Bounded.h"

#include "scene/SelectableNode.h"
Expand Down Expand Up @@ -32,7 +33,8 @@ class EntityNode :
public SelectionTestable,
public Namespaced,
public TargetableNode,
public Transformable
public Transformable,
public scene::IComparableNode
{
protected:
// The entity class
Expand Down Expand Up @@ -113,6 +115,9 @@ class EntityNode :
Matrix4 localToParent() const override { return _localToParent; }
Matrix4& localToParent() override { return _localToParent; }

// IComparableNode implementation
std::size_t getFingerprint() override;

// SelectionTestable implementation
virtual void testSelect(Selector& selector, SelectionTest& test) override;

Expand Down

0 comments on commit ffe86cf

Please sign in to comment.