mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 08:19:56 -04:00
Add physics_steps = 2: at least a 60 fps frame's solver steps in every update on 1.1.1.
Link is carried by the Deku Tree's floating platform fully at 60 fps, about a tenth at 160 and not at all at 240, which follows the solver steps an update (4, 2, 1 with physics_steps = 1) rather than those a second. The new set osolverfull raises the rounded-up count to the 60 Hz frame's 4 in every update; physics_steps = 2 switches it on and osolver off at start, and the mode is logged. 60 and 30 fps keep the game's 4 and 8. It costs more physics time above 60 fps: 576 solver steps a second at 144 fps and 960 at 240, against 288 and 240 with 1, the default, which stays until a run confirms the carry. frame_step_check runs the lifted words of all three counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,6 +129,25 @@ static uint32_t sim(uint64_t object, float seconds) {
|
||||
memcpy("ient, &c.v[0], 4);
|
||||
return cut_fcvtzs(quotient); // the game's fcvtzs after the site
|
||||
}
|
||||
// The physics solver step count (patches-v111.txt osolver and osolverfull, lifted by frame_step_check.py): the step
|
||||
// setup's words from the literal load to the cut, run on the frames per update in s0 and the count (4) in s1 as the
|
||||
// game loads them, x8 pointing at the literal 0.001 the original loads. Returns w1, the steps.
|
||||
void solver_game(Cpu *c);
|
||||
void solver_osolver(Cpu *c);
|
||||
void solver_osolverfull(Cpu *c);
|
||||
static uint32_t solver_steps(void (*fn)(Cpu *), float frames) {
|
||||
static float literal[0x410 / 4];
|
||||
literal[0x40c / 4] = 0.001f;
|
||||
Cpu c;
|
||||
memset(&c, 0, sizeof c);
|
||||
uint32_t bits;
|
||||
memcpy(&bits, &frames, 4);
|
||||
c.v[0] = bits, c.v[1] = 4, c.x[8] = (uint64_t)(uintptr_t)literal, c.x[1] = ~0ull;
|
||||
fn(&c);
|
||||
CHECK(c.x[1] >> 32 == 0, "the solver count leaves x1's upper half %#llx", (unsigned long long)c.x[1]);
|
||||
return (uint32_t)c.x[1];
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int mean = argc > 1 && !strcmp(argv[1], "mean");
|
||||
if (mean) steady = "0";
|
||||
@@ -341,6 +360,25 @@ int main(int argc, char **argv) {
|
||||
sound_gate_take(&g, 0, 0.0f), "NaN and 0 run as the game has them and clear what is owed");
|
||||
fake_manager = 0;
|
||||
}
|
||||
// The solver step count: at 60 and 30 fps all three give the game's 4 and 8 (also with the steady step a little
|
||||
// off them); above 60 fps the game's count falls to 1 and to 0, osolver's rounds up (2 at 144 fps, 1 at 240), and
|
||||
// osolverfull's keeps every update at the 60 Hz frame's 4.
|
||||
{
|
||||
const struct { float frames; uint32_t game, up, full; } want[] = {
|
||||
{1.0f, 4, 4, 4}, {2.0f, 8, 8, 8}, {0.98f, 3, 4, 4}, {1.02f, 4, 4, 4}, {60.0f / 144.0f, 1, 2, 4},
|
||||
{60.0f / 160.0f, 1, 2, 4}, {0.25f, 1, 1, 4}, {60.0f / 300.0f, 0, 1, 4}, {1.5f, 6, 6, 6}};
|
||||
for (size_t i = 0; i < sizeof want / sizeof want[0]; i++) {
|
||||
uint32_t g = solver_steps(solver_game, want[i].frames), u = solver_steps(solver_osolver, want[i].frames),
|
||||
f = solver_steps(solver_osolverfull, want[i].frames);
|
||||
CHECK(g == want[i].game && u == want[i].up && f == want[i].full,
|
||||
"%.4f frames an update: solver steps %u / %u / %u, not %u / %u / %u", want[i].frames, g, u, f,
|
||||
want[i].game, want[i].up, want[i].full);
|
||||
}
|
||||
// steps a second at 144 and 240 fps: osolver 288 and 240, osolverfull 576 and 960
|
||||
printf("frame_step_check: solver steps a second at 144 / 240 fps: physics_steps 1 %u / %u, 2 %u / %u\n",
|
||||
144 * solver_steps(solver_osolver, 60.0f / 144.0f), 240 * solver_steps(solver_osolver, 0.25f),
|
||||
144 * solver_steps(solver_osolverfull, 60.0f / 144.0f), 240 * solver_steps(solver_osolverfull, 0.25f));
|
||||
}
|
||||
printf("frame_step_check: %s\n", fails ? "FAILED" : "ok");
|
||||
return fails != 0;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MSYS_BIN = Path(r'C:\msys64\ucrt64\bin')
|
||||
sys.path[:0] = [str(ROOT / 'recomp')]
|
||||
sys.path[:0] = [str(ROOT), str(ROOT / 'recomp')]
|
||||
from lifter import Lifter # noqa: E402
|
||||
from patches import load # noqa: E402
|
||||
from tools.check_content import GENERATED_MARKER # noqa: E402
|
||||
|
||||
PAGE = 0x4ea0000 # the patch page of 1.1.1, main+0x4ea0000
|
||||
# The sites that call frame_rate.c's hosts, as recomp/patches-v111.txt has them: set, module offset, the original word,
|
||||
@@ -54,17 +56,55 @@ def check_sites():
|
||||
return bad
|
||||
|
||||
|
||||
# The solver step count's words at the step setup's first copy (main+0x38aebe4..0x38aebf4; the second copy at
|
||||
# main+0x38afd10 has the same words): the original's, the set osolver's and the set osolverfull's, lifted as the
|
||||
# generator lifts them into one C function each, with the scvtf between them (main+0x38aebec) that every variant keeps.
|
||||
SOLVER_SITES = (0x38aebe4, 0x38aebf0, 0x38aebf4)
|
||||
SOLVER_COPY = (0x38afd10, 0x38afd1c, 0x38afd20)
|
||||
SCVTF = 0x5e21d821 # scvtf s1, s1
|
||||
|
||||
|
||||
def solver_functions():
|
||||
table = load(ROOT / 'recomp/patches-v111.txt', [('main', 0x7000000000, PAGE)])
|
||||
names = {i: t[0] for i, t in enumerate(table.sets)}
|
||||
variants = {'game': [], 'osolver': [], 'osolverfull': []}
|
||||
for site, copy in zip(SOLVER_SITES, SOLVER_COPY):
|
||||
alts = {names[key]: (words, have) for key, words, have in table.sites['main'][site]}
|
||||
copies = {names[key]: (words, have) for key, words, have in table.sites['main'][copy]}
|
||||
assert set(alts) == {'osolver', 'osolverfull'} and alts == copies, (hex(site), alts, copies)
|
||||
original = alts['osolver'][1]
|
||||
variants['game'].append([original])
|
||||
for name in ('osolver', 'osolverfull'):
|
||||
variants[name].append(alts[name][0])
|
||||
lift = Lifter(0, simd='c')
|
||||
out = [f'// {GENERATED_MARKER}: the solver step count words lifted by tests/frame_step_check.py.',
|
||||
'#include "cpu.h"', '#include "simd.h"', '']
|
||||
for name, sites in variants.items():
|
||||
body = []
|
||||
for k, words in enumerate(sites):
|
||||
for w in words:
|
||||
insn = lift.lift(w, 0x7000000000 + SOLVER_SITES[k])
|
||||
assert insn.kind == 'op', (name, hex(w), insn.kind)
|
||||
body.append(' ' + insn.code)
|
||||
if k == 0:
|
||||
body.append(' ' + lift.lift(SCVTF, 0x70038aebec).code)
|
||||
out.append(f'void solver_{name}(Cpu *c) {{\n' + '\n'.join(body) + '\n}\n')
|
||||
return '\n'.join(out)
|
||||
|
||||
|
||||
def main():
|
||||
work = ROOT / 'build' / 'test' / 'frame_step'
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
(work / 'layout.h').write_text(LAYOUT)
|
||||
exe = work / ('frame_step_check.exe' if os.name == 'nt' else 'frame_step_check')
|
||||
solver = work / 'solver_sites.c'
|
||||
solver.write_text(solver_functions())
|
||||
env = dict(os.environ)
|
||||
if os.name == 'nt' and MSYS_BIN.exists():
|
||||
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
|
||||
subprocess.check_call([compiler(), '-O1', '-Wall', '-Wno-unused-function', '-fno-strict-aliasing',
|
||||
'-I', str(ROOT / 'runtime'), '-I', str(work),
|
||||
str(ROOT / 'tests' / 'frame_step_check.c'), '-o', str(exe), '-lm'], env=env)
|
||||
str(ROOT / 'tests' / 'frame_step_check.c'), str(solver), '-o', str(exe), '-lm'], env=env)
|
||||
rc = subprocess.run([str(exe)], env=env).returncode
|
||||
return subprocess.run([str(exe), 'mean'], env=env).returncode or rc or check_sites()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user