Skip to content

Commit

Permalink
#5893: Handle visibiltiy of attached entities. Move show/hide functio…
Browse files Browse the repository at this point in the history
…ns to scenelib.h
  • Loading branch information
codereader committed Feb 12, 2022
1 parent 42abd0b commit d7e9a56
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 52 deletions.
49 changes: 49 additions & 0 deletions libs/scenelib.h
Expand Up @@ -235,6 +235,55 @@ inline bool Node_hasSelectedChildNodes(const scene::INodePtr& node)
namespace scene
{

inline void setNodeHidden(const INodePtr& node, bool hide)
{
if (!node->supportsStateFlag(Node::eHidden))
{
return;
}

if (hide)
{
node->enable(Node::eHidden);
}
else
{
node->disable(Node::eHidden);
}
}

inline void showNode(const INodePtr& node)
{
setNodeHidden(node, false);
}

inline void showSubgraph(const INodePtr& node)
{
showNode(node);

node->foreachNode([&](const INodePtr& child)
{
showNode(child);
return true;
});
}

inline void hideNode(const INodePtr& node)
{
setNodeHidden(node, true);
}

inline void hideSubgraph(const INodePtr& node)
{
hideNode(node);

node->foreachNode([&](const INodePtr& child)
{
hideNode(child);
return true;
});
}

/**
* greebo: This walker removes all encountered child nodes without
* traversing each node's children. This deselects all removed nodes as well.
Expand Down
27 changes: 27 additions & 0 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -317,6 +317,11 @@ void EntityNode::onInsertIntoScene(scene::IMapRootNode& root)

attachToRenderSystem();

for (const auto& attachment : _attachedEnts)
{
attachment->onInsertIntoScene(root);
}

SelectableNode::onInsertIntoScene(root);
TargetableNode::onInsertIntoScene(root);
}
Expand All @@ -328,6 +333,11 @@ void EntityNode::onRemoveFromScene(scene::IMapRootNode& root)

detachFromRenderSystem();

for (const auto& attachment : _attachedEnts)
{
attachment->onRemoveFromScene(root);
}

_modelKey.disconnectUndoSystem(root.getUndoSystem());
_spawnArgs.disconnectUndoSystem(root.getUndoSystem());

Expand Down Expand Up @@ -451,6 +461,23 @@ std::size_t EntityNode::getHighlightFlags()
return isGroupMember() ? (Highlight::Selected | Highlight::GroupMember) : Highlight::Selected;
}

void EntityNode::onVisibilityChanged(bool isVisibleNow)
{
SelectableNode::onVisibilityChanged(isVisibleNow);

for (const auto& node : _attachedEnts)
{
if (isVisibleNow)
{
scene::showSubgraph(node);
}
else
{
scene::hideSubgraph(node);
}
}
}

ModelKey& EntityNode::getModelKey()
{
return _modelKey;
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -190,6 +190,8 @@ class EntityNode :
// Optional implementation: gets invoked by the EntityModule when the settings are changing
virtual void onEntitySettingsChanged();

void onVisibilityChanged(bool isVisibleNow) override;

// Returns the current world origin of this entity (also up to date during transformations)
virtual const Vector3& getWorldPosition() const = 0;

Expand Down
55 changes: 3 additions & 52 deletions radiantcore/selection/algorithm/General.cpp
Expand Up @@ -170,64 +170,15 @@ void selectAllOfType(const cmd::ArgumentList& args)
SceneChangeNotify();
}

class HideSubgraphWalker :
public scene::NodeVisitor
{
public:
bool pre(const scene::INodePtr& node)
{
if (node->supportsStateFlag(scene::Node::eHidden))
{
node->enable(scene::Node::eHidden);
}

return true;
}
};

class ShowSubgraphWalker :
public scene::NodeVisitor
{
public:
bool pre(const scene::INodePtr& node)
{
if (node->supportsStateFlag(scene::Node::eHidden))
{
node->disable(scene::Node::eHidden);
}

return true;
}
};

inline void hideSubgraph(const scene::INodePtr& node, bool hide)
{
if (hide)
{
HideSubgraphWalker walker;
node->traverse(walker);
}
else
{
ShowSubgraphWalker walker;
node->traverse(walker);
}
}

inline void hideNode(const scene::INodePtr& node, bool hide)
{
if (!node->supportsStateFlag(scene::Node::eHidden))
{
return;
}

if (hide)
{
node->enable(scene::Node::eHidden);
scene::hideSubgraph(node);
}
else
{
node->disable(scene::Node::eHidden);
scene::showSubgraph(node);
}
}

Expand Down Expand Up @@ -332,7 +283,7 @@ class HideAllWalker :
{}

bool pre(const scene::INodePtr& node) {
hideNode(node, _hide);
scene::setNodeHidden(node, _hide);
return true;
}
};
Expand Down

0 comments on commit d7e9a56

Please sign in to comment.