ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

commit 7d59b21ec70b5eb0692101a3e4a27176e08a291c
parent ea60c4512057f56ca607741fbd3b2eaf998648a4
Author: amin <dev@aminmesbah.com>
Date:   Mon, 10 Jun 2024 20:20:29 +0000

Build ohsp on Windows

FossilOrigin-Name: f2cec4eb402b6c405aa3b6d8931d64cdf2e76e1d1d5f0a4be7ee4ce3914391b6
Diffstat:
Msrc/platform_sdl.c | 19+++++++++++++++++++
Msrc/platform_sdl.h | 2+-
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/platform_sdl.c b/src/platform_sdl.c @@ -1,5 +1,6 @@ #include "platform_sdl.h" +#if !defined(OHSP_NO_HOT_RELOAD) #include <dlfcn.h> #include <sys/stat.h> #include <stdio.h> @@ -73,9 +74,11 @@ struct SDLGameCode load_game_code(char *source_lib_path) return game_code; } +#endif #include <stdbool.h> #include <stdio.h> +#include <string.h> #include <time.h> #ifndef MAP_ANONYMOUS @@ -366,7 +369,9 @@ int main(int argc, char *argv[]) struct GameControllerInput controller_input = {0}; +#if !defined(OHSP_NO_HOT_RELOAD) struct SDLGameCode game_code = load_game_code(GAME_LIB_PATH); +#endif while (running) { @@ -376,6 +381,7 @@ int main(int argc, char *argv[]) lag += elapsed_ms; //printf("%" PRIu64 ", %" PRIu64 ", %f\n", elapsed_ms, lag, MS_PER_UPDATE); +#if !defined(OHSP_NO_HOT_RELOAD) time_t last_write_time = file_get_modified_time(GAME_LIB_PATH); bool game_code_has_changed = last_write_time && (last_write_time != game_code.last_write_time); if (game_code_has_changed) @@ -387,6 +393,7 @@ int main(int argc, char *argv[]) // TODO: fall back to backup? } } +#endif SDL_Event event; while (SDL_PollEvent(&event)) @@ -469,14 +476,22 @@ int main(int argc, char *argv[]) // per frame. This is so that recorded input played back // over the initial state always results in the same // sequence of states. +#if !defined(OHSP_NO_HOT_RELOAD) game_code.game_update(&game_state, controller_input, buffer.width, buffer.height); +#else + game_update(&game_state, controller_input, buffer.width, buffer.height); +#endif lag -= MS_PER_UPDATE; } else { while (lag >= MS_PER_UPDATE) { +#if !defined(OHSP_NO_HOT_RELOAD) game_code.game_update(&game_state, controller_input, buffer.width, buffer.height); +#else + game_update(&game_state, controller_input, buffer.width, buffer.height); +#endif //printf("\t%" PRIu64 ", %f\n", lag, MS_PER_UPDATE); lag -= MS_PER_UPDATE; } @@ -486,7 +501,11 @@ int main(int argc, char *argv[]) { clear_screen(&global_back_buffer, COLOR_BACKGROUND); } +#if !defined(OHSP_NO_HOT_RELOAD) game_code.game_render(&buffer, lag/SECOND, &game_state); +#else + game_render(&buffer, lag/SECOND, &game_state); +#endif sdl_update_window(renderer, &global_back_buffer); if (elapsed_ms <= MS_PER_FRAME) { diff --git a/src/platform_sdl.h b/src/platform_sdl.h @@ -1,6 +1,6 @@ #ifndef PLATFORM_SDL_H -#include <SDL2/SDL.h> +#include "SDL.h" #include "game.h" #include <stdbool.h>