Skip to content

Commit

Permalink
#5408: Rename interface header file to imapfilechangetracker.h
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 25, 2021
1 parent 86112a3 commit d228c9c
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 69 deletions.
2 changes: 1 addition & 1 deletion include/imap.h
Expand Up @@ -22,7 +22,7 @@ const char* const LOAD_PREFAB_AT_CMD = "LoadPrefabAt";
class INamespace;
typedef std::shared_ptr<INamespace> INamespacePtr;

// see mapfile.h
// see imapfilechangetracker.h
class IMapFileChangeTracker;

// see ientity.h
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion include/precompiled_interfaces.h
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libs/ObservedUndoable.h
@@ -1,7 +1,7 @@
#pragma once

#include "iundo.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include <functional>
#include "BasicUndoMemento.h"

Expand Down
79 changes: 33 additions & 46 deletions libs/UndoFileChangeTracker.h
@@ -1,7 +1,7 @@
#pragma once

#include "iundo.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include <limits>
#include <sigc++/signal.h>

Expand All @@ -12,78 +12,65 @@ class UndoFileChangeTracker :
private:
constexpr static std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits<std::size_t>::max();

std::size_t _size;
std::size_t _saved;
std::size_t _currentChangeCount;
std::size_t _savedChangeCount;
sigc::signal<void()> _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<void()>& 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();
}
};
2 changes: 1 addition & 1 deletion 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"
Expand Down
2 changes: 1 addition & 1 deletion libs/scene/TraversableNodeSet.cpp
Expand Up @@ -4,7 +4,7 @@
#include <algorithm>
#include "LayerValidityCheckWalker.h"
#include "BasicUndoMemento.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include "Node.h"

namespace scene
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/Face.h
Expand Up @@ -2,7 +2,7 @@

#include "irender.h"
#include "iundo.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include "iselectiontest.h"
#include <sigc++/connection.h>

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/entity/ModelKey.h
Expand Up @@ -2,7 +2,7 @@

#include <string>
#include "inode.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include "ObservedUndoable.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/map/Map.cpp
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/map/MapResource.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -267,14 +267,14 @@ sigc::signal<void(bool)>& 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();
}
}

Expand Down
10 changes: 5 additions & 5 deletions radiantcore/map/autosaver/AutoSaver.cpp
Expand Up @@ -3,7 +3,7 @@
#include "i18n.h"
#include <numeric>
#include <iostream>
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include "itextstream.h"
#include "iscenegraph.h"
#include "iradiant.h"
Expand Down Expand Up @@ -57,7 +57,7 @@ namespace

AutoMapSaver::AutoMapSaver() :
_snapshotsEnabled(false),
_changes(0)
_savedChangeCount(0)
{}

void AutoMapSaver::registryKeyChanged()
Expand All @@ -67,7 +67,7 @@ void AutoMapSaver::registryKeyChanged()

void AutoMapSaver::clearChanges()
{
_changes = 0;
_savedChangeCount = 0;
}

void AutoMapSaver::saveSnapshot()
Expand Down Expand Up @@ -195,7 +195,7 @@ void AutoMapSaver::collectExistingSnapshots(std::map<int, std::string>& 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;
}
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/map/autosaver/AutoSaver.h
Expand Up @@ -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<sigc::connection> _signalConnections;

Expand Down
2 changes: 1 addition & 1 deletion 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"
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/patch/Patch.h
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/undo/StackFiller.h
@@ -1,7 +1,7 @@
#pragma once

#include "iundo.h"
#include "mapfile.h"
#include "imapfilechangetracker.h"
#include "Stack.h"

namespace undo
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/undo/UndoSystem.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/include.vcxproj
Expand Up @@ -140,6 +140,7 @@
<ClInclude Include="..\..\include\imanipulator.h" />
<ClInclude Include="..\..\include\imap.h" />
<ClInclude Include="..\..\include\imapexporter.h" />
<ClInclude Include="..\..\include\imapfilechangetracker.h" />
<ClInclude Include="..\..\include\imapformat.h" />
<ClInclude Include="..\..\include\imapinfofile.h" />
<ClInclude Include="..\..\include\imapmerge.h" />
Expand Down Expand Up @@ -196,7 +197,6 @@
<ClInclude Include="..\..\include\iundo.h" />
<ClInclude Include="..\..\include\iversioncontrol.h" />
<ClInclude Include="..\..\include\ivolumetest.h" />
<ClInclude Include="..\..\include\mapfile.h" />
<ClInclude Include="..\..\include\modelskin.h" />
<ClInclude Include="..\..\include\ModResource.h" />
<ClInclude Include="..\..\include\precompiled_interfaces.h" />
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/include.vcxproj.filters
Expand Up @@ -100,7 +100,6 @@
<ClInclude Include="..\..\include\iundo.h" />
<ClInclude Include="..\..\include\iversioncontrol.h" />
<ClInclude Include="..\..\include\ivolumetest.h" />
<ClInclude Include="..\..\include\mapfile.h" />
<ClInclude Include="..\..\include\modelskin.h" />
<ClInclude Include="..\..\include\ModResource.h" />
<ClInclude Include="..\..\include\precompiled_interfaces.h" />
Expand Down Expand Up @@ -162,6 +161,7 @@
<ClInclude Include="..\..\include\ui\iwxgl.h">
<Filter>ui</Filter>
</ClInclude>
<ClInclude Include="..\..\include\imapfilechangetracker.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="ui">
Expand Down

0 comments on commit d228c9c

Please sign in to comment.