CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Timer.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
13
14#include <asio/high_resolution_timer.hpp>
15
16namespace CeresEngine {
17
18 template<typename Clock> class TTimer {
19 public:
20 using TimePoint = typename Clock::time_point;
21 using Duration = typename Clock::duration;
23
24 private:
25 using TimerType = asio::basic_waitable_timer<Clock, asio::wait_traits<Clock>, AnyIOExecutor>;
27
29 bool mRepeating = false;
31
32 public:
33 // TTimer(ExecutionContext& context, Duration duration, Callback callback, bool repeating = false);
34 TTimer(AnyIOExecutor executor, Duration duration, Callback callback, bool repeating = false);
35
36 // TTimer(ExecutionContext& context, Duration duration, Callback callback, Duration repeatInterval);
38
39 // TTimer(ExecutionContext& context, TimePoint timePoint, Callback callback);
41
42 // TTimer(ExecutionContext& context, TimePoint timePoint, Callback callback, Duration repeatInterval);
44
46
47 private:
50 void fire();
51
52 public:
53 // /// \copydoc TTimer(ExecutionContext&, Duration, Callback, bool)
54 // static UPtr<TTimer> create(ExecutionContext& context, Duration duration, Callback callback, bool repeating = false);
55
58
59 // /// \copydoc TTimer(ExecutionContext&, Duration, Callback, Duration);
60 // static UPtr<TTimer> create(ExecutionContext& context, Duration duration, Callback callback, Duration repeatInterval);
61
64
65 // /// \copydoc TTimer(ExecutionContext&, TimePoint, Callback);
66 // static UPtr<TTimer> create(ExecutionContext& context, TimePoint timePoint, Callback callback);
67
70
71 // /// \copydoc TTimer(ExecutionContext&, TimePoint, Callback, Duration);
72 // static UPtr<TTimer> create(ExecutionContext& context, TimePoint timePoint, Callback callback, Duration repeatInterval);
73
76 };
77
81
85
86} // namespace CeresEngine
The AnyExecutor type is a polymorphic executor that supports the set of properties required by I/O ob...
Definition ExecutionContext.hpp:309
Definition Timer.hpp:18
TTimer(AnyIOExecutor executor, TimePoint timePoint, Callback callback)
Duration mRepeatInterval
Definition Timer.hpp:30
Callback mCallback
Definition Timer.hpp:28
void setup(Duration duration)
static UPtr< TTimer > create(AnyIOExecutor executor, Duration duration, Callback callback, bool repeating=false)
TimerType mTimer
Definition Timer.hpp:26
TTimer(AnyIOExecutor executor, Duration duration, Callback callback, Duration repeatInterval)
asio::basic_waitable_timer< Clock, asio::wait_traits< Clock >, AnyIOExecutor > TimerType
Definition Timer.hpp:25
typename Clock::duration Duration
Definition Timer.hpp:21
bool mRepeating
Definition Timer.hpp:29
TTimer(AnyIOExecutor executor, TimePoint timePoint, Callback callback, Duration repeatInterval)
TTimer(AnyIOExecutor executor, Duration duration, Callback callback, bool repeating=false)
UniqueFunction< void(TTimer *)> Callback
Definition Timer.hpp:22
typename Clock::time_point TimePoint
Definition Timer.hpp:20
Definition Application.hpp:19
std::unique_ptr< T, Deleter > UPtr
UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that o...
Definition SmartPtr.hpp:28
FunctionBase< true, false, fu2::capacity_default, true, false, Signatures... > UniqueFunction
An owning non copyable function wrapper for arbitrary callable types.
Definition Function.hpp:59
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668