MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ spawn_sync()

void MayaFlux::Portal::Forma::Bridge::spawn_sync ( uint32_t  id,
std::function< void()>  sync_fn 
)

Spawn a per-frame GraphicsRoutine that calls sync_fn each tick.

Stores the task name in the outbound_tasks of the record for id so that unbind() cancels it correctly. The coroutine body is type-free – all type-specific work is captured inside sync_fn by the caller.

Parameters
idElement id whose outbound_tasks receives the task name.
sync_fnCallable invoked once per frame. Typically a lambda capturing Mapped<T> by reference and calling sync().

Definition at line 368 of file Bridge.cpp.

369{
370 auto name = make_task_name(id, "sync");
371 m_records[id].outbound_tasks.push_back(name);
372
373 auto routine = [](Vruta::TaskScheduler&,
374 std::function<void()> fn) -> Vruta::GraphicsRoutine {
375 auto& p = co_await Kriya::GetGraphicsPromise {};
376 while (!p.should_terminate) {
377 fn();
378 co_await Kriya::FrameDelay { .frames_to_wait = 1 };
379 }
380 };
381
383 std::make_shared<Vruta::GraphicsRoutine>(
384 routine(m_scheduler, std::move(sync_fn))),
385 name, false);
386}
Vruta::TaskScheduler & m_scheduler
Definition Bridge.hpp:522
std::string make_task_name(uint32_t id, const char *suffix) const
Definition Bridge.cpp:346
std::unordered_map< uint32_t, ElementRecord > m_records
Definition Bridge.hpp:527
void add_task(const std::shared_ptr< Routine > &routine, const std::string &name="", bool initialize=false)
Add a routine to the scheduler based on its processing token.
Definition Scheduler.cpp:23
GetPromiseBase< Vruta::graphics_promise > GetGraphicsPromise
Graphics domain promise accessor.

References MayaFlux::Vruta::TaskScheduler::add_task(), MayaFlux::Kriya::FrameDelay::frames_to_wait, m_records, m_scheduler, and make_task_name().

+ Here is the call graph for this function: