-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
113 lines (94 loc) · 2.04 KB
/
main.c
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "syslayer/syslayer.h"
#include "standard.h"
#include "types.h"
#include "define.h"
#include "cvote_test.h"
typedef struct Global
{
Bool is_running;
} Global;
Global* global = null;
Int
global_init(None)
{
global = new(Global);
if (global == null)
{
fprintf(stderr, "error, can't allocate global map\n");
return error_out_of_mem;
}
memset(global, 0x0, sizeof(Global));
return ok;
}
Int
global_terminate(None)
{
if (global == null)
{
fprintf(stderr, "warn, global termination called twice\n");
return warn_already;
}
free(global);
return ok;
}
Int
read_events(None)
{
Sysevent event;
while (syslayer_read_event(&event) != event_none)
{
switch (event.type)
{
case event_quit:
global->is_running = false;
break;
case event_keydown:
if (event.key.code == key_q)
global->is_running = false;
break;
}
}
return ok;
}
Int
test_all(None)
{
fprintf(stdout, " > testing all\n");
CVOTE_TEST_BEGIN();
CVOTE_TEST(test_syslayer);
CVOTE_TEST_END();
}
Int
main(None)
{
GameColor background_color = (GameColor)
{ .r = 0x00, .g = 0xff, .b = 0xff, .a = 0xff };
GameRect player_rect = (GameRect)
{ .x = 0x10, .y = 0x20, .w = 0x10, .h = 0x10 };
GameColor player_color = (GameColor)
{ .r = 0xff, .g = 0x00, .b = 0x00, .a = 0xff };
#ifdef DEBUG
if (test_all() != ok) return error_test;
#endif
if (syslayer_init() < ok)
{
fprintf(stderr, " => can't init syslayer\n");
return error_upper;
}
if (global_init() < ok)
{
fprintf(stderr, " => can't init global syslayer\n");
return error_upper;
}
global->is_running = true;
while (global != null && global->is_running == true)
{
syslayer_clear_window(background_color);
syslayer_draw_rect(player_rect, player_color);
syslayer_draw_window();
read_events();
}
if (global != null) global_terminate();
if (syslayer != null) syslayer_terminate();
return ok;
}