Skip to content

Commit

Permalink
#5584: Notify LightNodes when entity settings change.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
codereader committed Dec 5, 2021
1 parent db61a5d commit 803d511
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
21 changes: 21 additions & 0 deletions radiantcore/entity/EntityModule.cpp
Expand Up @@ -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<LightNode>(node);

if (light)
{
light->onEntitySettingsChanged();
}

return true;
});
}

// Static module instance
module::StaticModule<Doom3EntityModule> entityModule;

Expand Down
17 changes: 12 additions & 5 deletions radiantcore/entity/EntityModule.h
Expand Up @@ -2,14 +2,18 @@

#include "ientity.h"
#include "ieclass.h"
#include <sigc++/connection.h>

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;
Expand All @@ -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
5 changes: 5 additions & 0 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -621,4 +621,9 @@ void LightNode::onVisibilityChanged(bool isVisibleNow)
}
}

void LightNode::onEntitySettingsChanged()
{
_renderableOctagon.queueUpdate();
}

} // namespace entity
2 changes: 2 additions & 0 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -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.
Expand Down

0 comments on commit 803d511

Please sign in to comment.