aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-05-01 03:44:54 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-05-01 03:48:51 +0200
commit08eada80a4fd13028f2a19108788f76752cc459b (patch)
tree1a109892e15527f73d3ab6f91dc8eda840e12dc3 /main.c
parente21ab733cc063527099bb819f64f4c7396059f03 (diff)
downloadstalag-08eada80a4fd13028f2a19108788f76752cc459b.tar.gz
Custom FPS cli argument
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 19 insertions, 3 deletions
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[]) {
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,20 +28,34 @@ int main(int argc, char *argv[]) {
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);
42 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 }
58
43 if (skip_title) { 59 if (skip_title) {
44 if (LoadMap(game.map_path)) { 60 if (LoadMap(game.map_path)) {
45 game.mode = STATE_PLAYING; 61 game.mode = STATE_PLAYING;