Files
anm2ed/src/snapshots.hpp
T
shweetandClaude Opus 5.5 4c569cb1e5 Stage 10a: delete dead code, merge tiny files, unify duplicated concepts
- Dead code: util/map, util/unordered_map, unused vector/math/string/input
  helpers, Document getters, special-interpolation bake leftovers,
  triggers_sort, SnapshotStack::max_size_get, AudioStream capture API.
- Merges: util/xml, util/string, resource/strings.cpp inlined; constants
  into input.hpp; tooltip into layout; Recorder into render; onionskin,
  tools, welcome and frame properties are panel functions; timeline
  popups.cpp folded into timeline.cpp.
- util/origin.hpp replaced by model Origin (the merge setting stays a
  combo index, so saved preferences keep their meaning).
- Item type names/icons/colors moved from model/common.hpp to the
  timeline header; the model no longer includes icon/strings headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 18:35:22 -04:00

80 lines
2.1 KiB
C++

#pragma once
#include <deque>
#include <map>
#include <optional>
#include <string>
#include "model/model.hpp"
#include "playback.hpp"
#include "selection.hpp"
namespace anm2ed::snapshots
{
constexpr auto ACTION = "Action";
constexpr auto MAX = 20;
};
namespace anm2ed
{
using AssetKeys = std::map<int, std::uint64_t>;
#define SNAPSHOT_STEP_STATE_FIELDS \
X(model::Model, model) \
X(Playback, playback) \
X(Selection, selection) \
X(float, frameTime) \
X(AssetKeys, textures) \
X(AssetKeys, sounds)
// Everything undo restores. The model's animations are shared between snapshots and copied only when edited.
struct Snapshot
{
#define X(type, name) type name{};
SNAPSHOT_STEP_STATE_FIELDS
#undef X
std::string message = snapshots::ACTION;
};
// One undoable edit: the state before and after it; undo/redo restore only the fields the edit changed.
struct SnapshotStep
{
Snapshot before{};
Snapshot after{};
};
class SnapshotStack
{
public:
bool is_empty();
std::size_t size() const;
void push(SnapshotStep);
std::optional<SnapshotStep> pop();
void clear();
void trim_to_limit();
static void max_size_set(int);
private:
static int maxSize;
std::deque<SnapshotStep> stack;
};
class Snapshots
{
public:
SnapshotStack undoStack{};
SnapshotStack redoStack{};
Snapshot current{};
std::optional<Snapshot> pending{};
std::optional<Reference> pendingFocus{};
void push(const std::string&);
void commit();
bool undo();
bool redo();
void reset();
void apply_limit();
};
}