Make a moving floor carry Link above 100 fps as it does at 60 (set ofollow, floor_carry = 1).

The character controller's three follow-surface modules kept only a tenth of the floor's velocity whenever the physics' inverse step passed 100, which every update above 100 fps did. The gate now compares with 100 over frames per update from the patch page above 60 fps, and with the game's 100 at 60 and 30 fps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 07:07:34 -05:00
parent d9429b0c00
commit c84724da2c
7 changed files with 149 additions and 8 deletions

View File

@@ -21,8 +21,8 @@ const char *cfg_get(const char *key) {
return NULL;
}
unsigned cfg_version(void) { return version; }
int rt_patch_set(const char *name) { return !strcmp(name, "ostep") ? 0 : -1; }
int rt_patch_enabled(int set) { return set == 0; }
int rt_patch_set(const char *name) { return !strcmp(name, "ostep") ? 0 : !strcmp(name, "ofollow") ? 1 : -1; }
int rt_patch_enabled(int set) { return set == 0 || set == 1; }
void rt_patch_disable(int set) { (void)set; }
void rt_patch_switch(int set, int on) { (void)set, (void)on; }
void *rt_patch_page(void) { return page; }
@@ -148,13 +148,29 @@ static uint32_t solver_steps(void (*fn)(Cpu *), float frames) {
return (uint32_t)c.x[1];
}
// The floor-carry gate (set ofollow): 1 when its b.gt is taken, which keeps a tenth of the floor's velocity. s0 is the
// physics' inverse step; the set's load reads the page through x8.
void follow_game(Cpu *c);
void follow_ofollow(Cpu *c);
static int follow_cut(void (*fn)(Cpu *), float inverse) {
Cpu c;
memset(&c, 0, sizeof c);
uint32_t bits;
memcpy(&bits, &inverse, 4);
c.v[0] = bits, c.x[8] = (uint64_t)(uintptr_t)page;
fn(&c);
return !FLAG_Z(&c) && FLAG_N(&c) == FLAG_V(&c); // gt
}
int main(int argc, char **argv) {
int mean = argc > 1 && !strcmp(argv[1], "mean");
if (mean) steady = "0";
frame_step_init();
float one;
float one, cut0;
memcpy(&one, page + 256, 4);
memcpy(&cut0, page + 260, 4);
CHECK(one == 1.0f, "the page holds one frame before the first present, not %g", one);
CHECK(cut0 == 100.0f, "the floor carry's cut is the game's 100 before the first present, not %g", cut0);
const double p60 = 16666667e-9, p240 = 4166667e-9;
if (mean) { // the comparison setting: 5 and 30 ms in turn give 15 and 20 ms in turn
@@ -379,6 +395,32 @@ int main(int argc, char **argv) {
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));
}
// The floor carry (set ofollow). The physics' inverse step is 60 / (frames per update * time scale); the game cuts
// a floor's velocity to a tenth above 100, which at 60 fps is a time scale under 0.6 and above 100 fps every
// update. With the page's 100 / frames per update the set cuts exactly where the game cuts at 60 fps at any rate
// above 60; at 60 and 30 fps the page holds 100 and the set cuts where the game's own words do.
{
const char *limits[] = {"60", "30", "90", "120", "144", "240"};
const int hz[] = {60, 30, 90, 120, 144, 240};
const float scales[] = {1.0f, 0.8f, 0.62f, 0.58f, 0.5f, 0.25f};
for (int r = 0; r < 6; r++) {
set_limit(limits[r]);
float frames = 0, cut;
for (int i = 0; i < 60; i++) frames = present(1.0 / hz[r]);
memcpy(&cut, page + 260, 4);
CHECK(cut == (frames < 1 ? 100.0f / frames : 100.0f), "%d fps (%g frames): the floor carry's cut is %g",
hz[r], frames, cut);
for (int s = 0; s < 6; s++) {
float inverse = 60.0f / (frames * scales[s]);
int set = follow_cut(follow_ofollow, inverse),
want = follow_cut(follow_game, hz[r] > 60 ? 60.0f / scales[s] : inverse);
CHECK(set == want, "%d fps, time scale %.2f: the set %s, the game %s %s", hz[r], scales[s],
set ? "cuts" : "carries", hz[r] > 60 ? "at 60 fps" : "here", want ? "cuts" : "carries");
}
CHECK(follow_cut(follow_game, 60.0f / frames) == (hz[r] > 100), "%d fps: the game's own words %s", hz[r],
hz[r] > 100 ? "do not cut" : "cut");
}
}
printf("frame_step_check: %s\n", fails ? "FAILED" : "ok");
return fails != 0;
}

View File

@@ -92,13 +92,50 @@ def solver_functions():
return '\n'.join(out)
# The floor-carry gate of the three follow-surface modules (set ofollow): mov w8, #100.0 and fmov s1, w8 before the
# game's fcmp s0, s1 (s0 the physics' inverse step) and the b.gt to the tenth of the floor's velocity. The set makes the
# two words adrp x8, page and ldr s1, [x8, #260]; the test lifts the load and the fcmp with x8 set to its page.
FOLLOW_SITES = (0x13d704, 0x13a064, 0x389ac20)
FOLLOW_GAME = (0x52a85908, 0x1e270101) # mov w8, #0x42c80000; fmov s1, w8
FOLLOW_LOAD = 0xbd410501 # ldr s1, [x8, #260]
FCMP = 0x1e212000 # fcmp s0, s1
def check_follow():
"""Each gate's two words are the set ofollow's adrp to the page in x8 and its load of +260, over the game's."""
table = load(ROOT / 'recomp/patches-v111.txt', [('main', 0x7000000000, PAGE)])
names = {i: t[0] for i, t in enumerate(table.sets)}
bad = 0
for site in FOLLOW_SITES:
first = {names[k]: (words, have) for k, words, have in table.sites['main'].get(site, [])}
second = {names[k]: (words, have) for k, words, have in table.sites['main'].get(site + 4, [])}
if (first != {'ofollow': ([('page', 8)], FOLLOW_GAME[0])} or
second != {'ofollow': ([FOLLOW_LOAD], FOLLOW_GAME[1])}):
print(f'FAIL: the floor-carry gate at main+{site:#x} is {first} / {second}')
bad += 1
return bad
def follow_functions():
lift = Lifter(0, simd='c')
out = []
for name, words in (('game', FOLLOW_GAME + (FCMP,)), ('ofollow', (FOLLOW_LOAD, FCMP))):
body = []
for k, w in enumerate(words):
insn = lift.lift(w, 0x7000000000 + FOLLOW_SITES[0] + 4 * k + (4 if name == 'ofollow' else 0))
assert insn.kind == 'op', (name, hex(w), insn.kind)
body.append(' ' + insn.code)
out.append(f'void follow_{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())
solver.write_text(solver_functions() + '\n' + follow_functions())
env = dict(os.environ)
if os.name == 'nt' and MSYS_BIN.exists():
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
@@ -106,7 +143,7 @@ def main():
'-I', str(ROOT / 'runtime'), '-I', str(work),
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()
return subprocess.run([str(exe), 'mean'], env=env).returncode or rc or check_sites() + check_follow()
if __name__ == '__main__':