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