jubilant-funicular
Classes | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
nta::CallbackManager Class Reference

#include <CallbackManager.h>

Collaboration diagram for nta::CallbackManager:
Collaboration graph
[legend]

Classes

struct  event
 A function to run at a certain time with some regularity. More...
 

Static Public Member Functions

static uint64_t setInterval (const Thunk &thunk, uint64_t when, uint64_t period)
 
static uint64_t setTimeout (const Thunk &thunk, uint64_t when)
 Schedules a function to be called once after when frames and then repeatedly after.
 
static bool delay (uint64_t id, uint64_t when, bool absolute=true)
 Changes when an event is next scheduled to run.
 
static void init ()
 Initializes the CallbackManager.
 
static void clear (uint64_t id)
 Removes the event with the given id.
 
static void increment_frame ()
 Informs CallbackManager that a frame has passed.
 
static void destroy ()
 Destroys the CallbackManager.
 

Static Private Member Functions

static void dispatch ()
 
static void dequeue (uint64_t id)
 Removes event from m_queue but not m_active (assumes id is valid)
 

Static Private Attributes

static std::map< uint64_t, eventm_active
 The events waiting to happen (key is event.id)
 
static std::map< uint64_t, std::vector< event * > > m_queue
 "Priority queue" of events ordered by when they should occur
 
static utils::ThreadPool m_pool
 ThreadPool used for scheduling events to happen.
 
static std::thread m_dispatcher
 Thread used to dispatch events.
 
static std::atomic< uint64_t > m_next
 id given to the next created event
 
static std::mutex m_mutex
 
static std::condition_variable_any m_cv
 
static bool m_working
 Global flag saying whether or not the CallbackManager has been destroyed.
 
static uint64_t m_curr_frame
 The current frame.
 

Detailed Description

Allows scheduling of functions to be called at a later point in time

Todo:

Add ability to base timing off of actual time instead of frames

make non-static (ideally, one CallbackManager per ScreenManager)

Definition at line 12 of file CallbackManager.h.


Class Documentation

◆ nta::CallbackManager::event

struct nta::CallbackManager::event

A function to run at a certain time with some regularity.

Definition at line 15 of file CallbackManager.h.

Collaboration diagram for nta::CallbackManager::event:
Class Members
uint64_t id id of event
uint64_t period How many frames between consecutive runs.
Thunk thunk Function to execute.
uint64_t when How many frames to run it in.

Member Function Documentation

◆ dispatch()

void nta::CallbackManager::dispatch ( )
staticprivate

Function run by m_dispatcher Handles calling of the various events at the right times

Definition at line 56 of file CallbackManager.cpp.

Referenced by init().

◆ setInterval()

uint64_t nta::CallbackManager::setInterval ( const Thunk &  thunk,
uint64_t  when,
uint64_t  period 
)
static

Schedules a function to be called after when frames and then repeatedly after each subsequent period frames

Definition at line 15 of file CallbackManager.cpp.

Referenced by setTimeout().


The documentation for this class was generated from the following files: