mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
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:
231
tests/test_title_tabs.py
Normal file
231
tests/test_title_tabs.py
Normal file
@@ -0,0 +1,231 @@
|
||||
"""The title's tabs, Mods and Save Select at the picture's top left with their buttons' prompts under them, and Quit Game under
|
||||
the title's list (gpu/vk/title_tabs.h, vk_menu.cpp draw_title_tabs, title_tab_go and menu_tick; host/oot_menu.c, nn_hid.c,
|
||||
display.c; no game).
|
||||
|
||||
(Triforce) The owner: "I want you to move the mod tab and the save select tab to the top left of the screen. I want there to be
|
||||
a button prompt below the tabs, such as, for example, an Xbox controller. The player should select Y to open the mod menu. And
|
||||
X to open the save select. Triangle for mods and Square for save select for PlayStation. PC should be able to select those tabs
|
||||
by mouse optimize those placements for every aspect ratio", and "Add a quit game option below the Options tab". They were
|
||||
entries under the title's list (Mods under Options, Save Select under Mods), reached with Down.
|
||||
|
||||
This compiles title_tabs.h alone (with game_grid.h) and checks where the tabs land in the window's pixels:
|
||||
|
||||
- in every shape (a 16:9, 21:9, 32:9, 16:10 and 4:3 picture filling its window; the owner's 3416 x 1440 picture in a
|
||||
3440 x 1440 window; a 21:9 picture between bars in a 16:9 window; a 16:9 picture between bars in a 21:9 window; no picture
|
||||
known yet) both tabs are inside the picture (never in a bar) and inside the window, a margin in from the picture's own top
|
||||
left corner, in its left third and top fifth (clear of the title's logo and list), side by side without overlap;
|
||||
- their size follows the picture's height (2160 units down it) as the title's own words do, and is squeezed across with the
|
||||
game's layouts on a picture narrower than 16:9;
|
||||
- with a controller the box a click counts in reaches under the icon; without one it ends under the label;
|
||||
- the point test: each label's and each icon's middle is its tab, the gap between them and the picture's middle none; with
|
||||
the save files off there is the one tab, Mods.
|
||||
|
||||
And the sources: the tabs are drawn with the game's own icons of what the Switch's X (Mods: the top face button, Y on an Xbox
|
||||
pad, Triangle on a PlayStation one) and Y (Save Select: the left one, X and Square) are bound to; the pad's own buttons, a
|
||||
click, or the host's words 6 and 7 (a test's scripted X and Y) choose them; the entry under the title's list is Quit Game.
|
||||
|
||||
python -I -B tests/test_title_tabs.py [--cxx clang++]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
|
||||
|
||||
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 <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include "title_tabs.h"
|
||||
using namespace mkwvk;
|
||||
static int fails;
|
||||
#define CHECK(x) do { if (!(x)) { std::printf("FAIL:%d %s (%s)\n", __LINE__, #x, name); fails++; } } while (0)
|
||||
|
||||
struct Case { const char* name; uint32_t pw, ph, ww, wh; double aspect; };
|
||||
|
||||
// the tabs of one case, in the window's pixels
|
||||
struct Win { float x0, y0, x1, y1, lx, ly, ix, iy; };
|
||||
static Win to_window(const title_tabs::Tab& t, const game_grid::Map& m) {
|
||||
return {m.x(t.x0), m.y(t.y0), m.x(t.x1), m.y(t.y1), m.x(t.label_x), m.y(t.label_y), m.x(t.icon_x), m.y(t.icon_y)};
|
||||
}
|
||||
|
||||
static void one(const Case& c) {
|
||||
const char* name = c.name;
|
||||
const game_grid::Place g = game_grid::of(c.pw, c.ph, c.ww, c.wh, c.aspect);
|
||||
const game_grid::Map m = game_grid::map_of(g);
|
||||
const float unit = g.h / 2160.0f;
|
||||
// (the labels at the title's size: "Mods" about 150 units wide, "Save Select" about 330; the icons 84)
|
||||
const float lw[2] = {150 * unit, 330 * unit}, iw[2] = {84 * unit, 84 * unit};
|
||||
const float left = title_tabs::picture_left(g, m), top = title_tabs::picture_top(g, m);
|
||||
// (the picture in the window: the grid itself while none is known)
|
||||
const float px0 = g.picture ? g.pic_x : g.x, py0 = g.picture ? g.pic_y : g.y;
|
||||
const float pw = g.picture ? g.pic_w : g.w, ph = g.picture ? g.pic_h : g.h;
|
||||
for (int icons = 0; icons < 2; icons++) {
|
||||
const title_tabs::Layout l = title_tabs::place(left, top, unit, lw, iw, 2, icons != 0);
|
||||
CHECK(l.n == 2);
|
||||
Win w[2] = {to_window(l.tab[0], m), to_window(l.tab[1], m)};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
CHECK(w[i].x0 >= px0 + 1 && w[i].y0 >= py0 + 1); // (a margin in from the picture's corner)
|
||||
CHECK(w[i].x1 <= px0 + pw / 3 && w[i].y1 <= py0 + ph / 5); // (its left third, its top fifth)
|
||||
CHECK(w[i].x0 >= 0 && w[i].y0 >= 0 && w[i].x1 <= (float)c.ww && w[i].y1 <= (float)c.wh);
|
||||
CHECK(w[i].x1 - w[i].x0 > 40 * unit * m.kx && w[i].y1 - w[i].y0 > 60 * unit); // (a box to click)
|
||||
CHECK(w[i].lx > w[i].x0 && w[i].lx < w[i].x1 && w[i].ly > w[i].y0 && w[i].ly < w[i].y1);
|
||||
CHECK(std::fabs((w[i].ly - py0) - title_tabs::kTop * unit) < 1.5f); // (the same place down every picture)
|
||||
// (the point test, in the column's pixels as menu_tick has the mouse)
|
||||
CHECK(title_tabs::at(l, l.tab[i].label_x, l.tab[i].label_y) == i);
|
||||
if (icons) {
|
||||
CHECK(title_tabs::at(l, l.tab[i].icon_x, l.tab[i].icon_y) == i);
|
||||
CHECK(std::fabs(w[i].ix - w[i].lx) < 0.01f && w[i].iy > w[i].ly + title_tabs::kText * 0.5f * unit);
|
||||
CHECK(w[i].y1 > w[i].iy + title_tabs::kIcon * 0.5f * unit - 0.5f); // (the box reaches under the icon)
|
||||
} else {
|
||||
CHECK(title_tabs::at(l, l.tab[i].icon_x, l.tab[i].icon_y + title_tabs::kIcon * 0.5f * unit) == -1);
|
||||
}
|
||||
}
|
||||
CHECK(w[0].x1 < w[1].x0); // (side by side, a gap between)
|
||||
CHECK(title_tabs::at(l, (l.tab[0].x1 + l.tab[1].x0) * 0.5f, l.tab[0].label_y) == -1);
|
||||
CHECK(title_tabs::at(l, m.back_x(px0 + pw * 0.5f), m.back_y(py0 + ph * 0.5f)) == -1);
|
||||
CHECK(std::fabs((w[0].x0 - px0) - (title_tabs::kLeft - title_tabs::kPadX) * unit * m.kx) < 1.5f);
|
||||
// (the clip they are drawn in is the whole picture, in the window too, and holds both tabs whole)
|
||||
float cx0, cy0, cx1, cy1;
|
||||
title_tabs::picture_clip(g, m, &cx0, &cy0, &cx1, &cy1);
|
||||
CHECK(std::fabs(m.x(cx0) - px0) < 0.5f && std::fabs(m.y(cy0) - py0) < 0.5f && std::fabs(m.x(cx1) - (px0 + pw)) < 0.5f && std::fabs(m.y(cy1) - (py0 + ph)) < 0.5f);
|
||||
for (int i = 0; i < 2; i++) CHECK(l.tab[i].x0 >= cx0 && l.tab[i].x1 <= cx1 && l.tab[i].y0 >= cy0 && l.tab[i].y1 <= cy1);
|
||||
// (the save files off: Mods alone, where it was)
|
||||
const title_tabs::Layout one_tab = title_tabs::place(left, top, unit, lw, iw, 1, icons != 0);
|
||||
CHECK(one_tab.n == 1 && one_tab.tab[0].x0 == l.tab[0].x0 && one_tab.tab[0].x1 == l.tab[0].x1);
|
||||
CHECK(title_tabs::at(one_tab, l.tab[1].label_x, l.tab[1].label_y) == -1);
|
||||
}
|
||||
const title_tabs::Layout l = title_tabs::place(left, top, unit, lw, iw, 2, true);
|
||||
std::printf("%-34s unit %.3f kx %.3f: Mods %4.0f..%4.0f, Save Select %4.0f..%4.0f, down to %3.0f (picture from %4.0f, %3.0f)\n", c.name,
|
||||
unit, m.kx, m.x(l.tab[0].x0), m.x(l.tab[0].x1), m.x(l.tab[1].x0), m.x(l.tab[1].x1), m.y(l.tab[1].y1), px0, py0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
static const Case cases[] = {
|
||||
{"16:9 1920x1080", 1920, 1080, 1920, 1080, 0},
|
||||
{"16:9 1280x720", 1280, 720, 1280, 720, 0},
|
||||
{"21:9 3440x1440", 3440, 1440, 3440, 1440, 0},
|
||||
{"the owner's 3416x1440 in 3440x1440", 3416, 1440, 3440, 1440, 0},
|
||||
{"32:9 5120x1440", 5120, 1440, 5120, 1440, 0},
|
||||
{"16:10 1920x1200", 1920, 1200, 1920, 1200, 0},
|
||||
{"4:3 1440x1080", 1440, 1080, 1440, 1080, 0},
|
||||
{"21:9 picture in 1600x900", 3440, 1440, 1600, 900, 0},
|
||||
{"16:9 picture in 3440x1440", 2560, 1440, 3440, 1440, 0},
|
||||
{"no picture yet, 1600x900", 0, 0, 1600, 900, 0},
|
||||
{"no picture yet, 3440x1440", 0, 0, 3440, 1440, 0},
|
||||
};
|
||||
for (const Case& c : cases) one(c);
|
||||
{ // (the size against the picture: twice the height, twice the tabs; a 16:10 picture's are squeezed across)
|
||||
const char* name = "sizes";
|
||||
const game_grid::Place a = game_grid::of(1280, 720, 1280, 720, 0), b = game_grid::of(2560, 1440, 2560, 1440, 0);
|
||||
CHECK(std::fabs(b.h / 2160.0f - 2 * (a.h / 2160.0f)) < 1e-4f);
|
||||
const game_grid::Place n = game_grid::of(1920, 1200, 1920, 1200, 0);
|
||||
CHECK(game_grid::map_of(n).kx < 0.95f && game_grid::map_of(b).kx == 1.0f);
|
||||
}
|
||||
std::printf(fails ? "FAILED\n" : "ok\n");
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", default="clang++")
|
||||
args = parser.parse_args()
|
||||
|
||||
header = (VK / "title_tabs.h").read_text(encoding="utf-8")
|
||||
check("#include <imgui" not in header and "vulkan" not in header.split("#pragma once")[1], "title_tabs.h is not free of ImGui and Vulkan")
|
||||
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
||||
host = (ROOT / "host" / "oot_menu.c").read_text(encoding="utf-8")
|
||||
hid = (ROOT / "host" / "nn_hid.c").read_text(encoding="utf-8")
|
||||
window = (ROOT / "host" / "display.c").read_text(encoding="utf-8")
|
||||
|
||||
# the drawing: from the picture's own corner, on the grid the title's entry is drawn on; the icons the game's own of the
|
||||
# bindings (X the top face button: Mods; Y the left one: Save Select); the tabs' place kept for the mouse
|
||||
tabs = block(menu, "void draw_title_tabs(ui::Ctx& c, bool decide) {")
|
||||
check("title_tabs::place(title_tabs::picture_left(title_grid, m), title_tabs::picture_top(title_grid, m), unit, lw, iw, n, pad);" in tabs
|
||||
and "const game_grid::Map m = game_grid::map_of(title_grid);" in tabs,
|
||||
"the tabs are not placed from the picture's top left corner on the game's grid")
|
||||
check('static const char* const labels[title_tabs::kTabs] = {"Mods", "Save Select"};' in tabs
|
||||
and "static const char* const icons[title_tabs::kTabs] = {ui::kIconX, ui::kIconY};" in tabs,
|
||||
"Mods is not the Switch's X (the top face button) and Save Select its Y (the left one)")
|
||||
check("const bool pad = game_prompts_pad();" in tabs and "if (!pad || show <= 0) continue;" in tabs
|
||||
and "c.d->AddText(c.f.glyph, ipx, at, ui::alpha(ui::kInk, show), icons[i]);" in tabs,
|
||||
"the prompts under the tabs are not the game's icons, shown with a controller and fading with the list")
|
||||
check("title_tab_layout = l, title_tab_map = m, title_tab_ns = prof_now();" in tabs, "where the tabs were drawn is not kept for the mouse")
|
||||
# ((Triforce) the lab's first run: on the owner's 21:9 picture the corner is left of the column, and nothing was drawn)
|
||||
check(tabs.index("title_tabs::picture_clip(title_grid, m,") < tabs.index("c.d->PushClipRect(ImVec2(clip[0], clip[1]), ImVec2(clip[2], clip[3]), false);")
|
||||
< tabs.index("const title_tabs::Tab& t = l.tab[i];") < tabs.index("c.d->PopClipRect();")
|
||||
and tabs.count("PushClipRect") == tabs.count("PopClipRect") == 1,
|
||||
"the tabs are drawn in the window's clip rectangle in the column's pixels: left of the column on a wide picture, not at all")
|
||||
check("const float px = ui::lu(c, kTitleText * ui::kType)" in tabs.replace("unit = ui::lu(c, 1), ", "")
|
||||
and "constexpr float kText = 52;" in header and "kTitleText = 65 * 0.8f" in menu,
|
||||
"the tabs' words are not the size of the title's own entries")
|
||||
for caller, line in (("void draw_mods_row_shut(ui::Ctx& c) {", "title_grid = g;"), ("void draw_menu(ui::Ctx& c, bool perf_under) {", "title_grid = g;")):
|
||||
check(line in block(menu, caller), "the tabs' grid is not told by " + caller)
|
||||
|
||||
# the input: the pad's own buttons bound to X and Y, the mouse over them and its click, the first read's click left out
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
live = tick[tick.index("if (title_tabs_live()) {"):tick.index("auto later = [&] {")]
|
||||
check("host->binding(HOS_BIND_PAD, i ? HOS_SW_Y : HOS_SW_X, 0)" in live and "if (hos_pad_bindable(p) && (pad_press >> p & 1)) go = i, pad_last = true;" in live,
|
||||
"the tabs are not opened by the pad's own buttons the Switch's X and Y are bound to")
|
||||
check("HOS_BIND_KEY" not in live, "a key or a mouse button bound to X or Y opens a tab (the left mouse button is Y by default)")
|
||||
check("if (pad_press || under < 0) hover = -1;" in live and "else if (tab_moved || (tp.pressed & HOS_MOUSE_LEFT)) hover = under;" in live
|
||||
and "if (go < 0 && on && (tp.pressed & HOS_MOUSE_LEFT) && under >= 0) go = under, pad_last = false;" in live,
|
||||
"the mouse over a tab does not light it, or a click on one does not choose it")
|
||||
check("if (!title_tab_read) tp.pressed = 0;" in live and "title_tab_read = false;" in tick[tick.index("auto later = [&] {") - 400:tick.index("auto later = [&] {")],
|
||||
"a click from before the title's list came is taken as a tab's")
|
||||
check("for (int i = 0; i < K_N; i++) press[i] = false;" in live, "the press that chose a tab is also the page's it opens")
|
||||
check("} else if (!tick_sound_done && (sound_before.open || !after.open || after.page != kModsRowPage)) {" in tick
|
||||
and "tick_sound_done = false;" in tick, "a tab chosen sounds a second time, by what the tick changed")
|
||||
|
||||
# the host: Quit Game alone under the title's list; the tabs told to the window (clicks) and the scripted presses
|
||||
list_tick = block(host, "static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {")
|
||||
check("mods_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2};" in list_tick
|
||||
and "quit_entry = title ? (Rect){0, 0, 0, 0} :" in list_tick and "hos_save_files_on()" not in list_tick,
|
||||
"the title's list has not the one entry under its last button")
|
||||
there = block(host, "int hos_oot_title_tabs(void) {")
|
||||
check("InterlockedCompareExchange(&mods_entry_title, 0, 0)" in there and "return 1 | (hos_save_files_on() ? 2 : 0);" in there
|
||||
and "int hos_oot_title_tabs(void) { return 0; }" in host, "the host does not say the title's tabs are there, or its other half has no word")
|
||||
check("else if (bit == HOS_MOUSE_LEFT && hos_oot_title_tabs()) InterlockedOr(&ptr_pressed, bit);" in block(window, "static void game_menu_press(LPARAM lp, LONG bit) {"),
|
||||
"the window does not keep the title's clicks for its tabs")
|
||||
mods_input = block(hid, "static void mods_input(uint64_t *buttons_io, int32_t stick[4]) {")
|
||||
check("const uint64_t taps = script_now, fresh = taps & ~taps_was;" in mods_input
|
||||
and "script_now = *buttons;" in block(hid, "static void read_input(uint64_t *buttons, int32_t stick[4]) {")
|
||||
and "if ((fresh >> B_X & 1) && (tabs & 1)) rx_option_set(HOS_OPT_MODS_ENTER, 6), buttons &= ~(1ULL << B_X);" in mods_input
|
||||
and "else if ((fresh >> B_Y & 1) && (tabs & 2)) rx_option_set(HOS_OPT_MODS_ENTER, 7), buttons &= ~(1ULL << B_Y);" in mods_input,
|
||||
"a test's scripted X or Y on the title is not its tab's word")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="title-tabs-") as tmp:
|
||||
src, exe = Path(tmp) / "tabs.cpp", Path(tmp) / "tabs.exe"
|
||||
src.write_text(PROGRAM, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-I" + str(VK), str(src), "-o", str(exe)], check=True)
|
||||
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
||||
check(r.returncode == 0, "the tabs' places:\n" + r.stdout)
|
||||
print(r.stdout.strip())
|
||||
print("PASS: the title's tabs at the picture's top left in every shape; Quit Game under the title's list")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user