93 return try_resume(current_value);
198 template <
typename... Args>
201 update_params_impl(std::forward<Args>(args)...);
213 template <
typename T>
216 set_state_impl(key, std::move(value));
228 template <
typename T>
231 return get_state_impl<T>(key);
243 template <
typename T>
246 void* raw_ptr = get_state_impl_raw(key);
251 return std::any_cast<T>(
static_cast<std::any*
>(raw_ptr));
252 }
catch (
const std::bad_any_cast&) {
272 template <
typename T,
typename... Args>
275 set_state(key, std::move(value));
276 if constexpr (
sizeof...(args) > 0) {
277 update_params_impl(std::forward<Args>(args)...);
366 [[nodiscard]]
bool is_active()
const override;
368 bool initialize_state(uint64_t current_sample = 0U)
override;
370 bool try_resume(uint64_t current_context)
override;
372 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
374 bool force_resume()
override;
378 return m_handle.promise().active_delay_context;
383 m_handle.promise().active_delay_context = context;
386 bool restart()
override;
388 [[nodiscard]] uint64_t next_execution()
const override;
390 [[nodiscard]]
bool requires_clock_sync()
const override;
394 return m_handle.promise().auto_resume;
399 m_handle.promise().auto_resume = auto_resume;
404 return m_handle.promise().should_terminate;
409 m_handle.promise().should_terminate = should_terminate;
414 return m_handle.promise().sync_to_clock;
419 return m_handle.promise().next_sample;
424 m_handle.promise().next_sample = next_sample;
429 return m_handle.promise().next_buffer_cycle;
434 m_handle.promise().next_buffer_cycle = next_cycle;
442 void set_state_impl(
const std::string& key, std::any value)
override;
443 void* get_state_impl_raw(
const std::string& key)
override;
547 [[nodiscard]]
bool is_active()
const override;
549 bool initialize_state(uint64_t current_frame = 0U)
override;
551 bool try_resume(uint64_t current_context)
override;
553 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
555 bool force_resume()
override;
559 return m_handle.promise().active_delay_context;
564 m_handle.promise().active_delay_context = context;
567 bool restart()
override;
569 [[nodiscard]] uint64_t next_execution()
const override;
571 [[nodiscard]]
bool requires_clock_sync()
const override;
575 return m_handle.promise().auto_resume;
580 m_handle.promise().auto_resume = auto_resume;
585 return m_handle.promise().should_terminate;
590 m_handle.promise().should_terminate = should_terminate;
595 return m_handle.promise().sync_to_clock;
600 return m_handle.promise().next_frame;
605 m_handle.promise().next_frame = next_frame;
613 void set_state_impl(
const std::string& key, std::any value)
override;
614 void* get_state_impl_raw(
const std::string& key)
override;
656 [[nodiscard]]
bool is_active()
const override;
657 bool initialize_state(uint64_t current_context = 0U)
override;
658 bool try_resume(uint64_t current_context)
override;
659 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
660 bool force_resume()
override;
661 bool restart()
override;
663 [[nodiscard]] uint64_t next_execution()
const override;
664 [[nodiscard]]
bool requires_clock_sync()
const override;
668 return m_handle.promise().active_delay_context.load(std::memory_order_acquire);
673 m_handle.promise().active_delay_context.store(context, std::memory_order_release);
678 return m_handle.promise().auto_resume;
683 m_handle.promise().auto_resume = auto_resume;
688 return m_handle.promise().should_terminate;
693 m_handle.promise().should_terminate = should_terminate;
698 return m_handle.promise().sync_to_clock;
703 return m_handle.promise().next_sample.load(std::memory_order_acquire);
708 m_handle.promise().next_sample.store(next_sample, std::memory_order_release);
713 return m_handle.promise().next_frame.load(std::memory_order_acquire);
718 m_handle.promise().next_frame.store(next_frame, std::memory_order_release);
722 void set_state_impl(
const std::string& key, std::any value)
override;
723 void* get_state_impl_raw(
const std::string& key)
override;
759 explicit FreeRoutine(std::coroutine_handle<promise_type>
h);
767 [[nodiscard]]
bool is_active()
const override;
768 bool initialize_state(uint64_t current_context = 0U)
override;
769 bool try_resume(uint64_t current_context)
override;
770 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
771 bool force_resume()
override;
772 bool restart()
override;
779 return m_handle ? m_handle.promise().auto_resume :
false;
785 m_handle.promise().auto_resume = v;
790 return m_handle ? m_handle.promise().should_terminate :
true;
796 m_handle.promise().should_terminate = v;
807 void set_state_impl(
const std::string& key, std::any value)
override;
808 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 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
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
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 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 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.