93 return try_resume(current_value);
209 template <
typename... Args>
212 update_params_impl(std::forward<Args>(args)...);
224 template <
typename T>
227 set_state_impl(key, std::move(
value));
239 template <
typename T>
242 return get_state_impl<T>(key);
254 template <
typename T>
257 void* raw_ptr = get_state_impl_raw(key);
262 return std::any_cast<T>(
static_cast<std::any*
>(raw_ptr));
263 }
catch (
const std::bad_any_cast&) {
283 template <
typename T,
typename... Args>
286 set_state(key, std::move(
value));
287 if constexpr (
sizeof...(args) > 0) {
288 update_params_impl(std::forward<Args>(args)...);
377 [[nodiscard]]
bool is_active()
const override;
379 bool initialize_state(uint64_t current_sample = 0U)
override;
381 bool try_resume(uint64_t current_context)
override;
383 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
385 bool force_resume()
override;
389 return m_handle.promise().active_delay_context;
394 m_handle.promise().active_delay_context = context;
397 bool restart()
override;
399 [[nodiscard]] uint64_t next_execution()
const override;
401 [[nodiscard]]
bool requires_clock_sync()
const override;
405 return m_handle.promise().auto_resume;
410 m_handle.promise().auto_resume = auto_resume;
415 return m_handle.promise().should_terminate;
420 m_handle.promise().set_should_terminate(should_terminate);
425 m_handle.promise().on_complete(std::move(
callback));
430 return m_handle.promise().sync_to_clock;
435 return m_handle.promise().next_sample;
440 m_handle.promise().next_sample = next_sample;
445 return m_handle.promise().next_buffer_cycle;
450 m_handle.promise().next_buffer_cycle = next_cycle;
458 void set_state_impl(
const std::string& key, std::any
value)
override;
459 void* get_state_impl_raw(
const std::string& key)
override;
563 [[nodiscard]]
bool is_active()
const override;
565 bool initialize_state(uint64_t current_frame = 0U)
override;
567 bool try_resume(uint64_t current_context)
override;
569 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
571 bool force_resume()
override;
575 return m_handle.promise().active_delay_context;
580 m_handle.promise().active_delay_context = context;
583 bool restart()
override;
585 [[nodiscard]] uint64_t next_execution()
const override;
587 [[nodiscard]]
bool requires_clock_sync()
const override;
591 return m_handle.promise().auto_resume;
596 m_handle.promise().auto_resume = auto_resume;
601 return m_handle.promise().should_terminate;
606 m_handle.promise().set_should_terminate(should_terminate);
611 m_handle.promise().on_complete(std::move(
callback));
616 return m_handle.promise().sync_to_clock;
621 return m_handle.promise().next_frame;
626 m_handle.promise().next_frame = next_frame;
634 void set_state_impl(
const std::string& key, std::any
value)
override;
635 void* get_state_impl_raw(
const std::string& key)
override;
677 [[nodiscard]]
bool is_active()
const override;
678 bool initialize_state(uint64_t current_context = 0U)
override;
679 bool try_resume(uint64_t current_context)
override;
680 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
681 bool force_resume()
override;
682 bool restart()
override;
684 [[nodiscard]] uint64_t next_execution()
const override;
685 [[nodiscard]]
bool requires_clock_sync()
const override;
689 return m_handle.promise().active_delay_context.load(std::memory_order_acquire);
694 m_handle.promise().active_delay_context.store(context, std::memory_order_release);
699 return m_handle.promise().auto_resume;
704 m_handle.promise().auto_resume = auto_resume;
709 return m_handle.promise().should_terminate;
714 m_handle.promise().set_should_terminate(should_terminate);
719 m_handle.promise().on_complete(std::move(
callback));
724 return m_handle.promise().sync_to_clock;
729 return m_handle.promise().next_sample.load(std::memory_order_acquire);
734 m_handle.promise().next_sample.store(next_sample, std::memory_order_release);
739 return m_handle.promise().next_frame.load(std::memory_order_acquire);
744 m_handle.promise().next_frame.store(next_frame, std::memory_order_release);
748 void set_state_impl(
const std::string& key, std::any
value)
override;
749 void* get_state_impl_raw(
const std::string& key)
override;
785 explicit FreeRoutine(std::coroutine_handle<promise_type>
h);
793 [[nodiscard]]
bool is_active()
const override;
794 bool initialize_state(uint64_t current_context = 0U)
override;
795 bool try_resume(uint64_t current_context)
override;
796 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
797 bool force_resume()
override;
798 bool restart()
override;
805 return m_handle ? m_handle.promise().auto_resume :
false;
811 m_handle.promise().auto_resume = v;
816 return m_handle ? m_handle.promise().should_terminate.load() :
true;
822 m_handle.promise().set_should_terminate(v);
828 m_handle.promise().on_complete(std::move(
callback));
839 void set_state_impl(
const std::string& key, std::any
value)
override;
840 void* get_state_impl_raw(
const std::string& key)
override;
bool get_auto_resume() const override
Get auto_resume flag from promise.
std::coroutine_handle< promise_type > m_handle
void set_auto_resume(bool auto_resume) override
Set auto_resume flag in promise.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
void set_delay_context(DelayContext context) override
Set the active delay context for this routine.
void set_next_frame(uint64_t next_frame) override
Set next frame execution time (graphics domain)
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
void on_complete(std::function< void()> callback) override
Register a callback invoked once at final suspend or a termination request, whichever occurs first.
void set_next_sample(uint64_t next_sample) override
Set next sample execution time (audio domain)
bool get_should_terminate() const override
Get should_terminate flag from promise.
DelayContext get_delay_context() const override
Get the active delay context for this routine.
void set_should_terminate(bool should_terminate) override
Set should_terminate flag in promise.
Coroutine resumed by more than one clock.
FreeRoutine(const FreeRoutine &other)=delete
std::coroutine_handle< promise_type > m_handle
void on_complete(std::function< void()> callback) override
Register a callback invoked once at final suspend or a termination request, whichever occurs first.
FreeRoutine & operator=(const FreeRoutine &other)=delete
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
bool get_auto_resume() const override
Get auto_resume flag from promise.
uint64_t next_execution() const override
Gets the sample position when this routine should next execute.
void set_next_frame(uint64_t) override
Set next frame execution time (graphics domain)
void set_should_terminate(bool v) override
Set should_terminate flag in promise.
bool requires_clock_sync() const override
Check if the routine should synchronize with a clock.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
void set_auto_resume(bool v) override
Set auto_resume flag in promise.
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
void set_next_sample(uint64_t) override
Set next sample execution time (audio domain)
bool get_should_terminate() const override
Get should_terminate flag from promise.
Coroutine resumed when a caller-supplied condition becomes true.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
void set_auto_resume(bool auto_resume) override
Set auto_resume flag in promise.
void set_should_terminate(bool should_terminate) override
Set should_terminate flag in promise.
bool get_should_terminate() const override
Get should_terminate flag from promise.
void set_next_frame(uint64_t next_frame) override
Set next frame execution time (graphics domain)
GraphicsRoutine(const GraphicsRoutine &other)=delete
void set_next_sample(uint64_t) override
Set next sample execution time (audio domain)
bool get_auto_resume() const override
Get auto_resume flag from promise.
GraphicsRoutine & operator=(const GraphicsRoutine &other)=delete
void on_complete(std::function< void()> callback) override
Register a callback invoked once at final suspend or a termination request, whichever occurs first.
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
DelayContext get_delay_context() const override
Get the active delay context for this routine.
void set_delay_context(DelayContext context) override
Set the active delay context for this routine.
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
A C++20 coroutine-based graphics processing task with frame-accurate timing.
void set_state(const std::string &key, T value)
Sets a named state value in the coroutine.
virtual void set_next_frame(uint64_t next_frame)=0
Set next frame execution time (graphics domain)
virtual bool force_resume()=0
Force resume the coroutine, bypassing all checks Used only during shutdown to push coroutines to fina...
virtual void on_complete(std::function< void()> callback)=0
Register a callback invoked once at final suspend or a termination request, whichever occurs first.
virtual uint64_t get_next_sample() const =0
Get next sample execution time (audio domain)
virtual bool try_resume_with_context(uint64_t current_value, DelayContext)
Attempts to resume the coroutine with explicit temporal context.
virtual bool restart()=0
Restarts the coroutine from the beginning.
virtual void set_delay_context(DelayContext)
Set the active delay context for this routine.
void update_params(Args... args)
Updates multiple named parameters in the coroutine's state.
virtual bool is_active() const =0
Checks if the coroutine is still active.
virtual ProcessingToken get_processing_token() const =0
Get the processing token that determines how this routine should be scheduled.
virtual void set_state_impl(const std::string &key, std::any value)=0
virtual ~Routine()=default
Destructor.
virtual bool get_sync_to_clock() const =0
Get sync_to_clock flag from promise.
virtual uint64_t next_execution() const =0
Gets the sample position when this routine should next execute.
virtual void set_should_terminate(bool should_terminate)=0
Set should_terminate flag in promise.
virtual bool requires_clock_sync() const =0
Check if the routine should synchronize with a clock.
virtual void set_next_sample(uint64_t next_sample)=0
Set next sample execution time (audio domain)
virtual void set_auto_resume(bool auto_resume)=0
Set auto_resume flag in promise.
virtual void update_params_impl()
brief Implementation helper for update_params
virtual bool get_should_terminate() const =0
Get should_terminate flag from promise.
virtual void * get_state_impl_raw(const std::string &key)=0
virtual uint64_t get_next_frame() const =0
Get next frame execution time (graphics domain)
T * get_state(const std::string &key)
Gets a named state value from the coroutine.
void update_params_impl(const std::string &key, T value, Args... args)
Implementation helper for update_params.
virtual DelayContext get_delay_context() const
Get the active delay context for this routine.
virtual bool initialize_state(uint64_t current_context=0U)=0
Initializes the coroutine's state for execution.
virtual bool try_resume(uint64_t current_context)=0
Attempts to resume the coroutine if it's ready to execute.
T * get_state_impl(const std::string &key)
Implementation helper for get_state.
virtual bool get_auto_resume() const =0
Get auto_resume flag from promise.
Base class for all coroutine types in the MayaFlux engine.
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
SoundRoutine(const SoundRoutine &other)=delete
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
void set_auto_resume(bool auto_resume) override
Set auto_resume flag in promise.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
bool get_auto_resume() const override
Get auto_resume flag from promise.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
void set_next_sample(uint64_t next_sample) override
Set next sample execution time (audio domain)
SoundRoutine & operator=(const SoundRoutine &other)=delete
bool get_should_terminate() const override
Get should_terminate flag from promise.
void on_complete(std::function< void()> callback) override
Register a callback invoked once at final suspend or a termination request, whichever occurs first.
void set_next_frame(uint64_t next_cycle) override
Set next frame execution time (graphics domain)
void set_delay_context(DelayContext context) override
Set the active delay context for this routine.
DelayContext get_delay_context() const override
Get the active delay context for this routine.
void set_should_terminate(bool should_terminate) override
Set should_terminate flag in promise.
A C++20 coroutine-based audio processing task with sample-accurate timing.
DelayContext
Discriminator for different temporal delay mechanisms.
Coroutine promise type for audio processing tasks with sample-accurate timing.
Coroutine promise for routines suspended on an arbitrary boolean condition.
Coroutine promise for routines resumed by more than one clock.
Coroutine promise type for graphics processing tasks with frame-accurate timing.