tiny.rig.part
Defined in tiny.rig.
Parts: what each joint draws.
API (6)
Actions
Public operations.
Slot.select: The chosen part, ornonefor a choice past the slot's parts.resolve: The part each joint draws,nonewhere it draws nothing.
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
Source
Source: fun/rig/src/part.zig
zig
//! Parts: what each joint draws.//!//! A part is an index into the caller's table of meshes. A joint draws a//! fixed part, nothing, or whichever part a slot currently selects, as a//! stop-motion face swaps eyes and mouths. A clip's part channels, or the//! caller, write each slot's choice; `resolve` turns choices into the part//! each joint draws.const std = @import("std");const assert = std.debug.assert;pub const Part = u16;pub const none: Part = std.math.maxInt(Part);pub const Slot = struct { /// The parts a choice indexes. parts: []const Part, /// The chosen part, or `none` for a choice past the slot's parts. pub fn select(slot: Slot, choice: u8) Part { if (choice >= slot.parts.len) return none; return slot.parts[choice]; }};pub const Attachment = union(enum) { nothing, part: Part, slot: u16,};/// The part each joint draws, `none` where it draws nothing.pub fn resolve( attachments: []const Attachment, slots: []const Slot, choices: []const u8, out: []Part,) void { assert(choices.len == slots.len); assert(out.len == attachments.len); for (attachments, out) |attachment, *drawn| { drawn.* = switch (attachment) { .nothing => none, .part => |fixed| fixed, .slot => |index| blk: { assert(index < slots.len); break :blk slots[index].select(choices[index]); }, }; }}test "slots swap parts and fixed parts stay" { const slots = [_]Slot{.{ .parts = &.{ 10, 11, 12 } }}; const attachments = [_]Attachment{ .nothing, .{ .part = 3 }, .{ .slot = 0 } }; var out: [3]Part = undefined; resolve(&attachments, &slots, &.{2}, &out); try std.testing.expectEqualSlices(Part, &.{ none, 3, 12 }, &out); resolve(&attachments, &slots, &.{7}, &out); try std.testing.expectEqual(none, out[2]);}Source: fun/rig/src/root.zig:24
zig
pub const part = @import("part.zig");Audit
| Definitions | 7 |
|---|---|
| Public names | 7 |
| Members | 4 |
| Version | 26.7.0 |
| Revision | daab053ee433 |