~mil/mepo

39f7b207c4d584ca7d00cd2c47f622eef21f24b3 — Miles Alan 10 months ago aeba20c
pin_cycle: Only invoke mepo.blit_pinlayer_cache.clearAndFree() if delta changes
1 files changed, 8 insertions(+), 4 deletions(-)

M src/api/pin_cycle.zig
M src/api/pin_cycle.zig => src/api/pin_cycle.zig +8 -4
@@ 21,13 21,12 @@ fn execute(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
pub fn pin_cycle(mepo: *Mepo, viewport_only: bool, delta: i32) !void {
    const active_group = mepo.pin_groups[mepo.pin_group_active].items;
    if (active_group.len == 0) return;
    defer mepo.blit_pinlayer_cache.clearAndFree();

    var target_i = if (mepo.pin_group_active_item) |active_item| @as(i32, @intCast(active_item)) else 0;
    const group_unordered = !p.get(p.pingroup_prop(mepo.pin_group_active, .Ordered)).b;
    const add: i32 = if (delta > 0) 1 else -1;
    for (0..std.math.absCast(delta)) |_| {
        var pin_i = if (mepo.pin_group_active_item) |active_item| @as(i32, @intCast(active_item)) + add else 0;

        var pin_i = target_i + add;
        // E.g. two conditions to skip and continually increase pin_i:
        // 1. Within an ordered group, structural pins should be skipped
        // 2. Requested to cycle only viewport visible pins, non visible pins skipped


@@ 35,12 34,17 @@ pub fn pin_cycle(mepo: *Mepo, viewport_only: bool, delta: i32) !void {
            const unstructural = active_group[@intCast(pin_i)].category != .Structural;
            const visible = !viewport_only or pin_in_viewport(mepo, pin_i);
            if ((group_unordered or unstructural) and visible) {
                if (visible) mepo.pin_group_active_item = @intCast(pin_i);
                target_i = @intCast(pin_i);
                break;
            }
            pin_i += add;
        }
    }

    if (mepo.pin_group_active_item == null or mepo.pin_group_active_item.? != target_i) {
        mepo.pin_group_active_item = @intCast(target_i);
        mepo.blit_pinlayer_cache.clearAndFree();
    }
}

fn pin_in_viewport(mepo: *Mepo, pin_index: i32) bool {