Entry 617

F_Obj records as DecodeF_Obj sets them and the engine's glam matrices as the game's setters

Files58 in 29 directories
crates/piney-battle/src/boss.rscrates/piney-battle/src/boss/corbenik/eff.rssecond.rsthird.rscrates/piney-battle/src/boss/gorre/brother.rscrates/piney-battle/src/boss/kyvia/core.rscrates/piney-battle/src/boss/macha.rstarvos.rscrates/piney-data/src/anim.rsscene.rsvu0.rscrates/piney-data/src/dungeon/place.rscrates/piney-data/src/statics/mod.rscrates/piney-data/tests/anim.rsdisc.rscrates/piney-demo/src/draw.rsnames.rsopening.rscrates/piney-desktop/src/anm.rsdesktop.rsframes.rsmail.rsview.rscrates/piney-fieldui/src/menus/hack.rscrates/piney-game/src/gameover.rscrates/piney-game/src/session/tests/kyvia_stage.rscrates/piney-gs/src/convert.rscrates/piney-stream/examples/fobj_probe.rscrates/piney-stream/src/load.rsscene.rscrates/piney-viewer/src/mesh.rscrates/piney-world/src/chara/body.rsfoe.rspose.rscrates/piney-world/src/combat/boss.rsbreath.rsstage.rsweapon.rscrates/piney-world/src/draw.rsworld.rscrates/piney-world/src/field/area.rscrates/piney-world/src/grunty/mod.rsrace.rscrates/piney-world/src/story_map/disc.rsmod.rstruths_core.rscrates/piney-world/src/systems/fireflies.rslake_sky.rssky.rsstatics.rscrates/piney-world/src/town/mod.rsdocs/README.mddocs/engine/animation.mdboss.mddesktop.mdflag-race.mdstream.mdtools/test_fobj_rs.py

Mentioned incrates/piney-world/src/combat/boss.rs:207

616 noticed that the desktop built an F_Obj record's matrix from glam's host-float Euler turns, and asked whether it differed from the game. It did, and so did the other path: the bodies' F_Obj poses (ObjRecord::pose) multiplied the scale into a finished rotation, which is not what the game does either. Both now go through one function, piney_data::anim::FObj, which is DecodeF_Obj's arithmetic, and a new harness compares every F_Obj record of the four discs with the game's own code. The same review turned up a dozen other matrices built in glam that the game builds with VU0; each now calls the game's setter.

What the game does with an F_Obj record

ccStream::DecodeF_Obj (INF 0x0014e950, MUT 0x0014e9d0, OUT 0x0014d7a0, QUA 0x0014d560; OUT's and QUA's are recompiled, 872 bytes instead of 904, with the same arithmetic) runs when DecodeFrameChunk reaches the record's frame. The desktop's ccAnm::_AnimateForward, the bodies' animations and the streams all reach it.

  1. ccRingBufferTh::ReadStruct reads the 52 bytes whole.
  2. Three stack vectors are built. The position gets w 1. Each rotation lane is mul.s by π (0x40490fdb), then div.s by 180 (0x43340000), with w 0. The scale gets w 1.
  3. The transparency is held to 0..1: c.lt.s against 0, then c.le.s against 1.
  4. The object's type (+0x8e) picks the branch:
    • 0x100, a plain object: dispSW (+0xa2) is the flags' low bit, with bit 1 set unless +0xa1 bit 0 (the part flag, which ccObj::Init 0x0013b5c0 takes from Obj2 flag bit 1) is set and every position lane is 0 (c.eq.s). Then ccCoord::SetMatrix_PosRotZYXScale(pos, rot, scale) (INF 0x00138120), and localtp (+0x88) is the held transparency, as is worldtp (+0x84) unless +0x8c bit 0 (succession) is set.
    • 0xd00, a particle: the setter alone.
    • 0xe00, an effect: the stream's effect branch, already ported.
  5. SetMatrix_PosRotZYXScale puts the scale on the unit matrix's diagonal, turns it with sceVu0RotMatrix (z, then y, then x, each on the left, each rounded) and moves it with sceVu0TransMatrix. It sets matCalcSW (+0x8d).

vu0::pos_rot_zyx_scale was already this setter, and the streams' scene already used it. The desktop and the bodies did not.

Whether the old paths differed

To measure, the old formulas were put back for one run of the probe:

