Skip to content

Commit

Permalink
Refactor filter system InstanceUpdateWalker
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 29, 2020
1 parent 93f9ead commit b3c7017
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
5 changes: 3 additions & 2 deletions radiant/filters/BasicFilterSystem.cpp
Expand Up @@ -558,10 +558,11 @@ bool BasicFilterSystem::setFilterRules(const std::string& filter,
return false; // not found or readonly
}

void BasicFilterSystem::updateSubgraph(const scene::INodePtr& root) {
void BasicFilterSystem::updateSubgraph(const scene::INodePtr& root)
{
// Construct an InstanceUpdateWalker and traverse the scenegraph to update
// all instances
InstanceUpdateWalker walker;
InstanceUpdateWalker walker(*this);
root->traverse(walker);
}

Expand Down
53 changes: 28 additions & 25 deletions radiant/filters/InstanceUpdateWalker.h
Expand Up @@ -7,14 +7,16 @@
#include "ipatch.h"
#include "ibrush.h"

namespace filters {
namespace filters
{

// Walker: de-selects a complete subgraph
class Deselector :
public scene::NodeVisitor
{
public:
bool pre(const scene::INodePtr& node) {
bool pre(const scene::INodePtr& node) override
{
Node_setSelected(node, false);
return true;
}
Expand All @@ -32,7 +34,7 @@ class NodeVisibilityUpdater :
_filtered(setFiltered)
{}

bool pre(const scene::INodePtr& node)
bool pre(const scene::INodePtr& node) override
{
node->setFiltered(_filtered);
return true;
Expand All @@ -47,62 +49,64 @@ class InstanceUpdateWalker :
public scene::NodeVisitor
{
private:
FilterSystem& _filterSystem;

// Helper visitors to update subgraphs
NodeVisibilityUpdater _hideWalker;
NodeVisibilityUpdater _showWalker;
Deselector _deselector;

// Cached boolean to avoid GlobalFilterSystem() queries for each node
// Cached boolean to avoid FilterSystem queries for each node
bool _patchesAreVisible;
bool _brushesAreVisible;

public:
InstanceUpdateWalker() :
InstanceUpdateWalker(FilterSystem& filterSystem) :
_filterSystem(filterSystem),
_hideWalker(true),
_showWalker(false),
_patchesAreVisible(GlobalFilterSystem().isVisible(FilterRule::TYPE_OBJECT, "patch")),
_brushesAreVisible(GlobalFilterSystem().isVisible(FilterRule::TYPE_OBJECT, "brush"))
_patchesAreVisible(_filterSystem.isVisible(FilterRule::TYPE_OBJECT, "patch")),
_brushesAreVisible(_filterSystem.isVisible(FilterRule::TYPE_OBJECT, "brush"))
{}

// Pre-descent walker function
bool pre(const scene::INodePtr& node)
bool pre(const scene::INodePtr& node) override
{
// Retrieve the parent entity and check its entity class.
Entity* entity = Node_getEntity(node);

if (entity != NULL)
// Check entity eclass and spawnargs
if (Node_isEntity(node))
{
Entity* entity = Node_getEntity(node);

// Check the eclass first
bool entityIsVisible = GlobalFilterSystem().isEntityVisible(FilterRule::TYPE_ENTITYCLASS, *entity) &&
GlobalFilterSystem().isEntityVisible(FilterRule::TYPE_ENTITYKEYVALUE, *entity);
bool entityIsVisible = _filterSystem.isEntityVisible(FilterRule::TYPE_ENTITYCLASS, *entity) &&
_filterSystem.isEntityVisible(FilterRule::TYPE_ENTITYKEYVALUE, *entity);

node->traverse(entityIsVisible ? _showWalker : _hideWalker);

if (!entityIsVisible)
{
// de-select this node and all children
Deselector deselector;
node->traverse(deselector);
node->traverse(_deselector);
}

// If the entity is hidden, don't traverse the child nodes
return entityIsVisible;
}

// greebo: Update visibility of Patches
IPatchNodePtr patchNode = std::dynamic_pointer_cast<IPatchNode>(node);

if (patchNode != NULL)
if (Node_isPatch(node))
{
auto patchNode = std::dynamic_pointer_cast<IPatchNode>(node);

bool isVisible = _patchesAreVisible && patchNode->getPatch().hasVisibleMaterial();

node->traverse(isVisible ? _showWalker : _hideWalker);
}

// greebo: Update visibility of Brushes
IBrush* brush = Node_getIBrush(node);

if (brush != NULL)
else if (Node_isBrush(node))
{
auto brush = Node_getIBrush(node);

bool isVisible = _brushesAreVisible && brush->hasVisibleMaterial();

node->traverse(isVisible ? _showWalker : _hideWalker);
Expand All @@ -117,8 +121,7 @@ class InstanceUpdateWalker :
if (!node->visible())
{
// de-select this node and all children
Deselector deselector;
node->traverse(deselector);
node->traverse(_deselector);
}

// Continue the traversal
Expand Down

0 comments on commit b3c7017

Please sign in to comment.