mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-28 20:08:51 -04:00
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.
274 lines
18 KiB
Python
274 lines
18 KiB
Python
"""(Triforce, 11-26) The options' Apply: the rows that took a restart and now change in play. The owner: "Every option that
|
|
requires a restart should be changed in game without having to restart unless if the setting has to have the game be
|
|
restarted. I want you to implement an apply option in the menu ... If the player tries to back out without applying the
|
|
settings, they should get a pop-up that asks them to apply these settings. Same prompt as the Restart pop up."
|
|
|
|
What it checks:
|
|
- host/res_follow.h, compiled and run: the Render resolution's scale as the menu applies it, each present (fixed to fixed,
|
|
Auto and back, a smaller one, the pool held to its size at a 5K picture, the same scale asked again, before the renderer
|
|
answers, HOS_RES_SCALE's place).
|
|
- The renderer reads the three rows taken at Apply as applied (vk_menu.h applied_dlss and its kin), never as the rows are
|
|
being stepped: the upscaler's engine (vk_temporal.cpp, vk_fsr3.cpp, vk_draw.cpp), DLSS's feature size (vk_dlss.cpp), the
|
|
upscale before the bloom, read each time (vk_temporal.cpp pre_wanted), and the host's options 2 and 3 (vk_replay.cpp), by the
|
|
applied choice alone (no stand-in, no N64 Classic: they would remake the game's targets back and forth).
|
|
- host/nn_vi.c takes the options each present: no value read once at the start; Steady pacing from the row each present
|
|
(steady_mode), its set made again on a change and the renderer told when it is off.
|
|
- The menu: the rows' flags (none of the three takes a restart, Frame pacing neither), the state (apply_init, set_row's note,
|
|
menu_apply), the guide (Apply first among them while a row waits, on the tuning bar too, a click on it, the key and the
|
|
button bound to the Switch's X), the question (Apply's before the restart question, on the same page, with Later and Apply
|
|
Now; then the restart question if one waits), and the texts in every one of the menu's languages.
|
|
No game, no GPU.
|
|
|
|
python -I -B tests/test_menu_apply.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]
|
|
VK = ROOT / "gpu" / "vk"
|
|
|
|
FOLLOW_TEST = r"""
|
|
#include "res_follow.h"
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
|
|
int main(void) {
|
|
/* before the renderer answers: nothing taken, the game's own 1.0 stays */
|
|
ResFollow f = {-1, 0, 0};
|
|
assert(res_follow(&f, -1, -1, 0) == RES_SAME && f.scale == -1 && f.largest == 0);
|
|
/* the start: fixed 50%, taken; the largest is it */
|
|
assert(res_follow(&f, 0, 5000, 0) == RES_TAKE && f.scale == 5000 && f.largest == 5000);
|
|
assert(res_follow(&f, 0, 5000, 0) == RES_SAME); /* (each present after: nothing new) */
|
|
/* Apply 100%, the pool not held: taken at once */
|
|
assert(res_follow(&f, 0, 10000, 0) == RES_TAKE && f.scale == 10000 && f.largest == 10000);
|
|
/* Apply 33%: taken, the largest stays */
|
|
assert(res_follow(&f, 0, 3333, 0) == RES_TAKE && f.scale == 3333 && f.largest == 10000);
|
|
/* Apply Auto: the dynamic path's; the fixed scale stays as it was for the way back */
|
|
assert(res_follow(&f, 1, 0, 0) == RES_SAME && f.scale == 3333);
|
|
/* back to fixed 67%: taken */
|
|
assert(res_follow(&f, 0, 6667, 0) == RES_TAKE && f.scale == 6667);
|
|
|
|
/* a 5K picture, the pool held to its 900 MB: the start's 50% */
|
|
ResFollow k = {-1, 0, 0};
|
|
assert(res_follow(&k, 0, 5000, 1) == RES_TAKE && k.largest == 5000);
|
|
/* 100% asked: kept for the next start, said once */
|
|
assert(res_follow(&k, 0, 10000, 1) == RES_HOLD && k.held == 10000 && k.scale == 5000);
|
|
assert(res_follow(&k, 0, 10000, 1) == RES_SAME && k.held == 10000);
|
|
/* 33% asked: smaller, taken; nothing kept back */
|
|
assert(res_follow(&k, 0, 3333, 1) == RES_TAKE && k.scale == 3333 && k.held == 0);
|
|
/* back up to 50%, the start's: no larger than the largest, taken */
|
|
assert(res_follow(&k, 0, 5000, 1) == RES_TAKE && k.scale == 5000);
|
|
/* 67% asked, then back to the scale in force: kept, then freed */
|
|
assert(res_follow(&k, 0, 6667, 1) == RES_HOLD && k.held == 6667);
|
|
assert(res_follow(&k, 0, 5000, 1) == RES_FREE && k.held == 0 && k.scale == 5000);
|
|
/* held, then Auto: freed */
|
|
assert(res_follow(&k, 0, 6667, 1) == RES_HOLD);
|
|
assert(res_follow(&k, 1, 0, 1) == RES_FREE && k.held == 0);
|
|
|
|
/* a 5K picture that started on Auto: the largest is the dynamic path's 75%; 67% is taken, 100% kept back */
|
|
ResFollow a = {-1, 0, 0};
|
|
assert(res_follow(&a, 1, 0, 1) == RES_SAME && a.largest == 7500);
|
|
assert(res_follow(&a, 0, 6667, 1) == RES_TAKE && a.scale == 6667);
|
|
assert(res_follow(&a, 0, 10000, 1) == RES_HOLD && a.scale == 6667);
|
|
puts("res_follow: all checks passed");
|
|
return 0;
|
|
}
|
|
"""
|
|
|
|
|
|
def function(source, start):
|
|
at = source.find(start)
|
|
if at < 0:
|
|
raise SystemExit("%s is missing" % start)
|
|
body = source[at:]
|
|
return body[:body.index("\n}\n")]
|
|
|
|
|
|
def check(ok, why):
|
|
if not ok:
|
|
raise SystemExit("FAIL: " + why)
|
|
|
|
|
|
def row(menu, start):
|
|
at = menu.find(start)
|
|
check(at >= 0, "the row " + start + " is missing")
|
|
return menu[at:menu.index("},", at)]
|
|
|
|
|
|
def renderer():
|
|
temporal = (VK / "vk_temporal.cpp").read_text(encoding="utf-8")
|
|
mode = function(temporal, "int temporal_mode() {")
|
|
check("const int v = applied_dlss();" in mode and "rearm_on_choice(v);" in mode and "return temporal_mode_of(v, true);" in mode,
|
|
"temporal_mode does not run the Upscaler as applied")
|
|
mode_of = function(temporal, "int temporal_mode_of(int choice, bool now) {")
|
|
check("opts.dlss" not in mode_of and "if (now) v = n64_rules::upscaler(n64_in_front(), v);" in mode_of and
|
|
"if (now && stood_in(v)) return ur::GAME;" in mode_of and "if (fsr3_wanted_of(choice, now)) return ur::GAME;" in mode_of,
|
|
"temporal_mode_of does not leave the stand-ins out without now")
|
|
check("int v = applied_dlss();" in function(temporal, "int temporal_stood_in() {"), "temporal_stood_in reads the row as stepped")
|
|
pre = function(temporal, "bool pre_wanted(int mode) {")
|
|
check("applied_upscale_pre() != 0" in pre and "static const bool on" not in pre and "upscale_pre_at_start" not in pre,
|
|
"Upscale before bloom is not read each time, as applied")
|
|
fsr3 = (VK / "vk_fsr3.cpp").read_text(encoding="utf-8")
|
|
check("bool fsr3_wanted() { return fsr3_wanted_of(applied_dlss(), true); }" in fsr3 and
|
|
"bool fsr3_native() { return fsr3_native_of(applied_dlss(), true); }" in fsr3, "FSR 3.1 does not run as applied")
|
|
wanted = function(fsr3, "bool fsr3_wanted_of(int choice, bool now) {")
|
|
check("opts.dlss" not in wanted and "upscaler_rows::is_fsr3(choice)" in wanted and "if (now && n64_rules::upscaler(" in wanted,
|
|
"fsr3_wanted_of does not read its choice")
|
|
check("opts.dlss" not in function(fsr3, "bool fsr3_native_of(int choice, bool now) {"), "fsr3_native_of reads the row")
|
|
dlss = (VK / "vk_dlss.cpp").read_text(encoding="utf-8")
|
|
check("s.range_seen || applied_resolution() == 0" in dlss and "opts.resolution" not in dlss, "DLSS's feature reads the row as stepped")
|
|
draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
|
|
off = function(draw, "static bool upscale_off_on() {")
|
|
check("applied_dlss() == upscaler_rows::OFF" in off and "opts.dlss" not in off, "the Upscaler's Off is not as applied")
|
|
for name, src in (("vk_temporal.cpp", temporal), ("vk_fsr3.cpp", fsr3), ("vk_draw.cpp", draw)):
|
|
check(not re.search(r"\bopts\.dlss\b", re.sub(r"//[^\n]*", "", src)), name + " reads the Upscaler row as it is being stepped")
|
|
replay = (VK / "vk_replay.cpp").read_text(encoding="utf-8")
|
|
check("id == 2 ? resolution_auto() && !resolution_full() : id == 3 ? (resolution_full() ? 10000 : resolution_scale())" in replay,
|
|
"the host's options 2 and 3 are not the Render resolution as applied")
|
|
check("if (id == HOS_OPT_STEADY_ROW) return menu_steady_row();" in replay, "the host is not told the Steady row")
|
|
api = (VK / "vk_api.h").read_text(encoding="utf-8")
|
|
check("enum { HOS_OPT_STEADY_ROW = 430 };" in api and "enum { HOS_OPT_RES_HELD = 431 };" in api, "the two options' numbers")
|
|
check("#define MKWVK_API_VERSION 25" in api, "the options need no new function: MKWVK_API_VERSION stays")
|
|
|
|
|
|
def host():
|
|
vi = (ROOT / "host" / "nn_vi.c").read_text(encoding="utf-8")
|
|
check('#include "res_follow.h"' in vi, "nn_vi.c does not take res_follow.h")
|
|
step = function(vi, "static void realtime_step(int64_t now) {")
|
|
check("dyn_at_start" not in step and "if (scale < 0) scale = rx_option(3, -1);" not in step,
|
|
"realtime_step still reads the Render resolution once, at the start")
|
|
check("const int asked = rx_option(2, -1);" in step and "res_dyn = asked;" in step and
|
|
"hos_fixed_resolution = !pulsed && res_dyn == 0 && hos_dynres_runs >= from;" in step,
|
|
"realtime_step does not follow Auto as applied")
|
|
check("res_follow(&follow, res_dyn, asked, pinned)" in step and "hos_rt_pool_pinned()" in step and
|
|
"rx_option_set(HOS_OPT_RES_HELD, asked);" in step and "memcpy((void *)&hos_fixed_scale_bits, &v, 4);" in step,
|
|
"realtime_step does not take the applied scale, or keep a larger one back where the pool is held")
|
|
check(step.index("res_follow(") < step.index('getenv("HOS_RES_SCALE")) { float v'), "HOS_RES_SCALE no longer goes over the row")
|
|
mode = function(vi, "static int steady_mode(void) {")
|
|
check("rx_option(HOS_OPT_STEADY_ROW, -1)" in mode and 'getenv("HOS_FPS_STEADY")' in mode and
|
|
'hos_ini_option("steady_frame_rate", PACE_STEADY_OFF)' in mode, "steady_mode does not follow the row, the switch over it")
|
|
check("steady = steady_mode();" in function(vi, "static void movie_pace_decide(void) {"), "the movie pacing reads Steady once")
|
|
period = function(vi, "static int64_t steady_period(int64_t base, int64_t now) {")
|
|
check("const int want = steady_mode();" in period and "pace_steady_reset(&steady);" in period and
|
|
"rx_option_set(HOS_OPT_PACE_STEADY, 0);" in period and "mode = want, cap = 0, frames = 0;" in period and
|
|
"if (mode < 0) {" not in period, "steady_period does not make its set again on a change in play")
|
|
|
|
|
|
def menu():
|
|
src = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
|
hdr = (VK / "vk_menu.h").read_text(encoding="utf-8")
|
|
for f in ("int applied_dlss();", "int applied_resolution();", "int applied_upscale_pre();", "bool resolution_full();",
|
|
"int menu_steady_row();"):
|
|
check(f in hdr, "vk_menu.h does not declare " + f)
|
|
check("int applied_rows[3] = {Options().dlss, Options().resolution, Options().upscale_pre};" in src, "the applied values")
|
|
check("bool applies(const Row& r) { return r.value == &opts.dlss || r.value == &opts.resolution || r.value == &opts.upscale_pre; }"
|
|
in src, "the rows taken at Apply")
|
|
# (the rows: none of the three takes a restart now, nor Frame pacing; each help says Apply)
|
|
for start, help_end in (('{TAB_GRAPHICS, "Upscaler", &opts.dlss,', 'Takes effect after Apply.", hn_upscaler'),
|
|
('{TAB_GRAPHICS, "Render resolution", &opts.resolution,', 'Takes effect after Apply.", hn_resolution'),
|
|
('{TAB_GRAPHICS, "Upscale before bloom", &opts.upscale_pre,', 'Takes effect after Apply.", nullptr, false, true')):
|
|
entry = row(src, start)
|
|
check(help_end in entry and not re.search(r",\s*true$", entry.split("hn_")[0] if "hn_" in entry else ""),
|
|
start + " is not a row taken at Apply")
|
|
check(row(src, '{TAB_GRAPHICS, "Frame pacing", &merged.pacing,').rstrip().endswith("hn_pacing"), "Frame pacing still takes a restart")
|
|
value_of = function(src, "int restart_value_of(const Row& r) {")
|
|
check("merged.pacing" not in value_of and "ur::full_scale(opts.dlss)" not in value_of and
|
|
"if (r.value == &opts.resolution) return res_held.load(std::memory_order_relaxed) != 0;" in value_of,
|
|
"restart_value_of: the Render resolution takes a restart only while the host keeps a larger 3D back")
|
|
check("if (id == HOS_OPT_RES_HELD) {" in function(src, "void menu_option_set(int id, int value) {"), "the host's word is not kept")
|
|
# (the state)
|
|
check("apply_init();" in function(src, "void menu_init() {"), "menu_init does not take the file's choice as what runs")
|
|
check("apply_state.note(now);" in function(src, "void set_row("), "set_row does not tell the Apply state of a change")
|
|
ap = function(src, "void menu_apply(const char* why) {")
|
|
check("applied_take(was);" in ap and "save();" in ap and "apply_state.later = false;" in ap, "menu_apply does not take the choice")
|
|
take = function(src, "void applied_take(unsigned mask) {")
|
|
check("__atomic_store_n(to, *rows[i].value, __ATOMIC_RELAXED);" in take and "apply_state.start[slot] = *rows[i].value;" in take,
|
|
"applied_take does not store what runs")
|
|
check("applied_take_row(&opts.resolution);" in function(src, "void menu_first_start() {"), "a first start's Render resolution waits")
|
|
check("applied_take_row(&opts.dlss), applied_take_row(&opts.resolution);" in function(src, "void auto_start() {"),
|
|
"Auto (this PC)'s choice for new hardware waits for Apply at the start")
|
|
check("applied_take_row(&opts.resolution);" in function(src, "void auto_tick() {"), "Auto (this PC)'s tuning waits for a restart")
|
|
# (what runs for the host and the performance panel: the applied rows, the choice alone)
|
|
check("bool resolution_auto() { return applied_resolution() == 0; }" in src and
|
|
"bool resolution_full() { return ur::full_scale(upscaler_of(applied_dlss(), false)); }" in src, "resolution_*")
|
|
check("ur::snap(upscaler_of(applied_dlss(), false), applied_resolution())" in function(src, "int resolution_scale() {"),
|
|
"resolution_scale is not the Render resolution as applied")
|
|
perf = function(src, "const char* perf_upscaling_text(char* out, size_t n) {")
|
|
check("upscaler_of(applied_dlss(), true)" in perf and "resolution_name(up, applied_resolution())" in perf,
|
|
"the performance panel shows the rows as stepped")
|
|
check("int upscaler() { return upscaler_of(opts.dlss, true); }" in src, "the rows do not show the choice")
|
|
# (the guide)
|
|
opt = function(src, "void draw_options(ui::Ctx& c) {")
|
|
check("prompt_list[0] = {ui::kApply, \"Apply\"}, prompts_n++;" in opt and "const bool to_apply = apply_pending() != 0;" in opt and
|
|
"menu_hit::kButton, kApplyGuide" in opt and "row_pending(r)" in opt and "apply_line(c, kHintPt * s, cap_w - 20 * s)" in opt,
|
|
"the options' page has no Apply guide, its click or its rows' marks")
|
|
check("apply_changed(selr) ? kNoteApply" in opt, "the caption does not say a row waits for Apply")
|
|
bar = function(src, "void draw_tune_bar(ui::Ctx& c) {")
|
|
check("list[0] = {ui::kApply, \"Apply\"}, n++;" in bar and "kApplyGuide" in bar, "the tuning bar has no Apply")
|
|
tick = function(src, "void menu_tick() {")
|
|
check("menu_bound_key(HOS_SW_X, 0), menu_bound_key(HOS_SW_X, 1), (int)VK_SPACE, (int)'F'" in tick and
|
|
"host->binding(HOS_BIND_PAD, HOS_SW_X, 0)" in tick and
|
|
"pad(pad_apply)" in tick, "Apply's key and button are not the Switch's X as bound")
|
|
check("hit.part == menu_hit::kButton && hit.index == kApplyGuide" in tick and 'menu_apply("the guide");' in tick and
|
|
"apply_pending()" in tick, "page 0 does not apply on the guide")
|
|
check('if (!strcmp(key, "APPLY")) apply_press = true;' in tick, "RX_VK_MENU_SCRIPT has no APPLY")
|
|
# (the question)
|
|
first = tick[tick.index("auto ask_first = [&] {"):]
|
|
first = first[:first.index("};")]
|
|
check(first.index("apply_ask()") < first.index("restart_ask()") and "page = 5" in first, "Apply's question is not asked first")
|
|
later = tick[tick.index("auto later = [&] {"):]
|
|
later = later[:later.index("\n };")]
|
|
check("apply_state.choose_later(now);" in later and "ask_kind = kQuestionRestart, ask_sel = 0" in later,
|
|
"Apply's Later does not go on to the restart question")
|
|
check("press[5] && ask_first()" in tick and "open_now.load() && ask_first()" in tick, "closing does not ask first")
|
|
now = tick[tick.index("press[7] && ask_kind == kQuestionApply"):]
|
|
now = now[:now.index("} else if (press[7]) {")]
|
|
check('menu_apply("the question\'s Apply Now");' in now and "if (restart_ask()) ask_kind = kQuestionRestart" in now,
|
|
"Apply Now does not apply, then ask about the restart")
|
|
ask = function(src, "void draw_ask(ui::Ctx& c) {")
|
|
for need in ('"Apply Settings"', 'i18n::tr("Apply ")', '"Apply Now"', '"Later"', "apply_list_shown(i18n::tr(\" and \"))"):
|
|
check(need in ask, "the question has no " + need)
|
|
# (inside the game's own Options screen the game's list showed through under the question's text: darker there)
|
|
check("dim_page(c, ui::rgba(8, 5, 2, c.over_game ? 215 : 110));" in ask, "the question does not dim the game's own screen")
|
|
ui = (VK / "vk_ui.h").read_text(encoding="utf-8")
|
|
check("kClear, kApply };" in ui and "case kApply: return icon(x, c.apply_icon);" in ui and
|
|
"if (pr.g == kApply && !c.pad) return key(x, c.key_apply);" in ui, "vk_ui.h has no Apply guide")
|
|
|
|
|
|
def languages():
|
|
table = (VK / "menu_i18n.h").read_text(encoding="utf-8")
|
|
names = re.findall(r"inline constexpr Entry (k\w+)\[\] = \{\n(.*?)\n\};", table, re.S)
|
|
check(len(names) == 13, "the menu's 13 languages")
|
|
for name, body in names:
|
|
for text in ("Apply Settings", "Apply ", "Apply Now", "The game goes on where it is. The picture may pause for a moment.",
|
|
"Apply needed: ", "Takes effect after Apply",
|
|
"What draws the 3D up to the Output resolution. Takes effect after Apply."):
|
|
check(' {"%s", "' % text in body, "%s: %r is not translated" % (name, text))
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--cc", default="gcc")
|
|
args = parser.parse_args()
|
|
renderer()
|
|
host()
|
|
menu()
|
|
languages()
|
|
with tempfile.TemporaryDirectory(prefix="menu-apply-") as tmp:
|
|
src = Path(tmp) / "res_follow_test.c"
|
|
src.write_text(FOLLOW_TEST, encoding="utf-8")
|
|
exe = Path(tmp) / ("res-follow" + (".exe" if sys.platform == "win32" else ""))
|
|
subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT / "host"), str(src), "-o", str(exe)], check=True)
|
|
subprocess.run([str(exe)], check=True)
|
|
print("PASS: the options' Apply")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|