pathrecords differing from the game
desktop (fobj_matrix, glam)xddesk01 2,873 of 2,928; eex1 100 of 108; eii1 154 of 169; elgx 169 of 183; ending 17,853 of 17,853
bodies (ObjRecord::pose, rotation times scale)xddesk01 1,382 of 2,928; eex1 36 of 108; eii1 33 of 169; elgx 43 of 183; ending 280 of 17,853

The glam path was wrong in the low bits nearly everywhere. It also put a tiny value where the game has an exact 0, and the reverse. The bodies' path was off by a few ulps where the scale is not exactly 1. The xddesk01 column shows what that path would have given the desktop.

One home

  • piney_data::anim::FObj is the record: from_words, local, localtp and disp_sw(part).
  • ObjRecord holds an FObj (set). ObjRecord::pose and the glam Pose::transform are gone.
  • Animation::obj_records_at replaces obj_poses_at. entry_locals_at replaces entry_poses_at and returns a Local (matrix bits and alpha), so a track's pose and a record's matrix reach the bodies the same way. transforms_at, which nothing used, is gone.
  • The desktop's own F_Obj parser (frames::fobj_records, fobj_objects, its FObj) and fobj_matrix are gone. Anm applies Animation::objs. Its dispSW is FObj::disp_sw, with the part flag read from the scene's Obj2 chunks (Scene::parts, new). Its locals, local_of and set_local are bits.
  • The streams' f_obj reads an FObj too. Its effect branch now uses TransMatrix on the unit matrix (a -0 or denormal place lands as +0, as on the EE) and the EE clamp.

The other glam matrices

Every from_rotation_*, Mat4::from_* and Mat3::from_* in the engine was checked against the game's code. These were built in glam where the game uses a ccCoord setter or libvu0, and now call the same routine:

  • The ccAnm's own matrix. Anm::set_pos_rot (glam, XYZ order) becomes set_root(M4), which the owner fills with its own setter:
    • the NEW mark: SetMatrix_PosRotXYZ (desktop 0x00402280);
    • the title's panels: UnitMatrix + TransMatrix, or SetMatrix_PosRotXYZ;
    • the boot card: SetMatrix_PosRotXYZScale(0, 0, scale), which was a glam scale product in draw_anm_scaled (now gone);
    • the Flag Race's clips: SetMatrix_PosRotZYX (MUT gcmn 0x005fe590). The port turned them in XYZ order, which is the wrong composition whenever the camera's pitch and heading are both set.
  • The hack menu's crystal roll: sceVu0RotMatrixZ on the unit matrix, then MulMatrix(mat, it) (gcmn 0x005656c4).
  • The drained enemy in Data Drain's movie: SetMatrix_PosRotZYX((0, -900, 130), (0, 0, π)) (gcmn 0x00432000).
  • The mail photo: SetPhot's UnitMatrix + TransMatrix (desktop 0x00409438).
  • The boss waves. Out::Wave carries a WavePlace (the setter) instead of a scale:
    • SetMatrix_PosRotZYX: the base's, Tarvos's, a Gorre brother's, Macha's Epitaph wave, and Corbenik's second and third forms';
    • SetMatrix_PosRotXYZ: Kyvia's core (MUT 0x004f90f0);
    • SetMatrix_PosRotZYXScale at 2: Macha's own wave (QUA 0x003a6ca4);
    • the unit matrix moved: Corbenik's ccBossEffWave (QUA 0x00377ccc).
  • The boss after-images: SetMatrix_PosRotZYXScale (QUA 0x0035f810), where the port multiplied a glam scale into the turned matrix. Their per-draw steps were host floats with a fixed fade. They now follow ccBossAfterImageEx::Draw (MUT 0x00471320) on the ENTRYAFTERIMAGE_T it keeps (AfterImage::p):
    • maxFrame down to 0;
    • colorAlpha by colorSpd, held to 0-100;
    • the transparency by transSpd, dying at 0 or at 1 and drawn that once more. The old step never killed an image whose transparency rose.
    • the scale by (es - ss) * (1 / scaleTime) in VU0 vectors, each lane held at es's once larger in size (fabs and _dpfgt).
  • The Grunty's scaled root: SetMatrix_PosRotZYXScale.
  • The story map's rocks: SetMatrix_PosRotXYZ(pos, (rot, 0, 0)) (MUT gcmn 0x0041f27c). The port had T·Rx in glam.
  • The story map's bodies and their hit matrices, the static models (STATICMODEL::Draw), the field's ground tiles (FIELD_MESH::draw) and covers (FCOVER::Draw): UnitMatrix + TransMatrix (vu0::translation, new).
  • The skies' dummy and bob clumps: each DrawBG's SetMatrix_PosRotZYX at a zero turn.
  • The lake sky: DUNGEON::DrawBG's SetMatrix_PosRotZYXScale((x, y, 0), 0, (s, s, s)) (gcmn 0x005ce824).
  • STATICOBJECT's root (StaticObj::root) now uses the same Position::bits (moved from piney-world's town::dummy_bits) and vu0::pos_rot_zyx as piney-world's static objects.
  • combat::stage::mat4, a copy of vu0::to_mat4, is gone.

