mlg-run: --basepath and --basegame for Quake3e's game data

With --quake3, --basepath DIR and --basegame NAME become fs_basepath and
fs_basegame, which Quake3e reads at start. mlg-run first checks that
DIR/NAME (baseq3 without --basegame) holds .pk3 files and stops with what
is missing otherwise; both are refused without --quake3. OpenArena 0.8.8,
free data kept outside the repository, runs as --basegame baseoa (its game
VM and maps load in a Quake3e dedicated server from this pin).
test-mlg-run covers the settings and the refusals.
This commit is contained in:
geramyloveless committed 2026-10-04 07:24:39 -07:00
1 parent a46365e5d0
commit fb0fb232ab
6 files changed
+115 -14

No files matched your search

+5 -4
View File
@@ -9,9 +9,10 @@
# path to the Apple GPU), with the SDL2 it bundles for macOS.
# 3. Puts quake3e.aarch64 and its libSDL2-2.0.0.dylib in build/quake3e.
#
# Game data is not fetched: put baseq3/pak*.pk3 from a Quake III Arena
# installation (or the demo's) where the game looks, or pass
# +set fs_basepath <directory that holds baseq3>.
# Game data is not fetched and never goes in the repository: Quake III
# Arena's baseq3 from an installation, or OpenArena 0.8.8 (free, from
# openarena.ws / SourceForge) unpacked outside the tree, which Quake3e runs
# as fs_basegame baseoa (mlg-run --basepath DIR --basegame baseoa).
#
# Options:
# --clean build from scratch
@@ -72,4 +73,4 @@ codesign --force --sign - "$OUT/libSDL2-2.0.0.dylib" "$OUT/quake3e.aarch64" 2>/d
step "Quake3e built"
echo " $OUT/quake3e.aarch64"
echo " run: build/mlg-run --quake3 --mode fullscreen -- $OUT/quake3e.aarch64 +set fs_basepath <dir with baseq3>"
echo " run: build/mlg-run --quake3 --mode fullscreen --basepath <dir with baseoa> --basegame baseoa -- $OUT/quake3e.aarch64"
+53 -5
View File
@@ -3,7 +3,8 @@
* display output drives, whatever the program would pick on its own.
*
* mlg-run [--output CONNECTOR|auto] [--mode auto|fullscreen|windowed]
* [--quake3] [--icd RADEON_ICD.json] [--loader libvulkan.1.dylib]
* [--quake3 [--basepath DIR] [--basegame NAME]]
* [--icd RADEON_ICD.json] [--loader libvulkan.1.dylib]
* [--dry-run] -- PROGRAM [ARGS...]
*
* It finds the RADV ICD and the Vulkan loader, asks the driver which
@@ -12,10 +13,13 @@
* plan.c: only RADV for the loader, the loader for SDL, MLG_WSI_OUTPUT and
* MLG_WSI_MODE for RADV's presentation, SDL's full screen on its own
* screen. --quake3 adds Quake3e's settings that put its window on that
* screen in that mode. --dry-run prints all that and runs nothing.
* screen in that mode; --basepath and --basegame name the game data (for
* OpenArena: the directory that holds baseoa, and baseoa), which must hold
* .pk3 files. --dry-run prints all that and runs nothing.
*
* Every missing piece is an error that says what is missing; nothing is
* run in its place. */
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -23,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <CoreGraphics/CoreGraphics.h>
@@ -34,7 +39,8 @@
static void usage(void)
{
fprintf(stderr,
"usage: mlg-run [--output CONNECTOR|auto] [--mode auto|fullscreen|windowed] [--quake3]\n"
"usage: mlg-run [--output CONNECTOR|auto] [--mode auto|fullscreen|windowed]\n"
" [--quake3 [--basepath DIR] [--basegame NAME]]\n"
" [--icd RADEON_ICD.json] [--loader libvulkan.1.dylib] [--dry-run]\n"
" -- PROGRAM [ARGS...]\n");
}
@@ -111,6 +117,39 @@ static int find_loader(const char *given, char *out, size_t size)
return -1;
}
/* Quake3e's game data: @basepath/@basegame (baseq3 without --basegame)
* holds .pk3 files. The resolved base path goes to @out. */
static int check_game_data(const char *basepath, const char *basegame, char *out, size_t size)
{
char dir[PATH_MAX];
DIR *d;
struct dirent *e;
bool pk3 = false;
if (!realpath(basepath, out)) {
fprintf(stderr, "mlg-run: --basepath %s: %s\n", basepath, strerror(errno));
return -1;
}
(void)size;
snprintf(dir, sizeof(dir), "%s/%s", out, basegame ? basegame : "baseq3");
d = opendir(dir);
if (!d) {
fprintf(stderr, "mlg-run: no game directory %s: %s\n", dir, strerror(errno));
return -1;
}
while ((e = readdir(d)) && !pk3) {
size_t n = strlen(e->d_name);
pk3 = n > 4 && !strcasecmp(e->d_name + n - 4, ".pk3");
}
closedir(d);
if (!pk3) {
fprintf(stderr, "mlg-run: %s holds no .pk3 game data\n", dir);
return -1;
}
return 0;
}
/* The display output and its macOS display, from the driver. */
static int find_output(const char *wanted, struct plan_input *in, char *connector, size_t size)
{
@@ -171,8 +210,8 @@ static int find_output(const char *wanted, struct plan_input *in, char *connecto
int main(int argc, char **argv)
{
const char *output = "auto", *icd_arg = NULL, *loader_arg = NULL;
char icd[PATH_MAX], loader[PATH_MAX], connector[MLG_LX_SCANOUT_NAME_BYTES], why[160];
const char *output = "auto", *icd_arg = NULL, *loader_arg = NULL, *basepath_arg = NULL;
char icd[PATH_MAX], loader[PATH_MAX], basepath[PATH_MAX], connector[MLG_LX_SCANOUT_NAME_BYTES], why[160];
struct plan_input in = { .mode = PLAN_MODE_AUTO };
static struct plan plan;
bool dry_run = false;
@@ -196,6 +235,10 @@ int main(int argc, char **argv)
fprintf(stderr, "mlg-run: --mode %s: auto, fullscreen or windowed\n", argv[i]);
return 2;
}
} else if (!strcmp(a, "--basepath") && i + 1 < argc) {
basepath_arg = argv[++i];
} else if (!strcmp(a, "--basegame") && i + 1 < argc) {
in.basegame = argv[++i];
} else if (!strcmp(a, "--icd") && i + 1 < argc) {
icd_arg = argv[++i];
} else if (!strcmp(a, "--loader") && i + 1 < argc) {
@@ -215,6 +258,11 @@ int main(int argc, char **argv)
in.argc = argc - i;
in.argv = argv + i;
if (basepath_arg) {
if (check_game_data(basepath_arg, in.basegame, basepath, sizeof(basepath)))
return 1;
in.basepath = basepath;
}
if (find_icd(icd_arg, icd, sizeof(icd)) || find_loader(loader_arg, loader, sizeof(loader)) ||
find_output(output, &in, connector, sizeof(connector)))
return 1;
+28 -1
View File
@@ -46,6 +46,15 @@ static int arg(struct plan *p, int *added, const char *fmt, long value, const ch
return 0;
}
/* An argument the input owns (a path may be longer than args[]). */
static int arg_text(struct plan *p, const char *text)
{
if (p->argc == PLAN_MAX_ARGS)
return -1;
p->argv[p->argc++] = (char *)text;
return 0;
}
/* Quake3e: "+set name value". */
static int set(struct plan *p, int *added, const char *name, long value, const char *text)
{
@@ -67,6 +76,15 @@ int plan_make(const struct plan_input *in, struct plan *out, char *why, size_t w
snprintf(why, why_size, "no program to run");
return -1;
}
if ((in->basepath || in->basegame) && !in->quake3) {
snprintf(why, why_size, "--basepath and --basegame are Quake3e settings (--quake3)");
return -1;
}
if (in->basegame && (!in->basegame[0] || strlen(in->basegame) >= sizeof(out->args[0]) ||
strchr(in->basegame, '/'))) {
snprintf(why, why_size, "--basegame %s: a directory name in the base path", in->basegame);
return -1;
}
if (in->argc > PLAN_MAX_ARGS - 32) {
snprintf(why, why_size, "too many arguments (%d)", in->argc);
return -1;
@@ -89,7 +107,16 @@ int plan_make(const struct plan_input *in, struct plan *out, char *why, size_t w
if (in->quake3) {
const bool windowed = in->mode == PLAN_MODE_WINDOWED;
int r = set(out, &added, "cl_renderer", 0, "vulkan") ||
int r = 0;
/* The game data: fs_basepath and fs_basegame are read at start
* (OpenArena's is baseoa). */
if (in->basepath)
r = r || arg(out, &added, NULL, 0, "+set") || arg(out, &added, NULL, 0, "fs_basepath") ||
arg_text(out, in->basepath);
if (in->basegame)
r = r || set(out, &added, "fs_basegame", 0, in->basegame);
r = r || set(out, &added, "cl_renderer", 0, "vulkan") ||
set(out, &added, "r_swapInterval", 1, NULL) ||
set(out, &added, "r_fullscreen", windowed ? 0 : 1, NULL);
+2
View File
@@ -27,6 +27,8 @@ struct plan_input {
const char *connector; /* the output's connector ("DP-1") */
enum plan_mode mode;
bool quake3; /* the program is Quake3e: add its placement settings */
const char *basepath; /* Quake3e: the directory that holds the game data, or NULL */
const char *basegame; /* Quake3e: the game directory in it ("baseoa"), or NULL */
/* The macOS display that stands for the monitor, if there is one. */
bool have_display;
int32_t display_x, display_y; /* its bounds in global points */
+18 -2
View File
@@ -65,6 +65,19 @@ int main(void)
CHECK(!strcmp(setting(&p, "vid_xpos"), "2152") && !strcmp(setting(&p, "vid_ypos"), "60"));
CHECK(p.argv[p.argc] == NULL);
/* OpenArena's data: the base path and game directory, read at start. */
in.basepath = "/Users/someone/Games/OpenArena/openarena-0.8.8";
in.basegame = "baseoa";
CHECK(plan_make(&in, &p, why, sizeof(why)) == 0);
CHECK(!strcmp(setting(&p, "fs_basepath"), "/Users/someone/Games/OpenArena/openarena-0.8.8"));
CHECK(!strcmp(setting(&p, "fs_basegame"), "baseoa"));
CHECK(!strcmp(setting(&p, "r_mode"), "-2"));
in.basegame = "../baseoa";
CHECK(plan_make(&in, &p, why, sizeof(why)) == -1 && strstr(why, "--basegame"));
in.basegame = NULL;
CHECK(plan_make(&in, &p, why, sizeof(why)) == 0 && !setting(&p, "fs_basegame"));
in.basepath = NULL;
/* Windowed: three quarters of the screen, centred on it. */
in.mode = PLAN_MODE_WINDOWED;
CHECK(plan_make(&in, &p, why, sizeof(why)) == 0);
@@ -94,6 +107,9 @@ int main(void)
CHECK(plan_make(&in, &p, why, sizeof(why)) == 0);
CHECK(p.argc == 1 && !strcmp(p.argv[0], "vkcube") && p.argv[1] == NULL);
CHECK(env_of(&p, "MLG_WSI_OUTPUT") && !setting(&p, "r_mode"));
in.basegame = "baseoa";
CHECK(plan_make(&in, &p, why, sizeof(why)) == -1 && strstr(why, "--quake3"));
in.basegame = NULL;
/* Refusals. */
in.connector = "";
@@ -108,7 +124,7 @@ int main(void)
CHECK(plan_make(&in, &p, why, sizeof(why)) == -1 && strstr(why, "size"));
printf("PASS mlg-run plan: RADV-only loader environment, MLG_WSI_OUTPUT/MODE, SDL on its "
"screen, Quake3e placement full screen and windowed, with and without a macOS "
"display, refusals\n");
"screen, Quake3e placement full screen and windowed, game data (OpenArena), "
"with and without a macOS display, refusals\n");
return 0;
}
+9 -2
View File
@@ -291,9 +291,16 @@ screen. `--quake3` adds Quake3e's settings: the Vulkan renderer, vsync, and
full screen at the desktop's mode or a window three quarters of the
monitor's screen, placed on that screen. `--dry-run` prints the plan.
`--basepath DIR` and `--basegame NAME` name Quake3e's game data
(`fs_basepath`, `fs_basegame`); mlg-run checks that DIR/NAME holds .pk3
files. OpenArena 0.8.8 (free data, from openarena.ws / SourceForge, kept
outside the repository) runs as `--basegame baseoa`:
```sh
build/mlg-run --quake3 --mode fullscreen -- ./quake3e.aarch64
build/mlg-run --quake3 --mode windowed -- ./quake3e.aarch64 +map q3dm17
build/mlg-run --quake3 --mode fullscreen --basepath ~/Games/OpenArena/openarena-0.8.8 \
--basegame baseoa -- build/quake3e/quake3e.aarch64
build/mlg-run --quake3 --mode windowed --basepath ~/Games/OpenArena/openarena-0.8.8 \
--basegame baseoa -- build/quake3e/quake3e.aarch64 +map oa_dm1
```
## Remaining gaps