Entry 612
Keyed rotations and the dungeon checks to the bit
Documented in Animation playback, Dungeon generation.
This entry answers what was left open by question 13 of Open questions after the triage: towns, fields and dungeons, question 2 of The later discs' last harnesses, and gcmn's statics as the overlay loads.
Files22 in 10 directories
anim.rslibm.rsvu0.rslight.rscrates/piney-data/src/field/ee.rscrates/piney-data/tests/anim.rsanim_fixture.txtcrates/piney-world/src/chara/pose.rsfoe.rsbody.rscrates/piney-world/src/dungeon/mod.rscrates/piney-desktop/src/anm.rscrates/piney-effect/src/nodes.rstools/anim.pytest_anim.pytest_dungeon_rt.pytest_foe_rs.pytest_world_rs.pytest_effect_draw_rs.pydocs/engine/animation.mddungeon.mdUNKNOWNS.mdtools/test_dungeon_rt.py compared the doors' swinging leaves within 1e-5
and 0.05 (up to 12,288 ULPs apart on the later discs), and had five skip
paths. piney_data::anim turned keyed rotations in double precision; the
game does its own float arithmetic, with one double atan2. The port now
runs every op the game runs, and the harness compares every word with
nothing skipped.
The game's ops
A keyed rotation (ccAnmCtrlRot_SetCtrl main 0x001470c0, _Set 0x00146f30,
_Init 0x00146e30; INF addresses):
- Keys.
s16(int(deg * 182.044))then* pi/32768(mul.s), the key's matrixsceVu0RotMatrix. Infection and Mutation truncate throughfptosi, Outbreak and Quarantine throughcvt.w.s(OUT 0x00145c04). Every keyed rotation key on the four discs (31,384 to 32,861 controllers) is within ±1,800 degrees and none has exponent 255, so the two agree. - The step between keys is
sceVu0MulMatrix(R_i, R_{i-1}^T), turned into (axis, angle) bym2a(0x00105ec0):EigenVector(0x00105be0):sub.s1 off the diagonal; the cofactors(i+1, j+1)(i+2, j+2) - (i+1, j+2)(i+2, j+1)bymula.s/msub.s; theirfabsthroughfptodp,fabs,dptofp(the sign cleared); the first strictly largest wins (c.le.s); the axissceVu0Normalize(sceVu0OuterProduct(row i+1, row i+2)); below 0x2d2febffm2astores zeros.EigenVec2Mat(0x00105e00): the frame of the axis, row i+1 and their cross product, eachsceVu0Normalized again.- The angle:
atan2(L[1][2], L[1][1])ofL = F (m F^T), newlib's doubleatan2(__ieee754_atan20x00122b00,atan0x001269d0) on the soft float routines (dpadd,dpsub,dpmul,dpdiv,dpcmp), which round as IEEE doubles do;dptofpto the nearest float.
a2m(0x00105f80):sinf,cosfof the angle; the cross termssceVu0ScaleVector(aa, s)(neg.son one side), the outer rows(aa * aa[r]) * (1 - c), added tocor the cross term.- Playback. The work holds the running matrix and the time into the
current segment. Each call passes the segments strictly shorter than
the time (
a2m(turn) * W), then returnsa2m(axis, angle * frac) * W,fracas for the floats.
By disc: Mutation's routines are Infection's at other addresses (the
double atan/atan2 differ only in their constants' addresses, the
constants the same). Outbreak's and Quarantine's are recompiled with the
same operations in the same order. The libvu0 routines, sinf and cosf
are the same on all four.
The port
piney_data::anim:eigen_vector,eigen_frame,m2a,a2mandRotKeyedin the EE's and VU0's arithmetic; each segment keeps the running matrix it starts from, so a pose costs onea2mand one product.Pose::bitsisSetAnmCtrlWork's local matrix (R * S, then the position),Pose::matrixreads it. The old duplicateanim::eemodule is gone:anim::eere-exportsfield::ee, which gainedfrom_u32,eq,negativeandto_f64.piney_data::libm: the doubleatanandatan2, from the game's code.piney_data::light: a keyed light rotation the same (no light of any disc has one).vu0::of_mat4/to_mat4.chara::pose::Play::instances/worlds,foe::Model::worlds,piney_desktop::anm: the world matrices are_SetLWMatrix's VU0 products from the anm's own matrix down;body::rootisSetMatrix_PosRotZYXto the bit (town::pos_rot_zyx); a node's transparency is the anm's times its own bymul.s. The effects' anm already composed in VU0 arithmetic and now takesPose::bits.tools/anim.py: the same model in Python (newlib'ssinf/cosftranscribed, the doubleatan2on Python floats);tools/test_anim.pycompares the rotation and the object matrices word for word, andanim_fixture.txtholds the 16 words of each local matrix, whichtests/anim.rscompares exactly.
The skip paths
skipped (port error),special dungeons skipped (port error),leaf dungeons skipped (port error). The probe errs on none of them on any disc. They are now assertions.skipped (lake or special area).cases()never made one; the lakes and the story areas with branches of their own had tests of their own that did not walk them.test_dungeonsnow walks two lakes and the 15 story dungeons (walk_cases, each in a game of its own) through every check. That found a port bug: a lake's special objects (OBJ_0ps0*-OBJ_0ps3*) stand at the dummy plus its turn of an offset of their own (sceVu0ApplyMatrixw 0,sceVu0AddVector, gcmn 0x005bc0b0, 0x005bc3c0, 0x005bc6c8, 0x005bc9d0: (0, -400, 0), (-200, -100, 150), (0, 0, 150), (0, -150, 0)); the port took the dummy's own place (gim_place).test_draw_effnow runs the story dungeons too, and the other tests' silentcontinues on these conditions are assertions.roomless rows walked into by the door path (skipped). Area 67's dungeon has a type-34 row behind a door that noGotoNextRoombranch takes;SetRoomwould read through its null anm. Play never builds that dungeon: onlyGO(2)makes one, foreventAreaNumber; that is 67 only afterGO(1)on field 67 (66 and 67 share words and server, andccCheckEventAreaNumtakes 66, the first row);Enterreturns at once on field 67 (INF 0x0019de6c, MUT 0x001b2cb4, OUT 0x001a8b24, QUA 0x001b0334); no event script on the four discs has asceneinto area 2.test_area_67_dungeon_is_never_builtchecks all three on each volume; the walk asserts this row is the only such one.
Checked
- The animation model against the game (
tools/test_anim.py, each volume's own code): the unit tests on all four, andbulk 100000 1 1000, every animation with object records and every track of each, at random times and in several steps: 3,938, 3,984, 4,038 and 4,038 animations; 250,986, 262,052, 262,800 and 262,800 keyed-rotation cases (2.1 to 2.25 million segments passed); 2.6 to 2.8 million object matrices in playback. 0 failing.tests/anim.rsagainst the new fixture: exact. test_dungeon_rton all four volumes, OK, every word compared and no skip: Infection 41 dungeons (24 + 2 lakes + 15 story), 1,157SetRooms, 2,081,550 hit models identical, 1,260gimPosslots, 4,100 door and 233 stairsGotoNextRooms, 79DrawEffrooms (story ones now), 120 event-script scenes, none into a dungeon; Mutation 42 dungeons, 2,564,771 hit models, 1,508 slots.- The other exact checks:
test_foe_rs(2,220 nodes posed, 552 of the magic circle, every word and transparency),test_world_rs(Kite's hands, 200 frames, worst difference 0),test_effect_draw_rs(every animatedlwMatrixto the bit), andtest_effect_rs,test_evchar_rs,test_grunty_rs,test_boss_effect_rs,test_stfroll_rs,test_lights_rs,test_desktop_rs,test_toppage_rs,test_demo_rs: OK on all four volumes. No harness compares a pose within a tolerance any more (test_desktop_menu_rs's 0.01 is the menu's sprite places, not an animation). - The sweep on 6fdd576 (the code of this commit): 356 runs, all rc 0,
each result as
summary-main.txt's. The machine's out-of-memory storm (another program's) killed it at run 243 at about 19:02; the 113 runs left were run on the same tree. - Pins: 291 calls, 0 differ.
- Golden shots: a base from a clean 58151c4 equals
world2/shots/base(4,550 files, 0 differ). The tip differs in 4,033: 3,513 pictures and the 520 frame-hash files. A picture differs in 318 pixels at the median (p90 1,142), on the animated models: Kite, the NPCs, the enemies, animated props (the Chaos Gate's ring), their shadows and lights. Their roots are nowsceVu0RotMatrix's (its coarse sine), their bones the game's keyed rotations and VU0 products. Where the camera follows a node the whole view moves a little (the largest, the gate-hack arrival at act 24, 22,704 pixels). Side-by-side diffs of that one, the PC menu, a town, a field fight and a dungeon room show nothing else changed. cargo test --release --workspace(piney-game 349 passed, 0 failed, 153 ignored), clippy (all targets and features) clean, fmt,piney-gen gen|syms|carry --check,cairns check,tools/docs.py check.
The clock ran on through the storm (about 8 minutes down, 19:02 to 19:10);
took is the clock's.
Still unknown: nothing.