Skip to content

Commit

Permalink
#5584: The RenderableEntityName instance needs to get hold of the up-…
Browse files Browse the repository at this point in the history
…to-date origin during transformations. For now, I'm going to introduce a getWorldPosition() method which is implemented by all the entity classes.

The origin member is implemented in all 5 entity sub types in a very similar way which has great potential to be simplified and moved to the common EntityNode base.
  • Loading branch information
codereader committed Jan 24, 2022
1 parent c493305 commit 393c030
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 23 deletions.
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_library(radiantcore MODULE
entity/NamespaceManager.cpp
entity/RenderableArrow.cpp
entity/RenderableEntityBox.cpp
entity/RenderableEntityName.cpp
entity/RotationKey.cpp
entity/RotationMatrix.cpp
entity/ShaderParms.cpp
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/entity/EntityNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EntityNode::EntityNode(const IEntityClassPtr& eclass) :
_namespaceManager(_spawnArgs),
_originKey(std::bind(&EntityNode::_originKeyChanged, this)),
_nameKey(_spawnArgs),
_renderableName(_nameKey, _originKey.get()),
_renderableName(*this, _nameKey),
_modelKey(*this),
_keyObservers(_spawnArgs),
_shaderParms(_keyObservers, _colourKey),
Expand All @@ -42,7 +42,7 @@ EntityNode::EntityNode(const EntityNode& other) :
_namespaceManager(_spawnArgs),
_originKey(std::bind(&EntityNode::_originKeyChanged, this)),
_nameKey(_spawnArgs),
_renderableName(_nameKey, _originKey.get()),
_renderableName(*this, _nameKey),
_modelKey(*this),
_keyObservers(_spawnArgs),
_shaderParms(_keyObservers, _colourKey),
Expand Down
7 changes: 7 additions & 0 deletions radiantcore/entity/EntityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class EntityNode :
// Observes the "origin" keyvalue
OriginKey _originKey;

// Points to the origin value of this entity, is also kept up to date
// during transformations. Used to render the entity name at the correct position.
Vector3 _originTransformed;

// A helper class observing the "name" keyvalue
// Used for rendering the name and as Nameable implementation
NameKey _nameKey;
Expand Down Expand Up @@ -175,6 +179,9 @@ class EntityNode :
// Optional implementation: gets invoked by the EntityModule when the settings are changing
virtual void onEntitySettingsChanged();

// Returns the current world origin of this entity (also up to date during transformations)
virtual const Vector3& getWorldPosition() const = 0;

protected:
virtual void onModelKeyChanged(const std::string& value);

Expand Down
23 changes: 23 additions & 0 deletions radiantcore/entity/RenderableEntityName.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "RenderableEntityName.h"
#include "EntityNode.h"

namespace entity
{

const Vector3& RenderableEntityName::getWorldPosition()
{
return _entity.getWorldPosition();
}

const std::string& RenderableEntityName::getText()
{
return _nameKey.getName();
}

const Vector4& RenderableEntityName::getColour()
{
static Vector4 colour(1, 1, 1, 1);
return colour;
}

}
32 changes: 11 additions & 21 deletions radiantcore/entity/RenderableEntityName.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,26 @@
namespace entity
{

class EntityNode;

class RenderableEntityName :
public render::RenderableTextBase
{
private:
const EntityNode& _entity;
const NameKey& _nameKey;

// The origin in world coordinates
const Vector3& _entityOrigin;

public:
RenderableEntityName(const NameKey& nameKey, const Vector3& entityOrigin) :
_nameKey(nameKey),
_entityOrigin(entityOrigin)
RenderableEntityName(const EntityNode& entity, const NameKey& nameKey) :
_entity(entity),
_nameKey(nameKey)
{}

const Vector3& getWorldPosition() override
{
return _entityOrigin;
}

const std::string& getText() override
{
return _nameKey.getName();
}

const Vector4& getColour() override
{
static Vector4 colour(1, 1, 1, 1);
return colour;
}
const Vector3& getWorldPosition() override;

const std::string& getText() override;

const Vector4& getColour() override;
};

}
5 changes: 5 additions & 0 deletions radiantcore/entity/doom3group/StaticGeometryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ const Vector3& StaticGeometryNode::getUntransformedOrigin()
return m_originKey.get();
}

