-
Notifications
You must be signed in to change notification settings - Fork 0
/
Events.h
45 lines (34 loc) · 1.11 KB
/
Events.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <list>
#include "Data\CallbackTypes.h"
#include "Utils\TypedCallback.h"
enum InternalEventType
{
PERIODIC,
SINGLE_OFFSET_TIME,
SINGLE_GAME_TIME
};
struct InternalEvent
{
int id;
InternalEventType internalType;
TypedCallback<EventType> callback;
float triggerTime;
float elapsedTime;
InternalEvent(int id, InternalEventType internalType, TypedCallback<EventType> callback, float triggerTime, float elapsedTime)
: id(id), internalType(internalType), callback(callback), triggerTime(triggerTime), elapsedTime(elapsedTime)
{}
};
// Manages a list of events that are updateable, can run, and are cancelleable.
class Events
{
std::list<InternalEvent> events;
int id;
public:
Events();
int AddPeriodicEvent(TypedCallback<EventType> callback, float repeatTimeInSec, bool startImmediately);
int AddSingleEvent(TypedCallback<EventType> callback, float startAfterTimeInSec);
int AddGameTimeEvent(TypedCallback<EventType> callback, float gameTimeInSec);
void UpdateEvents(float gameTime, float elapsedTime);
void Cancel(int id);
};