Skip to content

Commit

Permalink
#5430: Use the override colour changed signal to update the eclasses …
Browse files Browse the repository at this point in the history
…during runtime
  • Loading branch information
codereader committed Nov 24, 2020
1 parent 21d391e commit 8ab345c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 19 deletions.
3 changes: 2 additions & 1 deletion include/ieclasscolours.h
Expand Up @@ -40,7 +40,8 @@ class IColourManager :
virtual void clearOverrideColours() = 0;

// Signal invoked when an override of a specific eclass is added, changed or removed
virtual sigc::signal<void, const std::string&>& sig_overrideColourChanged() = 0;
// function signature: void(const std::string& eclass, bool hasBeenRemoved)
virtual sigc::signal<void, const std::string&, bool>& sig_overrideColourChanged() = 0;
};

}
Expand Down
29 changes: 17 additions & 12 deletions radiantcore/eclass/Doom3EntityClass.cpp
Expand Up @@ -299,6 +299,22 @@ void Doom3EntityClass::setColour(const Vector3& colour)
_changedSignal.emit();
}

void Doom3EntityClass::resetColour()
{
// (Re)set the colour
const EntityClassAttribute& colourAttr = getAttribute("editor_color");

if (!colourAttr.getValue().empty())
{
setColour(string::convert<Vector3>(colourAttr.getValue()));
}
else
{
// If no colour is set, assign the default entity colour to this class
setColour(DefaultEntityColour);
}
}

const Vector3& Doom3EntityClass::getColour() const {
return _colour;
}
Expand Down Expand Up @@ -436,18 +452,7 @@ void Doom3EntityClass::resolveInheritance(EntityClasses& classmap)
_colourTransparent = true;
}

// (Re)set the colour
const EntityClassAttribute& colourAttr = getAttribute("editor_color");

if (!colourAttr.getValue().empty())
{
setColour(string::convert<Vector3>(colourAttr.getValue()));
}
else
{
// If no colour is set, assign the default entity colour to this class
setColour(DefaultEntityColour);
}
resetColour();
}

bool Doom3EntityClass::isOfType(const std::string& className)
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/eclass/Doom3EntityClass.h
Expand Up @@ -165,6 +165,8 @@ class Doom3EntityClass
const Vector3& getColour() const override;
/// Set the display colour
void setColour(const Vector3& colour) override;
// Resets the colour to the value defined in the attributes
void resetColour();
const std::string& getWireShader() const override;
const std::string& getFillShader() const override;
EntityClassAttribute& getAttribute(const std::string& name) override;
Expand Down
8 changes: 4 additions & 4 deletions radiantcore/eclass/EClassColourManager.cpp
Expand Up @@ -9,7 +9,7 @@ namespace eclass
void EClassColourManager::addOverrideColour(const std::string& eclass, const Vector3& colour)
{
_overrides[eclass] = colour;
_overrideChangedSignal.emit(eclass);
_overrideChangedSignal.emit(eclass, false); // false ==> colour added
}

void EClassColourManager::applyColours(const IEntityClassPtr& eclass)
Expand Down Expand Up @@ -38,7 +38,7 @@ void EClassColourManager::foreachOverrideColour(
void EClassColourManager::removeOverrideColour(const std::string& eclass)
{
_overrides.erase(eclass);
_overrideChangedSignal.emit(eclass);
_overrideChangedSignal.emit(eclass, true); // true ==> colour removed
}

void EClassColourManager::clearOverrideColours()
Expand All @@ -53,11 +53,11 @@ void EClassColourManager::clearOverrideColours()

// Fire signal, this might call applyColours which will
// find the colour has have been removed
_overrideChangedSignal.emit(eclass);
_overrideChangedSignal.emit(eclass, true); // true ==> colour removed
}
}

sigc::signal<void, const std::string&>& EClassColourManager::sig_overrideColourChanged()
sigc::signal<void, const std::string&, bool>& EClassColourManager::sig_overrideColourChanged()
{
return _overrideChangedSignal;
}
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/eclass/EClassColourManager.h
Expand Up @@ -11,7 +11,7 @@ class EClassColourManager :
{
private:
std::map<std::string, Vector3> _overrides;
sigc::signal<void, const std::string&> _overrideChangedSignal;
sigc::signal<void, const std::string&, bool> _overrideChangedSignal;

public:
// IColourManager implementation
Expand All @@ -21,7 +21,7 @@ class EClassColourManager :
void foreachOverrideColour(const std::function<void(const std::string&, const Vector3&)>& functor) override;
void removeOverrideColour(const std::string& eclass) override;
void clearOverrideColours() override;
sigc::signal<void, const std::string&>& sig_overrideColourChanged() override;
sigc::signal<void, const std::string&, bool>& sig_overrideColourChanged() override;

// RegisterableModule implementation

Expand Down
28 changes: 28 additions & 0 deletions radiantcore/eclass/EClassManager.cpp
Expand Up @@ -315,12 +315,17 @@ void EClassManager::initialiseModule(const IApplicationContext& ctx)
}

GlobalCommandSystem().addCommand("ReloadDefs", std::bind(&EClassManager::reloadDefsCmd, this, std::placeholders::_1));

_eclassColoursChanged = GlobalEclassColourManager().sig_overrideColourChanged().connect(
sigc::mem_fun(this, &EClassManager::onEclassOverrideColourChanged));
}

void EClassManager::shutdownModule()
{
rMessage() << "EntityClassDoom3::shutdownModule called." << std::endl;

_eclassColoursChanged.disconnect();

GlobalFileSystem().removeObserver(*this);

// Unrealise ourselves and wait for threads to finish
Expand All @@ -334,6 +339,29 @@ void EClassManager::shutdownModule()
_models.clear();
}

void EClassManager::onEclassOverrideColourChanged(const std::string& eclass, bool overrideRemoved)
{
// An override colour in the IColourManager instance has changed
// Do we have an affected eclass with that name?
auto foundEclass = _entityClasses.find(eclass);

if (foundEclass == _entityClasses.end())
{
return;
}

// If the override was removed, we just reset the colour
// We perform this switch to avoid firing the eclass changed signal twice
if (overrideRemoved)
{
foundEclass->second->resetColour();
}
else
{
GlobalEclassColourManager().applyColours(foundEclass->second);
}
}

// This takes care of relading the entityDefs and refreshing the scenegraph
void EClassManager::reloadDefsCmd(const cmd::ArgumentList& args)
{
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/eclass/EClassManager.h
@@ -1,5 +1,6 @@
#pragma once

#include <sigc++/connection.h>
#include "ieclass.h"
#include "icommandsystem.h"
#include "ifilesystem.h"
Expand Down Expand Up @@ -51,6 +52,8 @@ class EClassManager :
sigc::signal<void> _defsLoadedSignal;
sigc::signal<void> _defsReloadedSignal;

sigc::connection _eclassColoursChanged;

public:
// Constructor
EClassManager();
Expand Down Expand Up @@ -111,6 +114,8 @@ class EClassManager :
void resolveInheritance();

void reloadDefsCmd(const cmd::ArgumentList& args);

void onEclassOverrideColourChanged(const std::string& eclass, bool overrideRemoved);
};
typedef std::shared_ptr<EClassManager> EClassManagerPtr;

Expand Down

0 comments on commit 8ab345c

Please sign in to comment.