Mercurial > molko
comparison examples/example-trace/example-trace.c @ 415:a5b98db4fd87
misc: fix .hgignore too greedy
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 09 Oct 2022 13:53:33 +0200 |
parents | |
children | 773a082f0b91 |
comparison
equal
deleted
inserted
replaced
414:6947c1fefe5c | 415:a5b98db4fd87 |
---|---|
1 /* | |
2 * example-trace.c -- example on how to use custom trace handlers | |
3 * | |
4 * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <core/core.h> | |
20 #include <core/event.h> | |
21 #include <core/game.h> | |
22 #include <core/sys.h> | |
23 #include <core/window.h> | |
24 #include <core/painter.h> | |
25 #include <core/panic.h> | |
26 #include <core/state.h> | |
27 #include <core/trace.h> | |
28 #include <core/util.h> | |
29 | |
30 #include <ui/theme.h> | |
31 #include <ui/ui.h> | |
32 | |
33 #include "trace_hud.h" | |
34 | |
35 #define W 1280 | |
36 #define H 720 | |
37 | |
38 static struct state *states[1]; | |
39 | |
40 static void | |
41 init(void) | |
42 { | |
43 if (core_init("fr.malikania", "example-trace") < 0 || ui_init() < 0) | |
44 panic(); | |
45 if (window_open("Example - Trace", W, H) < 0) | |
46 panic(); | |
47 | |
48 trace_handler = trace_hud_handler; | |
49 } | |
50 | |
51 static void | |
52 handle(struct state *st, const union event *ev) | |
53 { | |
54 (void)st; | |
55 | |
56 switch (ev->type) { | |
57 case EVENT_KEYDOWN: | |
58 switch (ev->key.key) { | |
59 case KEY_ESCAPE: | |
60 trace_hud_clear(); | |
61 break; | |
62 default: | |
63 tracef("keydown pressed: %d", ev->key.key); | |
64 break; | |
65 } | |
66 break; | |
67 case EVENT_CLICKDOWN: | |
68 tracef("click at %d,%d", ev->click.x, ev->click.y); | |
69 break; | |
70 case EVENT_QUIT: | |
71 game_quit(); | |
72 break; | |
73 default: | |
74 break; | |
75 } | |
76 } | |
77 | |
78 static void | |
79 update(struct state *st, unsigned int ticks) | |
80 { | |
81 (void)st; | |
82 | |
83 trace_hud_update(ticks); | |
84 } | |
85 | |
86 static void | |
87 draw(struct state *st) | |
88 { | |
89 (void)st; | |
90 | |
91 painter_set_color(0x4f8fbaff); | |
92 painter_clear(); | |
93 trace_hud_draw(); | |
94 painter_present(); | |
95 } | |
96 | |
97 static void | |
98 run(void) | |
99 { | |
100 struct state state = { | |
101 .handle = handle, | |
102 .update = update, | |
103 .draw = draw | |
104 }; | |
105 | |
106 game_init(states, UTIL_SIZE(states)); | |
107 game_push(&state); | |
108 game_loop(); | |
109 } | |
110 | |
111 static void | |
112 quit(void) | |
113 { | |
114 window_finish(); | |
115 ui_finish(); | |
116 core_finish(); | |
117 } | |
118 | |
119 int | |
120 main(int argc, char **argv) | |
121 { | |
122 (void)argc; | |
123 (void)argv; | |
124 | |
125 init(); | |
126 run(); | |
127 quit(); | |
128 } | |
129 |