From 803d511826ae5b8cd268d97afec256239141e424 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 5 Dec 2021 06:36:48 +0100 Subject: [PATCH] #5584: Notify LightNodes when entity settings change. All LightNodes could subscribe to the settings signal themselves, but the house-keeping code on scene insertion/removal for every single node is not worth the trouble. --- radiantcore/entity/EntityModule.cpp | 21 +++++++++++++++++++++ radiantcore/entity/EntityModule.h | 17 ++++++++++++----- radiantcore/entity/light/LightNode.cpp | 5 +++++ radiantcore/entity/light/LightNode.h | 2 ++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/radiantcore/entity/EntityModule.cpp b/radiantcore/entity/EntityModule.cpp index a6628f5774..690514fd1c 100644 --- a/radiantcore/entity/EntityModule.cpp +++ b/radiantcore/entity/EntityModule.cpp @@ -295,16 +295,37 @@ void Doom3EntityModule::initialiseModule(const IApplicationContext& ctx) GlobalCommandSystem().addCommand("CreateSpeaker", std::bind(&algorithm::CreateSpeaker, std::placeholders::_1), { cmd::ARGTYPE_STRING, cmd::ARGTYPE_VECTOR3 }); + + _settingsListener = EntitySettings::InstancePtr()->signal_settingsChanged().connect( + sigc::mem_fun(this, &Doom3EntityModule::onEntitySettingsChanged)); } void Doom3EntityModule::shutdownModule() { rMessage() << getName() << "::shutdownModule called." << std::endl; + _settingsListener.disconnect(); + // Destroy the settings instance EntitySettings::destroy(); } +void Doom3EntityModule::onEntitySettingsChanged() +{ + // Actively notify all LightNodes (only those for now) about the settings change + GlobalMapModule().getRoot()->foreachNode([](const scene::INodePtr& node) + { + auto light = std::dynamic_pointer_cast(node); + + if (light) + { + light->onEntitySettingsChanged(); + } + + return true; + }); +} + // Static module instance module::StaticModule entityModule; diff --git a/radiantcore/entity/EntityModule.h b/radiantcore/entity/EntityModule.h index 1035734fa1..907f8c6f97 100644 --- a/radiantcore/entity/EntityModule.h +++ b/radiantcore/entity/EntityModule.h @@ -2,14 +2,18 @@ #include "ientity.h" #include "ieclass.h" +#include namespace entity { /// Implementation of the IEntityModule interface for Doom 3 -class Doom3EntityModule : +class Doom3EntityModule final : public IEntityModule { +private: + sigc::connection _settingsListener; + public: // EntityCreator implementation IEntityNodePtr createEntity(const IEntityClassPtr& eclass) override; @@ -25,10 +29,13 @@ class Doom3EntityModule : IEntityNodePtr createEntityFromSelection(const std::string& name, const Vector3& origin) override; // RegisterableModule implementation - virtual const std::string& getName() const override; - virtual const StringSet& getDependencies() const override; - virtual void initialiseModule(const IApplicationContext& ctx) override; - virtual void shutdownModule() override; + const std::string& getName() const override; + const StringSet& getDependencies() const override; + void initialiseModule(const IApplicationContext& ctx) override; + void shutdownModule() override; + +private: + void onEntitySettingsChanged(); }; } // namespace entity diff --git a/radiantcore/entity/light/LightNode.cpp b/radiantcore/entity/light/LightNode.cpp index 407c4542f9..544e97c3cc 100644 --- a/radiantcore/entity/light/LightNode.cpp +++ b/radiantcore/entity/light/LightNode.cpp @@ -621,4 +621,9 @@ void LightNode::onVisibilityChanged(bool isVisibleNow) } } +void LightNode::onEntitySettingsChanged() +{ + _renderableOctagon.queueUpdate(); +} + } // namespace entity diff --git a/radiantcore/entity/light/LightNode.h b/radiantcore/entity/light/LightNode.h index cf51a70bea..4cdf6f4a96 100644 --- a/radiantcore/entity/light/LightNode.h +++ b/radiantcore/entity/light/LightNode.h @@ -130,6 +130,8 @@ class LightNode : // Returns the original "origin" value const Vector3& getUntransformedOrigin() override; + void onEntitySettingsChanged(); + protected: // Gets called by the Transformable implementation whenever // scale, rotation or translation is changed.