Skip to content

Commit

Permalink
#5231: Split off the eclass colour management from the EClassManager …
Browse files Browse the repository at this point in the history
…itself, as this is UI-related.
  • Loading branch information
codereader committed May 9, 2020
1 parent 64de2a3 commit 68b17e1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 40 deletions.
5 changes: 5 additions & 0 deletions include/ieclass.h
Expand Up @@ -248,6 +248,9 @@ class IEntityClass
/// Return the display colour of this entity class
virtual const Vector3& getColour() const = 0;

// Overrides the colour defined in the .def files
virtual void setColour(const Vector3& colour) = 0;

/**
* Get the named Shader used for rendering this entity class in
* wireframe mode.
Expand Down Expand Up @@ -384,6 +387,8 @@ class IEntityClassManager :
public RegisterableModule
{
public:
/// Signal emitted when all DEFs have been loaded (after module initialisation)
virtual sigc::signal<void> defsLoadedSignal() const = 0;

/// Signal emitted when all DEFs are reloaded
virtual sigc::signal<void> defsReloadedSignal() const = 0;
Expand Down
35 changes: 17 additions & 18 deletions radiant/eclassmgr/Doom3EntityClass.h
Expand Up @@ -148,31 +148,30 @@ class Doom3EntityClass

~Doom3EntityClass();

/// Set the display colour
void setColour(const Vector3& colour);

/// Add a new attribute
void addAttribute(const EntityClassAttribute& attribute);

// IEntityClass implementation
std::string getName() const;
const IEntityClass* getParent() const;
sigc::signal<void> changedSignal() const;
bool isFixedSize() const;
AABB getBounds() const;
bool isLight() const;
const Vector3& getColour() const;
const std::string& getWireShader() const;
const std::string& getFillShader() const;
EntityClassAttribute& getAttribute(const std::string& name);
const EntityClassAttribute& getAttribute(const std::string& name) const;
std::string getName() const override;
const IEntityClass* getParent() const override;
sigc::signal<void> changedSignal() const override;
bool isFixedSize() const override;
AABB getBounds() const override;
bool isLight() const override;
const Vector3& getColour() const override;
/// Set the display colour
void setColour(const Vector3& colour) override;
const std::string& getWireShader() const override;
const std::string& getFillShader() const override;
EntityClassAttribute& getAttribute(const std::string& name) override;
const EntityClassAttribute& getAttribute(const std::string& name) const override;
void forEachClassAttribute(std::function<void(const EntityClassAttribute&)>,
bool) const;
bool) const override;

const std::string& getModelPath() const { return _model; }
const std::string& getSkin() const { return _skin; }
const std::string& getModelPath() const override { return _model; }
const std::string& getSkin() const override { return _skin; }

bool isOfType(const std::string& className);
bool isOfType(const std::string& className) override;

/// Set a model on this entity class.
void setModelPath(const std::string& path) {
Expand Down
33 changes: 11 additions & 22 deletions radiant/eclassmgr/EClassManager.cpp
Expand Up @@ -8,7 +8,6 @@
#include "icommandsystem.h"
#include "imainframe.h"
#include "iradiant.h"
#include "iuimanager.h"
#include "ifilesystem.h"
#include "parser/DefTokeniser.h"

Expand All @@ -30,6 +29,11 @@ EClassManager::EClassManager() :
_curParseStamp(0)
{}

sigc::signal<void> EClassManager::defsLoadedSignal() const
{
return _defsLoadedSignal;
}

sigc::signal<void> EClassManager::defsReloadedSignal() const
{
return _defsReloadedSignal;
Expand Down Expand Up @@ -168,24 +172,6 @@ void EClassManager::resolveInheritance()
}
}
}

// greebo: Override the eclass colours of two special entityclasses
Vector3 worlspawnColour = ColourSchemes().getColour("default_brush");
Vector3 lightColour = ColourSchemes().getColour("light_volumes");

Doom3EntityClassPtr light = findInternal("light");

if (light)
{
light->setColour(lightColour);
}

Doom3EntityClassPtr worldspawn = findInternal("worldspawn");

if (worldspawn)
{
worldspawn->setColour(worlspawnColour);
}
}

void EClassManager::ensureDefsLoaded()
Expand All @@ -199,6 +185,8 @@ void EClassManager::loadDefAndResolveInheritance()
{
parseDefFiles();
resolveInheritance();

_defsLoadedSignal.emit();
}

void EClassManager::realise()
Expand Down Expand Up @@ -287,14 +275,15 @@ const std::string& EClassManager::getName() const {
return _name;
}

const StringSet& EClassManager::getDependencies() const {
const StringSet& EClassManager::getDependencies() const
{
static StringSet _dependencies;

if (_dependencies.empty()) {
if (_dependencies.empty())
{
_dependencies.insert(MODULE_VIRTUALFILESYSTEM);
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_RENDERSYSTEM);
_dependencies.insert(MODULE_UIMANAGER);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_COMMANDSYSTEM);
}
Expand Down
2 changes: 2 additions & 0 deletions radiant/eclassmgr/EClassManager.h
Expand Up @@ -48,13 +48,15 @@ class EClassManager :
// definitions have been parsed
std::size_t _curParseStamp;

sigc::signal<void> _defsLoadedSignal;
sigc::signal<void> _defsReloadedSignal;

public:
// Constructor
EClassManager();

// IEntityClassManager implementation
sigc::signal<void> defsLoadedSignal() const override;
sigc::signal<void> defsReloadedSignal() const override;
virtual IEntityClassPtr findOrInsert(const std::string& name,
bool has_brushes) override;
Expand Down
75 changes: 75 additions & 0 deletions radiant/ui/EntityClassColourManager.h
@@ -0,0 +1,75 @@
#pragma once

#include <sigc++/functors/mem_fun.h>
#include <sigc++/connection.h>
#include "ieclass.h"
#include "iuimanager.h"
#include "wxutil/event/SingleIdleCallback.h"

namespace ui
{

class EntityClassColourManager :
public wxutil::SingleIdleCallback
{
private:
sigc::connection _loadedConn;
sigc::connection _reloadedConn;

public:
EntityClassColourManager()
{
_loadedConn = GlobalEntityClassManager().defsLoadedSignal().connect(
sigc::mem_fun(*this, &EntityClassColourManager::onEntityDefsLoaded)
);
_reloadedConn = GlobalEntityClassManager().defsReloadedSignal().connect(
sigc::mem_fun(*this, &EntityClassColourManager::onEntityDefsReloaded)
);
}

~EntityClassColourManager()
{
_loadedConn.disconnect();
_reloadedConn.disconnect();
}

protected:
void onIdle() override
{
applyColourScheme();
}

private:
void applyColourScheme()
{
// greebo: Override the eclass colours of two special entityclasses
Vector3 worlspawnColour = ColourSchemes().getColour("default_brush");
Vector3 lightColour = ColourSchemes().getColour("light_volumes");

auto light = GlobalEntityClassManager().findClass("light");

if (light)
{
light->setColour(lightColour);
}

auto worldspawn = GlobalEntityClassManager().findClass("worldspawn");

if (worldspawn)
{
worldspawn->setColour(worlspawnColour);
}
}

void onEntityDefsLoaded()
{
requestIdleCallback();
}

void onEntityDefsReloaded()
{
requestIdleCallback();
}
};

}
3 changes: 3 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -125,10 +125,13 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)
FilterOrthoContextMenuItem::DeselectByFilter),
IOrthoContextMenu::SECTION_FILTER
);

_eClassColourManager.reset(new EntityClassColourManager);
}

void UserInterfaceModule::shutdownModule()
{
_eClassColourManager.reset();
}

void UserInterfaceModule::refreshShadersCmd(const cmd::ArgumentList& args)
Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -4,6 +4,8 @@
#include "iorthocontextmenu.h"
#include "icommandsystem.h"

#include "EntityClassColourManager.h"

namespace ui
{

Expand All @@ -17,6 +19,9 @@ namespace ui
class UserInterfaceModule :
public RegisterableModule
{
private:
std::unique_ptr<EntityClassColourManager> _eClassColourManager;

public:
// RegisterableModule
const std::string & getName() const override;
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -1195,6 +1195,7 @@
<ClInclude Include="..\..\radiant\ui\Documentation.h" />
<ClInclude Include="..\..\radiant\ui\eclasstree\EClassTree.h" />
<ClInclude Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.h" />
<ClInclude Include="..\..\radiant\ui\EntityClassColourManager.h" />
<ClInclude Include="..\..\radiant\ui\entitylist\EntityList.h" />
<ClInclude Include="..\..\radiant\ui\entitylist\GraphTreeModel.h" />
<ClInclude Include="..\..\radiant\ui\entitylist\GraphTreeModelPopulator.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -2808,6 +2808,9 @@
<ClInclude Include="..\..\radiant\ui\filters\editor\FilterEditor.h">
<Filter>src\ui\filters\editor</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\EntityClassColourManager.h">
<Filter>src\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 68b17e1

Please sign in to comment.