diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-01-25 17:26:54 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-01-25 17:38:27 -0800 |
commit | 6385931985fa6fa8dd7ed69c20785d6b8d9cf37a (patch) | |
tree | 8fd19a7f72e60202367b417827112f7a57c0f24e /src/threads.c | |
parent | 792d0a60dd05035435574633c4a13a666fe6ce5d (diff) |
rototiller: introduce ticks and wire up to modules
Most modules find themselves wanting some kind of "t" value increasing
with time or frames rendered. It's common for them to create and
maintain this variable locally, incrementing it with every frame
rendered.
It may be interesting to introduce a global notion of ticks since
rototiller started, and have all modules derive their "t" value from
this instead of having their own private versions of it.
In future modules and general innovations it seems likely that playing
with time, like jumping it forwards and backwards to achieve some
visual effects, will be desirable. This isn't applicable to all
modules, but for many their entire visible state is derived from their
"t" value, making them entirely reversible.
This commit doesn't change any modules functionally, it only adds the
plumbing to pull a ticks value down to the modules from the core.
A ticks offset has also been introduced in preparation for supporting
dynamic shifting of the ticks value, though no API is added for doing
so yet.
It also seems likely an API will be needed for disabling the
time-based ticks advancement, with functions for explicitly setting
its value. If modules are created for incorporating external
sequencers and music coordination, they will almost certainly need to
manage the ticks value explicitly. When a sequencer jumps
forwards/backwards in the creative process, the module glue
responsible will need to keep ticks synchronized with the
sequencer/editor tool.
Before any of this can happen, we need ticks as a first-class core
thing shared by all modules.
Future commits will have to modify existing modules to use the ticks
appropriately, replacing their bespoke variants.
Diffstat (limited to 'src/threads.c')
-rw-r--r-- | src/threads.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/threads.c b/src/threads.c index 0a68861..3cd69d3 100644 --- a/src/threads.c +++ b/src/threads.c @@ -22,10 +22,11 @@ typedef struct threads_t { pthread_mutex_t frame_mutex; pthread_cond_t frame_cond; - void (*render_fragment_func)(void *context, unsigned cpu, fb_fragment_t *fragment); + void (*render_fragment_func)(void *context, unsigned ticks, unsigned cpu, fb_fragment_t *fragment); void *context; fb_fragment_t *fragment; rototiller_fragmenter_t fragmenter; + unsigned ticks; unsigned next_fragment; unsigned frame_num; @@ -63,7 +64,7 @@ static void * thread_func(void *_thread) if (!threads->fragmenter(threads->context, threads->fragment, frag_num, &fragment)) break; - threads->render_fragment_func(threads->context, thread->id, &fragment); + threads->render_fragment_func(threads->context, threads->ticks, thread->id, &fragment); } /* report as idle */ @@ -90,7 +91,7 @@ void threads_wait_idle(threads_t *threads) /* submit a frame's fragments to the threads */ -void threads_frame_submit(threads_t *threads, fb_fragment_t *fragment, rototiller_fragmenter_t fragmenter, void (*render_fragment_func)(void *context, unsigned cpu, fb_fragment_t *fragment), void *context) +void threads_frame_submit(threads_t *threads, fb_fragment_t *fragment, rototiller_fragmenter_t fragmenter, void (*render_fragment_func)(void *context, unsigned ticks, unsigned cpu, fb_fragment_t *fragment), void *context, unsigned ticks) { threads_wait_idle(threads); /* XXX: likely non-blocking; already happens pre page flip */ @@ -99,6 +100,7 @@ void threads_frame_submit(threads_t *threads, fb_fragment_t *fragment, rototille threads->fragmenter = fragmenter; threads->render_fragment_func = render_fragment_func; threads->context = context; + threads->ticks = ticks; threads->frame_num++; threads->n_idle = threads->next_fragment = 0; pthread_cond_broadcast(&threads->frame_cond); |