Name the keep switch for what it does: nka_set_keep_at_rest

nka_set_lazy_init(a, 0) read as a double negative at every call site. The
switch is now nka_set_keep_at_rest(a, on), off by default, so behavior is
unchanged: a tween first asked at its target is stored only when it is on.
nka_lazy_init becomes nka_keep_at_rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 09:09:13 +02:00
co-authored by Claude Opus 5.5
parent 9e4eaf6a12
commit 3067dd406a
3 changed files with 11 additions and 10 deletions
+2
View File
@@ -75,6 +75,8 @@ glyph, and an inspector window with clip timelines and a profiler. Tested with N
the `dt` of every call, and `nka_busy` tells an app that only draws on input when to keep going.
- Nuklear cannot turn text: glyphs on a path stay upright, and the rotate effect fades. Scaled text needs
a backend that draws Nuklear's vertex output.
- A tween first asked at its target is not stored until it moves, which saves an entry for every value
that never animates; `nka_set_keep_at_rest(anim, 1)` stores it anyway.
- Parametric curves are computed exactly rather than read from lookup tables.
- Clip files became buffers you read and write yourself, little-endian and checksummed.
- Bugs fixed on the way, among them: the queue policy only waited a frame, additive tweens added their
+7 -8
View File
@@ -85,9 +85,9 @@ NKA_API void nka_clear(struct nka_context *a);
NKA_API void nka_reserve(struct nka_context *a, int tweens);
NKA_API void nka_set_time_scale(struct nka_context *a, float scale);
NKA_API float nka_time_scale(const struct nka_context *a);
/* On by default: a tween asked for its init value is not stored. */
NKA_API void nka_set_lazy_init(struct nka_context *a, int on);
NKA_API int nka_lazy_init(const struct nka_context *a);
/* Off by default: a tween first asked at its target is not stored. */
NKA_API void nka_set_keep_at_rest(struct nka_context *a, int on);
NKA_API int nka_keep_at_rest(const struct nka_context *a);
/* The sizes that relative targets are fractions of. */
NKA_API void nka_set_anchor(struct nka_context *a, int space, struct nk_vec2 size);
NKA_API struct nk_vec2 nka_anchor(const struct nka_context *a, int space);
@@ -954,7 +954,7 @@ struct nka_context {
double time;
float dt, scale;
nk_uint frame;
int lazy, busy;
int keep_at_rest, busy;
nka_ease_fn custom[16];
struct nk_vec2 anchors[NKA_ANCHOR_COUNT];
struct nka__map chans, anims;
@@ -1535,7 +1535,7 @@ static void nka__tween(struct nka_context *a, nk_hash id, nk_hash ch, int kind,
nk_hash key = nka__key(id, ch, kind);
struct nka__chan *c = (struct nka__chan *)nka__get(&a->chans, key);
if (!c) {
if (a->lazy && policy < NKA_POLICY_ADDITIVE && nka__near(target, init, n)) c = 0;
if (!a->keep_at_rest && policy < NKA_POLICY_ADDITIVE && nka__near(target, init, n)) c = 0;
else c = (struct nka__chan *)nka__put(a, &a->chans, key, 0);
if (!c) {
for (i = 0; i < 4; ++i) out[i] = target[i];
@@ -6925,7 +6925,6 @@ NKA_API struct nka_context *nka_create(const struct nk_allocator *alloc)
nka__zero(a, sizeof *a);
a->alloc = al;
a->scale = 1;
a->lazy = 1;
a->chans.size = sizeof(struct nka__chan);
a->anims.size = sizeof(struct nka__anim);
a->path_map.size = sizeof(struct nka__path_data);
@@ -7014,8 +7013,8 @@ NKA_API void nka_reserve(struct nka_context *a, int tweens)
NKA_API void nka_set_time_scale(struct nka_context *a, float scale) { if (a) a->scale = scale > 0 ? scale : 0; }
NKA_API float nka_time_scale(const struct nka_context *a) { return a ? a->scale : 1; }
NKA_API void nka_set_lazy_init(struct nka_context *a, int on) { if (a) a->lazy = on != 0; }
NKA_API int nka_lazy_init(const struct nka_context *a) { return a ? a->lazy : 1; }
NKA_API void nka_set_keep_at_rest(struct nka_context *a, int on) { if (a) a->keep_at_rest = on != 0; }
NKA_API int nka_keep_at_rest(const struct nka_context *a) { return a ? a->keep_at_rest : 0; }
#endif /* NKA__IMPLEMENTED */
#endif /* NUKANIM_IMPLEMENTATION */
+2 -2
View File
@@ -159,10 +159,10 @@ static void test_tweens(void)
CHECK(nka_tween_float(a, id, x, 0, 1, linear, NKA_POLICY_CROSSFADE, 0) == 0);
CHECK(!nka_busy(a));
nka_set_lazy_init(a, 0);
nka_set_keep_at_rest(a, 1);
CHECK(nka_tween_float(a, id, nka_id("eager"), 3, 1, linear, NKA_POLICY_CROSSFADE, 3) == 3);
CHECK(a->chans.len == 2 && !nka_busy(a));
nka_set_lazy_init(a, 1);
nka_set_keep_at_rest(a, 0);
CHECK(nka_tween_float(a, id, nka_id("cut"), 5, 1, linear, NKA_POLICY_CUT, 0) == 5);
CHECK(!nka_busy(a));