Drop dead model code, and let edits that select nothing return nothing

Model::uid_get, the UidIndex element types, Playback's accumulator, ID_NONE and track_frames_count_get were unused.
Fourteen edit functions only ever returned an empty selection, so they return void.
This commit is contained in:
shweet committed 2026-11-22 18:39:08 -05:00
1 parent c44c7fe8df
commit 544ab3cac9
16 files changed
+79 -117

No files matched your search

+1 -1
View File
@@ -1052,7 +1052,7 @@ bool Document::frames_range_select(Reference firstReference, Reference lastRefer
return false; return false;
auto item = model.track_get(lastReference); auto item = model.track_get(lastReference);
if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= track_frames_count_get(*item)) if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= (int)item->frames.size())
return false; return false;
auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex); auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex);
+3 -5
View File
@@ -114,11 +114,10 @@ Uids animation_add(Model& model, int index, int groupId, int templateIndex, cons
return {uid}; return {uid};
} }
Uids animations_remove(Model& model, const std::set<int>& indices, const std::set<int>& groupIds) void animations_remove(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
{ {
animations_take(model, indices, {}); animations_take(model, indices, {});
animation_groups_remove(model, groupIds); animation_groups_remove(model, groupIds);
return {};
} }
// Moves animations and whole groups beside a target animation or group. Animations dropped on their own join the // Moves animations and whole groups beside a target animation or group. Animations dropped on their own join the
@@ -176,17 +175,16 @@ Uids animations_move(Model& model, const std::set<int>& indices, const std::set<
} }
// Gathers animations into a new group placed where the first of them was. // Gathers animations into a new group placed where the first of them was.
Uids animations_group(Model& model, const std::set<int>& indices, const std::string& name) void animations_group(Model& model, const std::set<int>& indices, const std::string& name)
{ {
auto first = indices.empty() ? nullptr : model.animation_get(*indices.begin()); auto first = indices.empty() ? nullptr : model.animation_get(*indices.begin());
if (!first) if (!first)
return {}; return;
auto& entries = model.animations.entries; auto& entries = model.animations.entries;
auto entry = animation_place_get(model, first->uid).entry; auto entry = animation_place_get(model, first->uid).entry;
AnimationGroup group = { AnimationGroup group = {
.id = group_next_id(entries), .name = name, .items = animations_take(model, indices, {}).items}; .id = group_next_id(entries), .name = name, .items = animations_take(model, indices, {}).items};
entries.insert(entries.begin() + std::clamp(entry, 0, (int)entries.size()), std::move(group)); entries.insert(entries.begin() + std::clamp(entry, 0, (int)entries.size()), std::move(group));
return {};
} }
// Pastes clipboard animations (and groups, which get new ids) before the animation at `start`. Lone animations join // Pastes clipboard animations (and groups, which get new ids) before the animation at `start`. Lone animations join
+6 -11
View File
@@ -39,7 +39,7 @@ template <class Callback> static void layer_frames_each(Model& model, int animat
} }
// Makes a region for each distinct crop/size/pivot among the frames (and points frames at them when mapping is SET). // Makes a region for each distinct crop/size/pivot among the frames (and points frames at them when mapping is SET).
Uids regions_generate(Model& model, const std::set<int>& animationIndices, const std::set<Reference>& frames, void regions_generate(Model& model, const std::set<int>& animationIndices, const std::set<Reference>& frames,
const std::string& format, RegionFrameMapping mapping) const std::string& format, RegionFrameMapping mapping)
{ {
std::unordered_map<int, int> regionNumbers; std::unordered_map<int, int> regionNumbers;
@@ -66,11 +66,10 @@ Uids regions_generate(Model& model, const std::set<int>& animationIndices, const
if (spritesheet && source && source->regionId == -1) if (spritesheet && source && source->regionId == -1)
frame_apply(*model.frame_edit(reference), spritesheet->id); frame_apply(*model.frame_edit(reference), spritesheet->id);
} }
return {};
} }
// Points frames without a region at a region of their spritesheet with the same crop/size/pivot. // Points frames without a region at a region of their spritesheet with the same crop/size/pivot.
Uids regions_scan(Model& model) void regions_scan(Model& model)
{ {
for (int i = 0; i < model.animations_count_get(); ++i) for (int i = 0; i < model.animations_count_get(); ++i)
layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) { layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) {
@@ -79,17 +78,15 @@ Uids regions_scan(Model& model)
if (auto match = region_matched_get(item_get(model.content.spritesheets, spritesheetId)->regions, frame)) if (auto match = region_matched_get(item_get(model.content.spritesheets, spritesheetId)->regions, frame))
frame.regionId = match->id; frame.regionId = match->id;
}); });
return {};
} }
// Copies each layer frame's region crop/size/pivot onto it. Frames pointing at a missing region lose it. // Copies each layer frame's region crop/size/pivot onto it. Frames pointing at a missing region lose it.
Uids region_frames_sync(Model& model) void region_frames_sync(Model& model)
{ {
for (int i = 0; i < model.animations_count_get(); ++i) for (int i = 0; i < model.animations_count_get(); ++i)
layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) { layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) {
frame_region_apply(frame, item_get(model.content.spritesheets, spritesheetId)->regions); frame_region_apply(frame, item_get(model.content.spritesheets, spritesheetId)->regions);
}); });
return {};
} }
// Clears frame references to the spritesheet's unused regions, then removes them. // Clears frame references to the spritesheet's unused regions, then removes them.
@@ -97,7 +94,7 @@ Uids region_frames_sync(Model& model)
// in every animation, an event or sound from its triggers (dropping those left with neither), a shader from its // in every animation, an event or sound from its triggers (dropping those left with neither), a shader from its
// frames (which go back to the default), a region from its frames (which keep its crop, size and pivot), a // frames (which go back to the default), a region from its frames (which keep its crop, size and pivot), a
// spritesheet's plain layers, and a library's layers, flattened into plain ones. // spritesheet's plain layers, and a library's layers, flattened into plain ones.
Uids content_remove(Model& model, ElementType type, const std::set<int>& ids, int spritesheetId, void content_remove(Model& model, ElementType type, const std::set<int>& ids, int spritesheetId,
const LibraryGet& library_get, const SpritesheetPathGet& path_get) const LibraryGet& library_get, const SpritesheetPathGet& path_get)
{ {
auto& content = model.content; auto& content = model.content;
@@ -186,21 +183,19 @@ Uids content_remove(Model& model, ElementType type, const std::set<int>& ids, in
default: default:
break; break;
} }
return {};
} }
// Pastes regions into a spritesheet at a position. They get fresh ids after the existing ones. // Pastes regions into a spritesheet at a position. They get fresh ids after the existing ones.
Uids regions_paste(Model& model, int spritesheetId, const std::string& text, int insertIndex, std::string* errorString) void regions_paste(Model& model, int spritesheetId, const std::string& text, int insertIndex, std::string* errorString)
{ {
auto spritesheet = item_get(model.content.spritesheets, spritesheetId); auto spritesheet = item_get(model.content.spritesheets, spritesheetId);
if (!spritesheet) if (!spritesheet)
return {}; return;
auto regions = items_from_string<Region>(text, errorString); auto regions = items_from_string<Region>(text, errorString);
for (auto& region : regions) for (auto& region : regions)
region.id = item_next_id_get(spritesheet->regions) + (int)(&region - regions.data()); region.id = item_next_id_get(spritesheet->regions) + (int)(&region - regions.data());
insertIndex = std::clamp(insertIndex, 0, (int)spritesheet->regions.size()); insertIndex = std::clamp(insertIndex, 0, (int)spritesheet->regions.size());
spritesheet->regions.insert(spritesheet->regions.begin() + insertIndex, regions.begin(), regions.end()); spritesheet->regions.insert(spritesheet->regions.begin() + insertIndex, regions.begin(), regions.end());
return {};
} }
// Appends grid frames to each layer track (optionally making a region per frame) and fits the animation length. // Appends grid frames to each layer track (optionally making a region per frame) and fits the animation length.
+14 -14
View File
@@ -94,39 +94,39 @@ Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, cons
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&); std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&);
Uids frame_insert(Model&, Reference, int); Uids frame_insert(Model&, Reference, int);
Uids frames_delete(Model&, const std::set<Reference>&); void frames_delete(Model&, const std::set<Reference>&);
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference); Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
Uids frames_reverse(Model&, const std::set<Reference>&); void frames_reverse(Model&, const std::set<Reference>&);
Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool); Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool);
Uids frame_split(Model&, Reference, int); Uids frame_split(Model&, Reference, int);
Uids frames_split(Model&, const std::set<Reference>&, int); Uids frames_split(Model&, const std::set<Reference>&, int);
Uids frames_move(Model&, const std::set<Reference>&, Reference, int); Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
Uids frame_durations_set(Model&, const std::map<Reference, int>&); void frame_durations_set(Model&, const std::map<Reference, int>&);
Uids trigger_at_frame_set(Model&, Reference, int); void trigger_at_frame_set(Model&, Reference, int);
Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*); Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions); Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
Uids items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&); void items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
Uids items_group(Model&, int, int, const std::set<int>&, const std::string&); Uids items_group(Model&, int, int, const std::set<int>&, const std::string&);
Uids items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool); void items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
Uids animation_length_fit(Model&, int); void animation_length_fit(Model&, int);
int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination); int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination);
std::set<int> animation_group_ids_get(const Model&); std::set<int> animation_group_ids_get(const Model&);
std::set<int> animation_group_indices_get(const Model&, int); std::set<int> animation_group_indices_get(const Model&, int);
void animation_groups_remove(Model&, const std::set<int>&); void animation_groups_remove(Model&, const std::set<int>&);
Uids animation_add(Model&, int, int, int, const std::string&); Uids animation_add(Model&, int, int, int, const std::string&);
Uids animations_remove(Model&, const std::set<int>&, const std::set<int>&); void animations_remove(Model&, const std::set<int>&, const std::set<int>&);
Uids animations_move(Model&, const std::set<int>&, const std::set<int>&, AnimationTarget); Uids animations_move(Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
Uids animations_group(Model&, const std::set<int>&, const std::string&); void animations_group(Model&, const std::set<int>&, const std::string&);
Uids animations_paste(Model&, const std::string&, int, int, std::set<int>&, std::string*); Uids animations_paste(Model&, const std::string&, int, int, std::set<int>&, std::string*);
Uids animations_merge(Model&, int, std::set<int>, Merge, bool, const std::set<int>&); Uids animations_merge(Model&, int, std::set<int>, Merge, bool, const std::set<int>&);
std::string region_name_get(const std::string&, int); std::string region_name_get(const std::string&, int);
Uids regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&, RegionFrameMapping); void regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&, RegionFrameMapping);
Uids regions_scan(Model&); void regions_scan(Model&);
Uids region_frames_sync(Model&); void region_frames_sync(Model&);
Uids regions_paste(Model&, int, const std::string&, int, std::string*); void regions_paste(Model&, int, const std::string&, int, std::string*);
Uids animation_grid_generate(Model&, const std::vector<Reference>&, const GridOptions&); Uids animation_grid_generate(Model&, const std::vector<Reference>&, const GridOptions&);
Uids frames_change_apply(Model&, const ChangeTargets&, FrameChange, ChangeType); Uids frames_change_apply(Model&, const ChangeTargets&, FrameChange, ChangeType);
bool regions_trim(Model&, int, const std::set<int>&, const Image&); bool regions_trim(Model&, int, const std::set<int>&, const Image&);
@@ -136,6 +136,6 @@ std::optional<Image> spritesheets_merge(Model&, const std::set<int>&, const Imag
// Where a spritesheet path of a document (this one, or a library) points, from this document. // Where a spritesheet path of a document (this one, or a library) points, from this document.
using SpritesheetPathGet = std::function<std::filesystem::path(const Model&, const std::filesystem::path&)>; using SpritesheetPathGet = std::function<std::filesystem::path(const Model&, const std::filesystem::path&)>;
Model animation_layers_flatten(Model, const LibraryGet&, const SpritesheetPathGet&, const std::set<int>& = {}); Model animation_layers_flatten(Model, const LibraryGet&, const SpritesheetPathGet&, const std::set<int>& = {});
Uids content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&, const SpritesheetPathGet&); void content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&, const SpritesheetPathGet&);
Model isaac_bridge(Model); Model isaac_bridge(Model);
bool file_merge(Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset); bool file_merge(Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
+5 -9
View File
@@ -53,14 +53,13 @@ Uids frame_insert(Model& model, Reference reference, int time)
return {frame.uid}; return {frame.uid};
} }
Uids frames_delete(Model& model, const std::set<Reference>& frames) void frames_delete(Model& model, const std::set<Reference>& frames)
{ {
for (auto& [trackReference, indices] : frames_by_track_get(frames)) for (auto& [trackReference, indices] : frames_by_track_get(frames))
if (auto track = model.track_edit(trackReference)) if (auto track = model.track_edit(trackReference))
for (auto it = indices.rbegin(); it != indices.rend(); ++it) for (auto it = indices.rbegin(); it != indices.rend(); ++it)
if (*it >= 0 && *it < (int)track->frames.size()) if (*it >= 0 && *it < (int)track->frames.size())
track->frames.erase(track->frames.begin() + *it); track->frames.erase(track->frames.begin() + *it);
return {};
} }
Uids frames_duplicate(Model& model, const std::set<Reference>& frames, Reference focus) Uids frames_duplicate(Model& model, const std::set<Reference>& frames, Reference focus)
@@ -100,7 +99,7 @@ Uids frames_duplicate(Model& model, const std::set<Reference>& frames, Reference
} }
// Reverses the selected frames of each track as one block placed where the first of them was. // Reverses the selected frames of each track as one block placed where the first of them was.
Uids frames_reverse(Model& model, const std::set<Reference>& frames) void frames_reverse(Model& model, const std::set<Reference>& frames)
{ {
for (auto& [trackReference, indices] : frames_by_track_get(frames)) for (auto& [trackReference, indices] : frames_by_track_get(frames))
{ {
@@ -118,7 +117,6 @@ Uids frames_reverse(Model& model, const std::set<Reference>& frames)
auto index = std::min(*indices.begin(), (int)track->frames.size()); auto index = std::min(*indices.begin(), (int)track->frames.size());
track->frames.insert(track->frames.begin() + index, reversed.begin(), reversed.end()); track->frames.insert(track->frames.begin() + index, reversed.begin(), reversed.end());
} }
return {};
} }
Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval, bool isRoundScale, bool isRoundRotation) Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval, bool isRoundScale, bool isRoundRotation)
@@ -319,25 +317,23 @@ Uids frames_property_set(Model& model, const std::set<Reference>& references, Fr
return uids; return uids;
} }
Uids frame_durations_set(Model& model, const std::map<Reference, int>& durations) void frame_durations_set(Model& model, const std::map<Reference, int>& durations)
{ {
for (auto [reference, duration] : durations) for (auto [reference, duration] : durations)
if (auto frame = model.frame_edit(reference)) if (auto frame = model.frame_edit(reference))
frame->duration = std::clamp(duration, FRAME_DURATION_MIN, FRAME_DURATION_MAX); frame->duration = std::clamp(duration, FRAME_DURATION_MIN, FRAME_DURATION_MAX);
return {};
} }
// Places a trigger at a frame, stepping it back past any other trigger already there. // Places a trigger at a frame, stepping it back past any other trigger already there.
Uids trigger_at_frame_set(Model& model, Reference reference, int atFrame) void trigger_at_frame_set(Model& model, Reference reference, int atFrame)
{ {
auto trigger = model.frame_edit(reference); auto trigger = model.frame_edit(reference);
if (!trigger) if (!trigger)
return {}; return;
trigger->atFrame = atFrame; trigger->atFrame = atFrame;
for (auto& other : model.track_get(reference)->frames) for (auto& other : model.track_get(reference)->frames)
if (&other != trigger && other.atFrame == trigger->atFrame) if (&other != trigger && other.atFrame == trigger->atFrame)
trigger->atFrame--; trigger->atFrame--;
return {};
} }
// Pastes clipboard frames after the track's selected frames (or its current frame). Triggers go at `time`, stepping // Pastes clipboard frames after the track's selected frames (or its current frame). Triggers go at `time`, stepping
+6 -9
View File
@@ -8,7 +8,7 @@ static std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIn
return animation ? &animation_entries_get(*animation, type) : nullptr; return animation ? &animation_entries_get(*animation, type) : nullptr;
} }
Uids items_remove(Model& model, int animationIndex, const std::map<int, std::set<int>>& ids, void items_remove(Model& model, int animationIndex, const std::map<int, std::set<int>>& ids,
const std::map<int, std::set<int>>& groupIds) const std::map<int, std::set<int>>& groupIds)
{ {
for (auto type : {LAYER, NULL_}) for (auto type : {LAYER, NULL_})
@@ -18,7 +18,6 @@ Uids items_remove(Model& model, int animationIndex, const std::map<int, std::set
auto typeGroupIds = groupIds.contains(type) ? groupIds.at(type) : std::set<int>{}; auto typeGroupIds = groupIds.contains(type) ? groupIds.at(type) : std::set<int>{};
entries_take(*entries, [&](Track& track) { return typeIds.contains(track.id); }, typeGroupIds); entries_take(*entries, [&](Track& track) { return typeIds.contains(track.id); }, typeGroupIds);
} }
return {};
} }
// Wraps ungrouped tracks in a new group placed where the first of them was. // Wraps ungrouped tracks in a new group placed where the first of them was.
@@ -36,17 +35,17 @@ Uids items_group(Model& model, int animationIndex, int type, const std::set<int>
// Moves tracks and whole groups next to (or into) a target row. Layers are listed bottom-up, so for them "after" on // Moves tracks and whole groups next to (or into) a target row. Layers are listed bottom-up, so for them "after" on
// screen is "before" in the file. // screen is "before" in the file.
Uids items_move(Model& model, int animationIndex, int type, const std::set<int>& ids, const std::set<int>& groupIds, void items_move(Model& model, int animationIndex, int type, const std::set<int>& ids, const std::set<int>& groupIds,
RowTarget target, bool isDropAfter, bool isDropIntoGroup) RowTarget target, bool isDropAfter, bool isDropIntoGroup)
{ {
if ((target.groupId != -1 && groupIds.contains(target.groupId)) || (target.isGroup && groupIds.contains(target.id))) if ((target.groupId != -1 && groupIds.contains(target.groupId)) || (target.isGroup && groupIds.contains(target.id)))
return {}; return;
auto entries = track_entries_edit(model, animationIndex, type); auto entries = track_entries_edit(model, animationIndex, type);
if (!entries) if (!entries)
return {}; return;
auto taken = entries_take(*entries, [&](Track& track) { return ids.contains(track.id); }, groupIds); auto taken = entries_take(*entries, [&](Track& track) { return ids.contains(track.id); }, groupIds);
if (taken.items.empty() && taken.groups.empty()) if (taken.items.empty() && taken.groups.empty())
return {}; return;
// Where top-level items go: beside the target row, or beside the group that holds it. // Where top-level items go: beside the target row, or beside the group that holds it.
auto isAfter = type == LAYER ? !isDropAfter : isDropAfter; auto isAfter = type == LAYER ? !isDropAfter : isDropAfter;
@@ -80,14 +79,12 @@ Uids items_move(Model& model, int animationIndex, int type, const std::set<int>&
taken.items.clear(); taken.items.clear();
} }
entries_insert(*entries, topIndex, std::move(taken)); entries_insert(*entries, topIndex, std::move(taken));
return {};
} }
Uids animation_length_fit(Model& model, int animationIndex) void animation_length_fit(Model& model, int animationIndex)
{ {
if (auto animation = model.animation_edit(animationIndex)) if (auto animation = model.animation_edit(animationIndex))
animation->frameNum = animation_length_get(*animation); animation->frameNum = animation_length_get(*animation);
return {};
} }
// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation. // Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation.
+6 -26
View File
@@ -333,12 +333,6 @@ Handle Model::handle_get(Reference reference, bool isGroup) const
return handle; return handle;
} }
std::uint64_t Model::uid_get(Reference reference, bool isGroup) const
{
auto handle = handle_get(reference, isGroup);
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
}
template <class Callback> static void animation_uids_each(Animation& animation, Callback&& callback) template <class Callback> static void animation_uids_each(Animation& animation, Callback&& callback)
{ {
callback(animation.uid); callback(animation.uid);
@@ -403,11 +397,6 @@ std::set<int> spritesheets_vector_used_get(const Model& model)
return ids; return ids;
} }
int track_frames_count_get(const Track& track)
{
return (int)track.frames.size();
}
int track_length_get(const Track& track) int track_length_get(const Track& track)
{ {
int length = 0; int length = 0;
@@ -452,17 +441,14 @@ Animation animation_clone(Animation animation)
return animation; return animation;
} }
static void track_locations_add(std::unordered_map<std::uint64_t, UidIndex::Location>& locations, const Track& track, static void track_locations_add(std::unordered_map<std::uint64_t, Reference>& locations, const Track& track,
Reference reference) Reference reference)
{ {
constexpr ElementType TRACK_TYPES[] = {ElementType::UNKNOWN, ElementType::ROOT_ANIMATION, locations[track.uid] = reference;
ElementType::LAYER_ANIMATION, ElementType::NULL_ANIMATION,
ElementType::TRIGGERS};
locations[track.uid] = {reference, TRACK_TYPES[(int)track.type]};
for (auto& frame : track.frames) for (auto& frame : track.frames)
{ {
++reference.frameIndex; ++reference.frameIndex;
locations[frame.uid] = {reference, track.type == ItemType::TRIGGER ? ElementType::TRIGGER : ElementType::FRAME}; locations[frame.uid] = reference;
} }
} }
@@ -470,7 +456,7 @@ UidIndex::UidIndex(const Model& model)
{ {
for (auto [index, animation] : model.animations_get()) for (auto [index, animation] : model.animations_get())
{ {
locations[animation->uid] = {{index}, ElementType::ANIMATION}; locations[animation->uid] = {index};
track_locations_add(locations, animation->root, {index, ROOT}); track_locations_add(locations, animation->root, {index, ROOT});
track_locations_add(locations, animation->triggers, {index, TRIGGER}); track_locations_add(locations, animation->triggers, {index, TRIGGER});
for (auto type : {LAYER, NULL_}) for (auto type : {LAYER, NULL_})
@@ -481,7 +467,7 @@ UidIndex::UidIndex(const Model& model)
{index, type, track.id, -1, group ? type : NONE, group ? group->id : -1}); {index, type, track.id, -1, group ? type : NONE, group ? group->id : -1});
}, },
[&](const TrackGroup& group) { [&](const TrackGroup& group) {
locations[group.uid] = {{index, type, group.id}, ElementType::GROUP}; locations[group.uid] = {index, type, group.id};
track_locations_add(locations, group.root, {index, ROOT, -1, -1, type, group.id}); track_locations_add(locations, group.root, {index, ROOT, -1, -1, type, group.id});
}); });
} }
@@ -495,13 +481,7 @@ bool UidIndex::contains(std::uint64_t uid) const
std::optional<Reference> UidIndex::reference_get(std::uint64_t uid) const std::optional<Reference> UidIndex::reference_get(std::uint64_t uid) const
{ {
auto it = locations.find(uid); auto it = locations.find(uid);
return it == locations.end() ? std::nullopt : std::optional<Reference>(it->second.reference); return it == locations.end() ? std::nullopt : std::optional<Reference>(it->second);
}
ElementType UidIndex::type_get(std::uint64_t uid) const
{
auto it = locations.find(uid);
return it == locations.end() ? ElementType::UNKNOWN : it->second.type;
} }
// Equality by value. Animations shared with another model compare by pointer first. // Equality by value. Animations shared with another model compare by pointer first.
+2 -13
View File
@@ -375,30 +375,20 @@ public:
Frame frame_effective(int, const Frame&) const; Frame frame_effective(int, const Frame&) const;
std::set<int> unused_get(ElementType, const Animation* = nullptr) const; std::set<int> unused_get(ElementType, const Animation* = nullptr) const;
int uses_count(ElementType, const std::set<int>&, int = -1, const Animation* = nullptr) const; int uses_count(ElementType, const std::set<int>&, int = -1, const Animation* = nullptr) const;
std::uint64_t uid_get(Reference, bool = false) const;
Handle handle_get(Reference, bool = false) const; Handle handle_get(Reference, bool = false) const;
void uids_repair(); void uids_repair();
}; };
// uid -> where that element is now (as a Reference) and what it is, built in one walk of the animations. // uid -> where that element is now, as a Reference, built in one walk of the animations.
class UidIndex class UidIndex
{ {
public: std::unordered_map<std::uint64_t, Reference> locations;
struct Location
{
Reference reference = {};
ElementType type = {};
};
private:
std::unordered_map<std::uint64_t, Location> locations;
public: public:
UidIndex() = default; UidIndex() = default;
explicit UidIndex(const Model&); explicit UidIndex(const Model&);
bool contains(std::uint64_t) const; bool contains(std::uint64_t) const;
std::optional<Reference> reference_get(std::uint64_t) const; std::optional<Reference> reference_get(std::uint64_t) const;
ElementType type_get(std::uint64_t) const;
}; };
bool is_model_equal(const Model&, const Model&); bool is_model_equal(const Model&, const Model&);
@@ -408,7 +398,6 @@ Vec2 region_pivot_get(const Region&);
void frame_region_rect_set(Frame&, const Region&); void frame_region_rect_set(Frame&, const Region&);
void frame_region_apply(Frame&, const std::vector<Region>&); void frame_region_apply(Frame&, const std::vector<Region>&);
std::set<int> spritesheets_vector_used_get(const Model&); std::set<int> spritesheets_vector_used_get(const Model&);
int track_frames_count_get(const Track&);
int track_length_get(const Track&); int track_length_get(const Track&);
int animation_length_get(const Animation&); int animation_length_get(const Animation&);
IVec2 animation_play_range_get(const Animation&); IVec2 animation_play_range_get(const Animation&);
-9
View File
@@ -10,12 +10,6 @@ void Playback::toggle()
time = 0.0f; time = 0.0f;
isFinished = false; isFinished = false;
isPlaying = !isPlaying; isPlaying = !isPlaying;
timing_reset();
}
void Playback::timing_reset()
{
tickAccumulator = 0.0f;
} }
void Playback::clamp(int length) void Playback::clamp(int length)
@@ -48,7 +42,6 @@ void Playback::tick(int fps, int start, int end, bool isLoop, float deltaSeconds
time = (float)end - 1.0f; time = (float)end - 1.0f;
isPlaying = false; isPlaying = false;
isFinished = true; isFinished = true;
timing_reset();
} }
} }
@@ -56,12 +49,10 @@ void Playback::decrement(int length)
{ {
--time; --time;
clamp(length); clamp(length);
timing_reset();
} }
void Playback::increment(int length) void Playback::increment(int length)
{ {
++time; ++time;
clamp(length); clamp(length);
timing_reset();
} }
-4
View File
@@ -8,12 +8,8 @@ public:
bool isFinished = false; bool isFinished = false;
void toggle(); void toggle();
void timing_reset();
void clamp(int); void clamp(int);
void tick(int, int, int, bool, float); void tick(int, int, int, bool, float);
void decrement(int); void decrement(int);
void increment(int); void increment(int);
private:
float tickAccumulator = 0;
}; };
-1
View File
@@ -58,4 +58,3 @@ enum class OnionskinMode
INDEX INDEX
}; };
constexpr auto ID_NONE = -1;
-2
View File
@@ -156,7 +156,6 @@ void AnimationPreview::tick(Manager& manager, Settings& settings, float deltaSec
{ {
playback.isPlaying = false; playback.isPlaying = false;
playback.isFinished = false; playback.isFinished = false;
playback.timing_reset();
} }
else else
{ {
@@ -237,7 +236,6 @@ void AnimationPreview::recording_start(Manager& manager, Settings& settings, Doc
return recording_stop(manager, document); return recording_stop(manager, document);
} }
document.playback.isPlaying = true; document.playback.isPlaying = true;
document.playback.timing_reset();
document.playback.time = recorder.time_get(); document.playback.time = recorder.time_get();
document.frameTime = document.playback.time; document.frameTime = document.playback.time;
} }
+2 -4
View File
@@ -625,14 +625,12 @@ void animations_update(Panel& panel, AnimationsPanel& animations)
auto targets = animation_groupable_indices_get(document); auto targets = animation_groupable_indices_get(document);
command_push(panel, command_push(panel,
[&state, targets = std::set<int>(targets.begin(), targets.end())](Document& document) { [&state, targets = std::set<int>(targets.begin(), targets.end())](Document& document) {
auto groupIds = animation_group_ids_get(document.model); auto groupId = group_next_id(document.model.animations.entries);
auto groupId = groupIds.empty() ? 0 : *groupIds.rbegin() + 1;
document.edit_apply(EDIT_GROUP_ITEMS, [&](Model& model) { document.edit_apply(EDIT_GROUP_ITEMS, [&](Model& model) {
auto uids = animations_group(model, targets, localize.get(TEXT_NEW_GROUP)); animations_group(model, targets, localize.get(TEXT_NEW_GROUP));
animations_selection_set(document, targets, {groupId}); animations_selection_set(document, targets, {groupId});
document.reference_set({*targets.begin()}); document.reference_set({*targets.begin()});
state.scrollId = *targets.begin(); state.scrollId = *targets.begin();
return uids;
}); });
}); });
}); });
-1
View File
@@ -38,7 +38,6 @@ void TimelineContext::playback_stop()
{ {
playback.isPlaying = false; playback.isPlaying = false;
playback.isFinished = false; playback.isFinished = false;
playback.timing_reset();
} }
void TimelineContext::context_menu() void TimelineContext::context_menu()
+1 -1
View File
@@ -301,7 +301,7 @@ void TimelineContext::item_child(const TimelineRow& row, int index)
return value ? localize.get(BASIC_YES) : localize.get(BASIC_NO); return value ? localize.get(BASIC_YES) : localize.get(BASIC_NO);
}; };
auto visibleLabel = yesNoLabel(isVisible); auto visibleLabel = yesNoLabel(isVisible);
auto framesCount = item ? track_frames_count_get(*item) : 0; auto framesCount = item ? (int)item->frames.size() : 0;
switch (type) switch (type)
{ {
+33 -7
View File
@@ -151,12 +151,20 @@ TEST_CASE("edit layer operations")
{"frame_insert", "02_items.anm2", [&](Model& anm2) { return frame_insert(anm2, {0, LAYER, 0, 0}, 0); }, 1}, {"frame_insert", "02_items.anm2", [&](Model& anm2) { return frame_insert(anm2, {0, LAYER, 0, 0}, 0); }, 1},
{"trigger_insert", "02_items.anm2", [&](Model& anm2) { return frame_insert(anm2, {0, TRIGGER, -1, 0}, 2); }, 1}, {"trigger_insert", "02_items.anm2", [&](Model& anm2) { return frame_insert(anm2, {0, TRIGGER, -1, 0}, 2); }, 1},
{"frames_delete", "02_items.anm2", {"frames_delete", "02_items.anm2",
[&](Model& anm2) { return frames_delete(anm2, {{0, LAYER, 0, 0}, {0, ROOT, -1, 1}}); }, 0}, [&](Model& anm2) {
frames_delete(anm2, {{0, LAYER, 0, 0}, {0, ROOT, -1, 1}});
return Uids{};
},
0},
{"frames_duplicate", "02_items.anm2", {"frames_duplicate", "02_items.anm2",
[&](Model& anm2) { return frames_duplicate(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, {0, LAYER, 0, 1}); }, [&](Model& anm2) { return frames_duplicate(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, {0, LAYER, 0, 1}); },
2}, 2},
{"frames_reverse", "07_special_interpolation.anm2", {"frames_reverse", "07_special_interpolation.anm2",
[&](Model& anm2) { return frames_reverse(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 2}}); }, 0}, [&](Model& anm2) {
frames_reverse(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 2}});
return Uids{};
},
0},
{"frames_bake", "07_special_interpolation.anm2", {"frames_bake", "07_special_interpolation.anm2",
[&](Model& anm2) { return frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, true, false); }, 5}, [&](Model& anm2) { return frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, true, false); }, 5},
{"frame_split", "02_items.anm2", [&](Model& anm2) { return frame_split(anm2, {0, LAYER, 1, 0}, 2); }, 1}, {"frame_split", "02_items.anm2", [&](Model& anm2) { return frame_split(anm2, {0, LAYER, 1, 0}, 2); }, 1},
@@ -178,16 +186,33 @@ TEST_CASE("edit layer operations")
{"items_group", "03b_groups_legacy_flat.anm2", {"items_group", "03b_groups_legacy_flat.anm2",
[&](Model& anm2) { return items_group(anm2, 0, LAYER, {2}, "New"); }, 1}, [&](Model& anm2) { return items_group(anm2, 0, LAYER, {2}, "New"); }, 1},
{"items_move", "03b_groups_legacy_flat.anm2", {"items_move", "03b_groups_legacy_flat.anm2",
[&](Model& anm2) { return items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, false, true); }, 0}, [&](Model& anm2) {
items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, false, true);
return Uids{};
},
0},
{"items_remove", "03b_groups_legacy_flat.anm2", {"items_remove", "03b_groups_legacy_flat.anm2",
[&](Model& anm2) { return items_remove(anm2, 0, {{LAYER, {2}}}, {{NULL_, {3}}}); }, 0}, [&](Model& anm2) {
items_remove(anm2, 0, {{LAYER, {2}}}, {{NULL_, {3}}});
return Uids{};
},
0},
{"animation_add", "03a_groups_nested.anm2", [&](Model& anm2) { return animation_add(anm2, 1, 0, 0, "Added"); }, {"animation_add", "03a_groups_nested.anm2", [&](Model& anm2) { return animation_add(anm2, 1, 0, 0, "Added"); },
1}, 1},
{"animations_remove", "03a_groups_nested.anm2", [&](Model& anm2) { return animations_remove(anm2, {1}, {0}); }, {"animations_remove", "03a_groups_nested.anm2",
[&](Model& anm2) {
animations_remove(anm2, {1}, {0});
return Uids{};
},
0}, 0},
{"animations_move", "02_items.anm2", {"animations_move", "02_items.anm2",
[&](Model& anm2) { return animations_move(anm2, {0}, {}, {.animationIndex = 1, .isAfter = true}); }, 1}, [&](Model& anm2) { return animations_move(anm2, {0}, {}, {.animationIndex = 1, .isAfter = true}); }, 1},
{"animations_group", "02_items.anm2", [&](Model& anm2) { return animations_group(anm2, {0, 1}, "Group"); }, 0}, {"animations_group", "02_items.anm2",
[&](Model& anm2) {
animations_group(anm2, {0, 1}, "Group");
return Uids{};
},
0},
{"animations_paste", "02_items.anm2", {"animations_paste", "02_items.anm2",
[&](Model& anm2) { [&](Model& anm2) {
std::set<int> groupIds; std::set<int> groupIds;
@@ -198,7 +223,8 @@ TEST_CASE("edit layer operations")
{"regions_paste", "05_regions.anm2", {"regions_paste", "05_regions.anm2",
[&](Model& anm2) { [&](Model& anm2) {
auto region = item_get(item_get(anm2.content.spritesheets, 0)->regions, 1); auto region = item_get(item_get(anm2.content.spritesheets, 0)->regions, 1);
return regions_paste(anm2, 0, item_to_string(*region), 1, nullptr); regions_paste(anm2, 0, item_to_string(*region), 1, nullptr);
return Uids{};
}, },
0}, 0},
{"animation_grid_generate", "05_regions.anm2", {"animation_grid_generate", "05_regions.anm2",