const Vector3& StaticGeometryNode::getWorldPosition() const
{
return m_origin;
}

const AABB& StaticGeometryNode::localAABB() const {
m_curveBounds = m_curveNURBS.getBounds();
m_curveBounds.includeAABB(m_curveCatmullRom.getBounds());
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/doom3group/StaticGeometryNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class StaticGeometryNode :
// Returns the original "origin" value
const Vector3& getUntransformedOrigin() override;

const Vector3& getWorldPosition() const override;

protected:
// Gets called by the Transformable implementation whenever
// scale, rotation or translation is changed.
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/entity/eclassmodel/EclassModelNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ const Vector3& EclassModelNode::getUntransformedOrigin()
return _originKey.get();
}

const Vector3& EclassModelNode::getWorldPosition() const
{
return _origin;
}

void EclassModelNode::updateTransform()
{
_renderOrigin.queueUpdate();
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/eclassmodel/EclassModelNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class EclassModelNode :

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

const Vector3& getWorldPosition() const override;

protected:
// Gets called by the Transformable implementation whenever
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/entity/generic/GenericEntityNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ const Vector3& GenericEntityNode::getUntransformedOrigin()
return m_originKey.get();
}

const Vector3& GenericEntityNode::getWorldPosition() const
{
return m_origin;
}

void GenericEntityNode::onChildAdded(const scene::INodePtr& child)
{
EntityNode::onChildAdded(child);
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/generic/GenericEntityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class GenericEntityNode final : public EntityNode, public Snappable
// Returns the original "origin" value
const Vector3& getUntransformedOrigin() override;

const Vector3& getWorldPosition() const override;

void onChildAdded(const scene::INodePtr& child) override;
void onChildRemoved(const scene::INodePtr& child) override;

Expand Down
7 changes: 7 additions & 0 deletions radiantcore/entity/light/LightNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ void LightNode::selectedChangedComponent(const ISelectable& selectable)

void LightNode::onPreRender(const VolumeTest& volume)
{
EntityNode::onPreRender(volume);

// Pick the colour shader according to our settings
const auto& colourShader = _overrideColKey.get() ? getColourShader() : _colourKey.getColourShader();
_renderableOctagon.update(colourShader);
Expand Down Expand Up @@ -537,6 +539,11 @@ const Vector3& LightNode::getUntransformedOrigin()
return m_originKey.get();
}

const Vector3& LightNode::getWorldPosition() const
{
return _originTransformed;
}

void LightNode::onVisibilityChanged(bool isVisibleNow)
{
EntityNode::onVisibilityChanged(isVisibleNow);
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/light/LightNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class LightNode :
// Returns the original "origin" value
const Vector3& getUntransformedOrigin() override;

const Vector3& getWorldPosition() const override;

void onEntitySettingsChanged() override;

// Is this light projected or omni?
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/entity/speaker/SpeakerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,9 @@ void SpeakerNode::onRemoveFromScene(scene::IMapRootNode& root)
_renderableRadiiFill.clear();
}

const Vector3& SpeakerNode::getWorldPosition() const
{
return m_origin;
}

} // namespace entity
2 changes: 2 additions & 0 deletions radiantcore/entity/speaker/SpeakerNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class SpeakerNode final :
void onInsertIntoScene(scene::IMapRootNode& root) override;
void onRemoveFromScene(scene::IMapRootNode& root) override;

const Vector3& getWorldPosition() const override;

protected:
// Gets called by the Transformable implementation whenever
// scale, rotation or translation is changed.
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<ClCompile Include="..\..\radiantcore\entity\NamespaceManager.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableArrow.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityBox.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityName.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\RotationMatrix.cpp" />
<ClCompile Include="..\..\radiantcore\entity\ShaderParms.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,9 @@
<ClCompile Include="..\..\radiantcore\brush\RenderableBrushVertices.cpp">
<Filter>src\brush</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\entity\RenderableEntityName.cpp">
<Filter>src\entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down

0 comments on commit 393c030

Please sign in to comment.