From d228c9c02bea090ec60c0848804aa814bb5555b5 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 25 Oct 2021 20:44:53 +0200 Subject: [PATCH] #5408: Rename interface header file to imapfilechangetracker.h --- include/imap.h | 2 +- .../{mapfile.h => imapfilechangetracker.h} | 0 include/precompiled_interfaces.h | 2 +- libs/ObservedUndoable.h | 2 +- libs/UndoFileChangeTracker.h | 79 ++++++++----------- libs/scene/BasicRootNode.h | 2 +- libs/scene/TraversableNodeSet.cpp | 2 +- radiantcore/brush/Face.h | 2 +- radiantcore/entity/ModelKey.h | 2 +- radiantcore/map/Map.cpp | 2 +- radiantcore/map/MapResource.cpp | 6 +- radiantcore/map/autosaver/AutoSaver.cpp | 10 +-- radiantcore/map/autosaver/AutoSaver.h | 2 +- radiantcore/model/StaticModel.h | 2 +- radiantcore/patch/Patch.h | 2 +- radiantcore/undo/StackFiller.h | 2 +- radiantcore/undo/UndoSystem.cpp | 2 +- tools/msvc/include.vcxproj | 2 +- tools/msvc/include.vcxproj.filters | 2 +- 19 files changed, 56 insertions(+), 69 deletions(-) rename include/{mapfile.h => imapfilechangetracker.h} (100%) diff --git a/include/imap.h b/include/imap.h index 0bdbb34598..4d993d4391 100644 --- a/include/imap.h +++ b/include/imap.h @@ -22,7 +22,7 @@ const char* const LOAD_PREFAB_AT_CMD = "LoadPrefabAt"; class INamespace; typedef std::shared_ptr INamespacePtr; -// see mapfile.h +// see imapfilechangetracker.h class IMapFileChangeTracker; // see ientity.h diff --git a/include/mapfile.h b/include/imapfilechangetracker.h similarity index 100% rename from include/mapfile.h rename to include/imapfilechangetracker.h diff --git a/include/precompiled_interfaces.h b/include/precompiled_interfaces.h index 8a81994ca4..336b1f01e9 100644 --- a/include/precompiled_interfaces.h +++ b/include/precompiled_interfaces.h @@ -81,7 +81,7 @@ #include "itransformnode.h" #include "iundo.h" #include "ivolumetest.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "modelskin.h" #include "ModResource.h" #include "ishaderlayer.h" diff --git a/libs/ObservedUndoable.h b/libs/ObservedUndoable.h index e36e606f8c..bec9075b3b 100644 --- a/libs/ObservedUndoable.h +++ b/libs/ObservedUndoable.h @@ -1,7 +1,7 @@ #pragma once #include "iundo.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include #include "BasicUndoMemento.h" diff --git a/libs/UndoFileChangeTracker.h b/libs/UndoFileChangeTracker.h index 9507fadc6f..2986aa3c2e 100644 --- a/libs/UndoFileChangeTracker.h +++ b/libs/UndoFileChangeTracker.h @@ -1,7 +1,7 @@ #pragma once #include "iundo.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include #include @@ -12,78 +12,65 @@ class UndoFileChangeTracker : private: constexpr static std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits::max(); - std::size_t _size; - std::size_t _saved; + std::size_t _currentChangeCount; + std::size_t _savedChangeCount; sigc::signal _changed; public: UndoFileChangeTracker() : - _size(0), - _saved(MAPFILE_MAX_CHANGES) + _currentChangeCount(0), + _savedChangeCount(MAPFILE_MAX_CHANGES) {} - void push() + void setSavedChangeCount() override { - ++_size; + _savedChangeCount = _currentChangeCount; _changed.emit(); - } - - void pop() - { - --_size; - _changed.emit(); - } - - void pushOperation() - { - if (_size < _saved) - { - // redo queue has been flushed.. it is now impossible to get back to the saved state via undo/redo - _saved = MAPFILE_MAX_CHANGES; - } - push(); - } - - void clear() override - { - _size = 0; - _changed.emit(); - } - - void save() override - { - _saved = _size; - _changed.emit(); - } + } // Returns true if the current undo history position corresponds to the most recently saved state - bool saved() const override + bool isAtSavedPosition() const override { - return _saved == _size; - } + return _savedChangeCount == _currentChangeCount; + } sigc::signal& signal_changed() override { return _changed; - } + } - std::size_t changes() const override + std::size_t getCurrentChangeCount() const override { - return _size; - } + return _currentChangeCount; + } void onOperationRecorded() override { - pushOperation(); + if (_currentChangeCount < _savedChangeCount) + { + // redo queue has been flushed.. it is now impossible to get back to the saved state via undo/redo + _savedChangeCount = MAPFILE_MAX_CHANGES; + } + + ++_currentChangeCount; + _changed.emit(); } void onOperationUndone() override { - pop(); + --_currentChangeCount; + _changed.emit(); } void onOperationRedone() override { - push(); + ++_currentChangeCount; + _changed.emit(); + } + + void onAllOperationsCleared() override + { + _currentChangeCount = 0; + _changed.emit(); } }; diff --git a/libs/scene/BasicRootNode.h b/libs/scene/BasicRootNode.h index 43173aebd5..7a64a37888 100644 --- a/libs/scene/BasicRootNode.h +++ b/libs/scene/BasicRootNode.h @@ -1,7 +1,7 @@ #pragma once #include "imap.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "ilayer.h" #include "ientity.h" #include "iundo.h" diff --git a/libs/scene/TraversableNodeSet.cpp b/libs/scene/TraversableNodeSet.cpp index 80fa78da0b..627b45bd10 100644 --- a/libs/scene/TraversableNodeSet.cpp +++ b/libs/scene/TraversableNodeSet.cpp @@ -4,7 +4,7 @@ #include #include "LayerValidityCheckWalker.h" #include "BasicUndoMemento.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "Node.h" namespace scene diff --git a/radiantcore/brush/Face.h b/radiantcore/brush/Face.h index 8cfe22d971..9ab4089e80 100644 --- a/radiantcore/brush/Face.h +++ b/radiantcore/brush/Face.h @@ -2,7 +2,7 @@ #include "irender.h" #include "iundo.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "iselectiontest.h" #include diff --git a/radiantcore/entity/ModelKey.h b/radiantcore/entity/ModelKey.h index d78e7a1b23..2733002647 100644 --- a/radiantcore/entity/ModelKey.h +++ b/radiantcore/entity/ModelKey.h @@ -2,7 +2,7 @@ #include #include "inode.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "ObservedUndoable.h" /** diff --git a/radiantcore/map/Map.cpp b/radiantcore/map/Map.cpp index fe981ef6de..dc6a1966f3 100644 --- a/radiantcore/map/Map.cpp +++ b/radiantcore/map/Map.cpp @@ -80,7 +80,7 @@ void Map::clearMapResource() // Map is unnamed or load failed, reset map resource node to empty _resource->clear(); - _resource->getRootNode()->getUndoChangeTracker().save(); + _resource->getRootNode()->getUndoChangeTracker().setSavedChangeCount(); // Rename the map to "unnamed" in any case to avoid overwriting the failed map setMapName(_(MAP_UNNAMED_STRING)); diff --git a/radiantcore/map/MapResource.cpp b/radiantcore/map/MapResource.cpp index 47df7a87e5..feca5058d4 100644 --- a/radiantcore/map/MapResource.cpp +++ b/radiantcore/map/MapResource.cpp @@ -13,7 +13,7 @@ #include "imapinfofile.h" #include "map/RootNode.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "gamelib.h" #include "debugging/debugging.h" #include "os/path.h" @@ -267,14 +267,14 @@ sigc::signal& MapResource::signal_modifiedStatusChanged() void MapResource::onMapChanged() { - _signalModifiedStatusChanged.emit(!_mapRoot->getUndoChangeTracker().saved()); + _signalModifiedStatusChanged.emit(!_mapRoot->getUndoChangeTracker().isAtSavedPosition()); } void MapResource::mapSave() { if (_mapRoot) { - _mapRoot->getUndoChangeTracker().save(); + _mapRoot->getUndoChangeTracker().setSavedChangeCount(); } } diff --git a/radiantcore/map/autosaver/AutoSaver.cpp b/radiantcore/map/autosaver/AutoSaver.cpp index 8011d37c26..faac5544ff 100644 --- a/radiantcore/map/autosaver/AutoSaver.cpp +++ b/radiantcore/map/autosaver/AutoSaver.cpp @@ -3,7 +3,7 @@ #include "i18n.h" #include #include -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "itextstream.h" #include "iscenegraph.h" #include "iradiant.h" @@ -57,7 +57,7 @@ namespace AutoMapSaver::AutoMapSaver() : _snapshotsEnabled(false), - _changes(0) + _savedChangeCount(0) {} void AutoMapSaver::registryKeyChanged() @@ -67,7 +67,7 @@ void AutoMapSaver::registryKeyChanged() void AutoMapSaver::clearChanges() { - _changes = 0; + _savedChangeCount = 0; } void AutoMapSaver::saveSnapshot() @@ -195,7 +195,7 @@ void AutoMapSaver::collectExistingSnapshots(std::map& existing bool AutoMapSaver::runAutosaveCheck() { // Check, if changes have been made since the last autosave - if (!GlobalSceneGraph().root() || _changes == GlobalSceneGraph().root()->getUndoChangeTracker().changes()) + if (!GlobalSceneGraph().root() || _savedChangeCount == GlobalSceneGraph().root()->getUndoChangeTracker().getCurrentChangeCount()) { return false; } @@ -215,7 +215,7 @@ bool AutoMapSaver::runAutosaveCheck() void AutoMapSaver::performAutosave() { // Remember the change tracking counter - _changes = GlobalSceneGraph().root()->getUndoChangeTracker().changes(); + _savedChangeCount = GlobalSceneGraph().root()->getUndoChangeTracker().getCurrentChangeCount(); // only snapshot if not working on an unnamed map if (_snapshotsEnabled && !GlobalMapModule().isUnnamed()) diff --git a/radiantcore/map/autosaver/AutoSaver.h b/radiantcore/map/autosaver/AutoSaver.h index 204285d254..3fcf98bc0b 100644 --- a/radiantcore/map/autosaver/AutoSaver.h +++ b/radiantcore/map/autosaver/AutoSaver.h @@ -23,7 +23,7 @@ class AutoMapSaver final : // TRUE, if the autosaver generates snapshots bool _snapshotsEnabled; - std::size_t _changes; + std::size_t _savedChangeCount; std::vector _signalConnections; diff --git a/radiantcore/model/StaticModel.h b/radiantcore/model/StaticModel.h index 6b5aa941c3..3d8e40d16d 100644 --- a/radiantcore/model/StaticModel.h +++ b/radiantcore/model/StaticModel.h @@ -1,7 +1,7 @@ #pragma once #include "iundo.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "imodel.h" #include "math/AABB.h" #include "imodelsurface.h" diff --git a/radiantcore/patch/Patch.h b/radiantcore/patch/Patch.h index 0005b8d9ea..e9c90c75e6 100644 --- a/radiantcore/patch/Patch.h +++ b/radiantcore/patch/Patch.h @@ -6,7 +6,7 @@ #include "editable.h" #include "iundo.h" #include "irender.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "SurfaceShader.h" #include "PatchConstants.h" diff --git a/radiantcore/undo/StackFiller.h b/radiantcore/undo/StackFiller.h index 131822f3c4..b3507d2ea5 100644 --- a/radiantcore/undo/StackFiller.h +++ b/radiantcore/undo/StackFiller.h @@ -1,7 +1,7 @@ #pragma once #include "iundo.h" -#include "mapfile.h" +#include "imapfilechangetracker.h" #include "Stack.h" namespace undo diff --git a/radiantcore/undo/UndoSystem.cpp b/radiantcore/undo/UndoSystem.cpp index b04b9f4267..b57b451407 100644 --- a/radiantcore/undo/UndoSystem.cpp +++ b/radiantcore/undo/UndoSystem.cpp @@ -153,7 +153,7 @@ void UndoSystem::clear() setActiveUndoStack(nullptr); _undoStack.clear(); _redoStack.clear(); - foreachTracker([&](Tracker& tracker) { tracker.clear(); }); + foreachTracker([&](Tracker& tracker) { tracker.onAllOperationsCleared(); }); // greebo: This is called on map shutdown, so don't clear the observers, // there are some "persistent" observers like EntityInspector and ShaderClipboard diff --git a/tools/msvc/include.vcxproj b/tools/msvc/include.vcxproj index 6c615d9596..b290c063d0 100644 --- a/tools/msvc/include.vcxproj +++ b/tools/msvc/include.vcxproj @@ -140,6 +140,7 @@ + @@ -196,7 +197,6 @@ - diff --git a/tools/msvc/include.vcxproj.filters b/tools/msvc/include.vcxproj.filters index 822b0d464a..385793a9b9 100644 --- a/tools/msvc/include.vcxproj.filters +++ b/tools/msvc/include.vcxproj.filters @@ -100,7 +100,6 @@ - @@ -162,6 +161,7 @@ ui +