Skip to content

Commit

Permalink
#5623: Extract merge operation interface, rename interface header file.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 31, 2021
1 parent 789a748 commit 10cf700
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 23 deletions.
4 changes: 4 additions & 0 deletions include/imap.h
Expand Up @@ -4,6 +4,7 @@
#include "inode.h"
#include "imapexporter.h"
#include "imapformat.h"
#include "imapmerge.h"
#include "ikeyvaluestore.h"
#include <sigc++/signal.h>

Expand Down Expand Up @@ -187,6 +188,9 @@ class IMap :

// Can be called when in EditMode::Merge, will abort the current merge process
virtual void abortMergeOperation() = 0;

// Returns the currently active merge operation (or an empty reference if no merge is ongoing)
virtual scene::merge::IMergeOperation::Ptr getActiveMergeOperation() = 0;
};
typedef std::shared_ptr<IMap> IMapPtr;

Expand Down
17 changes: 17 additions & 0 deletions include/imergeaction.h → include/imapmerge.h
@@ -1,6 +1,7 @@
#pragma once

#include <memory>
#include <functional>
#include "inode.h"

namespace scene
Expand Down Expand Up @@ -69,6 +70,22 @@ class IEntityKeyValueMergeAction :
virtual const std::string& getValue() const = 0;
};

// A MergeOperation groups one or more merge actions
// together in order to apply a set of changes from source => base
class IMergeOperation
{
public:
using Ptr = std::shared_ptr<IMergeOperation>;

virtual ~IMergeOperation() {}

// Executes all active actions defined in this operation
virtual void applyActions() = 0;

// Invokes the given functor for each action in this operation
virtual void foreachAction(const std::function<void(const IMergeAction::Ptr&)>& visitor) = 0;
};

}

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/render/RenderableCollectionWalker.h
@@ -1,7 +1,7 @@
#pragma once

#include "iselection.h"
#include "imergeaction.h"
#include "imapmerge.h"
#include "ientity.h"
#include "ieclass.h"
#include "iscenegraph.h"
Expand Down
2 changes: 1 addition & 1 deletion libs/scene/merge/MergeAction.h
Expand Up @@ -2,7 +2,7 @@

#include <memory>
#include "ientity.h"
#include "imergeaction.h"
#include "imapmerge.h"
#include "../Clone.h"
#include "../scenelib.h"

Expand Down
2 changes: 1 addition & 1 deletion libs/scene/merge/MergeOperation.cpp
Expand Up @@ -101,7 +101,7 @@ void MergeOperation::applyActions()
}
}

