Kelsidavis-WoWee/tools/editor/editor_history.hpp
Kelsi 4e2f704124 fix(editor): undo now covers texture painting, fix stale buffer bug
- Extend undo/redo to snapshot alpha maps and texture layers alongside
  heights — texture painting operations are now fully undoable
- Bracket paint mode with beginStroke/endStroke like sculpt mode
- Fix stale static char buffer in quest objective loop (showed wrong
  objective's description when editing multiple objectives)
- Zero-initialize all quest UI text buffers for null termination safety
- Fix unused variable warnings in terrain_editor.cpp
2026-05-05 12:58:11 -07:00

54 lines
1.5 KiB
C++

#pragma once
#include "pipeline/adt_loader.hpp"
#include <vector>
#include <array>
#include <memory>
namespace wowee {
namespace editor {
struct ChunkSnapshot {
int chunkIndex;
std::array<float, 145> heights;
std::vector<uint8_t> alphaMap;
std::vector<pipeline::TextureLayer> layers;
};
struct EditCommand {
std::vector<ChunkSnapshot> before;
std::vector<ChunkSnapshot> after;
};
class EditorHistory {
public:
void beginEdit(const pipeline::ADTTerrain& terrain, const std::vector<int>& affectedChunks);
void endEdit(const pipeline::ADTTerrain& terrain);
bool canUndo() const { return !undoStack_.empty(); }
bool canRedo() const { return !redoStack_.empty(); }
void undo(pipeline::ADTTerrain& terrain);
void redo(pipeline::ADTTerrain& terrain);
void clear();
size_t undoCount() const { return undoStack_.size(); }
size_t redoCount() const { return redoStack_.size(); }
const std::vector<int>& lastAffectedChunks() const { return lastAffected_; }
private:
static ChunkSnapshot captureChunk(const pipeline::ADTTerrain& terrain, int idx);
static void restoreChunk(pipeline::ADTTerrain& terrain, const ChunkSnapshot& snap);
static bool snapshotChanged(const ChunkSnapshot& a, const ChunkSnapshot& b);
std::vector<EditCommand> undoStack_;
std::vector<EditCommand> redoStack_;
EditCommand pending_;
std::vector<int> lastAffected_;
static constexpr size_t MAX_UNDO = 100;
};
} // namespace editor
} // namespace wowee