For the matrices that were pure translations, sceVu0RotMatrix at a zero turn gives the unit matrix exactly (run in eemu), so the only difference was a -0 or denormal place lane.

These stay in host floats. Each says so in one line where it is:

  • the XYOFFSET matrices (View::to_screen, world draw::screen), the GS converter's bone normals and the game-over squeeze. These are the renderer's side, applied to draw commands past every game value.
  • piney-viewer's scene geometry: Transform::matrix, Scene::world, controller_worlds, anim::world and dungeon::place::room_matrix. For one run Transform::matrix used the game's setter. With it, dungeon_place's geometry checks failed: they hold facing doors to 1e-4, and VU0's sine is coarser than that at a quarter turn. That geometry is the viewer's, and no game value reads it.
  • tests and probes.

The harness

tools/test_fobj_rs.py (follows PINEY_VOLUME) uses the new piney-stream example fobj_probe. The probe lists every F_Obj record on the disc:

  • DATA.BIN's, by member and animation;
  • every stream file's that the tables name in either language, or that Outbreak's STREAM/STRT.BIN holds. A stream record is listed only if it is distinct, with each file's count.

For each record the probe prints FObj's matrix, localtp and dispSW as a plain object and as a part. For DATA.BIN it also prints, at each frame where a record holds, what the desktop's Anm::local_of gives after a step and what local_bits_at and entry_locals_at give.

The harness runs DecodeF_Obj itself in eemu on each record, with only ReadStruct hooked. Each record runs twice, part flag 0 and 1. It compares the matrix, localtp, worldtp, dispSW and matCalcSW word for word, and every user's held matrix against the game's for that record.

volumerecordsrun in the gameDATA.BIN held (anm / bits / entry)time
Infection16,689,1664,972,3263,366 / 1,908 / 3,366139 s
Mutation41,842,92214,236,9343,366 / 1,908 / 3,366372 s
Outbreak30,688,67518,850,89021,186 / 14,868 / 21,186501 s
Quarantine41,516,14625,002,02721,186 / 14,868 / 21,186676 s

Every record matched on every disc. The stream counts include each archive's copy (a file in both the Japanese and the English archive is counted twice). Some stream objects are parts (479,489 records on Infection to 2,150,779 on Quarantine). No DATA.BIN object is a part, and every DATA.BIN record has flag bit 0 set, so every one leaves dispSW 3. The bodies draw every object a record places, and do not need to read dispSW; this closes animation.md's unknown about the flag byte.

The stream rows with Infection's lengths

Outbreak's and Quarantine's English rows for streams 2-11 give Infection's inflated lengths. Their STR1E.BIN members are larger, because they carry two PCM tracks. For str0001 the member inflates to 38,134,224 bytes; the row says 25,023,360. The question was what the game plays from such a row. On Outbreak:

  1. RequestStrPlay's entry builder (0x001a2b60) copies the row's name, type, flag, gzip, ofs and size into the ccsTbl.
  2. ReadThread (0x001a30b0) reads size bytes from the row's sector. It tests gzip only against zero (0x001a3264), to choose the Gzip ring.
  3. GzipDecodeThread (0x001a3430) again tests gzip only for zero (0x001a34a0). It then calls ccUngzip::Decode(size) (0x00155a30), which inflates until the gzip stream ends; no output length is passed.
  4. DecodeThread (0x001a3570) reads only the row's type. The scene plays its own frame section to its end.

