Skip to content

Commit

Permalink
#5430: Add EClassColourManager interface and implementing module whic…
Browse files Browse the repository at this point in the history
…h will deal with the colour overrides for certain entity classes.
  • Loading branch information
codereader committed Nov 24, 2020
1 parent 67c635f commit 2227fd5
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
47 changes: 47 additions & 0 deletions include/ieclasscolours.h
@@ -0,0 +1,47 @@
#pragma once

#include "imodule.h"
#include "ieclass.h"
#include "math/Vector3.h"

namespace eclass
{

/**
* Manages the entity class colour overrides that are applied
* to certain eclasses as defined in the currently active
* colour scheme.
*/
class IColourManager :
public RegisterableModule
{
public:
virtual ~IColourManager() {}

// Register an override for the given entity class, such that the wire/fill shader
// colours of the named entity class are using the given colour instead of the one
// defined in the entityDef block.
// Adding an override for an entity class will replace any existing overrides.
// The colour is given in RGB values with each component in the interval [0..1].
virtual void addOverrideColour(const std::string& eclass, const Vector3& colour) = 0;

// Applies a possible colour override to the given entity class
virtual void applyColours(const IEntityClassPtr& eclass) = 0;

// Removes the override colour for the given entity class
virtual void removeOverrideColour(const std::string& eclass) = 0;
};

}

const char* const MODULE_ECLASS_COLOUR_MANAGER("EclassColourManager");

/**
* Return the global IEClassColourManager to the application.
* \ingroup eclass
*/
inline eclass::IColourManager& GlobalEclassColourManager()
{
static module::InstanceReference<eclass::IColourManager> _reference(MODULE_ECLASS_COLOUR_MANAGER);
return _reference;
}
1 change: 1 addition & 0 deletions radiantcore/Makefile.am
Expand Up @@ -52,6 +52,7 @@ libradiantcore_la_SOURCES = Radiant.cpp \
clipper/SplitAlgorithm.cpp \
commandsystem/CommandSystem.cpp \
eclass/Doom3EntityClass.cpp \
eclass/EClassColourManager.cpp \
eclass/EClassManager.cpp \
entity/ShaderParms.cpp \
entity/EntitySettings.cpp \
Expand Down
47 changes: 47 additions & 0 deletions radiantcore/eclass/EClassColourManager.cpp
@@ -0,0 +1,47 @@
#include "EClassColourManager.h"

#include "module/StaticModule.h"

namespace eclass
{

void EClassColourManager::addOverrideColour(const std::string& eclass, const Vector3& colour)
{
_overrides[eclass] = colour;
}

void EClassColourManager::applyColours(const IEntityClassPtr& eclass)
{
auto foundOverride = _overrides.find(eclass->getName());

if (foundOverride != _overrides.end())
{
eclass->setColour(foundOverride->second);
}
}

void EClassColourManager::removeOverrideColour(const std::string& eclass)
{
_overrides.erase(eclass);
}

const std::string& EClassColourManager::getName() const
{
static std::string _name(MODULE_ECLASS_COLOUR_MANAGER);
return _name;
}

const StringSet& EClassColourManager::getDependencies() const
{
static StringSet _dependencies;
return _dependencies;
}

void EClassColourManager::initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
}

module::StaticModule<EClassColourManager> eclassColourManagerModule;

}
29 changes: 29 additions & 0 deletions radiantcore/eclass/EClassColourManager.h
@@ -0,0 +1,29 @@
#pragma once

#include <map>
#include "ieclasscolours.h"

namespace eclass
{

class EClassColourManager :
public IColourManager
{
private:
std::map<std::string, Vector3> _overrides;

public:
// IColourManager implementation

void addOverrideColour(const std::string& eclass, const Vector3& colour) override;
void applyColours(const IEntityClassPtr& eclass) override;
void removeOverrideColour(const std::string& eclass) override;

// RegisterableModule implementation

const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
};

}
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -39,6 +39,7 @@
<ClCompile Include="..\..\radiantcore\clipper\ClipPoint.cpp" />
<ClCompile Include="..\..\radiantcore\clipper\SplitAlgorithm.cpp" />
<ClCompile Include="..\..\radiantcore\eclass\Doom3EntityClass.cpp" />
<ClCompile Include="..\..\radiantcore\eclass\EClassColourManager.cpp" />
<ClCompile Include="..\..\radiantcore\eclass\EClassManager.cpp" />
<ClCompile Include="..\..\radiantcore\entity\AngleKey.cpp" />
<ClCompile Include="..\..\radiantcore\entity\curve\Curve.cpp" />
Expand Down Expand Up @@ -716,6 +717,7 @@
<ClInclude Include="..\..\radiantcore\clipper\SplitAlgorithm.h" />
<ClInclude Include="..\..\radiantcore\eclass\Doom3EntityClass.h" />
<ClInclude Include="..\..\radiantcore\eclass\Doom3ModelDef.h" />
<ClInclude Include="..\..\radiantcore\eclass\EClassColourManager.h" />
<ClInclude Include="..\..\radiantcore\eclass\EClassManager.h" />
<ClInclude Include="..\..\radiantcore\entity\AngleKey.h" />
<ClInclude Include="..\..\radiantcore\entity\ColourKey.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -997,6 +997,9 @@
<ClCompile Include="..\..\radiantcore\model\export\PatchSurface.cpp">
<Filter>src\model\export</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\eclass\EClassColourManager.cpp">
<Filter>src\eclass</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2031,5 +2034,8 @@
<ClInclude Include="..\..\radiantcore\model\export\PatchSurface.h">
<Filter>src\model\export</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\eclass\EClassColourManager.h">
<Filter>src\eclass</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions tools/msvc/include.vcxproj
Expand Up @@ -111,6 +111,7 @@
<ClInclude Include="..\..\include\idatastream.h" />
<ClInclude Include="..\..\include\idialogmanager.h" />
<ClInclude Include="..\..\include\ieclass.h" />
<ClInclude Include="..\..\include\ieclasscolours.h" />
<ClInclude Include="..\..\include\ieditstopwatch.h" />
<ClInclude Include="..\..\include\ientity.h" />
<ClInclude Include="..\..\include\ientityinspector.h" />
Expand Down

0 comments on commit 2227fd5

Please sign in to comment.