diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-06-12 22:39:15 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-06-12 22:39:15 -0700 |
commit | 55ce5773333b41229798c2a9b238812660707b7d (patch) | |
tree | b11909013fe0320e09bde52807209f710a28bb33 /src/stage.c | |
parent | 19acc6de674d44d44f8d3bcb66568de3e5abfe3a (diff) |
libstage: add return value to stage_render_func_t
This introduces some stage_render() flow control and render-time
freeing of nodes via the nodes render_func().
It's particularly useful for one-shot ephemeral nodes which are
thrown on-screen and require nothing more than their render and
free funcs for a full lifecycle. An example would be something
running an effect briefly which runs autonomously from just a
timer alone, returning the free request from the final render once
the ending time arrives.
Diffstat (limited to 'src/stage.c')
-rw-r--r-- | src/stage.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/stage.c b/src/stage.c index a714f1f..63afbcb 100644 --- a/src/stage.c +++ b/src/stage.c @@ -302,19 +302,33 @@ static void _prepare_stage(stage_t *stage, float alpha, void *render_ctxt) } -static void _render_stage(const stage_t *stage, float alpha, void *render_ctxt) +static void _render_stage(stage_t *stage, float alpha, void *render_ctxt) { - float a = alpha * stage->alpha; + stage_render_func_ret_t r = STAGE_RENDER_FUNC_RET_CONTINUE; + float a; assert(stage); + a = alpha * stage->alpha; + if (stage->ops->render_func) - stage->ops->render_func(stage, stage->object, a, render_ctxt); + r = stage->ops->render_func(stage, stage->object, a, render_ctxt); + + switch (r) { + case STAGE_RENDER_FUNC_RET_FREE: + stage_free(stage); + case STAGE_RENDER_FUNC_RET_SKIP: + return; + case STAGE_RENDER_FUNC_RET_CONTINUE: + break; + default: + assert(0); + } for (int i = 0; i < STAGE_LAYERS_MAX; i++) { - stage_t *s; + stage_t *s, *_s; - DLL_FOR_EACH_ENTRY(&stage->layers[i], s, stage_t, layer) { + DLL_FOR_EACH_ENTRY_SAFE(&stage->layers[i], s, _s, stage_t, layer) { if (!s->active) continue; @@ -342,11 +356,11 @@ int stage_render(stage_t *stage, void *render_ctxt) _prepare_stage(stage, 1.f, render_ctxt); if (stage->dirty) { + stage->dirty = 0; + if (stage->active) _render_stage(stage, 1.f, render_ctxt); - stage->dirty = 0; - return 1; } |