"""The HUD on a picture wider than 16:9 (host/oot_wide_hud.h, host/oot_wide_hud.c, nx2/prompt_assets.py HUD_SIDE_PANES). With the Insert menu's Ultrawide HUD row on Screen edges the hearts and the item slot sit in the picture's top corners and the small map at its right edge; on Middle everything keeps the middle 16:9, as before. The rules checked here, without the game: - A layout in the middle: its projection times the squeeze, nothing moved. A kept one (a fade, a menu's background): untouched. A 16:9 picture (squeeze 1) or no squeeze: untouched. - A layout at an edge (the lab's switch): a point at the 16:9 grid's right edge lands on the picture's right edge, one at its left edge on the picture's left edge, and the layout keeps its shape. - A pane moved in a layout (the hearts', the item slot's, the small map's) goes as far as a whole layout moved by its projection: a corner pane lands on the picture's corner through the middle projection. - prompts/wide.bin: one entry per pane and copy of each layout, and one per animation key that puts a pane at the small map's place (the keys at 0 and other curves are left); a layout that is not the one known gives none. python -I -B tests/test_wide_hud.py """ import shutil import struct import subprocess import sys import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "nx2")) import prompt_assets # noqa: E402 FIXTURE = r''' #include #include #include "oot_wide_hud.h" static int fails; #define CHECK(cond, what) do { if (!(cond)) { fails++; printf("FAIL line %d: %s\n", __LINE__, what); } } while (0) static int near(float a, float b) { return fabsf(a - b) < 1e-4f; } /* clip x of the layout's point x through the projection (first column's m00, the move m03) */ static float clip(const float first[4], float move, float x) { return first[0] * x + move; } int main(void) { const float m00 = 2.0f / 3840.0f; const float q = (16.0f / 9.0f) / (21.0f / 9.0f); /* a 21:9 picture */ float first[4], move; /* the middle */ first[0] = m00, first[1] = first[2] = first[3] = 0, move = 0; oot_hud_row(first, &move, q, 0, OOT_HUD_MIDDLE); CHECK(near(clip(first, move, 1920.0f), q) && near(clip(first, move, -1920.0f), -q) && move == 0.0f, "the middle 16:9"); /* kept, and a 16:9 picture */ first[0] = m00, move = 0; oot_hud_row(first, &move, q, 1, OOT_HUD_RIGHT); CHECK(first[0] == m00 && move == 0.0f, "a kept layout is untouched"); oot_hud_row(first, &move, 1.0f, 0, OOT_HUD_RIGHT); CHECK(first[0] == m00 && move == 0.0f, "a 16:9 picture is untouched"); oot_hud_row(first, &move, 0.0f, 0, OOT_HUD_LEFT); CHECK(first[0] == m00 && move == 0.0f, "no squeeze: untouched"); /* the edges */ first[0] = m00, move = 0; oot_hud_row(first, &move, q, 0, OOT_HUD_RIGHT); CHECK(near(clip(first, move, 1920.0f), 1.0f), "the grid's right edge on the picture's right edge"); CHECK(near(clip(first, move, 1920.0f) - clip(first, move, -1920.0f), 2.0f * q), "its shape kept"); first[0] = m00, move = 0; oot_hud_row(first, &move, q, 0, OOT_HUD_LEFT); CHECK(near(clip(first, move, -1920.0f), -1.0f), "the grid's left edge on the picture's left edge"); /* a pane moved in the layout: as far as the projection would move it */ const float out = oot_hud_out(q); first[0] = m00, move = 0; oot_hud_row(first, &move, q, 0, OOT_HUD_MIDDLE); CHECK(near(clip(first, move, 1920.0f + out), 1.0f), "the right corner pane on the picture's corner"); CHECK(near(clip(first, move, -1920.0f - out), -1.0f), "the left corner pane on the picture's corner"); CHECK(near(clip(first, move, 1626.0f + out) - 1.0f, clip(first, move, 1626.0f) - q), "a pane beside it keeps its distance to the edge"); CHECK(oot_hud_out(1.0f) == 0.0f && oot_hud_out(0.0f) == 0.0f && oot_hud_out(1.5f) == 0.0f, "nothing on a 16:9 or narrower picture"); CHECK(near(oot_hud_out((16.0f / 9.0f) / (32.0f / 9.0f)), 1920.0f), "32:9: a whole half grid further out"); /* the classes */ CHECK(oot_hud_keep_bit(0x84c04fb0ULL) == 2u && oot_hud_keep_bit(0x84c08300ULL) == 0u, "the menus' background is kept, the map's screen is not"); printf(fails ? "wide hud: FAILED\n" : "wide hud: all checks passed\n"); return fails != 0; } ''' def layout(name, panes, curves=()): """a made-up layout as nx2/prompt_assets.py reads one: "BFFH", the names' and the records' tables' offsets at +0x118 and +0x120, the count at +0x130, the name before "RootPane" among the texts; panes: [(name, x)]; curves: [(value past the last key, [(value, slope)])], each an array as layout_keys reads one, 8-aligned, the first value 8 bytes before it""" names = ["RootPane"] + [n for n, _ in panes] xs = [0.0] + [x for _, x in panes] n = len(names) head = 0x140 names_at, recs_at = head, head + 8 * n rec0 = recs_at + 8 * n texts_at = rec0 + 0x44 * n texts = b"\0" + name.encode() + b"\0" offs = [] for t in names: offs.append(texts_at + len(texts)) texts += t.encode() + b"\0" b = bytearray(texts_at) + texts b[0:4] = b"BFFH" struct.pack_into(" 0}, {1920.0, 1626.0, 1270.0, 1536.0, 1470.0, 1490.0, 1706.0}) first = blarc.index(layout("PlayerStatus_00", GOOD)) self.assertTrue(all(off >= first for off, _, _ in got)) # (the other layout's pane of the same name: left) self.assertNotIn(1666.0, {x for _, _, x in got}) # (the whole-screen map's own pane: left) self.assertEqual(len({off for off, _, _ in got}), len(got)) with tempfile.TemporaryDirectory(prefix="widehud-") as d: path = Path(d) / "wide.bin" prompt_assets.write_wide(path, got) raw = path.read_bytes() self.assertEqual(raw[:4], b"HPWD") self.assertEqual(struct.unpack_from("x[0] - 0x1b8, _row, &_tx);", wide) menu = (ROOT / "gpu/vk/vk_menu.cpp").read_text(encoding="utf-8") self.assertIn('"Ultrawide HUD", &opts.wide_hud, 0, 1, 1, tx_wide_hud,', menu) if __name__ == "__main__": unittest.main()