Skip to content

Commit

Permalink
#5940: Provide a virtual method for entity subclasses to be notified …
Browse files Browse the repository at this point in the history
…about colour changes. When a LightNode's colour key is changing, its renderables need to be refreshed.
  • Loading branch information
codereader committed Apr 17, 2022
1 parent cacd77c commit 41bf96a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
6 changes: 3 additions & 3 deletions libs/render/RenderableGeometry.h
Expand Up @@ -129,10 +129,10 @@ class RenderableGeometry :
if (_shader != shader)
{
clear();
}

// Update our local shader reference
_shader = shader;
// Update our local shader reference
_shader = shader;
}

if (_shader)
{
Expand Down
23 changes: 16 additions & 7 deletions radiantcore/entity/ColourKey.h
@@ -1,8 +1,8 @@
#pragma once

#include <functional>
#include "ientity.h"
#include "irender.h"
#include <fmt/format.h>

namespace entity
{
Expand All @@ -20,20 +20,24 @@ class ColourKey :

RenderSystemWeakPtr _renderSystem;

std::function<void(const std::string&)> _onColourChanged;

public:
ColourKey() :
_colour(1,1,1)
{
captureShader();
}
// The given callback will be invoked after the _color spawnarg has been changed
ColourKey(const std::function<void(const std::string&)>& onColourChanged) :
_colour(1,1,1),
_onColourChanged(onColourChanged)
{
captureShader();
}

const Vector3& getColour() const
{
return _colour;
}

// Called when "_color" keyvalue changes
void onKeyValueChanged(const std::string& value)
void onKeyValueChanged(const std::string& value) override
{
// Initialise the colour with white, in case the string parse fails
_colour[0] = _colour[1] = _colour[2] = 1;
Expand All @@ -47,6 +51,11 @@ class ColourKey :
strm >> _colour.z();

captureShader();

if (_onColourChanged)
{
_onColourChanged(value);
}
}

void setRenderSystem(const RenderSystemPtr& renderSystem)
Expand Down
7 changes: 7 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -22,6 +22,7 @@ EntityNode::EntityNode(const IEntityClassPtr& eclass) :
_originKey(std::bind(&EntityNode::_originKeyChanged, this)),
_nameKey(_spawnArgs),
_renderableName(*this, _nameKey),
_colourKey(std::bind(&EntityNode::_colourKeyChanged, this, std::placeholders::_1)),
_modelKey(*this),
_keyObservers(_spawnArgs),
_shaderParms(_keyObservers, _colourKey),
Expand All @@ -45,6 +46,7 @@ EntityNode::EntityNode(const EntityNode& other) :
_originKey(std::bind(&EntityNode::_originKeyChanged, this)),
_nameKey(_spawnArgs),
_renderableName(*this, _nameKey),
_colourKey(std::bind(&EntityNode::_colourKeyChanged, this, std::placeholders::_1)),
_modelKey(*this),
_keyObservers(_spawnArgs),
_shaderParms(_keyObservers, _colourKey),
Expand Down Expand Up @@ -536,6 +538,11 @@ void EntityNode::_originKeyChanged()
// TODO: add virtual callout for subclasses
}

void EntityNode::_colourKeyChanged(const std::string& value)
{
onColourKeyChanged(value);
}

void EntityNode::_onNoShadowsSettingsChanged(const std::string& noShadowsValue)
{
_isShadowCasting = noShadowsValue != "1";
Expand Down
7 changes: 6 additions & 1 deletion radiantcore/entity/EntityNode.h
Expand Up @@ -205,7 +205,11 @@ class EntityNode :
virtual const Vector3& getWorldPosition() const = 0;

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

// Invoked when the colour key has changed its value
virtual void onColourKeyChanged(const std::string& value)
{}

/**
* greebo: construct() does the necessary setup, connects keyobservers, etc.
Expand All @@ -231,6 +235,7 @@ class EntityNode :
// Private function target - wraps to virtual protected signal
void _modelKeyChanged(const std::string& value);
void _originKeyChanged();
void _colourKeyChanged(const std::string& value);
void _onNoShadowsSettingsChanged(const std::string& value);

void acquireShaders();
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -1236,4 +1236,10 @@ const IRenderEntity& LightNode::getLightEntity() const
return *this;
}

void LightNode::onColourKeyChanged(const std::string& value)
{
_renderableOctagon.queueUpdate();
_renderableLightVolume.queueUpdate();
}

} // namespace entity
2 changes: 2 additions & 0 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -205,6 +205,8 @@ class LightNode :
void onVisibilityChanged(bool isVisibleNow) override;
void onSelectionStatusChange(bool changeGroupStatus) override;

void onColourKeyChanged(const std::string& value) override;

private:
void evaluateTransform();

Expand Down

0 comments on commit 41bf96a

Please sign in to comment.