aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/main.c b/main.c
index 9f32ecc..cc96b3b 100644
--- a/main.c
+++ b/main.c
@@ -10,15 +10,21 @@ 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;
14 int width = WINDOW_WIDTH;
15 int height = WINDOW_HEIGHT;
13 16
14 static struct option long_options[] = { 17 static struct option long_options[] = {
15 {"map", required_argument, 0, 'm'}, 18 {"map", required_argument, 0, 'm'},
19 {"fps", required_argument, 0, 'f'},
20 {"width", required_argument, 0, 'w'},
21 {"height", required_argument, 0, 'h'},
16 {0, 0, 0, 0} 22 {0, 0, 0, 0}
17 }; 23 };
18 24
19 int opt; 25 int opt;
20 int option_index = 0; 26 int option_index = 0;
21 while ((opt = getopt_long_only(argc, argv, "m:", long_options, &option_index)) != -1) { 27 while ((opt = getopt_long_only(argc, argv, "m:f:w:h:", long_options, &option_index)) != -1) {
22 switch (opt) { 28 switch (opt) {
23 case 'm': 29 case 'm':
24 sb_free(&map_path); 30 sb_free(&map_path);
@@ -26,20 +32,42 @@ int main(int argc, char *argv[]) {
26 sb_append_cstr(&map_path, optarg); 32 sb_append_cstr(&map_path, optarg);
27 skip_title = true; 33 skip_title = true;
28 break; 34 break;
35 case 'f':
36 target_fps = atoi(optarg);
37 break;
38 case 'w':
39 width = atoi(optarg);
40 break;
41 case 'h':
42 height = atoi(optarg);
43 break;
29 } 44 }
30 } 45 }
31 46
32 SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI); 47 unsigned int flags = FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI;
33 InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE); 48 if (target_fps < 0) flags |= FLAG_VSYNC_HINT;
49
50 SetConfigFlags(flags);
51 InitWindow(width, height, WINDOW_TITLE);
34 52
35 int monitor = GetCurrentMonitor(); 53 int monitor = GetCurrentMonitor();
36 SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); 54 SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2);
37 SetTargetFPS(GetMonitorRefreshRate(monitor));
38 55
39 vfs_init(VFS_DATA_PAK); 56 vfs_init(VFS_DATA_PAK);
40 InitGame(); 57 InitGame();
58 game.screen_width = width;
59 game.screen_height = height;
41 SetMap(map_path.data); 60 SetMap(map_path.data);
42 61
62 if (target_fps >= 0) {
63 game.target_fps = target_fps;
64 game.vsync = false;
65 SetTargetFPS(game.target_fps);
66 } else {
67 game.vsync = true;
68 SetTargetFPS(GetMonitorRefreshRate(monitor));
69 }
70
43 if (skip_title) { 71 if (skip_title) {
44 if (LoadMap(game.map_path)) { 72 if (LoadMap(game.map_path)) {
45 game.mode = STATE_PLAYING; 73 game.mode = STATE_PLAYING;