From c1f1006d3cfecb724d9a8040f1dcf6e4ebee9e2a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 18 Nov 2023 13:51:34 -0800 Subject: til_stream: add til_stream_render() This introduces a concept of a stream's module context, which is used to render the stream via til_stream_render(). The context is set using til_stream_set_module_context(), but at this time no reference is taken - it just puts the context into the stream for use by the render calls. The caller is responsible for ensuring it persist as long as the stream uses it. This is a preparatory commit for implementing pre/post render module contexts that get hooked into a stream. The impetus for this is supporting background music via modules like playit, without requiring stuff like rkt scenes to always include the bgm context in the scene's module context heirarchy. Nothing is functionally different here, the commit only adds the new interfaces for setting the context and rendering via stream instead of til_module_render() of the context you'd now set on the stream. --- src/til_stream.c | 22 ++++++++++++++++++++++ src/til_stream.h | 4 ++++ 2 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/til_stream.c b/src/til_stream.c index 8fd4b07..3f220fb 100644 --- a/src/til_stream.c +++ b/src/til_stream.c @@ -100,6 +100,7 @@ typedef struct til_stream_t { unsigned audio_controlled:1; til_stream_pipe_t *pipe_buckets[TIL_STREAM_PIPE_BUCKETS_COUNT]; til_stream_module_context_t *module_context_buckets[TIL_STREAM_CTXT_BUCKETS_COUNT]; + til_module_context_t *module_context; } til_stream_t; @@ -791,3 +792,24 @@ void til_stream_fprint_module_contexts(til_stream_t *stream, FILE *out) (void) til_stream_for_each_module_context(stream, til_stream_fprint_module_context_cb, out); fprintf(out, "\n"); } + + +void til_stream_set_module_context(til_stream_t *stream, til_module_context_t *context) +{ + assert(stream); + assert(context); + + /* TODO: it feels like this should probably take a reference */ + stream->module_context = context; +} + + +void til_stream_render(til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr) +{ + assert(stream); + assert(fragment_ptr); + + stream->frame++; + + til_module_render(stream->module_context, stream, ticks, fragment_ptr); +} diff --git a/src/til_stream.h b/src/til_stream.h index a0dde31..bae5abb 100644 --- a/src/til_stream.h +++ b/src/til_stream.h @@ -25,6 +25,7 @@ #include "til_setup.h" typedef struct til_audio_context_t til_audio_context_t; +typedef struct til_fb_fragment_t til_fb_fragment_t; typedef struct til_stream_t til_stream_t; typedef struct til_stream_module_context_t til_stream_module_context_t; typedef struct til_stream_pipe_t til_stream_pipe_t; @@ -80,4 +81,7 @@ int til_stream_find_module_contexts(til_stream_t *stream, const char *path, size unsigned til_stream_gc_module_contexts(til_stream_t *stream); void til_stream_fprint_module_contexts(til_stream_t *stream, FILE *out); +void til_stream_set_module_context(til_stream_t *stream, til_module_context_t *context); +void til_stream_render(til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr); + #endif -- cgit v1.2.3