tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit fbe6a927fb5356ec4c1aa97579458167d2b606bc
parent f962aafd82f7c687321789ed34ea194b39987e6d
Author: Connor Thomson <connor@gnufault.org>
Date:   Sun, 18 Oct 2026 17:05:02 -0700

Make some booleans be booleans

Diffstat:
Mplatforms/dos/dos.c | 11++++++-----
Mplatforms/sdl2/sdl2.c | 5+++--
Mplatforms/sdl3/sdl3.c | 5+++--
Mplatforms/wayland/wayland.c | 35++++++++++++++++++-----------------
4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/platforms/dos/dos.c b/platforms/dos/dos.c @@ -1,4 +1,5 @@ #include "ta_api.h" +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -73,7 +74,7 @@ static void blit(void) { dosmemput(ta_fb.buffers[0], WINDOW_WIDTH * WINDOW_HEIGHT, VGA_FB_ADDR); } -static ta_keyboard_keys key_from_dos(int key, int extended) { +static ta_keyboard_keys key_from_dos(int key, bool extended) { if (extended) { switch (key) { case 29: return KEY_LEFT_CTRL; @@ -166,20 +167,20 @@ int main(void) { ta_main_init(); - int running = 1; + bool running = true; while (running) { ta_keyboard_clear(); if (kbhit()) { int key = getch(); - int extended = 0; + bool extended = false; if (key == 0 || key == 224) { key = getch(); - extended = 1; + extended = true; } ta_keyboard_keys mapped_key = key_from_dos(key, extended); ta_keyboard_key_down(mapped_key); if (mapped_key == KEY_ESCAPE) { - running = 0; + running = false; } } diff --git a/platforms/sdl2/sdl2.c b/platforms/sdl2/sdl2.c @@ -1,4 +1,5 @@ #include "ta_api.h" +#include <stdbool.h> #include <SDL2/SDL.h> #include <unistd.h> #include <stdlib.h> @@ -90,12 +91,12 @@ int main(void) { WINDOW_HEIGHT ); - int running = 1; + bool running = true; while (running) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { - running = 0; + running = false; } else if (event.type == SDL_KEYDOWN) { ta_keyboard_key_down(key_from_sdl(event.key.keysym.sym)); } else if (event.type == SDL_KEYUP) { diff --git a/platforms/sdl3/sdl3.c b/platforms/sdl3/sdl3.c @@ -1,4 +1,5 @@ #include "ta_api.h" +#include <stdbool.h> #include <SDL3/SDL.h> #include <unistd.h> #include <stdlib.h> @@ -98,12 +99,12 @@ int main(void) { return 1; } - int running = 1; + bool running = true; while (running) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_EVENT_QUIT) { - running = 0; + running = false; } else if (event.type == SDL_EVENT_KEY_DOWN) { ta_keyboard_key_down(key_from_sdl(event.key.key)); } else if (event.type == SDL_EVENT_KEY_UP) { diff --git a/platforms/wayland/wayland.c b/platforms/wayland/wayland.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include "ta_api.h" +#include <stdbool.h> #include <errno.h> #include <fcntl.h> #include <linux/input-event-codes.h> @@ -36,10 +37,10 @@ typedef struct { struct xkb_state *xkb_state; void *pixels; size_t buffer_size; - int running; - int configured; - int frame_ready; - int buffer_released; + bool running; + bool configured; + bool frame_ready; + bool buffer_released; } wayland_state; static ta_keyboard_keys key_from_keysym(xkb_keysym_t symbol) { @@ -166,7 +167,7 @@ static void toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_ static void toplevel_close(void *data, struct xdg_toplevel *toplevel) { wayland_state *state = data; (void)toplevel; - state->running = 0; + state->running = false; } static const struct xdg_toplevel_listener toplevel_listener = { @@ -177,7 +178,7 @@ static const struct xdg_toplevel_listener toplevel_listener = { static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) { wayland_state *state = data; xdg_surface_ack_configure(xdg_surface, serial); - state->configured = 1; + state->configured = true; } static const struct xdg_surface_listener xdg_surface_listener = { @@ -227,7 +228,7 @@ static int create_buffer(wayland_state *state) { static void buffer_release(void *data, struct wl_buffer *buffer) { wayland_state *state = data; (void)buffer; - state->buffer_released = 1; + state->buffer_released = true; } static const struct wl_buffer_listener buffer_listener = { @@ -239,7 +240,7 @@ static void frame_done(void *data, struct wl_callback *callback, uint32_t time) wayland_state *state = data; wl_callback_destroy(callback); state->frame_callback = NULL; - state->frame_ready = 1; + state->frame_ready = true; } static const struct wl_callback_listener frame_listener = { @@ -332,7 +333,7 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t seri ta_keyboard_keys mapped = key_from_keysym(symbol); if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED) { ta_keyboard_key_down(mapped); - if (mapped == KEY_ESCAPE) state->running = 0; + if (mapped == KEY_ESCAPE) state->running = false; } else { ta_keyboard_key_up(mapped); } @@ -482,9 +483,9 @@ static void destroy_wayland(wayland_state *state) { int main(void) { wayland_state state; memset(&state, 0, sizeof(state)); - state.running = 1; - state.frame_ready = 1; - state.buffer_released = 1; + state.running = true; + state.frame_ready = true; + state.buffer_released = true; state.display = wl_display_connect(NULL); if (!state.display) { @@ -518,7 +519,7 @@ int main(void) { wl_surface_commit(state.surface); while (state.running && !state.configured) { - if (wl_display_dispatch(state.display) < 0) state.running = 0; + if (wl_display_dispatch(state.display) < 0) state.running = false; } if (!state.running || !create_buffer(&state)) { destroy_wayland(&state); @@ -528,12 +529,12 @@ int main(void) { while (state.running) { while (state.running && (!state.frame_ready || !state.buffer_released)) { - if (wl_display_dispatch(state.display) < 0) state.running = 0; + if (wl_display_dispatch(state.display) < 0) state.running = false; } if (!state.running) break; - state.frame_ready = 0; - state.buffer_released = 0; + state.frame_ready = false; + state.buffer_released = false; ta_main_update(); xdg_toplevel_set_title(state.toplevel, ta_title); memcpy(state.pixels, ta_fb.buffers[0], state.buffer_size); @@ -544,7 +545,7 @@ int main(void) { wl_surface_damage(state.surface, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); wl_surface_commit(state.surface); if (wl_display_flush(state.display) < 0 && errno != EAGAIN) { - state.running = 0; + state.running = false; } }