aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--all.h1
-rw-r--r--game.c2
-rw-r--r--main.c22
-rwxr-xr-xtbrun.sh10
-rw-r--r--trenchbroom/stalag/GameEngineProfiles.cfg2
5 files changed, 31 insertions, 6 deletions
diff --git a/all.h b/all.h
index 26ccffb..8821f86 100644
--- a/all.h
+++ b/all.h
@@ -130,6 +130,7 @@ typedef struct {
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
index 40d1876..d1149b4 100644
--- a/game.c
+++ b/game.c
@@ -42,7 +42,7 @@ void UpdateGame(void) {
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
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;
diff --git a/tbrun.sh b/tbrun.sh
index d933b6d..bf810bc 100755
--- a/tbrun.sh
+++ b/tbrun.sh
@@ -19,6 +19,7 @@ SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)"
19echo "$SCRIPT_DIR" 19echo "$SCRIPT_DIR"
20 20
21MAP="" 21MAP=""
22FPS=""
22while [ $# -gt 0 ]; do 23while [ $# -gt 0 ]; do
23 case "$1" in 24 case "$1" in
24 --map) 25 --map)
@@ -28,6 +29,13 @@ while [ $# -gt 0 ]; do
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,4 +43,4 @@ while [ $# -gt 0 ]; do
35done 43done
36 44
37cd "$SCRIPT_DIR" 45cd "$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
index 41cc5fb..fb04830 100644
--- a/trenchbroom/stalag/GameEngineProfiles.cfg
+++ b/trenchbroom/stalag/GameEngineProfiles.cfg
@@ -2,7 +2,7 @@
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 ],