phantasia

Phantasia - 2D SDL3 RPG prototype.
git clone git://git.beep.wimdupont.com/phantasia.git
Log | Files | Refs | README | LICENSE

commit 804d1b2c51e6396f7345e0d7991e8886ad94958d
parent b292695f902ff484649298fa947d97398df25c69
Author: beep <beep@wimdupont.com>
Date:   Sat,  4 Apr 2026 16:31:04 +0000

Add SDL render smoke test mode

Diffstat:
MMakefile | 5++++-
MREADME.adoc | 7+++++++
Msrc/game/main.c | 12++++++++++--
3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile @@ -23,7 +23,7 @@ else CPPFLAGS += -DPH_USE_SDL=0 endif -.PHONY: all clean smoke +.PHONY: all clean render-smoke smoke all: $(BIN) @@ -38,6 +38,9 @@ $(OBJDIR)/%.o: src/%.c smoke: $(BIN) $(BIN) --smoke-test +render-smoke: $(BIN) + SDL_VIDEODRIVER=dummy $(BIN) --render-smoke-test + clean: rm -rf $(BIN) $(OBJDIR) diff --git a/README.adoc b/README.adoc @@ -24,6 +24,13 @@ If SDL3 is not installed, this still builds a headless logic binary that can run make smoke ---- +To exercise the SDL renderer in a headless environment: + +[source,sh] +---- +make render-smoke +---- + With SDL3 available, run the game normally: [source,sh] diff --git a/src/game/main.c b/src/game/main.c @@ -236,12 +236,13 @@ ph_read_input(const bool *keys) } static int -ph_run_game(void) +ph_run_game(int frame_limit) { SDL_Window *window; SDL_Renderer *renderer; PhWorld world = ph_make_world(); Uint64 last_ticks; + int frame_count = 0; int running = 1; if (!SDL_Init(SDL_INIT_VIDEO)) { @@ -294,6 +295,10 @@ ph_run_game(void) ph_draw_items(renderer, &world); ph_draw_entities(renderer, &world); SDL_RenderPresent(renderer); + ++frame_count; + if (frame_limit > 0 && frame_count >= frame_limit) { + running = 0; + } SDL_Delay(16); } @@ -312,7 +317,10 @@ main(int argc, char **argv) } #if PH_USE_SDL - return ph_run_game(); + if (argc > 1 && strcmp(argv[1], "--render-smoke-test") == 0) { + return ph_run_game(8); + } + return ph_run_game(0); #else fprintf(stderr, "SDL3 not available in this build; run `%s --smoke-test`\n", argv[0]); return 1;