Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
TimerManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5#include <vector>
6
7#include <entt/entt.hpp>
8
9namespace Engine
10{
11 class EngineKern;
12}
13
14namespace Engine::Entities
15{
16 class Actor;
17}
18
19namespace Engine::Core
20{
22 {
23 public:
25 {
26 uint64_t id = 0;
27
28 [[nodiscard]] explicit operator bool() const
29 {
30 return id != 0;
31 }
32 };
33
34 using Callback = std::function<void()>;
35
36 TimerManager() = default;
37 explicit TimerManager( EngineKern * engine );
38
39 TimerHandle setTimer( double delaySeconds, Callback callback );
40
42 Entities::Actor * owner,
43 double delaySeconds,
44 std::function<void( Entities::Actor & )> callback
45 );
46
47 void cancelTimer( TimerHandle handle );
48 void cancelTimersFor( const Entities::Actor * owner );
49 void clear();
50 void tick( double nowSeconds );
51
52 private:
54 {
56 double fireTimeSeconds = 0.0;
58 entt::entity ownerEntity = entt::null;
60 };
61
62 [[nodiscard]] double getCurrentTimeSeconds() const;
63 [[nodiscard]] bool isEventStillValid( const TimerEvent & event ) const;
64 void insertTimer( TimerEvent event );
65
66 EngineKern * engine_ = nullptr;
67 std::vector<TimerEvent> timers_;
68 uint64_t nextTimerId_ = 1;
69 double currentTimeSeconds_ = 0.0;
70 };
71} // namespace Engine::Core
void cancelTimersFor(const Entities::Actor *owner)
std::function< void()> Callback
bool isEventStillValid(const TimerEvent &event) const
double getCurrentTimeSeconds() const
std::vector< TimerEvent > timers_
TimerHandle setTimer(double delaySeconds, Callback callback)
TimerManager(EngineKern *engine)
void insertTimer(TimerEvent event)
TimerHandle setActorTimer(Entities::Actor *owner, double delaySeconds, std::function< void(Entities::Actor &)> callback)
void tick(double nowSeconds)
void cancelTimer(TimerHandle handle)
An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform.
Definition Actor.h:65
Manages IBL (Image-Based Lighting) resources for specular reflections.