Stage 7: typed model; Element tree is internal to model/xml.cpp

- src/model: typed Model (Info, Content, nested TrackGroup/AnimationGroup,
  copy-on-write shared animations, Extras/XmlNode passthrough for unknown XML,
  layout vectors so saves stay byte-identical).
- src/edit, Document, Selection, Snapshots, every window, the timeline, wizards
  and popups now read and edit model::Model; no UI code touches Element.
- anm2/ is reduced to the XML reader/writer/normalizer behind model/xml.cpp;
  dead Element operations (merge, regions, item_add, rect, frame helpers,
  element_get/unused, deserialize) are deleted.
- Goldens, invariants, undo walk and the local corpus (1,251 files) match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 16:53:17 -04:00
1 parent 2d0f70b1e5
commit 0b6f67d9bd
72 files changed
+4974 -4025

No files matched your search

+33 -26
View File
@@ -12,22 +12,29 @@ constexpr int WALK_STEPS = 150;
constexpr int WALK_SEED = 1234;
constexpr int UNDO_LIMIT = 1000;
std::vector<Reference> references_all_get(const Anm2& anm2, bool isFrames)
std::vector<Reference> references_all_get(const model::Model& anm2, bool isFrames)
{
UidIndex index(anm2);
model::UidIndex index(anm2);
std::vector<Reference> result{};
element_each(anm2.root,
[&](const Element& element)
{
auto reference = index.reference_get(element.uid);
if (!reference || reference->itemType == NONE || reference->itemType == TRIGGER) return;
if (isFrames == (reference->frameIndex >= 0)) result.push_back(*reference);
});
auto add = [&](std::uint64_t uid)
{
auto reference = index.reference_get(uid);
if (!reference || reference->itemType == NONE || reference->itemType == TRIGGER) return;
if (isFrames == (reference->frameIndex >= 0)) result.push_back(*reference);
};
for (auto [i, animation] : anm2.animations_get())
model::animation_tracks_each(*animation,
[&](const model::Track& track)
{
add(track.uid);
for (const auto& frame : track.frames)
add(frame.uid);
});
return result;
}
// One random edit on randomly chosen live elements; returns false when nothing applicable exists.
bool edit_random_apply(Anm2& anm2, std::mt19937& random)
bool edit_random_apply(model::Model& anm2, std::mt19937& random)
{
auto frames = references_all_get(anm2, true);
auto tracks = references_all_get(anm2, false);
@@ -64,7 +71,7 @@ bool edit_random_apply(Anm2& anm2, std::mt19937& random)
edit::animation_add(anm2, 0, -1, frame.animationIndex, "Walk");
break;
default:
edit::animations_move(anm2, {frame.animationIndex}, {}, 0, -1);
edit::animations_move(anm2, {frame.animationIndex}, {}, {.animationIndex = 0});
break;
}
return true;
@@ -78,30 +85,31 @@ TEST_CASE("undo and redo restore every state of a random edit walk")
{
INFO("fixture: ", name);
Snapshots snapshots{};
snapshots.current.anm2 = anm2_load(file_load(CORPUS_DIR / name));
snapshots.current.model = model_load(file_load(CORPUS_DIR / name));
std::mt19937 random(WALK_SEED);
std::vector<std::uint64_t> hashes{snapshots.current.anm2.hash()};
std::vector<std::uint64_t> hashes{model::model_hash(snapshots.current.model)};
for (int step = 0; step < WALK_STEPS; ++step)
{
snapshots.push("Edit");
if (!edit_random_apply(snapshots.current.anm2, random)) break;
if (!edit_random_apply(snapshots.current.model, random)) break;
auto count = snapshots.undoStack.size();
snapshots.commit();
if (snapshots.current.anm2.hash() != hashes.back()) hashes.push_back(snapshots.current.anm2.hash());
if (snapshots.undoStack.size() != count) hashes.push_back(model::model_hash(snapshots.current.model));
}
REQUIRE(hashes.size() > 1);
for (auto it = hashes.rbegin() + 1; it != hashes.rend(); ++it)
{
REQUIRE(snapshots.undo());
CHECK(snapshots.current.anm2.hash() == *it);
CHECK(model::model_hash(snapshots.current.model) == *it);
}
CHECK_FALSE(snapshots.undo());
for (auto it = hashes.begin() + 1; it != hashes.end(); ++it)
{
REQUIRE(snapshots.redo());
CHECK(snapshots.current.anm2.hash() == *it);
CHECK(model::model_hash(snapshots.current.model) == *it);
}
}
}
@@ -110,21 +118,20 @@ TEST_CASE("selection follows its frame through an edit and its undo")
{
Snapshots snapshots{};
auto& current = snapshots.current;
current.anm2 = anm2_load(file_load(CORPUS_DIR / "02_items.anm2"));
current.anm2.uids_repair();
selection_focus_set(current.selection, current.anm2, {0, LAYER, 0, 1});
selection_references_set(current.selection, current.anm2, SelectionKind::FRAMES, {{0, LAYER, 0, 1}});
current.model = model_load(file_load(CORPUS_DIR / "02_items.anm2"));
selection_focus_set(current.selection, current.model, {0, LAYER, 0, 1});
selection_references_set(current.selection, current.model, SelectionKind::FRAMES, {{0, LAYER, 0, 1}});
snapshots.push("Insert");
edit::frame_insert(current.anm2, {0, LAYER, 0, -1}, 0);
auto& track = *current.anm2.element_get(Reference{0, LAYER, 0});
std::rotate(track.children.begin(), track.children.end() - 1, track.children.end());
edit::frame_insert(current.model, {0, LAYER, 0, -1}, 0);
auto& track = *current.model.track_edit(Reference{0, LAYER, 0});
std::rotate(track.frames.begin(), track.frames.end() - 1, track.frames.end());
snapshots.commit();
UidIndex index(current.anm2);
model::UidIndex index(current.model);
CHECK(selection_focus_get(current.selection, index) == Reference{0, LAYER, 0, 2});
CHECK(selection_references_get(current.selection, index, SelectionKind::FRAMES) ==
std::set<Reference>{{0, LAYER, 0, 2}});
REQUIRE(snapshots.undo());
CHECK(selection_focus_get(current.selection, UidIndex(current.anm2)) == Reference{0, LAYER, 0, 1});
CHECK(selection_focus_get(current.selection, model::UidIndex(current.model)) == Reference{0, LAYER, 0, 1});
}