8#ifdef COMPONENT_THREAD_SAFE
29class Tickable :
public std::enable_shared_from_this<Tickable> {
42 Tickable(
const bool isTicking,
const std::vector<std::shared_ptr<Action>>& actions);
53 bool Start(
const bool force =
false);
60 bool Stop(
const bool force =
false);
74 bool Tick(
const std::vector<EventID>& eventIds);
82 template <
typename T>
bool Tick(
const std::vector<EventID>& eventIds);
102#ifdef INCLUDE_PROFILING
132#ifdef COMPONENT_THREAD_SAFE
137#ifdef INCLUDE_PROFILING
138 Tickable& SetClock(
const ClockType clockType, std::chrono::time_point<std::chrono::steady_clock> clockValue);
139 std::chrono::time_point<std::chrono::steady_clock> GetClock(
const ClockType clockType)
const;
142#ifdef COMPONENT_THREAD_SAFE
143 std::atomic<bool> mIsTicking;
148#ifdef COMPONENT_THREAD_SAFE
149 mutable std::mutex mMutex;
151#ifdef INCLUDE_PROFILING
152 std::chrono::time_point<std::chrono::steady_clock> mClocks[
static_cast<size_t>(
ClockType::ClockMax)];
159#ifdef COMPONENT_THREAD_SAFE
160 if (!mIsTicking.load(std::memory_order_acquire)) {
166#ifdef INCLUDE_PROFILING
167 const auto start = std::chrono::steady_clock::now();
170 auto allActions = mActions.
Get(eventIds);
171 for (
const auto& action : *allActions) {
172 if (std::dynamic_pointer_cast<T>(action)) {
173 ran = action->Run() || ran;
176#ifdef INCLUDE_PROFILING
177 const auto end = std::chrono::steady_clock::now();
185#ifdef COMPONENT_THREAD_SAFE
186 if (!mIsTicking.load(std::memory_order_acquire)) {
192#ifdef INCLUDE_PROFILING
193 const auto start = std::chrono::steady_clock::now();
196 auto allActions = mActions.
Get(eventId);
197 for (
const auto& action : *allActions) {
198 if (std::dynamic_pointer_cast<T>(action)) {
199 ran = action->Run() || ran;
202#ifdef INCLUDE_PROFILING
203 const auto end = std::chrono::steady_clock::now();
int32_t EventID
Numeric identifier for an event. -1 is uninitialized, IDs < -1 are internally registered,...
Definition EventTypes.h:8
ActionList specialization with indexed EventAction lookup by EventID.
Definition EventActionList.h:27
std::shared_ptr< std::vector< std::shared_ptr< Action > > > Get(EventID eventId) const
Returns the indexed EventActions for a single EventID.
Definition EventActionList.h:83
Manages a collection of Actions and indexed EventActions.
Definition Tickable.h:29
virtual bool CanStop()
Permission hook; override to prevent stopping. Defaults to true.
const EventActionList & GetActionList() const
Returns a const reference to the internal EventActionList.
bool Start(const bool force=false)
Starts ticking, enabling EventID-targeted Tick() calls on Actions.
bool Stop(const bool force=false)
Stops ticking; subsequent Tick() calls become no-ops.
double GetTime(const ClockType clockType) const
Returns the wall-clock time for a profiling checkpoint.
bool Tick(const std::vector< EventID > &eventIds)
Ticks only indexed EventActions whose EventID matches one of the given IDs.
bool Tick(EventID eventId)
Ticks only indexed EventActions whose EventID matches the given ID.
Tickable(const bool isTicking, const std::vector< std::shared_ptr< Action > > &actions)
Constructs a Tickable with an initial set of Actions.
EventActionList & GetActionList()
Returns a mutable reference to the internal EventActionList.
virtual void Stopped(const bool forced)
Notification hook called after the Tickable has been stopped.
Tickable(const bool isTicking=true)
Constructs a Tickable.
virtual bool CanStart()
Permission hook; override to prevent starting. Defaults to true.
bool IsTicking() const
Returns true if this Tickable is currently ticking.
std::mutex & GetMutex()
Returns a reference to the internal mutex for synchronization. Only available when COMPONENT_THREAD_S...
virtual void Started(const bool forced)
Notification hook called after the Tickable has been started.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
ClockType
Identifies a profiling time-point within an Action or Tickable.
Definition Action.h:22