Fix geometry collision traps and implement authentic sector morphing

This commit is contained in:
Luxferre committed 2026-12-01 08:05:04 +02:00
1 parent cd63921ea4
commit b9353f552c
16 files changed
+1470 -131

No files matched your search

+284
View File
@@ -198,5 +198,289 @@ int main() {
}
std::cout << "[PASS] Gameplay rule toggles (fuel, weapons, damage, pickups, morphing) validated\n";
// 6. Authentic Sector Morphing across all 6 levels (Timed, Craft, Rocket triggers + columns/lights/pickups)
{
const size_t expected_morph_counts[6] = {1, 2, 5, 2, 7, 6};
for (int l = 1; l <= 6; ++l) {
assets::LevelData lvl;
CHECK(lvl.load(vfs, l));
CHECK(lvl.morphs.size() == expected_morph_counts[l - 1]);
}
// 6a. Level 1: Timed morph id=66 lowers (17,32) 1504 -> 1184, then oscillates back to 1504
{
sim::RaceSetup ms;
ms.track_number = 1;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl1, ms));
CHECK(msim.level().cell(17, 32).height == 1504);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
for (int t = 0; t < 290; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(17, 32).height == 1184);
for (int t = 0; t < 290; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(17, 32).height == 1504);
}
// 6b. Level 2: Craft trigger id=80 lowers & re-textures (109,20); Craft trigger id=198 unlocks grp=3 pickups
{
assets::LevelData lvl2;
CHECK(lvl2.load(vfs, 2));
sim::RaceSetup ms;
ms.track_number = 2;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl2, ms));
CHECK(msim.level().cell(109, 20).height == 2480);
CHECK(msim.level().cell(109, 20).tex_or_col == 72);
bool has_locked_g3 = false;
for (const auto& pk : msim.pickups()) {
if (pk.group == 3) {
has_locked_g3 = true;
CHECK(!pk.group_unlocked);
}
}
CHECK(has_locked_g3);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
msim.crafts_mut()[0].curr_pose.pos = Vec3(110.5f, msim.level().sample_height_world(110.5f, 19.5f) + 0.30f, 19.5f);
msim.crafts_mut()[0].prev_pose = msim.crafts_mut()[0].curr_pose;
for (int t = 0; t < 60; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(109, 20).height == 1840);
CHECK(msim.level().cell(109, 20).tex_or_col == 63);
msim.crafts_mut()[0].curr_pose.pos = Vec3(127.5f, msim.level().sample_height_world(127.5f, 21.5f) + 0.30f, 21.5f);
msim.crafts_mut()[0].prev_pose = msim.crafts_mut()[0].curr_pose;
for (int t = 0; t < 10; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
for (const auto& pk : msim.pickups()) {
if (pk.group == 3) CHECK(pk.group_unlocked && pk.active);
}
}
// 6c. Level 3: Rocket trigger id=176 removes solid columns at (67,63) and marks columns_dirty
{
assets::LevelData lvl3;
CHECK(lvl3.load(vfs, 3));
sim::RaceSetup ms;
ms.track_number = 3;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl3, ms));
CHECK(msim.level().cell(67, 63).tex_or_col == -87);
float col_y = msim.level().sample_height_world(67.5f, 63.5f) + 0.30f;
CHECK(msim.level().is_cell_solid_at_point(67, 63, 67.5f, 63.5f, col_y));
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
auto& p1 = msim.crafts_mut()[0];
p1.curr_pose.pos = Vec3(67.5f, msim.level().sample_height_world(67.5f, 67.5f) + 0.30f, 67.5f);
p1.curr_pose.yaw = kPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
bool saw_cols_dirty = false;
std::vector<sim::DirtyRect> rects;
for (int t = 0; t < 40; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
bool cdirty = false;
if (msim.consume_world_dirty(rects, cdirty) && cdirty) saw_cols_dirty = true;
}
CHECK(saw_cols_dirty);
CHECK(msim.level().cell(67, 63).tex_or_col >= 0);
CHECK(!msim.level().is_cell_solid_at_point(67, 63, 67.5f, 63.5f, col_y));
}
// 6d. Level 4: Rocket id=153 collapses reactor (68,75) & unlocks grp=10 pickups; Craft id=256 + Rocket id=40 open bunker ONCE
{
assets::LevelData lvl4;
CHECK(lvl4.load(vfs, 4));
sim::RaceSetup ms;
ms.track_number = 4;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl4, ms));
CHECK(msim.level().cell(68, 75).height == 3360);
CHECK(msim.level().cell(43, 114).tex_or_col == -172);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
auto& p1 = msim.crafts_mut()[0];
p1.curr_pose.pos = Vec3(69.5f, msim.level().sample_height_world(69.5f, 90.0f) + 0.30f, 90.0f);
p1.curr_pose.yaw = kPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
for (int t = 0; t < 60; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
}
CHECK(msim.level().cell(68, 75).height == 2048);
bool g10_unlocked = false;
for (const auto& pk : msim.pickups()) {
if (pk.group == 10) {
g10_unlocked = true;
CHECK(pk.group_unlocked);
float expected_y = msim.level().sample_height_world(pk.pos.x, pk.pos.z) + 0.45f;
CHECK(std::abs(pk.pos.y - expected_y) < 0.05f);
}
}
CHECK(g10_unlocked);
p1.curr_pose.pos = Vec3(44.5f, msim.level().sample_height_world(44.5f, 49.5f) + 0.30f, 49.5f);
p1.prev_pose = p1.curr_pose;
for (int t = 0; t < 40; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(43, 114).tex_or_col == -171);
p1.curr_pose.pos = Vec3(44.5f, msim.level().sample_height_world(44.5f, 117.0f) + 0.30f, 117.0f);
p1.curr_pose.yaw = kPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
p1.missile_cd = 0.0f;
for (int t = 0; t < 40; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
}
CHECK(msim.level().cell(43, 114).tex_or_col == -171);
}
// 6e. Level 5: Rocket id=286 blasts pillar (70,81); Craft id=275 starts blinking tunnel lights at (10,25)
{
assets::LevelData lvl5;
CHECK(lvl5.load(vfs, 5));
sim::RaceSetup ms;
ms.track_number = 5;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl5, ms));
CHECK(msim.level().cell(70, 81).tex_or_col == -53);
CHECK(msim.level().cell(10, 25).illumination == 12800);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
auto& p1 = msim.crafts_mut()[0];
p1.curr_pose.pos = Vec3(70.5f, msim.level().sample_height_world(70.5f, 84.0f) + 0.30f, 84.0f);
p1.curr_pose.yaw = kPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
bool saw_cols_dirty = false;
std::vector<sim::DirtyRect> rects;
for (int t = 0; t < 40; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
bool cdirty = false;
if (msim.consume_world_dirty(rects, cdirty) && cdirty) saw_cols_dirty = true;
}
CHECK(saw_cols_dirty);
CHECK(msim.level().cell(70, 81).tex_or_col == 117);
p1.curr_pose.pos = Vec3(20.5f, msim.level().sample_height_world(20.5f, 77.5f) + 0.30f, 77.5f);
p1.prev_pose = p1.curr_pose;
bool saw_dim = false;
for (int t = 0; t < 60; ++t) {
msim.step(CraftInput{}, CraftInput{}, dt);
if (msim.level().cell(10, 25).illumination == 8192) saw_dim = true;
}
CHECK(saw_dim);
bool saw_bright = false;
for (int t = 0; t < 60; ++t) {
msim.step(CraftInput{}, CraftInput{}, dt);
if (msim.level().cell(10, 25).illumination == 12800) saw_bright = true;
}
CHECK(saw_bright);
}
// 6f. Level 6: Timed id=3 oscillates ramp (10,75); Craft id=148 collapses (48,52); Rocket id=184 blasts (33,16)
{
assets::LevelData lvl6;
CHECK(lvl6.load(vfs, 6));
sim::RaceSetup ms;
ms.track_number = 6;
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl6, ms));
CHECK(msim.level().cell(10, 75).height == 2368);
CHECK(msim.level().cell(48, 52).tex_or_col == -480);
CHECK(msim.level().cell(33, 16).tex_or_col == -112);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(10, 75).height == 2048);
for (int t = 0; t < 180; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(10, 75).height == 2368);
auto& p1 = msim.crafts_mut()[0];
p1.curr_pose.pos = Vec3(70.5f, msim.level().sample_height_world(70.5f, 51.5f) + 0.30f, 51.5f);
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
bool saw_cols_dirty = false;
std::vector<sim::DirtyRect> rects;
for (int t = 0; t < 40; ++t) {
msim.step(CraftInput{}, CraftInput{}, dt);
bool cdirty = false;
if (msim.consume_world_dirty(rects, cdirty) && cdirty) saw_cols_dirty = true;
}
CHECK(saw_cols_dirty);
CHECK(msim.level().cell(48, 52).tex_or_col >= 0);
p1.curr_pose.pos = Vec3(33.5f, msim.level().sample_height_world(33.5f, 19.5f) + 0.30f, 19.5f);
p1.curr_pose.yaw = kPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0, 0, 0);
p1.missile_cd = 0.0f;
for (int t = 0; t < 40; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
}
CHECK(msim.level().cell(33, 16).tex_or_col >= 0);
}
// 6g. track_morphing_enabled = false disables Timed (L1), Craft (L2), and Rocket (L3) morphs
{
sim::RaceSetup off1;
off1.track_number = 1;
off1.num_ai = 0;
off1.track_morphing_enabled = false;
sim::RaceSim s1;
CHECK(s1.start_race(lvl1, off1));
for (int t = 0; t < 500; ++t) s1.step(CraftInput{}, CraftInput{}, dt);
CHECK(s1.level().cell(17, 32).height == 1504);
assets::LevelData lvl2;
CHECK(lvl2.load(vfs, 2));
sim::RaceSetup off2;
off2.track_number = 2;
off2.num_ai = 0;
off2.track_morphing_enabled = false;
sim::RaceSim s2;
CHECK(s2.start_race(lvl2, off2));
for (int t = 0; t < 200; ++t) s2.step(CraftInput{}, CraftInput{}, dt);
s2.crafts_mut()[0].curr_pose.pos = Vec3(110.5f, s2.level().sample_height_world(110.5f, 19.5f) + 0.30f, 19.5f);
s2.crafts_mut()[0].prev_pose = s2.crafts_mut()[0].curr_pose;
for (int t = 0; t < 60; ++t) s2.step(CraftInput{}, CraftInput{}, dt);
CHECK(s2.level().cell(109, 20).height == 2480);
assets::LevelData lvl3;
CHECK(lvl3.load(vfs, 3));
sim::RaceSetup off3;
off3.track_number = 3;
off3.num_ai = 0;
off3.track_morphing_enabled = false;
sim::RaceSim s3;
CHECK(s3.start_race(lvl3, off3));
for (int t = 0; t < 200; ++t) s3.step(CraftInput{}, CraftInput{}, dt);
s3.crafts_mut()[0].curr_pose.pos = Vec3(67.5f, s3.level().sample_height_world(67.5f, 67.5f) + 0.30f, 67.5f);
s3.crafts_mut()[0].curr_pose.yaw = kPi;
s3.crafts_mut()[0].prev_pose = s3.crafts_mut()[0].curr_pose;
for (int t = 0; t < 40; ++t) {
CraftInput fire;
fire.fire_missile = (t == 0);
s3.step(fire, CraftInput{}, dt);
}
CHECK(s3.level().cell(67, 63).tex_or_col == -87);
}
}
std::cout << "[PASS] Authentic sector morphing, Timed/Craft/Rocket triggers & groups verified across all 6 tracks\n";
return 0;
}
+161
View File
@@ -273,5 +273,166 @@ int main() {
CHECK(p1.finished);
}
std::cout << "[PASS] 1-lap autopilot completion verified across all 6 tracks\n";
// 8. 8-direction full-boost ramming stress test across all 6 tracks (0 column/cliff traps)
{
float dt = static_cast<float>(FixedStepClock::kFixedDt);
for (int l = 1; l <= 6; ++l) {
assets::LevelData lvl;
CHECK(lvl.load(vfs, l));
for (const auto& wp : lvl.main_waypoints) {
for (int di = 0; di < 8; ++di) {
float ang = static_cast<float>(di) * (kPi * 0.25f);
sim::CraftState c;
c.id = 0;
c.vehicle_idx = 0;
c.curr_pose.pos = Vec3(wp.x, lvl.sample_height_world(wp.x, wp.z) + 0.30f, wp.z);
c.curr_pose.yaw = ang;
c.prev_pose = c.curr_pose;
c.vel = Vec3(std::sin(ang) * 22.0f, 0.0f, std::cos(ang) * 22.0f);
c.fuel = c.max_fuel = 100.0f;
c.shield = c.max_shield = 100.0f;
CraftInput in;
in.throttle = 1.0f;
in.boost = true;
for (int t = 0; t < 150; ++t) {
sim::step_craft_physics(c, in, lvl, dt, false);
const Vec3& p = c.curr_pose.pos;
int ix = static_cast<int>(std::floor(p.x));
int iz = static_cast<int>(std::floor(p.z));
CHECK(ix >= 0 && ix < assets::kMapWidth && iz >= 0 && iz < assets::kMapHeight);
const auto& me = lvl.cell(ix, iz);
if (me.tex_or_col < 0 && -me.tex_or_col > 0 && -me.tex_or_col < assets::kMaxColumns) {
const auto& col = lvl.columns[-me.tex_or_col];
float gy = lvl.sample_height_world(p.x, p.z);
for (int s = 0; s < 8; ++s) {
if ((col.shape_mask & (1u << s)) == 0) continue;
float sb = gy + static_cast<float>(s);
float st = sb + 1.0f;
CHECK(!(sb <= p.y + 0.35f && st >= p.y - 0.02f));
}
}
if (!c.airborne && p.y <= lvl.sample_height_world(p.x, p.z) + 0.55f) {
Vec3 sn = lvl.sample_normal_world(p.x, p.z);
CHECK(sn.y >= 0.30f);
}
}
}
}
}
}
std::cout << "[PASS] 8-direction boost ramming stress test: 0 texture/cliff traps across all 6 tracks\n";
// 9. Targeted containment, bridge deck, cliff, and escape edge cases
{
float dt = static_cast<float>(FixedStepClock::kFixedDt);
// 9a. Sloped column containment on Level 5 (56, 16) (M1, dh=2.50)
assets::LevelData lvl5;
CHECK(lvl5.load(vfs, 5));
{
sim::CraftState c;
c.id = 0;
c.vehicle_idx = 0;
c.curr_pose.pos = Vec3(56.5f, lvl5.sample_height_world(56.5f, 17.6f) + 0.28f, 17.6f);
c.curr_pose.yaw = kPi;
c.prev_pose = c.curr_pose;
c.vel = Vec3(0.0f, 0.0f, -14.0f);
c.fuel = c.max_fuel = 100.0f;
CraftInput in;
in.throttle = 1.0f;
for (int t = 0; t < 30; ++t) {
sim::step_craft_physics(c, in, lvl5, dt, false);
int ix = static_cast<int>(std::floor(c.curr_pose.pos.x));
int iz = static_cast<int>(std::floor(c.curr_pose.pos.z));
CHECK(!(ix == 56 && iz == 16 &&
lvl5.is_cell_solid_at_point(ix, iz, c.curr_pose.pos.x, c.curr_pose.pos.z,
c.curr_pose.pos.y)));
}
}
// 9b. Overpass bridge deck support on Level 2 (M2), Level 3 (M6), and Level 6 (M2)
struct BridgeCase { int lvl_num; float wx; float wz; float top_offset; };
const BridgeCase bcases[3] = {
{2, 77.5f, 6.5f, 2.0f},
{3, 109.5f, 90.5f, 3.0f},
{6, 90.5f, 32.5f, 2.0f},
};
for (const auto& bc : bcases) {
assets::LevelData blvl;
CHECK(blvl.load(vfs, bc.lvl_num));
float gy = blvl.sample_height_world(bc.wx, bc.wz);
float deck_y = gy + bc.top_offset;
float floor_y = 0.0f, ceil_y = 1e6f;
blvl.sample_surface_and_ceiling(bc.wx, bc.wz, deck_y + 0.28f, floor_y, ceil_y);
CHECK(floor_y >= deck_y - 0.02f);
sim::CraftState c;
c.id = 0;
c.vehicle_idx = 0;
c.curr_pose.pos = Vec3(bc.wx, deck_y + 0.28f, bc.wz);
c.prev_pose = c.curr_pose;
c.fuel = c.max_fuel = 100.0f;
CraftInput neutral{};
for (int t = 0; t < 15; ++t) {
sim::step_craft_physics(c, neutral, blvl, dt, false);
}
CHECK(c.curr_pose.pos.y >= deck_y + 0.14f);
}
// 9c. Sheer terrain cliff blocking (Level 1 z=58..59) vs downhill drop clearance (Level 5 (22,99))
{
sim::CraftState cliff_car;
cliff_car.id = 0;
cliff_car.vehicle_idx = 0;
cliff_car.curr_pose.pos = Vec3(28.5f, lvl1.sample_height_world(28.5f, 57.5f) + 0.28f, 57.5f);
cliff_car.curr_pose.yaw = 0.0f;
cliff_car.prev_pose = cliff_car.curr_pose;
cliff_car.vel = Vec3(0.0f, 0.0f, 14.0f);
cliff_car.fuel = cliff_car.max_fuel = 100.0f;
CraftInput in;
in.throttle = 1.0f;
for (int t = 0; t < 40; ++t) {
sim::step_craft_physics(cliff_car, in, lvl1, dt, false);
}
CHECK(cliff_car.curr_pose.pos.z < 58.65f);
CHECK(cliff_car.curr_pose.pos.y < 1.0f);
sim::CraftState drop_car;
drop_car.id = 0;
drop_car.vehicle_idx = 0;
drop_car.curr_pose.pos = Vec3(22.5f, lvl5.sample_height_world(22.5f, 101.0f) + 0.28f, 101.0f);
drop_car.curr_pose.yaw = kPi;
drop_car.prev_pose = drop_car.curr_pose;
drop_car.vel = Vec3(0.0f, 0.0f, -14.0f);
drop_car.fuel = drop_car.max_fuel = 100.0f;
for (int t = 0; t < 40; ++t) {
sim::step_craft_physics(drop_car, in, lvl5, dt, false);
}
CHECK(drop_car.curr_pose.pos.z < 97.5f);
}
// 9d. Guaranteed escape from inside a solid 3x3 building block
for (int z = 30; z <= 32; ++z) {
for (int x = 30; x <= 32; ++x) {
syn.cell_mut(x, z).tex_or_col = -1;
}
}
sim::CraftState trapped;
trapped.id = 0;
trapped.vehicle_idx = 0;
trapped.curr_pose.pos = Vec3(31.5f, 0.28f, 31.5f);
trapped.prev_pose = trapped.curr_pose;
float imp = 0.0f;
bool scr = false;
CHECK(sim::resolve_world_collisions(trapped, syn, imp, scr));
CHECK(std::isfinite(trapped.curr_pose.pos.x) && std::isfinite(trapped.curr_pose.pos.z));
CHECK(!syn.is_cell_solid_at_point(static_cast<int>(std::floor(trapped.curr_pose.pos.x)),
static_cast<int>(std::floor(trapped.curr_pose.pos.z)),
trapped.curr_pose.pos.x, trapped.curr_pose.pos.z,
trapped.curr_pose.pos.y));
}
std::cout << "[PASS] Sloped column, overpass deck, cliff wall, downhill drop & escape verified\n";
return 0;
}
+36
View File
@@ -82,6 +82,42 @@ int main() {
// Verify partial morph region update stays valid
render::update_terrain_region(lvl, 10, 80, 15, 85, geo.terrain_verts);
if (l == 6) {
// Remove 39 solid columns at (44..57, 50..55) using morph id=140 source cells
assets::LevelData morphed = lvl;
for (int oz = 0; oz <= 5; ++oz) {
for (int ox = 0; ox <= 13; ++ox) {
morphed.cell_mut(44 + ox, 50 + oz) = lvl.cell(31 + ox, 41 + oz);
}
}
std::vector<render::WorldVertex> mverts;
std::vector<uint32_t> mindices;
render::rebuild_column_geometry(morphed, mverts, mindices);
CHECK(mindices.size() < geo.column_indices.size());
CHECK(!mverts.empty() && mindices.size() % 6 == 0);
for (const auto& v : mverts) {
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
}
CHECK(check_winding(mverts, mindices, false));
// Also verify bidirectional swap relocates column vertices cleanly with valid winding
assets::LevelData swapped = lvl;
for (int oz = 0; oz <= 5; ++oz) {
for (int ox = 0; ox <= 13; ++ox) {
auto dc = lvl.cell(44 + ox, 50 + oz);
auto sc = lvl.cell(31 + ox, 41 + oz);
swapped.cell_mut(44 + ox, 50 + oz) = sc;
swapped.cell_mut(31 + ox, 41 + oz) = dc;
}
}
render::rebuild_column_geometry(swapped, mverts, mindices);
CHECK(!mverts.empty() && mindices.size() == geo.column_indices.size());
CHECK(check_winding(mverts, mindices, false));
}
std::cout << " Level " << l << " geo: terrain_tris=" << geo.terrain_indices.size() / 3
<< " column_tris=" << geo.column_indices.size() / 3 << "\n";
}