Triforce v0.8.5

A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-28 10:54:41 -06:00
parent 2df08c751e
commit b527e29adb
203 changed files with 18821 additions and 2051 deletions

View File

@@ -0,0 +1,209 @@
"""Whose sound: the settings' tabs, the Mods screen and the step back to the pause menu's System list have a sound each
(the owner: "The SFX are incorrect. They should be using the title screen's SFX instead of the in-game Menu SFX."), the
system menu's cursor, small decide and cancel unless the environment names another for one of the seven:
HOS_MENU_SOUND_SETTINGS_NAVIGATE, _SETTINGS_SELECT, _SETTINGS_BACK the Triforce settings tabs
HOS_MENU_SOUND_MODS_NAVIGATE, _MODS_SELECT, _MODS_BACK the Mods screen
HOS_MENU_SOUND_PAUSE_BACK Back out of the Mods screen onto the pause menu's
System list, Cancel and B on Quit's dialog
Read in the source: the seven are sounds of their own in vk_api.h, after the system menu's two; host/menu_sound.c has a
file and a variable of the same name for each; the Mods screen's input (vk_menu.cpp mods_tick) asks for the Mods screen's
three and never for the in-game menu's cursor, decide and cancel, which nothing in vk_menu.cpp asks for any more; Quit's
dialog and the step back out of the Mods screen onto the pause menu's list ask for the pause menu's; docs/development.md
has the variables' row.
Compiled and run: triforce_env.txt takes the seven names with a sound's bare name (host/hos_main.c env_line_allowed, cut
out as it is, with menu_sound.c's own name check): every value the game takes for a role can be written there, and no
value that names a folder or a path is one the game takes.
tests/menu_sound_test.c (tests/test_menu_sound.py, "roles" and "voices") has the host's side run: the files, the
environment's word, the ticks; tests/test_menu_sound_events.py has sound_for and the queue.
python -I -B tests/test_menu_sound_roles.py [--cc gcc]
"""
import argparse
import re
import subprocess
import sys
import tempfile
from pathlib import Path
RUN_ALL_ARGS = ["--cc", "gcc"]
ROOT = Path(__file__).resolve().parents[1]
ROLES = ("SETTINGS_NAVIGATE", "SETTINGS_SELECT", "SETTINGS_BACK", "MODS_NAVIGATE", "MODS_SELECT", "MODS_BACK", "PAUSE_BACK",
"SETTINGS_ON", "SETTINGS_OFF") # ((Triforce, 11-25) a toggle switched On, Off)
OWN = {"NAVIGATE": "SE_Sys_SysMenu_Cursor00", "SELECT": "SE_Sys_SysMenu_DecideS00", "BACK": "SE_Sys_SysMenu_Cansel00",
"SETTINGS_SELECT": "SE_Sys_SysMenu_DecideL00", "SETTINGS_ON": "SE_Sys_SysMenu_DecideS00", "SETTINGS_OFF": "SE_Sys_SysMenu_Cansel00"} # (the owner's pick: the settings' Select is the title's Continue's)
own_of = lambda role: OWN.get(role) or OWN[role.split("_")[1]]
IN_GAME = ("HOS_MENU_SOUND_CURSOR", "HOS_MENU_SOUND_DECIDE", "HOS_MENU_SOUND_CANCEL")
def check(cond, what):
if not cond:
raise SystemExit("FAIL: " + what)
def block(text, marker):
start = text.index(marker)
end = text.index("{", start) + 1
depth = 1
while depth:
depth += (text[end] == "{") - (text[end] == "}")
end += 1
return text[start:end]
PROGRAM = r'''#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); exit(1); } } while (0)
@MOST@
@NAME_OK@
@ALLOWED@
static const char *const names[] = {@NAMES@};
/* (a sound's name, and what is not one) */
static const char *const values[] = {
"SE_Sys_Cursor00", "SE_Sys_Do00", "SE_Sys_Cancel00", "SE_Sys_SysMenu_Cursor00", "SE_Sys_SysMenu_DecideS00", "SE_Sys_SysMenu_DecideL00",
"SE_Sys_SysMenu_Cansel00", "SE_Sys_SysMenu_Error00", "BGM_ItemGet_Medium", "a", "_", "0", "1", "Z9_z",
"@A64@", /* (64 characters) */
"@A64@a", /* (65) */
"", ".", "..", "~", "~user", "SE_Sys_Cursor00.bwav", "../SE_Sys_Cursor00", "..\\SE_Sys_Cursor00", "Stream/SE_Sys_Cursor00",
"/SE_Sys_Cursor00", "\\SE_Sys_Cursor00", "C:SE_Sys_Cursor00", "C:\\Games\\x", "//server/share", "SE Sys", "SE-Sys", "a.b", "a,b", "a*",
"%s%n", "caf\xc3\xa9"};
int main(void) {
int taken = 0;
CHECK(sizeof names / sizeof *names == 9);
for (size_t n = 0; n < sizeof names / sizeof *names; n++) {
const size_t len = strlen(names[n]);
/* (not one of the names the file leaves out: a file's or a folder's, whatever its value) */
CHECK(strcmp(names[n] + len - 5, "_FILE") && strcmp(names[n] + len - 4, "_DIR") && !strncmp(names[n], "HOS_MENU_SOUND_", 15));
for (size_t v = 0; v < sizeof values / sizeof *values; v++) {
const int ok = role_name_ok(values[v]);
/* every name the game takes for a role can be written in triforce_env.txt */
if (ok && !env_line_allowed(names[n], values[v])) { fprintf(stderr, "%s=%s is left out of the file\n", names[n], values[v]); return 1; }
/* and nothing with a folder in it, a drive, a dot or a home is a name */
if (ok && (strpbrk(values[v], "/\\:.~") || !*values[v] || strlen(values[v]) > 64)) { fprintf(stderr, "%s is taken as a name\n", values[v]); return 1; }
taken += ok;
}
CHECK(env_line_allowed(names[n], "SE_Sys_Cursor00") && !env_line_allowed(names[n], "../SE_Sys_Cursor00") &&
!env_line_allowed(names[n], "C:\\Games\\x") && !env_line_allowed(names[n], "Stream/SE_Sys_Cursor00"));
}
CHECK(taken == 9 * 15); /* (the fourteen names and the one of 64; none of the rest) */
CHECK(role_name_ok(values[14]) && strlen(values[14]) == 64 && !role_name_ok(values[15]) && strlen(values[15]) == 65);
puts("triforce_env.txt takes the nine variables with a sound's bare name; a path is never a name");
return 0;
}
'''
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--cc", default="gcc")
a = p.parse_args()
api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8")
menu = (ROOT / "gpu" / "vk" / "vk_menu.cpp").read_text(encoding="utf-8")
sound = (ROOT / "host" / "menu_sound.c").read_text(encoding="utf-8")
main_c = (ROOT / "host" / "hos_main.c").read_text(encoding="utf-8")
guide = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
# the seven: sounds of their own, after the system menu's two and before the count
enum = block(api, "enum { HOS_MENU_SOUND_OPEN = 1")
ids = re.findall(r"\bHOS_MENU_SOUND_\w+", re.sub(r"/\*.*?\*/", "", enum, flags=re.S))
check(ids[-10:] == ["HOS_MENU_SOUND_" + r for r in ROLES] + ["HOS_MENU_SOUND_N"] and ids[-11] == "HOS_MENU_SOUND_SYS_DECIDE" and
len(ids) == len(set(ids)) == 20, "vk_api.h: the seven sounds are not the last, after the system menu's decide: %s" % ids)
# each with its own file, the system menu's, and the variable of its own name
for r in ROLES:
check(' [HOS_MENU_SOUND_%s] = "Sound/Resource/Stream/%s.bwav",\n' % (r, own_of(r)) in sound,
"host/menu_sound.c: HOS_MENU_SOUND_%s is not the system menu's %s" % (r, own_of(r)))
check(' {HOS_MENU_SOUND_%s, "HOS_MENU_SOUND_%s"},\n' % (r, r) in sound, "host/menu_sound.c: no variable for HOS_MENU_SOUND_%s" % r)
# (the array's own braces, not the struct's: block() would stop at "{ int id; const char *env; }")
table = sound[sound.index("static const struct { int id; const char *env; } roles[] = {"):]
table = table[:table.index("\n};\n")]
check(re.findall(r'"(HOS_\w+)"', table) == ["HOS_MENU_SOUND_" + r for r in ROLES], "host/menu_sound.c: the roles are not the seven, in the sounds' order")
for was, name in zip(IN_GAME, ("SE_Sys_Cursor00", "SE_Sys_Do00", "SE_Sys_Cancel00")): # (the in-game menu's stay what they were)
check(' [%s] = "Sound/Resource/Stream/%s.bwav",\n' % (was, name) in sound, "host/menu_sound.c: %s is no longer %s" % (was, name))
# the Mods screen's input: its own three, the fanfare and the categories' moves; never the in-game menu's or the settings'
tick = block(menu, "void mods_tick(bool* press, bool tab_left, bool tab_right, bool mouse, bool moved, const MkwVkPointer& ptr, int mx, int my, bool& changed) {")
asked = re.findall(r"mods_sound\(([^;]*)\);", tick)
check(len(asked) >= 20, "mods_tick: the Mods screen's sounds are not asked for where they were (%d)" % len(asked))
allowed = {"HOS_MENU_SOUND_MODS_NAVIGATE", "HOS_MENU_SOUND_MODS_SELECT", "HOS_MENU_SOUND_MODS_BACK", "HOS_MENU_SOUND_FANFARE",
"HOS_MENU_SOUND_TAB_LEFT", "HOS_MENU_SOUND_TAB_RIGHT"}
for arg in asked:
named = set(re.findall(r"HOS_MENU_SOUND_\w+", arg))
check(named <= allowed and (named or arg == "mods_back_sound()"), "mods_tick asks for a sound that is not the Mods screen's: mods_sound(%s)" % arg)
for kind in ("NAVIGATE", "SELECT", "BACK"):
check(any("HOS_MENU_SOUND_MODS_" + kind in arg for arg in asked), "mods_tick never asks for the Mods screen's " + kind.lower())
# (Not now on the warning leaves the screen: the step back's sound is the list's it goes back to)
check(" mods_sound(mods_back_sound());\n mods_back(changed);\n" in tick,
"mods_tick: Not now does not sound as the step back onto the list the Mods screen was opened from")
# the step back onto the pause menu's System list: where mods_back goes while that list is there, and not the title's
check("int mods_back_sound() { return mods_list_fresh() && !mods_title_list() ? HOS_MENU_SOUND_PAUSE_BACK : HOS_MENU_SOUND_MODS_BACK; }" in menu,
"vk_menu.cpp: the step back out of the Mods screen is not the pause menu's onto its list alone")
check("if (mods_list_fresh() && !mods_title_list()) page = kModsRowPage;" in block(menu, "void mods_back(bool& changed) {") and
"bool mods_title_list() { return (mods_list_bits.load(std::memory_order_relaxed) & HOS_MODS_LIST_TITLE) != 0; }" in menu,
"vk_menu.cpp: mods_back or mods_title_list changed: mods_back_sound tells the pause menu's list by them")
whole = block(menu, "void menu_tick() {")
rows = whole[whole.index("} else if (open_now.load() && page == kModsRowPage) {"):whole.index("} else if (open_now.load() && page == kModsPage) {")]
check(rows.count("HOS_MENU_SOUND_PAUSE_BACK") == 2 and "quit_cancel(), mods_sound(HOS_MENU_SOUND_PAUSE_BACK)" in rows and
"mods_sound(quit_sel == 2 ? HOS_MENU_SOUND_PAUSE_BACK : HOS_MENU_SOUND_SYS_DECIDE);" in rows,
"Quit's dialog: Cancel and B do not ask for the pause menu's step back")
# (the entries under the game's lists keep the system menu's cursor and decide)
check(set(re.findall(r"HOS_MENU_SOUND_\w+", rows)) == {"HOS_MENU_SOUND_PAUSE_BACK", "HOS_MENU_SOUND_SYS_CURSOR", "HOS_MENU_SOUND_SYS_DECIDE"},
"the entries under the game's lists ask for a sound that is not the system menu's or the pause menu's step back")
# nothing in the options asks for the in-game menu's three by name any more (held against menu_sound_events.h's alone)
for was in IN_GAME:
check(len(re.findall(r"\b%s\b" % was, menu)) == 1, "vk_menu.cpp asks for the in-game menu's %s" % was)
check("const int sound = menu_sound::sound_for(menu_sound::sound_of(sound_before, after, in), on_mods, to_pause);" in whole and
"sound_queue.put(menu_sound::toggle_sound(sound, sound_before, after), prof_now());" in whole and
whole.count("s.toggle = r.value && r.text == tx_onoff;") == 0 and
menu.count("s.toggle = r.value && r.text == tx_onoff;") == 2,
"menu_tick does not ask for the sound of whose cursor, decide or cancel it is")
# the ticks: the cursor's and the two roles', replaced by the decision of the same press. ((Triforce, 11-26) the
# navigation sounds, the ticks and the system menu's cursor, as the game's own (the owner's clip): each plays whole beside
# the ones before it, at the whole level, never thinned out but for one press asking twice)
play = block(sound, "void hos_menu_sound_play(int id, int64_t now_ns) {")
mix = block(sound, "void hos_menu_sound_mix(float *left, float *right, uint32_t frames, float gain) {")
check("return id == HOS_MENU_SOUND_CURSOR || id == HOS_MENU_SOUND_SETTINGS_NAVIGATE || id == HOS_MENU_SOUND_MODS_NAVIGATE;" in
block(sound, "static int is_tick(int id) {"), "host/menu_sound.c: the roles' two ticks are not ticks")
check("static int is_nav(int id) { return is_tick(id) || id == HOS_MENU_SOUND_SYS_CURSOR; }" in sound and
"#define NAV_GAP_NS 45000000ll" in sound and "CURSOR_GAP_NS" not in sound,
"host/menu_sound.c: the navigation sounds are not the ticks and the system menu's cursor, or are still thinned out")
check("if (is_nav(id) && now_ns - atomic_load(&last_start_ns) < NAV_GAP_NS) return;" in play and
"if (at >= 0 && (was == id || is_nav(was)) && AT_FRAME(at) < 2400) {" in play and
"NAV_FADE" not in sound and ".fade" not in sound and "CURSOR_GAIN" not in sound and
"left[i] += src[2 * (size_t)i] * gain;" in mix,
"host/menu_sound.c: a navigation sound is cut short by the next sound, or a tick is not at the whole level")
check("if (pick < 0) pick = nav >= 0 ? nav : oldest;" in play,
"host/menu_sound.c: with no voice free a navigation sound's is not the first to go")
# the guide's row
row = [ln for ln in guide.splitlines() if ln.startswith("| `HOS_MENU_SOUND_SETTINGS_NAVIGATE=<sound>`")]
check(len(row) == 1, "docs/development.md has no row for the sounds' variables")
for r in ROLES:
check("`HOS_MENU_SOUND_%s" % r in row[0].split(" | ")[0], "docs/development.md's row does not name HOS_MENU_SOUND_%s" % r)
for name in OWN.values():
check("`%s`" % name in row[0], "docs/development.md's row does not say %s" % name)
most = re.search(r"^#define ROLE_NAME_MOST 64$", sound, re.M)
check(most, "host/menu_sound.c: a sound's name is no longer 64 characters at most")
src = PROGRAM.replace("@MOST@", most.group(0)).replace("@NAME_OK@", block(sound, "static int role_name_ok(const char *name) {")) \
.replace("@ALLOWED@", block(main_c, "static int env_line_allowed(")) \
.replace("@NAMES@", ", ".join('"HOS_MENU_SOUND_%s"' % r for r in ROLES)).replace("@A64@", "a" * 64)
with tempfile.TemporaryDirectory(prefix="menu-sound-roles-") as tmp:
c, exe = Path(tmp) / "roles.c", Path(tmp) / "roles.exe"
c.write_text(src, encoding="utf-8")
subprocess.run([a.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", str(c), "-o", str(exe)], check=True)
r = subprocess.run([str(exe)], capture_output=True, text=True)
sys.stdout.write(r.stdout)
check(r.returncode == 0, "roles.c: " + r.stderr.strip())
print("PASS: the settings' tabs', the Mods screen's and the pause menu's own sounds, and the environment's names for them")
if __name__ == "__main__":
main()