Skip to content

Commit

Permalink
#5372: Attempt to fix brushes occasionally falling back to their blac…
Browse files Browse the repository at this point in the history
…k wire shader colour
  • Loading branch information
codereader committed Nov 3, 2020
1 parent eb63eaa commit df3e421
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 71 deletions.
2 changes: 1 addition & 1 deletion include/ieclass.h
Expand Up @@ -215,7 +215,7 @@ class IEntityClass
public:

/// Signal emitted when entity class contents are changed or reloaded
virtual sigc::signal<void> changedSignal() const = 0;
virtual sigc::signal<void>& changedSignal() = 0;

/// Get the name of this entity class
virtual std::string getName() const = 0;
Expand Down
3 changes: 2 additions & 1 deletion radiant/Makefile.am
Expand Up @@ -45,7 +45,8 @@ darkradiant_SOURCES = main.cpp \
eventmanager/Toggle.cpp \
eventmanager/WidgetToggle.cpp \
render/OpenGLModule.cpp \
ui/UserInterfaceModule.cpp \
ui/EntityClassColourManager.cpp \
ui/UserInterfaceModule.cpp \
ui/Documentation.cpp \
ui/eclasstree/EClassTree.cpp \
ui/eclasstree/EClassTreeBuilder.cpp \
Expand Down
5 changes: 4 additions & 1 deletion radiant/render/OpenGLModule.cpp
Expand Up @@ -24,7 +24,10 @@ void OpenGLModule::sharedContextDestroyed()

void OpenGLModule::drawString(const std::string& string) const
{
ftglRenderFont(_font->getFtglFont(),string.c_str(),0xFFFF);//FTGL_RENDER_ALL);
if (_font)
{
ftglRenderFont(_font->getFtglFont(), string.c_str(), 0xFFFF);//FTGL_RENDER_ALL);
}
}

void OpenGLModule::drawChar(char character) const
Expand Down
66 changes: 66 additions & 0 deletions radiant/ui/EntityClassColourManager.cpp
@@ -0,0 +1,66 @@
#include "EntityClassColourManager.h"

#include <sigc++/functors/mem_fun.h>
#include "ieclass.h"
#include "icolourscheme.h"
#include "UserInterfaceModule.h"

namespace ui
{

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

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

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

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

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

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

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

void EntityClassColourManager::onEntityDefsLoaded()
{
// Signal might receive us from a worker thread
GetUserInterfaceModule().dispatch([this]()
{
applyColourScheme();
});
}

void EntityClassColourManager::onEntityDefsReloaded()
{
// Signal might receive us from a worker thread
GetUserInterfaceModule().dispatch([this]()
{
applyColourScheme();
});
}

}
63 changes: 7 additions & 56 deletions radiant/ui/EntityClassColourManager.h
@@ -1,75 +1,26 @@
#pragma once

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

namespace ui
{

class EntityClassColourManager :
public wxutil::SingleIdleCallback
class EntityClassColourManager
{
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();

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

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

private:
void applyColourScheme()
{
// greebo: Override the eclass colours of two special entityclasses
Vector3 worlspawnColour = GlobalColourSchemeManager().getColour("default_brush");
Vector3 lightColour = GlobalColourSchemeManager().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();
}
void applyColourScheme();

void onEntityDefsLoaded();
void onEntityDefsReloaded();
};

}
4 changes: 3 additions & 1 deletion radiantcore/eclass/Doom3EntityClass.cpp
Expand Up @@ -232,7 +232,7 @@ const IEntityClass* Doom3EntityClass::getParent() const
return _parent;
}

sigc::signal<void> Doom3EntityClass::changedSignal() const
sigc::signal<void>& Doom3EntityClass::changedSignal()
{
return _changedSignal;
}
Expand Down Expand Up @@ -295,6 +295,8 @@ void Doom3EntityClass::setColour(const Vector3& colour)
fmt::format("({0:f} {1:f} {2:f})", _colour[0], _colour[1], _colour[2]);

_wireShader = fmt::format("<{0:f} {1:f} {2:f}>", _colour[0], _colour[1], _colour[2]);

_changedSignal.emit();
}

const Vector3& Doom3EntityClass::getColour() const {
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/eclass/Doom3EntityClass.h
Expand Up @@ -158,7 +158,7 @@ class Doom3EntityClass
// IEntityClass implementation
std::string getName() const override;
const IEntityClass* getParent() const override;
sigc::signal<void> changedSignal() const override;
sigc::signal<void>& changedSignal() override;
bool isFixedSize() const override;
AABB getBounds() const override;
bool isLight() const override;
Expand Down
33 changes: 23 additions & 10 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -117,6 +117,9 @@ void EntityNode::onEntityClassChanged()
{
// By default, we notify the KeyObservers attached to this entity
_keyObservers.refreshObservers();

// The colour might have changed too, so re-acquire the shaders if possible
acquireShaders();
}

void EntityNode::addKeyObserver(const std::string& key, KeyObserver& observer)
Expand Down Expand Up @@ -269,20 +272,30 @@ void EntityNode::renderWireframe(RenderableCollector& collector,
}
}

void EntityNode::acquireShaders()
{
acquireShaders(getRenderSystem());
}

void EntityNode::acquireShaders(const RenderSystemPtr& renderSystem)
{
if (renderSystem)
{
_fillShader = renderSystem->capture(_entity.getEntityClass()->getFillShader());
_wireShader = renderSystem->capture(_entity.getEntityClass()->getWireShader());
}
else
{
_fillShader.reset();
_wireShader.reset();
}
}

void EntityNode::setRenderSystem(const RenderSystemPtr& renderSystem)
{
SelectableNode::setRenderSystem(renderSystem);

if (renderSystem)
{
_fillShader = renderSystem->capture(_entity.getEntityClass()->getFillShader());
_wireShader = renderSystem->capture(_entity.getEntityClass()->getWireShader());
}
else
{
_fillShader.reset();
_wireShader.reset();
}
acquireShaders(renderSystem);

// The colour key is maintaining a shader object as well
_colourKey.setRenderSystem(renderSystem);
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -169,6 +169,9 @@ class EntityNode :

// Private function target - wraps to virtual protected signal
void _modelKeyChanged(const std::string& value);

void acquireShaders();
void acquireShaders(const RenderSystemPtr& renderSystem);
};

} // namespace entity
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -250,6 +250,7 @@
<ClCompile Include="..\..\radiant\ui\Documentation.cpp" />
<ClCompile Include="..\..\radiant\ui\eclasstree\EClassTree.cpp" />
<ClCompile Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.cpp" />
<ClCompile Include="..\..\radiant\ui\EntityClassColourManager.cpp" />
<ClCompile Include="..\..\radiant\ui\entitylist\EntityList.cpp" />
<ClCompile Include="..\..\radiant\ui\entitylist\GraphTreeModel.cpp" />
<ClCompile Include="..\..\radiant\ui\filters\editor\FilterDialog.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -667,6 +667,9 @@
<ClCompile Include="..\..\radiant\ui\common\SoundShaderDefinitionView.cpp">
<Filter>src\ui\common</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\EntityClassColourManager.cpp">
<Filter>src\ui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down

0 comments on commit df3e421

Please sign in to comment.