Bundle long parameter lists into option structs

FrameRender carries a render's canvas, shader, document, animation, bounds,
background, scale and root transform. Dash and DashedShape replace three
dash floats and a GL mode and count. ViewCamera carries the view menu's
zoom, pan, center, fit and whether fitting is possible. ItemAdd and
ItemsMove carry what item_add and items_move took as seven or eight
positional arguments.
This commit is contained in:
shweet committed 2026-11-22 19:57:11 -05:00
1 parent 9e193a3d5c
commit ae7dafaef6
16 files changed
+185 -107

No files matched your search

+6 -3
View File
@@ -57,8 +57,11 @@ TEST_CASE("file_merge presets")
TEST_CASE("item_add")
{
auto model = fixture_load("02_items.anm2");
CHECK(item_add(model, ItemType::LAYER, 0, -1, {.name = "added", .spritesheetId = 1}, {}, 1, DESTINATION_ALL) == 2);
CHECK(item_add(model, ItemType::NULL_, 1, -1, {}, {.name = "thisOnly"}, -1, DESTINATION_THIS) == 2);
CHECK(item_add(model, {.insertBeforeId = 1, .layer = {.name = "added", .spritesheetId = 1}}) == 2);
CHECK(item_add(model, {.type = ItemType::NULL_,
.animationIndex = 1,
.destination = DESTINATION_THIS,
.null = {.name = "thisOnly"}}) == 2);
operation_check("item_add", model);
}
@@ -190,7 +193,7 @@ TEST_CASE("edit layer operations")
[&](Model& anm2) { return items_group(anm2, 0, LAYER, {2}, "New"); }, 1},
{"items_move", "03b_groups_legacy_flat.anm2",
[&](Model& anm2) {
items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, DROP_INSIDE);
items_move(anm2, {.type = LAYER, .ids = {2}, .target = {true, LAYER, 0, -1}, .zone = DROP_INSIDE});
return Uids{};
},
0},
+23 -10
View File
@@ -71,12 +71,22 @@ struct RenderFixture
std::vector<uint8_t> frame_get(float time)
{
auto pixels =
animation_frame_render(*canvas, *shader, *document, *animation, time, bounds, SCALE, BACKGROUND, true);
auto pixels = animation_frame_render(render_get(), time);
pixels_unpremultiply(pixels);
return pixels;
}
FrameRender render_get()
{
return {.canvas = *canvas,
.shader = *shader,
.document = *document,
.animation = *animation,
.bounds = bounds,
.background = BACKGROUND,
.scale = SCALE};
}
TVec4<uint8_t> pixel_get(const std::vector<uint8_t>& pixels, Vec2 point)
{
auto position = IVec2((point - Vec2(bounds.x, bounds.y)) * SCALE);
@@ -126,8 +136,7 @@ TEST_CASE("a recorded spritesheet holds every frame")
.end = fixture.animation->frameNum - 1,
.animationFps = fixture.document->model.info.fps,
.fps = fixture.document->model.info.fps};
REQUIRE(animation_record(options, *fixture.canvas, *fixture.shader, *fixture.document, *fixture.animation,
fixture.bounds, SCALE, BACKGROUND, true));
REQUIRE(animation_record(options, fixture.render_get()));
Image sheet(options.path);
auto layout = spritesheet_layout_get(0, 0, fixture.animation->frameNum);
CHECK(sheet.size == IVec2(fixture.canvas->size) * IVec2(layout.columns, layout.rows));
@@ -152,8 +161,7 @@ TEST_CASE("a PNG sequence without a placeholder numbers each frame")
.end = fixture.animation->frameNum - 1,
.animationFps = fixture.document->model.info.fps,
.fps = fixture.document->model.info.fps};
REQUIRE(animation_record(options, *fixture.canvas, *fixture.shader, *fixture.document, *fixture.animation,
fixture.bounds, SCALE, BACKGROUND, true));
REQUIRE(animation_record(options, fixture.render_get()));
auto count = std::ranges::distance(std::filesystem::directory_iterator(directory));
CHECK(count == fixture.animation->frameNum);
CHECK(std::filesystem::exists(directory / "spin_000000.png"));
@@ -334,10 +342,15 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the
for (int time = 0; time < animation.frameNum; ++time)
{
INFO("time: ", time);
auto expected = animation_frame_render(canvas, shader, document, animation, (float)time, bounds, 1.0f,
Vec4(0.0f), true);
auto actual = animation_frame_render(canvas, shader, gameDocument, gameAnimation, (float)time, bounds, 1.0f,
Vec4(0.0f), true);
auto expected = animation_frame_render(
{.canvas = canvas, .shader = shader, .document = document, .animation = animation, .bounds = bounds},
(float)time);
auto actual = animation_frame_render({.canvas = canvas,
.shader = shader,
.document = gameDocument,
.animation = gameAnimation,
.bounds = bounds},
(float)time);
REQUIRE(actual.size() == expected.size());
CHECK(std::ranges::any_of(expected, [](uint8_t channel) { return channel != 0; }));
int mismatches = 0;
+2 -1
View File
@@ -81,7 +81,8 @@ TEST_CASE("track and group selection follow regrouping")
selection_references_set(selection, anm2, SelectionKind::TRACKS, {{0, LAYER, 0, -1, LAYER, groupId}});
selection_references_set(selection, anm2, SelectionKind::GROUPS, {{0, LAYER, groupId}});
selection_edit(anm2, selection, [&] { items_move(anm2, 0, LAYER, {0}, {}, {false, LAYER, 2, -1}, DROP_BEFORE); });
selection_edit(anm2, selection,
[&] { items_move(anm2, {.type = LAYER, .ids = {0}, .target = {false, LAYER, 2, -1}}); });
UidIndex index(anm2);
CHECK(selection_references_get(selection, index, SelectionKind::TRACKS) == std::set<Reference>{{0, LAYER, 0}});