ssruntime/types.rs
1//! POD return types shared across the runtime API surface.
2//!
3//! These are plain `#[repr(C)]` structs designed for return-by-value across
4//! the FFI boundary, but the definitions live at the crate root (not under
5//! `ffi/`) so they are also reachable from the `Context` API and from the
6//! `web` feature without dragging in the C extern "C" surface.
7//!
8//! They are intentionally separate from ssab/effect_draw_plan FlatBuffers data —
9//! FB is for persistent or zero-copy bulk data, POD is for ephemeral per-call
10//! return values.
11
12#![allow(non_camel_case_types)]
13
14/// Resolved per-slot Instance event state, returned by
15/// `ss_runtime_get_active_event_instance`.
16///
17/// The runtime forward-scans the parent's `EventsPerFrame` and reports the
18/// most recent `EventInstance` whose `frame_index <= current parent frame`
19/// for `slot_index`. When no event is active, the function returns SS6
20/// default semantics: `is_synthetic_default = true`, `loop_num = 1`,
21/// `speed = 1.0`, all label hashes 0 (unset), all flags false.
22///
23/// `start_label_hash` / `end_label_hash` are returned raw. They are
24/// already resolved internally by `ss_instance_slot_step` against the
25/// child runtime context, which keeps late binding intact across
26/// dynamic-swap of the child ssab.
27#[repr(C)]
28#[derive(Clone, Copy, Debug)]
29pub struct ss_event_instance_info {
30 /// Parent `frame_index` this `EventInstance` was emitted at; 0 for synthetic default.
31 pub event_frame: i32,
32 /// 0 = unset → the child animation's start frame.
33 pub start_label_hash: u32,
34 pub start_offset: i32,
35 /// 0 = unset → the child animation's end frame.
36 pub end_label_hash: u32,
37 pub end_offset: i32,
38 /// -1 = infinite, >=1 = finite count.
39 pub loop_num: i32,
40 pub speed: f32,
41 pub independent: bool,
42 pub reverse: bool,
43 pub pingpong: bool,
44 /// `true` = SS6 default (no real event active), `false` = real `EventInstance`.
45 pub is_synthetic_default: bool,
46}
47
48impl ss_event_instance_info {
49 pub const fn synthetic_default() -> Self {
50 Self { event_frame: 0, start_label_hash: 0, start_offset: 0, end_label_hash: 0, end_offset: 0, loop_num: 1, speed: 1.0, independent: false, reverse: false, pingpong: false, is_synthetic_default: true }
51 }
52}
53
54impl Default for ss_event_instance_info {
55 fn default() -> Self {
56 Self::synthetic_default()
57 }
58}
59
60/// Resolved per-slot Effect event state, returned by
61/// `ss_runtime_get_active_effect_event`.
62///
63/// The runtime forward-scans the parent's `EventsPerFrame` and reports the
64/// most recent `EventEffect` whose `frame_index <= current parent frame`
65/// for `slot_index`. When no event is active, the runtime falls back to the
66/// part's `InitialEvents.effect` (if present); if neither exists, returns
67/// SS6 default semantics: `is_synthetic_default = true`, `start_time = 0`,
68/// `speed = 1.0`, `independent = false`.
69#[repr(C)]
70#[derive(Clone, Copy, Debug)]
71pub struct ss_effect_event_info {
72 /// Parent `frame_index` this `EventEffect` was emitted at; 0 for synthetic default
73 /// or `InitialEvents.effect` fallback.
74 pub event_frame: i32,
75 pub start_time: i32,
76 pub speed: f32,
77 pub independent: bool,
78 /// `true` = no real `EventEffect` matched (either `InitialEvents.effect` fallback
79 /// or full SS6 default), `false` = real `EventEffect` matched.
80 pub is_synthetic_default: bool,
81}
82
83impl ss_effect_event_info {
84 pub const fn synthetic_default() -> Self {
85 Self { event_frame: 0, start_time: 0, speed: 1.0, independent: false, is_synthetic_default: true }
86 }
87}
88
89impl Default for ss_effect_event_info {
90 fn default() -> Self {
91 Self::synthetic_default()
92 }
93}
94
95/// Result of `EffectSlot::step` / `ss_effect_slot_step`.
96///
97/// `draw_plan_buf` is a FlatBuffer-encoded `EffectDrawPlan` (see
98/// `fbs/effect_draw_plan.fbs`). It is valid only when `visible == true`,
99/// and only until the next `step` call on the same slot — callers must consume
100/// it within the same frame and not retain pointers across calls.
101#[repr(C)]
102#[derive(Clone, Copy, Debug)]
103pub struct ss_effect_step_result {
104 pub visible: bool,
105 pub draw_plan_buf: *const u8,
106 pub draw_plan_len: usize,
107}
108
109impl ss_effect_step_result {
110 pub const fn not_visible() -> Self {
111 Self { visible: false, draw_plan_buf: core::ptr::null(), draw_plan_len: 0 }
112 }
113}
114
115impl Default for ss_effect_step_result {
116 fn default() -> Self {
117 Self::not_visible()
118 }
119}
120
121/// Result of `InstanceSlot::step` / `ss_instance_slot_step`.
122///
123/// `transitioned == true` indicates a new EventInstance edge — `step` has
124/// configured the child for the new key without starting it, so the caller
125/// plays the child on this tick. Frame stepping is already applied inside
126/// `step`, so callers only consume `child_frame_no` to redraw.
127#[repr(C)]
128#[derive(Clone, Copy, Debug)]
129pub struct ss_instance_step_result {
130 pub visible: bool,
131 pub transitioned: bool,
132 pub independent: bool,
133 pub child_frame_no: f32,
134 pub child_looped: bool,
135}
136
137impl ss_instance_step_result {
138 pub const fn not_visible() -> Self {
139 Self { visible: false, transitioned: false, independent: false, child_frame_no: 0.0, child_looped: false }
140 }
141}
142
143impl Default for ss_instance_step_result {
144 fn default() -> Self {
145 Self::not_visible()
146 }
147}