Elaztek Developer Hub
Switch Project...
blam!
Editing Kit
Guerilla
Sapien
Tool
Foundry
Libraries
Keystone
Strings
Forums
Discord
Doxygen
Jenkins
Guides
Gitlab
Blamite Game Engine - blam!
00406.12.10.23.1457.blamite
The core library for the Blamite Game Engine.
event.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <functional>
4
#include <vector>
5
6
namespace
discord
{
7
8
template
<
typename
... Args>
9
class
Event
final {
10
public
:
11
using
Token
= int;
12
13
Event
() { slots_.reserve(4); }
14
15
Event
(
Event
const
&) =
default
;
16
Event
(
Event
&&) =
default
;
17
~Event
() =
default
;
18
19
Event
&
operator=
(
Event
const
&) =
default
;
20
Event
&
operator=
(
Event
&&) =
default
;
21
22
template
<
typename
EventHandler>
23
Token
Connect
(EventHandler slot)
24
{
25
slots_.emplace_back(Slot{nextToken_, std::move(slot)});
26
return
nextToken_++;
27
}
28
29
void
Disconnect
(
Token
token)
30
{
31
for
(
auto
& slot : slots_) {
32
if
(slot.token == token) {
33
slot = slots_.back();
34
slots_.pop_back();
35
break
;
36
}
37
}
38
}
39
40
void
DisconnectAll
() { slots_ = {}; }
41
42
void
operator()
(Args... args)
43
{
44
for
(
auto
const
& slot : slots_) {
45
slot.fn(std::forward<Args>(args)...);
46
}
47
}
48
49
private
:
50
struct
Slot {
51
Token
token;
52
std::function<void(Args...)> fn;
53
};
54
55
Token
nextToken_{};
56
std::vector<Slot> slots_{};
57
};
58
59
}
// namespace discord
discord
Definition:
achievement_manager.cpp:12
discord::Event::Connect
Token Connect(EventHandler slot)
Definition:
event.h:23
discord::Event::operator()
void operator()(Args... args)
Definition:
event.h:42
discord::Event::~Event
~Event()=default
discord::Event::Disconnect
void Disconnect(Token token)
Definition:
event.h:29
discord::Event::Event
Event()
Definition:
event.h:13
discord::Event
Definition:
event.h:9
discord::Event::operator=
Event & operator=(Event const &)=default
discord::Event::DisconnectAll
void DisconnectAll()
Definition:
event.h:40
discord::Event< std::int64_t >::Token
int Token
Definition:
event.h:11
blam
components
3rdparty
discord
event.h
Generated on Sun Dec 10 2023 18:04:22 for Blamite Game Engine - blam! by
1.8.17