aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-05-01 03:53:58 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-05-01 03:53:58 +0200
commitfb96ec752215da56407c2266ab9d1eedf670e0d1 (patch)
tree9654257120ab890720946e5bc23bff9df0803348
parent08eada80a4fd13028f2a19108788f76752cc459b (diff)
downloadstalag-fb96ec752215da56407c2266ab9d1eedf670e0d1.tar.gz
Custom --width and --height cli argument
-rw-r--r--all.h2
-rw-r--r--main.c16
-rwxr-xr-xtbrun.sh21
-rw-r--r--trenchbroom/stalag/GameEngineProfiles.cfg16
4 files changed, 44 insertions, 11 deletions
diff --git a/all.h b/all.h
index 8821f86..b0dde0c 100644
--- a/all.h
+++ b/all.h
@@ -131,6 +131,8 @@ typedef struct {
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
index 1ca42bd..cc96b3b 100644
--- a/main.c
+++ b/main.c
@@ -11,16 +11,20 @@ int main(int argc, char *argv[]) {
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,6 +35,12 @@ int main(int argc, char *argv[]) {
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,13 +48,15 @@ int main(int argc, char *argv[]) {
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
index bf810bc..8a600b7 100755
--- a/tbrun.sh
+++ b/tbrun.sh
@@ -20,6 +20,8 @@ echo "$SCRIPT_DIR"
20 20
21MAP="" 21MAP=""
22FPS="" 22FPS=""
23WIDTH=""
24HEIGHT=""
23while [ $# -gt 0 ]; do 25while [ $# -gt 0 ]; do
24 case "$1" in 26 case "$1" in
25 --map) 27 --map)
@@ -36,6 +38,20 @@ while [ $# -gt 0 ]; do
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,4 +59,7 @@ while [ $# -gt 0 ]; do
43done 59done
44 60
45cd "$SCRIPT_DIR" 61cd "$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
index fb04830..81eda2f 100644
--- a/trenchbroom/stalag/GameEngineProfiles.cfg
+++ b/trenchbroom/stalag/GameEngineProfiles.cfg
@@ -1,10 +1,10 @@
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}