Files
Triforce-Source/host/loop_step.h
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

54 lines
3.1 KiB
C

/* (Triforce) The clock of an animation that loops over one frame or less. Such a loop is one pose: the frozen Zoras under the ice in
adult Zora's Domain (start 0, end 1) are drawn from it and stand still. At the console's 60 fps the step is 1, every update of
the clock lands on the same phase and the pose never changes. Under a Frame rate cap above 60 the step is the frame's own time
(host/nn_vi.c, hos_frame_seconds_bits: 0.36 at 165 fps), the phase moves by it each frame and wraps, so each frame draws a
different phase of the loop: the Zoras twitched.
Two places make the time a skeleton is drawn at (nx2/oot_patches.py, patch_loop_steps and patch_loop_pose):
- loop_step: the clock's step. The loop of one frame or less takes whole frames of it, the fractions carried per animation
entry, so it moves as often as at 60 fps and by the same whole steps;
- loop_pose: the time written for the skeleton to be drawn at. The loop's start: the phase a clock moving in whole frames
stays on.
Longer loops, and every loop at a cap of 60 (timed 0), keep the step and the time the game has. Not thread-safe by itself:
the caller holds a lock around loop_step. 4096 entries, found by their address with a short probe: a scene has some hundreds
at most, and an entry that finds no place starts again from 0 (a pose that stands still, as it did). */
#pragma once
#include <stdint.h>
#include <string.h>
#define LOOP_STEP_SLOTS 4096
#define LOOP_STEP_PROBE 32
typedef struct {
uint64_t at[LOOP_STEP_SLOTS];
float rem[LOOP_STEP_SLOTS];
} LoopStep;
/* (a loop of one frame or less: start < end and end - start <= 1; NaN is not) */
static inline int loop_is_pose(uint32_t start_bits, uint32_t end_bits) {
float start, end;
memcpy(&start, &start_bits, 4);
memcpy(&end, &end_bits, 4);
return end > start && end - start <= 1.0f;
}
/* The step (a float's bits) an entry at `at` takes. `timed`: the frames' own time is the step (a Frame rate cap above 60). */
static inline uint32_t loop_step(LoopStep *s, uint64_t at, uint32_t step_bits, uint32_t start_bits, uint32_t end_bits, int timed) {
float step;
memcpy(&step, &step_bits, 4);
if (!timed || !(step > 0.0f) || !loop_is_pose(start_bits, end_bits)) return step_bits;
uint32_t h = (uint32_t)((at * 0x9E3779B97F4A7C15ull) >> 40) % LOOP_STEP_SLOTS, k = 0;
while (k < LOOP_STEP_PROBE && s->at[(h + k) % LOOP_STEP_SLOTS] && s->at[(h + k) % LOOP_STEP_SLOTS] != at) k++;
const uint32_t i = (h + (k < LOOP_STEP_PROBE ? k : 0)) % LOOP_STEP_SLOTS;
if (s->at[i] != at) s->at[i] = at, s->rem[i] = 0.0f;
const float sum = s->rem[i] + step;
const float whole = sum >= 2147483648.0f ? 2147483648.0f : (float)(uint32_t)sum;
s->rem[i] = sum - whole;
memcpy(&step_bits, &whole, 4);
return step_bits;
}
/* The time (a float's bits) a skeleton is drawn at, for a clock that may only move in [start, end]: the start for a loop of
one frame or less while `timed`, else the time as it is. */
static inline uint32_t loop_pose(uint32_t time_bits, uint32_t start_bits, uint32_t end_bits, int timed) {
return timed && loop_is_pose(start_bits, end_bits) ? start_bits : time_bits;
}