Custom --width and --height cli argument
| Author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-05-01 03:53:58 +0200 |
| Committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-05-01 03:53:58 +0200 |
| Commit | fb96ec752215da56407c2266ab9d1eedf670e0d1 (patch) |
|
-rw-r--r-- |
all.h | 2 | |
-rw-r--r-- |
main.c | 16 | |
-rwxr-xr-x |
tbrun.sh | 21 | |
-rw-r--r-- |
trenchbroom/stalag/GameEngineProfiles.cfg | 16 |
4 files changed, 44 insertions, 11 deletions
| diff --git a/all.h b/all.h | |||
| ... | |||
| 131 | bool cursor_captured; |
131 | bool cursor_captured; |
| 132 | bool vsync; |
132 | bool vsync; |
| 133 | int target_fps; |
133 | int target_fps; |
| 134 | int screen_width; |
||
| 135 | int screen_height; |
||
| 134 | Font font_ui; |
136 | Font font_ui; |
| 135 | 137 | ||
| 136 | PlayerState player; |
138 | PlayerState player; |
| ... | |||
| diff --git a/main.c b/main.c | |||
| ... | |||
| 11 | 11 | ||
| 12 | bool skip_title = false; |
12 | bool skip_title = false; |
| 13 | int target_fps = -1; |
13 | int target_fps = -1; |
| 14 | int width = WINDOW_WIDTH; |
||
| 15 | int height = WINDOW_HEIGHT; |
||
| 14 | 16 | ||
| 15 | static struct option long_options[] = { |
17 | static struct option long_options[] = { |
| 16 | {"map", required_argument, 0, 'm'}, |
18 | {"map", required_argument, 0, 'm'}, |
| 17 | {"fps", required_argument, 0, 'f'}, |
19 | {"fps", required_argument, 0, 'f'}, |
| 20 | {"width", required_argument, 0, 'w'}, |
||
| 21 | {"height", required_argument, 0, 'h'}, |
||
| 18 | {0, 0, 0, 0} |
22 | {0, 0, 0, 0} |
| 19 | }; |
23 | }; |
| 20 | 24 | ||
| 21 | int opt; |
25 | int opt; |
| 22 | int option_index = 0; |
26 | int option_index = 0; |
| 23 | while ((opt = getopt_long_only(argc, argv, "m:f:", long_options, &option_index)) != -1) { |
27 | while ((opt = getopt_long_only(argc, argv, "m:f:w:h:", long_options, &option_index)) != -1) { |
| 24 | switch (opt) { |
28 | switch (opt) { |
| 25 | case 'm': |
29 | case 'm': |
| 26 | sb_free(&map_path); |
30 | sb_free(&map_path); |
| ... | |||
| 31 | case 'f': |
35 | case 'f': |
| 32 | target_fps = atoi(optarg); |
36 | target_fps = atoi(optarg); |
| 33 | break; |
37 | break; |
| 38 | case 'w': |
||
| 39 | width = atoi(optarg); |
||
| 40 | break; |
||
| 41 | case 'h': |
||
| 42 | height = atoi(optarg); |
||
| 43 | break; |
||
| 34 | } |
44 | } |
| 35 | } |
45 | } |
| 36 | 46 | ||
| ... | |||
| 38 | if (target_fps < 0) flags |= FLAG_VSYNC_HINT; |
48 | if (target_fps < 0) flags |= FLAG_VSYNC_HINT; |
| 39 | 49 | ||
| 40 | SetConfigFlags(flags); |
50 | SetConfigFlags(flags); |
| 41 | InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE); |
51 | InitWindow(width, height, WINDOW_TITLE); |
| 42 | 52 | ||
| 43 | int monitor = GetCurrentMonitor(); |
53 | int monitor = GetCurrentMonitor(); |
| 44 | SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); |
54 | SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); |
| 45 | 55 | ||
| 46 | vfs_init(VFS_DATA_PAK); |
56 | vfs_init(VFS_DATA_PAK); |
| 47 | InitGame(); |
57 | InitGame(); |
| 58 | game.screen_width = width; |
||
| 59 | game.screen_height = height; |
||
| 48 | SetMap(map_path.data); |
60 | SetMap(map_path.data); |
| 49 | 61 | ||
| 50 | if (target_fps >= 0) { |
62 | if (target_fps >= 0) { |
| ... | |||
| diff --git a/tbrun.sh b/tbrun.sh | |||
| ... | |||
| 20 | 20 | ||
| 21 | MAP="" |
21 | MAP="" |
| 22 | FPS="" |
22 | FPS="" |
| 23 | WIDTH="" |
||
| 24 | HEIGHT="" |
||
| 23 | while [ $# -gt 0 ]; do |
25 | while [ $# -gt 0 ]; do |
| 24 | case "$1" in |
26 | case "$1" in |
| 25 | --map) |
27 | --map) |
| ... | |||
| 36 | --fps=*) |
38 | --fps=*) |
| 37 | FPS="${1#--fps=}" |
39 | FPS="${1#--fps=}" |
| 38 | ;; |
40 | ;; |
| 41 | --width) |
||
| 42 | shift |
||
| 43 | WIDTH="$1" |
||
| 44 | ;; |
||
| 45 | --width=*) |
||
| 46 | WIDTH="${1#--width=}" |
||
| 47 | ;; |
||
| 48 | --height) |
||
| 49 | shift |
||
| 50 | HEIGHT="$1" |
||
| 51 | ;; |
||
| 52 | --height=*) |
||
| 53 | HEIGHT="${1#--height=}" |
||
| 54 | ;; |
||
| 39 | --) shift; break;; |
55 | --) shift; break;; |
| 40 | *) ;; |
56 | *) ;; |
| 41 | esac |
57 | esac |
| ... | |||
| 43 | done |
59 | done |
| 44 | 60 | ||
| 45 | cd "$SCRIPT_DIR" |
61 | cd "$SCRIPT_DIR" |
| 46 | ./bin/stalag --map "$MAP" --fps "$FPS" |
62 | ./bin/stalag --map "$MAP" \ |
| 63 | ${FPS:+--fps "$FPS"} \ |
||
| 64 | ${WIDTH:+--width "$WIDTH"} \ |
||
| 65 | ${HEIGHT:+--height "$HEIGHT"} |
||
| diff --git a/trenchbroom/stalag/GameEngineProfiles.cfg b/trenchbroom/stalag/GameEngineProfiles.cfg | |||
| 1 | { |
1 | { |
| 2 | "profiles": [ |
2 | "profiles": [ |
| 3 | { |
3 | { |
| 4 | "name": "Stalag", |
4 | "name": "Stalag", |
| 5 | "parameters": "--fps 120 --map maps/${MAP_BASE_NAME}.map", |
5 | "parameters": "--fps 120 --width 1920 --height 1080 --map maps/${MAP_BASE_NAME}.map", |
| 6 | "path": "/home/m/Projects/stalag/tbrun.sh" |
6 | "path": "/home/m/Projects/stalag/tbrun.sh" |
| 7 | } |
7 | } |
| 8 | ], |
8 | ], |
| 9 | "version": 1 |
9 | "version": 1 |
| 10 | } |
10 | } |