Skip to content

Commit

Permalink
#5408: Each scenegraph can monitor its own root node undo system, it …
Browse files Browse the repository at this point in the history
…doesn't need to be actively called from every undo system instance.
  • Loading branch information
codereader committed Oct 29, 2021
1 parent 4e9291a commit d6612b8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
34 changes: 33 additions & 1 deletion radiantcore/scenegraph/SceneGraph.cpp
Expand Up @@ -76,6 +76,8 @@ void SceneGraph::setRoot(const IMapRootNodePtr& newRoot)
return;
}

_undoEventHandler.disconnect();

if (_root)
{
// "Uninstantiate" the whole scene
Expand All @@ -86,17 +88,47 @@ void SceneGraph::setRoot(const IMapRootNodePtr& newRoot)
_root = newRoot;

// Refresh the space partition class
_spacePartition = ISpacePartitionSystemPtr(new Octree);
_spacePartition = std::make_shared<Octree>();

if (_root)
{
// New root not NULL, "instantiate" the whole scene
GraphPtr self = shared_from_this();
InstanceSubgraphWalker instanceWalker(self);
_root->traverse(instanceWalker);

_undoEventHandler = _root->getUndoSystem().signal_undoEvent().connect(
sigc::mem_fun(this, &SceneGraph::onUndoEvent)
);
}
}

void SceneGraph::onUndoEvent(IUndoSystem::EventType type, const std::string& operationName)
{
if (type == IUndoSystem::EventType::OperationUndone)
{
// Trigger the onPostUndo event on all scene nodes
foreachNode([&](const INodePtr& node)->bool
{
node->onPostUndo();
return true;
});

sceneChanged();
}
else if (type == IUndoSystem::EventType::OperationRedone)
{
// Trigger the onPostRedo event on all scene nodes
foreachNode([&](const INodePtr& node)->bool
{
node->onPostRedo();
return true;
});

sceneChanged();
}
}

void SceneGraph::boundsChanged()
{
_sigBoundsChanged();
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/scenegraph/SceneGraph.h
Expand Up @@ -3,6 +3,7 @@
#include <map>
#include <list>
#include <sigc++/signal.h>
#include <sigc++/connection.h>

#include "iscenegraph.h"
#include "imodule.h"
Expand Down Expand Up @@ -51,6 +52,8 @@ class SceneGraph :

bool _traversalOngoing;

sigc::connection _undoEventHandler;

public:
SceneGraph();

Expand Down Expand Up @@ -100,6 +103,8 @@ class SceneGraph :
const INode::VisitorFunc& functor, bool visitHidden);

void flushActionBuffer();

void onUndoEvent(IUndoSystem::EventType type, const std::string& operationName);
};
typedef std::shared_ptr<SceneGraph> SceneGraphPtr;

Expand Down
19 changes: 0 additions & 19 deletions radiantcore/undo/UndoSystem.cpp
@@ -1,7 +1,6 @@
#include "UndoSystem.h"

#include "itextstream.h"
#include "iscenegraph.h"

#include <iostream>

Expand Down Expand Up @@ -96,15 +95,6 @@ void UndoSystem::undo()
finishRedo(operationName);
_undoStack.pop_back();
_eventSignal.emit(EventType::OperationUndone, operationName);

// Trigger the onPostUndo event on all scene nodes
GlobalSceneGraph().foreachNode([&] (const scene::INodePtr& node)->bool
{
node->onPostUndo();
return true;
});

GlobalSceneGraph().sceneChanged();
}

void UndoSystem::redo()
Expand All @@ -130,15 +120,6 @@ void UndoSystem::redo()
finishUndo(operationName);
_redoStack.pop_back();
_eventSignal.emit(EventType::OperationRedone, operationName);

// Trigger the onPostRedo event on all scene nodes
GlobalSceneGraph().foreachNode([&] (const scene::INodePtr& node)->bool
{
node->onPostRedo();
return true;
});

GlobalSceneGraph().sceneChanged();
}

void UndoSystem::clear()
Expand Down

0 comments on commit d6612b8

Please sign in to comment.