Merge pull request #60 from TheBozos/claude/native-copsuv-aim-forward

Replace the two Cop SUV laser-aim forward transforms with native math
This commit is contained in:
boubou666 authored and GitHub committed 2026-11-08 18:44:22 +01:00
commit aadc76bd52
5 files changed
+119 -21

No files matched your search

+4
View File
@@ -15,6 +15,10 @@ The earlier v0.3.2 release remains in Git history and on GitHub for comparison;
## Architecture and build
[`NATIVE_COPSUV_AIM_FORWARD.md`](NATIVE_COPSUV_AIM_FORWARD.md) adds the two Cop SUV laser-aim
forwards. Coverage is 144/269 known forward returns (125 remain), with 134/134 known inverse
returns native.
[`NATIVE_LAUNCHER_AIM_FORWARD.md`](NATIVE_LAUNCHER_AIM_FORWARD.md) adds the Hearse, Minion and
Tanker launcher turret-aim forwards. Coverage is 142/269 known forward returns (127 remain),
with 134/134 known inverse returns native.
+81
View File
@@ -0,0 +1,81 @@
# Native Cop SUV laser-aim forward transforms
The two `Launcher::UpdateCopSUV` (`14ff58`) forward returns use native XYZ
arithmetic after the [launcher turret-aim forwards](NATIVE_LAUNCHER_AIM_FORWARD.md).
Known forward coverage grows from 142 to 144 of 269 returns (125 remain). Known
inverse coverage stays 134 of 134; BozoEngine stays at `4a8f70a`.
| Return PC | Branch | Producer and consumer |
| --- | --- | --- |
| `150094` | Mode `0x14` with a live player state | Laser offset table through the vehicle basis, in place, plus the shooter position, aimed at the player-state target |
| `1502cc` | Otherwise, a closest car within 600 units | Same offset and position, aimed at the car `GetClosestCar` chose |
As with the other launchers, the frame `+10` result is read only as XYZ, by
`mathfAddVector` and by the scalar `mathfRotationFromPointToPoint`. The owner never
reads frame `+1c` (the output W) and reads no VU registers, accumulator or flags.
The existing native helper computes separately rounded XYZ, preserves destination
W and leaves VU state untouched. Unknown and historical callers keep the original
ABI. No engine or gameplay formula changes.
## Generated comparisons
Evidence is under `D:/BozoScratch/copsuv-aim-forward`, against parent `5135b43`
(PR #59). Parent headless/window binaries are preserved there and match PR #59's
qualified build. Generated bodies, retail data and runtime recordings stay
outside Git.
- Added coverage is 1,024 generated sequences / 64 whole-memory comparisons
(caller kinds 247 and 248): helper-boundary continuations and full-owner
entries, across four rounding modes, FTZ/DAZ, RAM aliases, identity/quarter-turn
bases and arbitrary W payloads.
- Kind 247 sets the game mode to `0x14` with a live player state and a target
coordinate system, so full entries take the first branch even without a closest
car. Kind 248 places a car inside the laser's 600-unit range, so full entries take
the closest-car branch; that car's target flag (`+24bc`) is asserted, and the
no-target scenario returns normally without a transform. Producer reach is
asserted in every case.
- Both branches continue into `LauncherSound::startLaserSound` or
`stopLaserSound`, which call into the sound driver. Fixtures stop at those two
calls, after the aim point has been consumed, and assert that one of them was
reached; the laser sound and the turret matrix publication after it are not
executed here.
- Transform outputs are checked against an independent identity or quarter-turn
result in every reached case (the basis is the vehicle's own). The aim point
consumed by `mathfRotationFromPointToPoint` is asserted exactly against the
original FPU addition. The first site publishes in 512 cases, the second in 480.
- The VU rule from the earlier weapon increments applies. Only forward scratch W
at frame `+1c` is normalized for test comparison, after every real consumer.
- New caller kinds shift the shared random fill for later rounding modes, so two
data-dependent counts in earlier fixtures moved again (vehicle tire jumps
704 → 715, real libm errno cases 833 → 850). All scenario-defined counts and
assertions are unchanged.
- Aggregate caller coverage is 127,488 generated sequences / 5,952 whole-memory
comparisons. Historical forward ABI coverage is 8,640 / 540; inverse remains
8,576 / 134.
## Replay and window qualification
Player, headless runner, historical checker and all eleven native test targets
build. All eleven native suites and twelve Python tooling tests pass, with every
previous publication assertion enabled.
Default and strict routes complete 9,500 one-player and 8,500 actual four-player
frames. Every recording field matches parent `5135b43`: raw RAM, scratchpad,
calls, draws, sound, thread state and EE timing/counts. Sampled 32 MiB RAM images
are identical. Strict/default recordings and snapshots are byte exact; strict
comparisons report no mismatch. The closest-car return `1502cc` is live: it runs
natively 1,638 times on the one-player route and 845 times on the four-player route
with no recorded difference. The player-state return `150094` is cold on these
routes and is qualified by the generated owner suite above.
Fresh isolated window runs complete 6,500 one-player, 6,500 actual four-player
and 4,200 movie frames; `1502cc` runs natively 544 times in the one-player window
and 197 times in the four-player window. Reviewed captures show the intro and
credits, menus, vehicle and level selection, combat with the HUD and four
simultaneous views. Each route has five distinct captures. Stereo 48 kHz, 16-bit
WAV recordings contain nonzero audio.
Audio device underruns remain: 57.3 ms silence in one-player, 35.3 ms in
four-player and 15.2 ms in the movie run. These are functional checks, not a
performance or flawless-playback claim. The mode-`0x14` branch in actual play, full
campaign and physical controller/hardware acceptance remain open.
+7 -4
View File
@@ -1,5 +1,7 @@
# Native launcher turret aim forward transforms
[Cop SUV laser-aim forwards](NATIVE_COPSUV_AIM_FORWARD.md) follow with two more launcher sites.
Three launcher turret-aim forward returns use native XYZ arithmetic after the
[ricochet forwards](NATIVE_RICOCHET_FORWARD.md). Known forward coverage grows from
139 to 142 of 269 returns (127 remain). Known inverse coverage stays 134 of 134;
@@ -51,10 +53,11 @@ outside Git.
addition. Each site publishes in 480 cases.
- The VU rule from the earlier weapon increments applies. Only forward scratch W
at frame `+1c` is normalized for test comparison, after every real consumer.
- The new snapshot region changes the shared random fill sequence, so two
data-dependent counts in earlier suites moved (vehicle tire jumps 711 → 704,
real libm errno cases 825 → 833). All scenario-defined counts and assertions are
unchanged.
- New fixture regions and new caller kinds both change the shared random fill
sequence that later cases see (the loop runs every kind within each rounding
mode), so two data-dependent counts in earlier fixtures moved (vehicle tire jumps
711 → 704, real libm errno cases 825 → 833). All scenario-defined counts and
assertions are unchanged.
- Aggregate caller coverage is 126,464 generated sequences / 5,888 whole-memory
comparisons. Historical forward ABI coverage is 8,512 / 532; inverse remains
8,576 / 134.
+3 -2
View File
@@ -10,7 +10,7 @@
namespace tmb::math
{
// Audited XYZ-only consumers: collision queries, vehicle spatial records and hierarchy lighting/attachments.
inline constexpr std::array<uint32_t, 142> directionReturns{
inline constexpr std::array<uint32_t, 144> directionReturns{
0x168b30, 0x1cd618, 0x1cda54, 0x1cdabc, 0x11708c, 0x1880e0, 0x1d4284, 0x1d42e8, 0x1cb19c,
0x1cfd18, 0x1cfde8, 0x1d0224, 0x1d0250, // height-test collision/BSP results
0x1d25ec, 0x1d261c, 0x1d2784, 0x1d2804, // line-of-sight BSP/volume results
@@ -50,7 +50,8 @@ namespace tmb::math
0x1ada84, 0x1adb8c, 0x1adba0, 0x1adca8, 0x1adcbc, 0x1addc4, 0x1addd8, // Minion shield hit-point distances
0x1b1700, 0x1b1bbc, 0x1b339c, 0x1b3634, 0x1b371c, 0x1b3ef8, // weapon lock-on/look-ahead targets, satellite and rock movement
0x1b2fb0, 0x1b3118, // ricochet movement before its height test and after its reflection
0x150efc, 0x1511ec, 0x1513f4}; // Hearse, Minion and Tanker launcher turret aim points
0x150efc, 0x1511ec, 0x1513f4, // Hearse, Minion and Tanker launcher turret aim points
0x150094, 0x1502cc}; // Cop SUV laser aim points (player-state and closest-car branches)
struct alignas(16) Vector { std::array<uint32_t, 4> bits{}; };
struct Matrix { std::array<Vector, 4> column{}; };
+24 -15
View File
@@ -226,7 +226,7 @@ namespace
countMinionDirection(ctx); const auto before=*ctx; nativeDirectionImplementation(ram,ctx,rt);
require(vuUntouched(before,*ctx),"Minion forward leaf changed VU state");
}
constexpr uint32_t weaponDirectionReturns[]={0x1b1700,0x1b1bbc,0x1b339c,0x1b3634,0x1b371c,0x1b3ef8,0x1b2fb0,0x1b3118,0x150efc,0x1511ec,0x1513f4};
constexpr uint32_t weaponDirectionReturns[]={0x1b1700,0x1b1bbc,0x1b339c,0x1b3634,0x1b371c,0x1b3ef8,0x1b2fb0,0x1b3118,0x150efc,0x1511ec,0x1513f4,0x150094,0x1502cc};
std::array<unsigned,std::size(weaponDirectionReturns)> weaponDirectionCalls{};
void countWeaponDirection(const R5900Context *ctx) {
for(unsigned i=0;i<std::size(weaponDirectionReturns);++i) if(getRegU32(ctx,31)==weaponDirectionReturns[i]) ++weaponDirectionCalls[i];
@@ -347,7 +347,7 @@ void testHierarchyHelperCallers()
0x129e58,0x137cac,0x1b2d1c,0x1b3d30,0x1b3e00,
0x1ada84,0x1adb8c,0x1adba0,0x1adca8,0x1adcbc,0x1addc4,0x1addd8,
0x1b1700,0x1b1bbc,0x1b339c,0x1b3634,0x1b371c,0x1b3ef8,0x1b2fb0,0x1b3118,
0x150efc,0x1511ec,0x1513f4};
0x150efc,0x1511ec,0x1513f4,0x150094,0x1502cc};
const auto isInverse = [](unsigned kind) { return kind < 4 || kind == 12 || kind == 13 || (kind >= 24 && kind <= 30) || (kind >= 37 && kind <= 45) || (kind >= 50 && kind <= 57) || (kind >= 65 && kind <= 67) || (kind >= 76 && kind <= 96) || (kind >= 111 && kind <= 118) || (kind >= 123 && kind <= 125) || (kind >= 135 && kind <= 138) || (kind >= 155 && kind <= 187) || (kind >= 189 && kind <= 200); };
const unsigned saved = _mm_getcsr(); unsigned cases = 0, memoryCases = 0; std::array<unsigned,2> aiShotPublications{};
unsigned weaponJumpCases=0, lightingPublicationCases=0, rolloverPublicationCases=0;
@@ -356,7 +356,7 @@ void testHierarchyHelperCallers()
std::array<unsigned,4> collisionPublications{}; unsigned collisionErrnoCases=0;
std::array<unsigned,5> attachmentPublications{}; unsigned gridRemovals=0;
std::array<unsigned,4> minionPublications{}, minionDestructions{}; unsigned minionBoundaries=0;
std::array<unsigned,11> weaponPublications{};
std::array<unsigned,13> weaponPublications{};
for (unsigned mode = 0; mode < 4; ++mode) for (unsigned kind = 0; kind < std::size(callers); ++kind)
for (unsigned n = 0; n < 128; ++n)
{
@@ -1964,9 +1964,9 @@ void testHierarchyHelperCallers()
// Weapon lock-on, look-ahead, skill-satellite, rock and ricochet transforms through their real owners.
const unsigned site=kind-236;
const auto fp=[&](unsigned r,float v) { std::memcpy(&initial.fu[r],&v,4); };
constexpr uint32_t owners[]={0x1b16a8,0x1b1ae0,0x1b3350,0x1b3350,0x1b3350,0x1b3e28,0x1b2ee0,0x1b2ee0,0x150e68,0x151060,0x151358};
constexpr RecompiledFunction resumes[]={resume_0x1b16a8,resume_0x1b1ae0,resume_0x1b3350,resume_0x1b3350,resume_0x1b3350,resume_0x1b3e28,resume_0x1b2ee0,resume_0x1b2ee0,resume_0x150e68,resume_0x151060,resume_0x151358};
continuation=resumes[site]; entry=owners[site]; returnAt(site<2 ? 0x70 : site==8 ? 0x70 : site>=9 ? 0xd0 : site>=6 ? 0xb0 : 0x30);
constexpr uint32_t owners[]={0x1b16a8,0x1b1ae0,0x1b3350,0x1b3350,0x1b3350,0x1b3e28,0x1b2ee0,0x1b2ee0,0x150e68,0x151060,0x151358,0x14ff58,0x14ff58};
constexpr RecompiledFunction resumes[]={resume_0x1b16a8,resume_0x1b1ae0,resume_0x1b3350,resume_0x1b3350,resume_0x1b3350,resume_0x1b3e28,resume_0x1b2ee0,resume_0x1b2ee0,resume_0x150e68,resume_0x151060,resume_0x151358,resume_0x14ff58,resume_0x14ff58};
continuation=resumes[site]; entry=owners[site]; returnAt(site<2 ? 0x70 : site==8 ? 0x70 : site>=11 ? 0x80 : site>=9 ? 0xd0 : site>=6 ? 0xb0 : 0x30);
word(object+0x130,address(cs)); word(object+0x110,address(vehicle)); word(object+0x114,scenario==2 && n>=64 ? 0 : address(vehicle)); // no target only gates full entries
word(object+4,scenario==1 ? 4 : 9); word(object+0x34,scenario==3 ? 0 : 1); word(object+0x3c,n&1); word(object+0x40,0);
f(object+0x54,0.f); word(object+0x14,0); f(object+0x70,2.f); f(object+0x94,-5.f); f(object+0x98,scenario==4 ? .5f : 6.f);
@@ -1988,16 +1988,24 @@ void testHierarchyHelperCallers()
xyz(launcher+0x3a0,1.f,-2.f,3.f); xyz(0x23cfc0,2.f,-3.f,4.f); f(0x23cfd8,.5f); xyz(0x23d1f0,-1.f,5.f,2.f);
word(vehicle+0x2018,address(cs)); f(vehicle+0x1ecc,.25f);
word(scene+0x1b3db4,1); word(scene+0x1b3db0,0); f(gp-0x635c,1e6f);
word(car+0x580,1); xyz(car+0x1d0,500.f,600.f,700.f); word(car+0x2018,address(carCs)); xyz(carCs+0x10,500.f,600.f,700.f);
word(car+0x580,1); if(site>=11) xyz(car+0x1d0,250.f,350.f,450.f); else xyz(car+0x1d0,500.f,600.f,700.f); word(car+0x2018,address(carCs)); xyz(carCs+0x10,500.f,600.f,700.f); // Cop SUV laser range is 600
for(uint32_t at:{0x61e8u,0x61e4u,0x61e0u,0x61f8u,0x61f4u}) f(gp-at,.5f); // bounded turret angle smoothing
const uint32_t out=sp+0x10, matrix=sp+0x30;
if(site==8) { reg(16,out); reg(17,launcher); reg(18,vehicle); reg(19,vehicle+0x1d0); reg(4,cs+0x20); reg(5,out); xyz(out,2.f,-3.f,4.5f); }
if(site==8 || site>=11) { reg(16,out); reg(17,launcher); reg(18,vehicle); reg(19,vehicle+0x1d0); reg(4,cs+0x20); reg(5,out); xyz(out,2.f,-3.f,4.5f); }
else {
basis(matrix,n%4==0); reg(16,out); reg(17,matrix); reg(20,vehicle+0x1d0); reg(4,matrix); reg(6,out);
if(site==9) { reg(18,launcher); reg(19,vehicle); reg(5,launcher+0x3a0); }
else { reg(18,vehicle); reg(19,launcher); reg(5,0x23d1f0); }
}
if(site==8) reg(6,out);
if(site==8 || site>=11) reg(6,out);
if(site>=11) {
// Cop SUV: mode 0x14 with a live player state takes the first aim branch, otherwise the second.
// Both branches end in the laser-sound start/stop calls into the sound driver: the fixture stops there,
// after the aim point has been consumed.
ram[vehicle+0x483]=0; reg(20,vehicle+0x1d0); word(scene+0x1b3db0,site==11 ? 0x14 : 0);
word(scene+0x1ae650,1); word(scene+0x1ab500,address(carCs));
if(!(site==12 && n>=64 && scenario==1)) { services.stop=0x17baf0; services.stop2=0x17bba0; } // no target: the owner returns normally
}
}
else {
// Ricochet: s2 is the weapon. A low resulting height takes the real reflection branch to the second
@@ -2436,9 +2444,9 @@ void testHierarchyHelperCallers()
const unsigned site=kind-236, scenario=(n%64)/8;
const auto read=[&](uint32_t at) { uint32_t v; std::memcpy(&v,ram+at,4); return v; };
const bool active=!fromEntry || site>=2 || (scenario!=1 && scenario!=2 && scenario!=3);
std::array<unsigned,11> reached{};
std::array<unsigned,13> reached{};
std::vector<unsigned> order; // reached sites in execution order
if(site>=8) { const bool aim=!fromEntry || scenario!=1; reached[site]=aim; if(aim) order.push_back(site); }
if(site>=8) { const bool aim=!fromEntry || scenario!=1 || site==11; reached[site]=aim; if(aim) order.push_back(site); }
else if(site<6) { reached[site]=active; if(active) order.push_back(site); }
else {
// Ricochet: the first transform always runs from the entry; the reflection branch then reaches the second.
@@ -2446,7 +2454,7 @@ void testHierarchyHelperCallers()
if(!fromEntry || scenario!=4) { reached[7]=1; order.push_back(7); }
}
require(refWeaponDirections==reached,"weapon forward producer reach differs");
const uint32_t frame=fromEntry ? sp-(site<2 ? 0x90u : site==5 ? 0x60u : site==8 ? 0xa0u : site==9 ? 0x100u : site==10 ? 0xf0u : site>=6 ? 0xd0u : 0x50u) : sp;
const uint32_t frame=fromEntry ? sp-(site<2 ? 0x90u : site==5 ? 0x60u : site==8 ? 0xa0u : site>=11 ? 0xb0u : site==9 ? 0x100u : site==10 ? 0xf0u : site>=6 ? 0xd0u : 0x50u) : sp;
const uint32_t wAt=frame+(site>=8 ? 0x1cu : 0xcu);
require(referenceW.size()==unsigned(!order.empty()) && (order.empty() || referenceW[0].offset==wAt),"unexpected weapon forward-W exclusion");
require(refWeaponInputs.size()==order.size() && refWeaponOutputs.size()==order.size(),"weapon transform consumer not executed");
@@ -2454,7 +2462,7 @@ void testHierarchyHelperCallers()
// Independent quarter-turn/identity result where the basis is fixture-known, then the actual XYZ
// publication through mathfAddVector. Ricochet's second basis is rebuilt by the owner after its first.
const unsigned at=order[k];
const bool known=at>=9 ? !fromEntry : at!=7 || (site==7 && !fromEntry); // Minion/Tanker entries build their aim basis
const bool known=at==9 || at==10 ? !fromEntry : at!=7 || (site==7 && !fromEntry); // Minion/Tanker entries build their aim basis
const bool rotated=at==2 || (at>=5 && at<=7) ? n%4==1 : (at==3 || at==4) && fromEntry ? false : n%4==0;
float in[3], out[3]; std::memcpy(in,refWeaponInputs[k].data(),12); std::memcpy(out,refWeaponOutputs[k].data(),12);
if(known) require(out[0]==(rotated ? -in[1] : in[0]) && out[1]==(rotated ? in[0] : in[1]) && out[2]==in[2],"weapon independent transform differs");
@@ -2463,7 +2471,8 @@ void testHierarchyHelperCallers()
if(at>=8) {
// The aim point is consumed by the real mathfRotationFromPointToPoint toward the chosen car.
require(refWeaponTargets.size()==1 && refWeaponTargets[0]==sum,"launcher aim point differs");
if(at==8 && fromEntry) require(read(0x3624bc)==1,"hearse target flag not published"); // set before the transform
if((at==8 || at==12) && fromEntry) require(read(0x3624bc)==1,"launcher target flag not published"); // set before the transform
if(at>=11) require(a.pc==0x17baf0 || a.pc==0x17bba0,"Cop SUV laser-sound boundary not reached");
} else if(at==6) {
require(refAttachmentActions[6]==1 && refWeaponTargets.size()==1 && refWeaponTargets[0][0]==sum[0] && refWeaponTargets[0][1]==sum[1],
"ricochet height-test position differs");
@@ -2551,7 +2560,7 @@ void testHierarchyHelperCallers()
std::all_of(minionDestructions.begin(),minionDestructions.end(),[](unsigned n) { return n!=0; }) && minionBoundaries,"Minion fixtures missed damage/destruction/distance boundaries");
std::printf("Minion forward publication cases: damage %u/%u/%u/%u destruction %u/%u/%u/%u exact distance boundaries %u\n",minionPublications[0],minionPublications[1],minionPublications[2],minionPublications[3],minionDestructions[0],minionDestructions[1],minionDestructions[2],minionDestructions[3],minionBoundaries);
require(std::all_of(weaponPublications.begin(),weaponPublications.end(),[](unsigned n) { return n!=0; }),"weapon fixtures missed transform publication");
std::printf("Weapon forward publication cases: lock-on %u look-ahead %u skill-satellite %u/%u/%u rock %u ricochet %u/%u launcher aim hearse %u minion %u tanker %u\n",weaponPublications[0],weaponPublications[1],weaponPublications[2],weaponPublications[3],weaponPublications[4],weaponPublications[5],weaponPublications[6],weaponPublications[7],weaponPublications[8],weaponPublications[9],weaponPublications[10]);
std::printf("Weapon forward publication cases: lock-on %u look-ahead %u skill-satellite %u/%u/%u rock %u ricochet %u/%u launcher aim hearse %u minion %u tanker %u cop SUV %u/%u\n",weaponPublications[0],weaponPublications[1],weaponPublications[2],weaponPublications[3],weaponPublications[4],weaponPublications[5],weaponPublications[6],weaponPublications[7],weaponPublications[8],weaponPublications[9],weaponPublications[10],weaponPublications[11],weaponPublications[12]);
host.enabled = false; unsigned historical = 0;
for (unsigned kind = 4; kind < std::size(callers); ++kind) for (unsigned n = 0; n < 64; ++n)
{