-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.cc
73 lines (58 loc) · 1.02 KB
/
test.cc
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) 2017-2017 ChaosForge Ltd
// http://chaosforge.org/
#include "nova-ecs/field_detection.hh"
#include "nova-ecs/ecs.hh"
struct position
{
int x;
int y;
};
enum class msg
{
ACTION,
UPDATE_TIME,
DESTROY,
};
struct msg_action
{
static const int message_id = int( msg::ACTION );
handle entity;
};
struct msg_update_time
{
static const int message_id = int( msg::UPDATE_TIME );
float time;
};
struct msg_destroy
{
static const int message_id = int( msg::DESTROY );
handle entity;
};
using msg_list = mpl::list<
msg_action,
msg_update_time,
msg_destroy
>;
using game_ecs = ecs< msg_list >;
struct position_system
{
void update( game_ecs& ecs, position& p )
{
p.x++;
}
void on( const msg_action& a, position& p )
{
p.y--;
}
};
int main( int argc, char* argv[] )
{
game_ecs e;
e.register_component< position >();
e.register_system< position_system >();
handle being = e.create();
e.add_component< position >( being, 3, 4 );
e.dispatch< msg_action >( being );
e.update( 1.0f );
return 0;
}