From 08eada80a4fd13028f2a19108788f76752cc459b Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Fri, 1 May 2026 03:44:54 +0200 Subject: Custom FPS cli argument --- all.h | 1 + game.c | 2 +- main.c | 22 +++++++++++++++++++--- tbrun.sh | 10 +++++++++- trenchbroom/stalag/GameEngineProfiles.cfg | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/all.h b/all.h index 26ccffb..8821f86 100644 --- a/all.h +++ b/all.h @@ -130,6 +130,7 @@ typedef struct { Camera camera; bool cursor_captured; bool vsync; + int target_fps; Font font_ui; PlayerState player; diff --git a/game.c b/game.c index 40d1876..d1149b4 100644 --- a/game.c +++ b/game.c @@ -42,7 +42,7 @@ void UpdateGame(void) { SetTargetFPS(GetMonitorRefreshRate(GetCurrentMonitor())); } else { ClearWindowState(FLAG_VSYNC_HINT); - SetTargetFPS(0); + SetTargetFPS(game.target_fps); } } diff --git a/main.c b/main.c index 9f32ecc..1ca42bd 100644 --- a/main.c +++ b/main.c @@ -10,15 +10,17 @@ int main(int argc, char *argv[]) { sb_append_cstr(&map_path, "maps/demo3.map"); bool skip_title = false; + int target_fps = -1; static struct option long_options[] = { {"map", required_argument, 0, 'm'}, + {"fps", required_argument, 0, 'f'}, {0, 0, 0, 0} }; int opt; int option_index = 0; - while ((opt = getopt_long_only(argc, argv, "m:", long_options, &option_index)) != -1) { + while ((opt = getopt_long_only(argc, argv, "m:f:", long_options, &option_index)) != -1) { switch (opt) { case 'm': sb_free(&map_path); @@ -26,20 +28,34 @@ int main(int argc, char *argv[]) { sb_append_cstr(&map_path, optarg); skip_title = true; break; + case 'f': + target_fps = atoi(optarg); + break; } } - SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI); + unsigned int flags = FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI; + if (target_fps < 0) flags |= FLAG_VSYNC_HINT; + + SetConfigFlags(flags); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE); int monitor = GetCurrentMonitor(); SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); - SetTargetFPS(GetMonitorRefreshRate(monitor)); vfs_init(VFS_DATA_PAK); InitGame(); SetMap(map_path.data); + if (target_fps >= 0) { + game.target_fps = target_fps; + game.vsync = false; + SetTargetFPS(game.target_fps); + } else { + game.vsync = true; + SetTargetFPS(GetMonitorRefreshRate(monitor)); + } + if (skip_title) { if (LoadMap(game.map_path)) { game.mode = STATE_PLAYING; diff --git a/tbrun.sh b/tbrun.sh index d933b6d..bf810bc 100755 --- a/tbrun.sh +++ b/tbrun.sh @@ -19,6 +19,7 @@ SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)" echo "$SCRIPT_DIR" MAP="" +FPS="" while [ $# -gt 0 ]; do case "$1" in --map) @@ -28,6 +29,13 @@ while [ $# -gt 0 ]; do --map=*) MAP="${1#--map=}" ;; + --fps) + shift + FPS="$1" + ;; + --fps=*) + FPS="${1#--fps=}" + ;; --) shift; break;; *) ;; esac @@ -35,4 +43,4 @@ while [ $# -gt 0 ]; do done cd "$SCRIPT_DIR" -./bin/stalag --map "$MAP" +./bin/stalag --map "$MAP" --fps "$FPS" diff --git a/trenchbroom/stalag/GameEngineProfiles.cfg b/trenchbroom/stalag/GameEngineProfiles.cfg index 41cc5fb..fb04830 100644 --- a/trenchbroom/stalag/GameEngineProfiles.cfg +++ b/trenchbroom/stalag/GameEngineProfiles.cfg @@ -2,7 +2,7 @@ "profiles": [ { "name": "Stalag", - "parameters": "--map maps/${MAP_BASE_NAME}.map", + "parameters": "--fps 120 --map maps/${MAP_BASE_NAME}.map", "path": "/home/m/Projects/stalag/tbrun.sh" } ], -- cgit v1.2.3