-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.c
More file actions
57 lines (41 loc) · 1.46 KB
/
app.c
File metadata and controls
57 lines (41 loc) · 1.46 KB
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
#include <engine.h>
#include <components/rect.h>
#include <components/color.h>
static window_t window;
int main(void){
id_t sqr1;
id_t sqr2;
SDL_Rect *r;
InitRenderer();
if (!CreateWindow(&window, "ecs test", 500, 400)){
return 1;
}
Register(&sqr1); /* Ask the system to give us a mapping of our entity and register it. */
Register(&sqr2);
/* Add components here. */
Rect_Add(sqr1, 10, 10, 69, 69);
Color_Add(sqr1, 161, 255, 130);
Rect_Add(sqr2, 10, 10, 20, 69);
Color_Add(sqr2, 0, 0, 255);
while (window.active){
r = Rect_Get(sqr1); /* Make them move so i know if i messed up the map implementation. */
r->x += 1;
r = Rect_Get(sqr2);
r->y += 1;
r->x += 1;
BeginRender(&window);
/* In real : Use group component that handles global lists. (eg. renderables) */
RenderEntity(&window, sqr1);
RenderEntity(&window, sqr2);
FinishRender(&window);
SDL_Delay(33); /* Sleep the main thread for 33ms (about 60 fps), saves some CPU. */
WindowPoll(&window);
}
Unregister(sqr1); /* Unregister our entities and let the components release their data. */
Unregister(sqr2);
FreeWindow(&window);
FreeECS(); /* Hypothetical free function, if something where to be on the heap. */
return 0;
}
/* This example application doesn't do much, just 2 moving squares of different sizes
It simply showcases the API. */