From fb96ec752215da56407c2266ab9d1eedf670e0d1 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Fri, 1 May 2026 03:53:58 +0200 Subject: Custom --width and --height cli argument --- all.h | 2 ++ main.c | 16 ++++++++++++++-- tbrun.sh | 21 ++++++++++++++++++++- trenchbroom/stalag/GameEngineProfiles.cfg | 16 ++++++++-------- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/all.h b/all.h index 8821f86..b0dde0c 100644 --- a/all.h +++ b/all.h @@ -131,6 +131,8 @@ typedef struct { bool cursor_captured; bool vsync; int target_fps; + int screen_width; + int screen_height; Font font_ui; PlayerState player; diff --git a/main.c b/main.c index 1ca42bd..cc96b3b 100644 --- a/main.c +++ b/main.c @@ -11,16 +11,20 @@ int main(int argc, char *argv[]) { bool skip_title = false; int target_fps = -1; + int width = WINDOW_WIDTH; + int height = WINDOW_HEIGHT; static struct option long_options[] = { {"map", required_argument, 0, 'm'}, {"fps", required_argument, 0, 'f'}, + {"width", required_argument, 0, 'w'}, + {"height", required_argument, 0, 'h'}, {0, 0, 0, 0} }; int opt; int option_index = 0; - while ((opt = getopt_long_only(argc, argv, "m:f:", long_options, &option_index)) != -1) { + while ((opt = getopt_long_only(argc, argv, "m:f:w:h:", long_options, &option_index)) != -1) { switch (opt) { case 'm': sb_free(&map_path); @@ -31,6 +35,12 @@ int main(int argc, char *argv[]) { case 'f': target_fps = atoi(optarg); break; + case 'w': + width = atoi(optarg); + break; + case 'h': + height = atoi(optarg); + break; } } @@ -38,13 +48,15 @@ int main(int argc, char *argv[]) { if (target_fps < 0) flags |= FLAG_VSYNC_HINT; SetConfigFlags(flags); - InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE); + InitWindow(width, height, WINDOW_TITLE); int monitor = GetCurrentMonitor(); SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); vfs_init(VFS_DATA_PAK); InitGame(); + game.screen_width = width; + game.screen_height = height; SetMap(map_path.data); if (target_fps >= 0) { diff --git a/tbrun.sh b/tbrun.sh index bf810bc..8a600b7 100755 --- a/tbrun.sh +++ b/tbrun.sh @@ -20,6 +20,8 @@ echo "$SCRIPT_DIR" MAP="" FPS="" +WIDTH="" +HEIGHT="" while [ $# -gt 0 ]; do case "$1" in --map) @@ -36,6 +38,20 @@ while [ $# -gt 0 ]; do --fps=*) FPS="${1#--fps=}" ;; + --width) + shift + WIDTH="$1" + ;; + --width=*) + WIDTH="${1#--width=}" + ;; + --height) + shift + HEIGHT="$1" + ;; + --height=*) + HEIGHT="${1#--height=}" + ;; --) shift; break;; *) ;; esac @@ -43,4 +59,7 @@ while [ $# -gt 0 ]; do done cd "$SCRIPT_DIR" -./bin/stalag --map "$MAP" --fps "$FPS" +./bin/stalag --map "$MAP" \ + ${FPS:+--fps "$FPS"} \ + ${WIDTH:+--width "$WIDTH"} \ + ${HEIGHT:+--height "$HEIGHT"} diff --git a/trenchbroom/stalag/GameEngineProfiles.cfg b/trenchbroom/stalag/GameEngineProfiles.cfg index fb04830..81eda2f 100644 --- a/trenchbroom/stalag/GameEngineProfiles.cfg +++ b/trenchbroom/stalag/GameEngineProfiles.cfg @@ -1,10 +1,10 @@ { - "profiles": [ - { - "name": "Stalag", - "parameters": "--fps 120 --map maps/${MAP_BASE_NAME}.map", - "path": "/home/m/Projects/stalag/tbrun.sh" - } - ], - "version": 1 + "profiles": [ + { + "name": "Stalag", + "parameters": "--fps 120 --width 1920 --height 1080 --map maps/${MAP_BASE_NAME}.map", + "path": "/home/m/Projects/stalag/tbrun.sh" + } + ], + "version": 1 } -- cgit v1.2.3