So the game plays the whole member, and the stale length changes nothing. The port already does the same. load::read_in reads size bytes, and the streams inflate through Archive whole: same bytes, same frames, same end. Nothing called load::Member::inflate, the one place that compared the length, so it is removed. load.rs's module doc and stream.md now say that gzip is only a flag. The probe reads the files the same way the streams do.

The shots

A same-day base from a clean worktree of main 0c29dc3 equals world2/shots/base: 4,550 files, 0 differ. The tip against that base gives 4,550 files with 16 different, in three groups. Every difference is 1 or 2 levels in a few pixels.

groupshotspixelscause
flag_race_shotsmut-race-result234, max 2, in the clip's boxthe race clips' root
kyvia_stage_shotsfight-0400, -0800, -10002-7, max 1the core's wave root
story_map_shotsfield 09 at 010 and 280, field 10 at 280, all four discs6-53, max 1the rocks' matrix

The evidence:

  • Each change reverted. One build put back the race clips' glam XYZ root, the rocks' glam T·Rx and the waves' old roots (the exact ZYX times a glam scale of 1, or of 2). With them, all three groups equal the base again: 5, 6 and 380 files, 0 differ.
  • Order versus arithmetic. A second build kept the exact maths but turned the race clips in XYZ order, and placed the core's wave with ZYX. Both groups then equal the tip, not the base. So the pixels come from the arithmetic (glam's host floats, and a glam product with a scale of 1 that flips zero signs). The turn order makes no visible difference in these frames: the clips' pitch is small and the core turns about one axis.
  • Fields 9-11 are EVENTAREAB8, whose DrawRock places each rock.

No other shot changed.

Checks

On 62c8733, the code of this entry before the stream clean-up:

  • The sweep: 416 of 416 rc 0. Every line is as in summary-main.txt, plus four new test_fobj_rs runs.
  • Battle pins: 291 calls, 0 differ (probe wt-fobj at 62c8733).
  • Crate tests: 786 passed, 0 failed.
  • The piney-game suite: 351 / 0 / 153.
  • The shots, as above.

On b7264f6 (with Member::inflate removed and the docs):

  • The sweep again: 416 of 416 rc 0, each line as in the first sweep.
  • piney-stream's tests: 47 passed.
  • piney-gen gen, syms and carry --check: all current.
  • Clippy (all targets and features): clean. fmt: clean. tools/docs.py check: passes.

During both sweeps a harness replaced the worktree's tools/eemu_rs.so symlink with a build. The symlink was put back each time, and main's file is untouched. After the sweeps only a comment changed (the after-image constant's, below) along with this entry. The base worktree and its target were removed.

The clock ran through an eight-day pause, from about 2026-11-19 23:00 to 2026-11-27 22:25 (191h 25m). took: is the clock's 204h 52m less that pause.

Noticed, not changed

Every boss's Out::AfterImage is drawn with one set of parameters: white at 100, 20 frames, 1 by -0.05. That is combat::boss::BOSS_EAI, and it was the old code's value too. The game's own m_eai differs by boss, as each constructor writes it:

  • Skeith (INF gcmn 0x0047bc04), Fidchell (OUT 0x004a3ac4) and Magus (MUT 0x0049e59c): colour -1, so no fog blend at all.
  • Innis (MUT 0x004948c0): 0x00187500 at 30, transparency 0.5 by -0.02, 80 frames.
  • Corbenik's second form (QUA 0x003b22ec): 0x00505000 at 100.

Some calls pass other parameters entirely. Macha's EntryAfterImage(0) takes the manager's null default, AfterImageParams::ENTRY. So the port blends these after-images where the game does not. The fix is to have each producer of Out::AfterImage carry the parameters its call passes.

Still unknown
  1. What scaleTime, ss and es hold in each boss's m_eai. Skeith's, Fidchell's, Innis's and Corbenik's constructors write the six fields above (Skeith's and Fidchell's also ss y and z), not scaleTime. ENTRYAFTERIMAGE_T has no constructor, and heap.md says nothing clears a block. Magus's copies 80 bytes in first (memcpy, MUT 0x0049e584) from a source not traced. Init scales the image only if scaleTime is above 0, and the port assumes it is not. Settling it needs each source, or the heap model's view of those bytes.
  2. Which parameters Tarvos's Out::AfterImage calls pass. Its constructor holds no m_eai block of the shape above.