comparison libmlk-adventure/adventure/molko.c @ 261:bfde372bf152

core: prefix utilities with util_
author David Demelier <markand@malikania.fr>
date Sun, 06 Dec 2020 23:06:34 +0100
parents 16be1ad3ddba
children cd5bdb995052
comparison
equal deleted inserted replaced
260:60a214ec1ab4 261:bfde372bf152
54 crash(void) 54 crash(void)
55 { 55 {
56 longjmp(panic_buf, 1); 56 longjmp(panic_buf, 1);
57 } 57 }
58 58
59 static void
60 loop(void)
61 {
62 struct clock clock = {0};
63
64 while (game.state) {
65 unsigned int elapsed = clock_elapsed(&clock);
66
67 clock_start(&clock);
68
69 for (union event ev; event_poll(&ev); ) {
70 switch (ev.type) {
71 case EVENT_QUIT:
72 return;
73 default:
74 game_handle(&ev);
75 break;
76 }
77 }
78
79 game_update(elapsed);
80 game_draw();
81
82 if ((elapsed = clock_elapsed(&clock)) < 20)
83 delay(20 - elapsed);
84 }
85 }
86
87 void 59 void
88 molko_init(void) 60 molko_init(void)
89 { 61 {
90 setlocale(LC_ALL, ""); 62 setlocale(LC_ALL, "");
91 63
113 void 85 void
114 molko_run(void) 86 molko_run(void)
115 { 87 {
116 if (setjmp(panic_buf) == 0) { 88 if (setjmp(panic_buf) == 0) {
117 /* Initial game run. */ 89 /* Initial game run. */
118 loop(); 90 game_loop();
119 } else { 91 } else {
120 /* Clear event queue to avoid accidental key presses. */ 92 /* Clear event queue to avoid accidental key presses. */
121 for (union event ev; event_poll(&ev); ) 93 for (union event ev; event_poll(&ev); )
122 continue; 94 continue;
123 95
124 game_switch(molko.panic, true); 96 game_switch(molko.panic, true);
125 loop(); 97 game_loop();
126 } 98 }
127 } 99 }
128 100
129 void 101 void
130 molko_teleport(const char *map, int origin_x, int origin_y) 102 molko_teleport(const char *map, int origin_x, int origin_y)
137 molko_path(const char *file) 109 molko_path(const char *file)
138 { 110 {
139 assert(file); 111 assert(file);
140 112
141 /* TODO: libmlk-adventure must be renamed. */ 113 /* TODO: libmlk-adventure must be renamed. */
142 return pprintf("%s/libmlk-adventure/%s", sys_dir(SYS_DIR_DATA), file); 114 return util_pathf("%s/libmlk-adventure/%s", sys_dir(SYS_DIR_DATA), file);
143 } 115 }
144 116
145 void 117 void
146 molko_finish(void) 118 molko_finish(void)
147 { 119 {