void MergeOperation::foreachAction(const std::function<void(const MergeAction::Ptr&)>& visitor)
void MergeOperation::foreachAction(const std::function<void(const IMergeAction::Ptr&)>& visitor)
{
for (const auto& action : _actions)
{
Expand Down
7 changes: 4 additions & 3 deletions libs/scene/merge/MergeOperation.h
Expand Up @@ -13,7 +13,8 @@ namespace merge

// A MergeOperation groups one or more merge actions
// together in order to apply a set of changes from source => base
class MergeOperation
class MergeOperation :
public IMergeOperation
{
private:
scene::IMapRootNodePtr _sourceRoot;
Expand All @@ -36,9 +37,9 @@ class MergeOperation
void addAction(const MergeAction::Ptr& action);

// Executes all active actions defined in this operation
void applyActions();
void applyActions() override;

void foreachAction(const std::function<void(const MergeAction::Ptr&)>& visitor);
void foreachAction(const std::function<void(const IMergeAction::Ptr&)>& visitor) override;

private:
void createActionsForEntity(const ComparisonResult::EntityDifference& difference);
Expand Down
1 change: 0 additions & 1 deletion radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -7,7 +7,6 @@
#include "ieclass.h"
#include "iregistry.h"
#include "ieventmanager.h"
#include "imergeaction.h"
#include "igame.h"
#include "imap.h"
#include "iundo.h"
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/EntityInspector.h
Expand Up @@ -5,7 +5,7 @@
#include "ientityinspector.h"
#include "iradiant.h"
#include "icommandsystem.h"
#include "imergeaction.h"
#include "imapmerge.h"
#include "iselection.h"
#include "ientity.h"
#include "string/string.h"
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/merge/MergeControlDialog.cpp
Expand Up @@ -267,6 +267,7 @@ void MergeControlDialog::onIdle(wxIdleEvent& ev)
if (!_updateNeeded) return;

_updateNeeded = false;
updateSummary();
updateControlSensitivity();
}

Expand Down
11 changes: 8 additions & 3 deletions radiantcore/map/Map.cpp
Expand Up @@ -225,6 +225,11 @@ void Map::abortMergeOperation()
setEditMode(EditMode::Normal);
}

scene::merge::IMergeOperation::Ptr Map::getActiveMergeOperation()
{
return _editMode == EditMode::Merge ? _mergeOperation : scene::merge::IMergeOperation::Ptr();
}

void Map::setMapName(const std::string& newName)
{
bool mapNameChanged = _mapName != newName;
Expand Down Expand Up @@ -1021,10 +1026,10 @@ void Map::createMergeOperation(const scene::merge::ComparisonResult& result)
_mergeOperation = scene::merge::MergeOperation::CreateFromComparisonResult(result);

// Group spawnarg actions into one single node if applicable
std::map<scene::INodePtr, std::vector<scene::merge::MergeAction::Ptr>> entityChanges;
std::vector<scene::merge::MergeAction::Ptr> otherChanges;
std::map<scene::INodePtr, std::vector<scene::merge::IMergeAction::Ptr>> entityChanges;
std::vector<scene::merge::IMergeAction::Ptr> otherChanges;

_mergeOperation->foreachAction([&](const scene::merge::MergeAction::Ptr& action)
_mergeOperation->foreachAction([&](const scene::merge::IMergeAction::Ptr& action)
{
scene::INodePtr affectedNode = action->getAffectedNode();

Expand Down
1 change: 1 addition & 0 deletions radiantcore/map/Map.h
Expand Up @@ -171,6 +171,7 @@ class Map :

void finishMergeOperation() override;
void abortMergeOperation() override;
scene::merge::IMergeOperation::Ptr getActiveMergeOperation() override;

// free all map elements, reinitialize the structures that depend on them
void freeMap();
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/map/MergeActionNode.cpp
Expand Up @@ -137,14 +137,14 @@ void MergeActionNodeBase::unhideAffectedNodes()

// ------------ KeyValueMergeActionNode ----------------------------

KeyValueMergeActionNode::KeyValueMergeActionNode(const std::vector<scene::merge::MergeAction::Ptr>& actions) :
KeyValueMergeActionNode::KeyValueMergeActionNode(const std::vector<scene::merge::IMergeAction::Ptr>& actions) :
_actions(actions)
{
assert(!_actions.empty());

_affectedNode = _actions.front()->getAffectedNode();
assert(std::find_if(_actions.begin(), _actions.end(),
[&](const scene::merge::MergeAction::Ptr& action) { return action->getAffectedNode() != _affectedNode; }) == _actions.end());
[&](const scene::merge::IMergeAction::Ptr& action) { return action->getAffectedNode() != _affectedNode; }) == _actions.end());
}

void KeyValueMergeActionNode::clear()
Expand Down Expand Up @@ -194,7 +194,7 @@ void KeyValueMergeActionNode::onRemoveFromScene(scene::IMapRootNode& rootNode)

// RegularMergeActionNode

RegularMergeActionNode::RegularMergeActionNode(const scene::merge::MergeAction::Ptr& action) :
RegularMergeActionNode::RegularMergeActionNode(const scene::merge::IMergeAction::Ptr& action) :
_action(action)
{
_affectedNode = _action->getAffectedNode();
Expand Down
10 changes: 5 additions & 5 deletions radiantcore/map/MergeActionNode.h
@@ -1,6 +1,6 @@
#pragma once

#include "imergeaction.h"
#include "imapmerge.h"
#include "iselectiontest.h"
#include "math/AABB.h"
#include "scene/SelectableNode.h"
Expand Down Expand Up @@ -71,10 +71,10 @@ class KeyValueMergeActionNode final :
public MergeActionNodeBase
{
private:
std::vector<scene::merge::MergeAction::Ptr> _actions;
std::vector<scene::merge::IMergeAction::Ptr> _actions;

public:
KeyValueMergeActionNode(const std::vector<scene::merge::MergeAction::Ptr>& actions);
KeyValueMergeActionNode(const std::vector<scene::merge::IMergeAction::Ptr>& actions);

void clear() override;

Expand All @@ -98,10 +98,10 @@ class RegularMergeActionNode final :
public MergeActionNodeBase
{
private:
scene::merge::MergeAction::Ptr _action;
scene::merge::IMergeAction::Ptr _action;

public:
RegularMergeActionNode(const scene::merge::MergeAction::Ptr& action);
RegularMergeActionNode(const scene::merge::IMergeAction::Ptr& action);

void onInsertIntoScene(scene::IMapRootNode& rootNode) override;
void onRemoveFromScene(scene::IMapRootNode& rootNode) override;
Expand Down
6 changes: 3 additions & 3 deletions test/MapMerging.cpp
Expand Up @@ -380,7 +380,7 @@ std::shared_ptr<T> findAction(const MergeOperation::Ptr& operation, const std::f
{
std::shared_ptr<T> foundAction;

operation->foreachAction([&](const MergeAction::Ptr& action)
operation->foreachAction([&](const IMergeAction::Ptr& action)
{
if (foundAction) return;

Expand All @@ -399,7 +399,7 @@ std::size_t countActions(const MergeOperation::Ptr& operation, const std::functi
{
std::size_t count = 0;

operation->foreachAction([&](const MergeAction::Ptr& action)
operation->foreachAction([&](const IMergeAction::Ptr& action)
{
auto derivedAction = std::dynamic_pointer_cast<T>(action);

Expand Down Expand Up @@ -772,7 +772,7 @@ TEST_F(MapMergeTest, DeactivatedChangePrimitiveActions)
auto operation = MergeOperation::CreateFromComparisonResult(*result);

// func_static_1 has 2 additions and 1 removal (== 1 addition, 1 replacement)
operation->foreachAction([&](const MergeAction::Ptr& action)
operation->foreachAction([&](const IMergeAction::Ptr& action)
{
auto addChildAction = std::dynamic_pointer_cast<AddChildAction>(action);

Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/include.vcxproj
Expand Up @@ -144,13 +144,13 @@
<ClInclude Include="..\..\include\imapexporter.h" />
<ClInclude Include="..\..\include\imapformat.h" />
<ClInclude Include="..\..\include\imapinfofile.h" />
<ClInclude Include="..\..\include\imapmerge.h" />
<ClInclude Include="..\..\include\imapresource.h" />
<ClInclude Include="..\..\include\imd5anim.h" />
<ClInclude Include="..\..\include\imd5model.h" />
<ClInclude Include="..\..\include\imediabrowser.h" />
<ClInclude Include="..\..\include\imenu.h" />
<ClInclude Include="..\..\include\imenumanager.h" />
<ClInclude Include="..\..\include\imergeaction.h" />
<ClInclude Include="..\..\include\imessagebus.h" />
<ClInclude Include="..\..\include\imodel.h" />
<ClInclude Include="..\..\include\imodelcache.h" />
Expand Down

0 comments on commit 10cf700

Please sign in to comment.