Add track recovery, fix Arctic Land bridge & 9-map sim/render, harden security & optimize runtime

- Add manual track recovery (R / Backspace / Gamepad Back), document controls in README.md, fix Track 8 (Arctic Land) bridge jump/clearance physics, and fix Track 5 respawn invincibility & Track 6 off-track AI recovery across all 9 maps
- Verify 9-map sector morphing, combat (swept projectiles/LOS), pitstop chargers, and overpass/bridge surface sampling
- Fix Overpass Bottom (-Y) diagonal split and AO, add TerrainChunk frustum culling, O(1) 3D Classic uPaletteLut, atlas gutter/bleed UVs, cached uniform locations, and reusable render scratch buffers
- Harden VFS path traversal, RNC decompression bombs/truncated headers, asset/WAV parsers, GameConfig, save loaders, CLI args, and FLIC lifecycle
- Optimize 48 kHz OPL3/SoundFont synthesis (trig LUTs, cached envelopes/filters), 64-bit XMI ticks, and audio parameter/thread safety
- Add security, rendering, physics, and gameplay regression tests across all test suites
This commit is contained in:
Luxferre committed 2026-12-01 18:50:29 +02:00
1 parent 5c2ac8e70f
commit db788a2739
50 files changed
+3522 -1100

No files matched your search

+98
View File
@@ -15,7 +15,9 @@
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
#include <optional>
using namespace top_octane;
@@ -386,5 +388,101 @@ int main() {
std::cout << "[PASS] Vfs relocatable & XDG data directory lookup validated\n";
}
// 9. GameConfig recovery keybindings defaults & persistence round-trip
{
GameConfig def_cfg;
CHECK(def_cfg.keys.recover == 21);
CHECK(def_cfg.keys.p2_recover == 42);
std::filesystem::path tmp_ini = std::filesystem::temp_directory_path() / "top_octane_test_config.ini";
std::filesystem::remove(tmp_ini);
GameConfig saved_cfg;
saved_cfg.keys.recover = 29; // Z
saved_cfg.keys.p2_recover = 76; // Delete
CHECK(saved_cfg.save(tmp_ini));
GameConfig loaded_cfg;
CHECK(loaded_cfg.load(tmp_ini));
CHECK(loaded_cfg.keys.recover == 29);
CHECK(loaded_cfg.keys.p2_recover == 76);
std::filesystem::remove(tmp_ini);
std::cout << "[PASS] GameConfig keybinding persistence validated\n";
}
// 10. Security hardening (VFS traversal, RNC1/RNC2 bombs & truncation, WAV, corrupt config)
{
std::vector<uint8_t> tmp_buf;
CHECK(!vfs.exists("../Makefile"));
CHECK(!vfs.exists("/etc/passwd"));
CHECK(!vfs.read_file("../Makefile", tmp_buf));
CHECK(!vfs.read_file("/etc/passwd", tmp_buf));
// RNC1 bomb (> 32 MiB) & truncated RNC1/RNC2 headers
const std::vector<uint8_t> rnc1_bomb = {
'R', 'N', 'C', 1, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0, 0, 0, 0, 0, 0
};
const std::vector<uint8_t> rnc1_trunc = {
'R', 'N', 'C', 1, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x10, 0, 0
};
const std::vector<uint8_t> rnc2_bomb = {
'R', 'N', 'C', 2, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0, 0, 0, 0, 0, 0
};
const std::vector<uint8_t> rnc2_trunc = {
'R', 'N', 'C', 2, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x04, 0, 0, 0, 0, 0, 0
};
CHECK(!rnc_unpack(rnc1_bomb, tmp_buf));
CHECK(!rnc_unpack(rnc1_trunc, tmp_buf));
CHECK(!rnc_unpack(rnc2_bomb, tmp_buf));
CHECK(!rnc_unpack(rnc2_trunc, tmp_buf));
// Invalid WAV / empty buffers
SoundSample bad_wav_out;
const std::vector<uint8_t> garbage_wav = {'R', 'I', 'F', 'F', 12, 0, 0, 0, 'W', 'A', 'V', 'E'};
CHECK(!decode_wav_bytes(nullptr, 0, bad_wav_out));
CHECK(!decode_wav_bytes(garbage_wav.data(), garbage_wav.size(), bad_wav_out));
// Corrupt GameConfig (NaN/Inf/out-of-range/path-traversal) rejected/sanitized cleanly
std::filesystem::path bad_ini = std::filesystem::temp_directory_path() / "top_octane_bad_cfg.ini";
{
std::ofstream ofs(bad_ini);
ofs << "fov_deg = nan\n"
<< "draw_distance = inf\n"
<< "master_volume = -inf\n"
<< "key_recover = -9\n"
<< "key_p2_recover = 99999\n"
<< "custom_soundfont_path = ../evil.sf2\n";
}
GameConfig bad_cfg;
CHECK(bad_cfg.load(bad_ini));
CHECK(std::isfinite(bad_cfg.fov_deg) && bad_cfg.fov_deg >= 50.0f && bad_cfg.fov_deg <= 105.0f);
CHECK(std::isfinite(bad_cfg.draw_distance) && bad_cfg.draw_distance >= 30.0f);
CHECK(std::isfinite(bad_cfg.master_volume) && bad_cfg.master_volume >= 0.0f && bad_cfg.master_volume <= 1.0f);
CHECK(bad_cfg.keys.recover == 21);
CHECK(bad_cfg.keys.p2_recover == 42);
CHECK(bad_cfg.custom_soundfont_path.empty());
std::filesystem::remove(bad_ini);
std::cout << "[PASS] VFS traversal, RNC bombs, invalid WAV & corrupt GameConfig hardening validated\n";
}
// 11. LevelData::sample_entity_surface_y on L6 skybridge, L8 bridge/archway, L9 alcove
{
LevelData lvl6, lvl8, lvl9;
CHECK(lvl6.load(vfs, 6));
CHECK(lvl8.load(vfs, 8));
CHECK(lvl9.load(vfs, 9));
CHECK(lvl6.sample_entity_surface_y(90.5f, 39.5f) >= 2.9f);
CHECK(lvl6.sample_entity_surface_y(87.5f, 39.5f) >= 2.9f);
CHECK(lvl8.sample_entity_surface_y(75.5f, 70.5f) >= 1.9f);
CHECK(lvl8.sample_entity_surface_y(46.5f, 19.5f) < 0.5f);
CHECK(lvl9.sample_entity_surface_y(10.0f, 88.0f) < 0.8f);
std::cout << "[PASS] LevelData::sample_entity_surface_y bridge/archway/alcove heights validated\n";
}
return 0;
}
+228
View File
@@ -10,6 +10,7 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
using namespace top_octane;
@@ -1082,5 +1083,232 @@ int main() {
}
std::cout << "[PASS] All 9 tracks 8-racer AI anti-stuck & progression validated\n";
// 12. Manual Track Recovery from pit, HUD stuck hint, anti-exploit, and SplitScreen P2
{
sim::RaceSetup rs;
rs.mode = sim::GameMode::SingleRace;
rs.track_number = 1;
rs.num_ai = 0;
rs.fuel_enabled = true;
sim::RaceSim rsim;
CHECK(rsim.start_race(lvl1, rs));
// Still in countdown -> cannot trigger manual recovery
CHECK(!rsim.request_track_recovery(0));
for (int t = 0; t < 200; ++t) rsim.step(CraftInput{}, CraftInput{}, dt);
auto& p1 = rsim.crafts_mut()[0];
p1.curr_pose.pos = Vec3(32.5f, lvl1.sample_height_world(32.5f, 57.5f) + 0.28f, 57.5f);
p1.curr_pose.yaw = kHalfPi;
p1.prev_pose = p1.curr_pose;
p1.vel = Vec3(0.0f, 0.0f, 0.0f);
p1.next_checkpoint = 1;
p1.shield = p1.max_shield * 0.50f;
p1.ammo = p1.max_ammo * 0.40f;
p1.fuel = 42.0f;
// Driving trapped inside pit triggers HUD stuck hint after ~2.0s
CraftInput drive_fwd;
drive_fwd.throttle = 1.0f;
for (int t = 0; t < 135; ++t) rsim.step(drive_fwd, CraftInput{}, dt);
CHECK(p1.curr_pose.pos.y < 0.0f);
CHECK(p1.stuck_in_pit_hint);
const float pre_shield = p1.shield;
const float pre_ammo = p1.ammo;
const float pre_fuel = p1.fuel;
// Press manual recover key
rsim.clear_events();
CraftInput rec_in;
rec_in.recover_pressed = true;
rsim.step(rec_in, CraftInput{}, dt);
CHECK(p1.recovery_state == sim::RecoveryState::CallingRepair);
CHECK(!p1.recovery_refill);
CHECK(!p1.stuck_in_pit_hint);
CHECK(!sim::get_recovery_visuals(rsim.crafts()).empty());
bool saw_recovery_banner = false;
for (const auto& ev : rsim.events()) {
if (ev.banner_text == "CALLING RECOVERY") saw_recovery_banner = true;
}
CHECK(saw_recovery_banner);
// Wait ~1.75s for manual recovery sequence (1.6s) to complete
for (int t = 0; t < 105; ++t) rsim.step(CraftInput{}, CraftInput{}, dt);
CHECK(p1.recovery_state == sim::RecoveryState::Active);
CHECK(p1.deaths == 0);
CHECK(p1.curr_pose.pos.y > 0.0f);
CHECK(p1.curr_pose.pos.x < 25.0f);
CHECK(p1.next_checkpoint == 1);
CHECK(!p1.stuck_in_pit_hint);
int px = static_cast<int>(std::floor(p1.curr_pose.pos.x));
int pz = static_cast<int>(std::floor(p1.curr_pose.pos.z));
CHECK(!lvl1.is_cell_solid_at_point(px, pz, p1.curr_pose.pos.x,
p1.curr_pose.pos.z, p1.curr_pose.pos.y));
CHECK(!lvl1.is_cliff_blocking_at_y(px, pz, p1.curr_pose.pos.y));
// Resources were not freely topped off (anti-exploit)
CHECK(std::abs(p1.shield - pre_shield) < 0.01f);
CHECK(std::abs(p1.ammo - pre_ammo) < 0.01f);
CHECK(p1.fuel <= pre_fuel + 0.01f);
CHECK(p1.fuel < p1.max_fuel * 0.6f);
// Cooldown prevents instant spam right after recovery completes
CHECK(p1.recovery_cooldown > 0.5f);
rsim.step(rec_in, CraftInput{}, dt);
CHECK(p1.recovery_state == sim::RecoveryState::Active);
// Finished craft cannot recover
p1.finished = true;
CHECK(!rsim.request_track_recovery(0));
// SplitScreen P2 manual recovery & emergency minimal fuel floor (<5 -> 8)
sim::RaceSetup ss;
ss.mode = sim::GameMode::SplitScreen;
ss.track_number = 1;
ss.num_ai = 0;
ss.fuel_enabled = true;
sim::RaceSim ssim;
CHECK(ssim.start_race(lvl1, ss));
for (int t = 0; t < 200; ++t) ssim.step(CraftInput{}, CraftInput{}, dt);
auto& s_p2 = ssim.crafts_mut()[1];
s_p2.curr_pose.pos = Vec3(32.5f, lvl1.sample_height_world(32.5f, 57.5f) + 0.28f, 57.5f);
s_p2.prev_pose = s_p2.curr_pose;
s_p2.next_checkpoint = 1;
s_p2.fuel = 1.0f;
ssim.step(CraftInput{}, rec_in, dt);
CHECK(s_p2.recovery_state == sim::RecoveryState::CallingRepair);
for (int t = 0; t < 110; ++t) ssim.step(CraftInput{}, CraftInput{}, dt);
CHECK(s_p2.recovery_state == sim::RecoveryState::Active);
CHECK(s_p2.curr_pose.pos.y > 0.0f);
CHECK(s_p2.curr_pose.pos.x < 25.0f);
CHECK(s_p2.fuel >= 5.0f && s_p2.fuel < 15.0f);
CHECK(ssim.request_track_recovery(0));
}
std::cout << "[PASS] Manual Track Recovery from pit, stuck prompt, anti-exploit & SplitScreen P2 validated\n";
// 13. Step dt safety, Track 6 off-track AI recovery, DamageCraft & Level 9 morph & save fuzzing
{
// 13a. RaceSim::step ignores dt <= 0 and NaN cleanly
sim::RaceSetup rs;
rs.mode = sim::GameMode::SingleRace;
rs.track_number = 1;
rs.num_ai = 1;
sim::RaceSim sim0;
CHECK(sim0.start_race(lvl1, rs));
for (int t = 0; t < 200; ++t) sim0.step(CraftInput{}, CraftInput{}, dt);
const Vec3 p_before = sim0.crafts()[0].curr_pose.pos;
sim0.step(CraftInput{0.5f, 1.0f}, CraftInput{}, 0.0f);
sim0.step(CraftInput{0.5f, 1.0f}, CraftInput{}, -0.1f);
sim0.step(CraftInput{0.5f, 1.0f}, CraftInput{}, std::numeric_limits<float>::quiet_NaN());
CHECK((sim0.crafts()[0].curr_pose.pos - p_before).len_sq() < 1e-8f);
// 13b. AI circling behind Track 6 perimeter berm recovers via ai_wp_stall_timer in < 10s
assets::LevelData lvl6;
CHECK(lvl6.load(vfs, 6));
sim::RaceSetup rs6;
rs6.mode = sim::GameMode::SingleRace;
rs6.track_number = 6;
rs6.num_ai = 1;
sim::RaceSim sim6;
CHECK(sim6.start_race(lvl6, rs6));
sim6.crafts_mut()[0].autopilot = true;
for (int t = 0; t < 200; ++t) sim6.step(CraftInput{}, CraftInput{}, dt);
auto& ai6 = sim6.crafts_mut()[1];
ai6.curr_pose.pos = Vec3(78.0f, lvl6.sample_height_world(78.0f, 15.0f) + 0.25f, 15.0f);
ai6.prev_pose = ai6.curr_pose;
ai6.vel = Vec3(5.0f, 0.0f, 0.0f);
ai6.current_wp = 0;
ai6.ai_target_wp = 1;
ai6.next_checkpoint = 1;
ai6.ai_stuck_timer = 0.0f;
ai6.ai_progress_timer = 0.0f;
ai6.ai_wp_stall_timer = 0.0f;
ai6.ai_wp_best_dist = 1e9f;
bool recovered = false;
for (int t = 0; t < 600; ++t) {
sim6.step(CraftInput{}, CraftInput{}, dt);
if (ai6.checkpoints_passed >= 1 || ai6.curr_pose.pos.x > 84.0f || ai6.curr_pose.pos.z < 10.0f) {
recovered = true;
break;
}
}
CHECK(recovered);
// 13c. Invincible craft takes zero weapon/barrel damage & never heals from negative damage
{
std::vector<sim::CraftState> cvec(2);
cvec[0].id = 0; cvec[0].recovery_state = sim::RecoveryState::Active;
cvec[0].curr_pose.pos = Vec3(10.0f, lvl1.sample_height_world(10.0f, 10.0f) + 0.25f, 10.0f);
cvec[0].prev_pose = cvec[0].curr_pose;
cvec[0].shield = 25.0f; cvec[0].max_shield = 100.0f;
cvec[0].invincible_timer = 3.0f;
cvec[1].id = 1; cvec[1].recovery_state = sim::RecoveryState::Active;
cvec[1].curr_pose.pos = cvec[0].curr_pose.pos + Vec3(0.0f, 0.0f, -2.0f);
cvec[1].prev_pose = cvec[1].curr_pose;
std::vector<sim::Projectile> pjs;
sim::Projectile prj;
prj.active = true; prj.owner_id = 1; prj.damage = 40.0f;
prj.pos = cvec[0].curr_pose.pos + Vec3(0.0f, 0.0f, -0.5f);
prj.vel = Vec3(0.0f, 0.0f, 60.0f);
pjs.push_back(prj);
std::vector<sim::PickupItem> pks;
std::vector<sim::PropObject> prs;
std::vector<sim::ParticleBurst> pts;
std::vector<sim::SimEvent> evs;
std::vector<CraftInput> ins(2);
bool ro = false;
int wid = -1;
sim::step_combat_and_world(rs, lvl1, cvec, ins, pjs, pks, prs, pts, evs, ro, wid, dt);
CHECK(std::abs(cvec[0].shield - 25.0f) < 1e-4f);
}
// 13d. Level 9 st=23 grp=1 permanent morph does not auto-activate and blank arena cells
assets::LevelData lvl9;
CHECK(lvl9.load(vfs, 9));
sim::RaceSetup rs9;
rs9.mode = sim::GameMode::DeathMatch;
rs9.track_number = 9;
rs9.num_ai = 3;
sim::RaceSim sim9;
CHECK(sim9.start_race(lvl9, rs9));
for (int t = 0; t < 600; ++t) sim9.step(CraftInput{}, CraftInput{}, dt);
int nontriv_arena_cells = 0;
for (const auto& pad : sim9.level().pads) {
int cx = static_cast<int>(std::floor(pad.cx));
int cz = static_cast<int>(std::floor(pad.cz));
const auto& cell = sim9.level().cell(cx, cz);
if (cell.tex_or_col != 0) ++nontriv_arena_cells;
}
CHECK(nontriv_arena_cells == static_cast<int>(sim9.level().pads.size()));
// 13e. Corrupt/malformed save files safely rejected without mutating valid state
std::filesystem::path bad_dir = std::filesystem::temp_directory_path() / "top_octane_bad_saves";
std::filesystem::create_directories(bad_dir);
{
std::ofstream ofs(bad_dir / "hiscores.dat");
ofs << "HIOCTANE_HISCORES_V2\n"
<< "TRACK 1 nan 1 DEADFISH 999\n";
}
game::HighscoreTable ht;
ht.load(bad_dir / "hiscores.dat");
for (const auto& rec : ht.tracks) {
CHECK(std::isfinite(rec.best_lap));
CHECK(std::isfinite(rec.best_race));
}
{
std::ofstream ofs(bad_dir / "clone_t1.dat");
ofs << "INVALID_MAGIC 1 -9 99 nan 9999999\n";
}
sim::CloneRecording cre;
CHECK(!game::load_clone_recording(bad_dir, 1, cre));
std::filesystem::remove_all(bad_dir);
std::cout << "[PASS] Gameplay dt/AI-basin/invincible/Level9-morph & save hardening validated\n";
}
return 0;
}
+144
View File
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
using namespace top_octane;
@@ -271,6 +272,9 @@ int main() {
std::cout << " Track " << l << " 1-lap autopilot: finished=" << p1.finished
<< " time=" << p1.race_time << "s\n";
CHECK(p1.finished);
if (l == 8) {
CHECK(p1.race_time < 45.0f);
}
}
std::cout << "[PASS] 1-lap autopilot completion verified across all 9 tracks\n";
@@ -479,5 +483,145 @@ int main() {
CHECK(cruise[3] - cruise[2] >= 8.5f); // Vampyr vs Jugga
std::cout << "[PASS] Vehicle top speeds & boost velocities strictly differentiate all 6 crafts\n";
}
// 11. Track recovery placement from deep pit & under overhead tunnel ceiling
{
assets::LevelData lvl1, lvl2;
CHECK(lvl1.load(vfs, 1));
CHECK(lvl2.load(vfs, 2));
// 11a. Pit trap in Level 1 (32.5, 57.5) between cp 0 and cp 1 stays on outbound leg (x < 25, y > 0)
sim::CraftState pit_car;
pit_car.id = 0;
pit_car.vehicle_idx = 0;
pit_car.next_checkpoint = 1;
pit_car.curr_pose.pos = Vec3(32.5f, lvl1.sample_height_world(32.5f, 57.5f) + 0.28f, 57.5f);
pit_car.prev_pose = pit_car.curr_pose;
pit_car.vel = Vec3(3.0f, -2.0f, 1.0f);
pit_car.wrong_way = true;
std::vector<sim::CraftState> peers{pit_car};
CHECK(sim::place_craft_on_track(pit_car, lvl1, peers, true));
CHECK(pit_car.curr_pose.pos.y > 0.0f);
CHECK(pit_car.curr_pose.pos.x < 25.0f);
CHECK(pit_car.vel.len() < 1e-4f);
CHECK(!pit_car.wrong_way);
int ix = static_cast<int>(std::floor(pit_car.curr_pose.pos.x));
int iz = static_cast<int>(std::floor(pit_car.curr_pose.pos.z));
CHECK(!lvl1.is_cell_solid_at_point(ix, iz, pit_car.curr_pose.pos.x,
pit_car.curr_pose.pos.z, pit_car.curr_pose.pos.y));
CHECK(!lvl1.is_cliff_blocking_at_y(ix, iz, pit_car.curr_pose.pos.y));
// 11b. High-Y craft above Level 2 tunnel waypoint (126.5, 23.5) recovers on road beneath roof
float gy2 = lvl2.sample_height_world(126.5f, 23.5f);
sim::CraftState tun_car;
tun_car.id = 0;
tun_car.vehicle_idx = 0;
tun_car.next_checkpoint = 1;
tun_car.curr_pose.pos = Vec3(126.5f, gy2 + 5.0f, 23.5f);
tun_car.prev_pose = tun_car.curr_pose;
std::vector<sim::CraftState> peers2{tun_car};
CHECK(sim::place_craft_on_track(tun_car, lvl2, peers2, true));
float road_y2 = lvl2.sample_height_world(tun_car.curr_pose.pos.x, tun_car.curr_pose.pos.z);
CHECK(tun_car.curr_pose.pos.y < road_y2 + 0.60f);
CHECK(tun_car.curr_pose.pos.y >= road_y2 + 0.14f);
std::cout << "[PASS] Track placement from pit & tunnel clearance verified\n";
}
// 12. Track 8 (Arctic Land) ramp jump & bridge deck clearance across all 6 vehicles
{
assets::LevelData lvl8;
CHECK(lvl8.load(vfs, 8));
const float dt = static_cast<float>(FixedStepClock::kFixedDt);
const float jump_yaw = std::atan2(90.5f - 56.0f, 70.5f - 69.5f);
auto run_bridge_jump = [&](int veh_idx, float start_x, float start_spd, int max_ticks) -> int {
sim::CraftState c;
c.id = 0;
c.vehicle_idx = veh_idx;
c.curr_pose.pos = Vec3(start_x, lvl8.sample_height_world(start_x, 69.5f) + sim::kVehicleSpecs[veh_idx].hover_offset, 69.5f);
c.curr_pose.yaw = jump_yaw;
c.prev_pose = c.curr_pose;
c.vel = Vec3(std::sin(jump_yaw) * start_spd, 0.0f, std::cos(jump_yaw) * start_spd);
c.fuel = c.max_fuel = 100.0f;
CraftInput in;
in.throttle = 1.0f;
float max_y = c.curr_pose.pos.y;
float min_y_over_gap = 1e6f;
for (int t = 0; t < max_ticks && c.curr_pose.pos.x < 79.0f; ++t) {
sim::step_craft_physics(c, in, lvl8, dt, false);
max_y = std::max(max_y, c.curr_pose.pos.y);
if (c.curr_pose.pos.x >= 68.0f && c.curr_pose.pos.x <= 77.5f) {
min_y_over_gap = std::min(min_y_over_gap, c.curr_pose.pos.y);
}
}
CHECK(c.curr_pose.pos.x >= 78.5f);
CHECK(max_y >= 2.15f);
CHECK(min_y_over_gap >= 1.40f);
return 0;
};
for (int v = 0; v < 6; ++v) {
CHECK(run_bridge_jump(v, 56.0f, sim::kVehicleSpecs[v].top_speed, 160) == 0);
}
// Slowest craft (Jugga, v=2) accelerating from dead stop right at wp[43] (65.5, 69.5)
CHECK(run_bridge_jump(2, 65.5f, 0.0f, 180) == 0);
std::cout << "[PASS] Track 8 (Arctic Land) bridge jump clearance verified for all 6 vehicles\n";
}
// 13. Non-finite/non-positive dt safety + elevated deck pitch & tunnel ceiling re-clamp
{
assets::LevelData lvl2, lvl8;
CHECK(lvl2.load(vfs, 2));
CHECK(lvl8.load(vfs, 8));
sim::CraftState c;
c.id = 0;
c.vehicle_idx = 0;
const Vec3 start_pos(75.5f, 2.25f, 70.5f);
c.curr_pose.pos = start_pos;
c.prev_pose = c.curr_pose;
c.vel = Vec3(8.0f, 0.0f, 0.0f);
c.fuel = c.max_fuel = 100.0f;
CraftInput drive;
drive.throttle = 1.0f;
drive.steer = 0.5f;
sim::step_craft_physics(c, drive, lvl8, 0.0f, true);
CHECK((c.curr_pose.pos - start_pos).len_sq() < 1e-8f);
sim::step_craft_physics(c, drive, lvl8, -1.0f, true);
CHECK((c.curr_pose.pos - start_pos).len_sq() < 1e-8f);
sim::step_craft_physics(c, drive, lvl8, std::numeric_limits<float>::quiet_NaN(), true);
CHECK(std::isfinite(c.curr_pose.pos.x) && std::isfinite(c.curr_pose.pos.y) && std::isfinite(c.curr_pose.pos.z));
CHECK((c.curr_pose.pos - start_pos).len_sq() < 1e-8f);
// Elevated bridge deck ride stability & smooth pitch
const float dt = static_cast<float>(FixedStepClock::kFixedDt);
for (int t = 0; t < 5; ++t) {
sim::step_craft_physics(c, drive, lvl8, dt, false);
}
CHECK(std::isfinite(c.curr_pose.pitch) && std::isfinite(c.curr_pose.roll));
CHECK(c.curr_pose.pos.y >= 1.9f);
// Tunnel ceiling re-clamp on Level 2 (126.5, 23.5)
float road_y2 = lvl2.sample_height_world(126.5f, 23.5f);
float fy = 0.0f, cy = 1e6f;
lvl2.sample_surface_and_ceiling(126.5f, 23.5f, road_y2 + 0.30f, fy, cy);
CHECK(cy < 1e5f);
sim::CraftState tun;
tun.id = 1;
tun.vehicle_idx = 0;
tun.curr_pose.pos = Vec3(126.5f, cy - 0.10f, 23.5f);
tun.prev_pose = tun.curr_pose;
tun.vel = Vec3(0.0f, 5.0f, 0.0f);
float dummy_imp = 0.0f;
bool dummy_scr = false;
sim::resolve_world_collisions(tun, lvl2, dummy_imp, dummy_scr);
CHECK(tun.curr_pose.pos.y <= cy - 0.45f);
CHECK(tun.vel.y <= 0.0f);
std::cout << "[PASS] Physics dt safety, bridge deck attitude & tunnel ceiling re-clamp verified\n";
}
return 0;
}
+73 -1
View File
@@ -6,6 +6,7 @@
#include "render/world_geometry.hpp"
#include "sim/vehicle_defs.hpp"
#include <algorithm>
#include <cmath>
#include <iostream>
@@ -165,13 +166,20 @@ int main() {
CHECK(check_range(281, 286));
}
// Verify 3D model GPU geometry conversion
// Verify 3D model GPU geometry conversion & TEX0-0 half-texel UV inset
assets::ObjectTextureAtlas atlas;
CHECK(atlas.load(vfs, pal));
const char* keys[] = {"CAR0-0", "TANK0-0", "JUGGA0-0", "JET0-0", "BIKE0-0", "SKIM0-0", "RECOV0-0"};
for (const char* k : keys) {
assets::ModelMesh mesh;
CHECK(mesh.load(vfs, std::string("OBJECTS/DATA/") + k + ".DAT", &atlas));
for (const auto& tri : mesh.triangles) {
if (!tri.textured) continue;
for (int c = 0; c < 3; ++c) {
CHECK(tri.u[c] > 0.0f && tri.u[c] < 1.0f);
CHECK(tri.v_coord[c] > 0.0f && tri.v_coord[c] < 1.0f);
}
}
render::ModelGeometry mg = render::build_model_geometry(mesh, pal);
CHECK(!mg.verts.empty());
CHECK(mg.indices.size() == mesh.triangles.size() * 3u);
@@ -183,6 +191,70 @@ int main() {
}
}
// Verify Bottom (-Y) overpass diagonal split, TerrainChunk AABBs & update bounds
{
assets::LevelData lvl8;
CHECK(lvl8.load(vfs, 8));
render::WorldGeometry geo8 = render::build_level_geometry(lvl8);
// 1. 16x16 TerrainChunk AABBs cover every vertex and sum to terrain_indices
const int gw = assets::kMapWidth - 1;
const int gh = assets::kMapHeight - 1;
const int cs = render::WorldGeometry::kTerrainChunkSize;
const int chunks_x = (gw + cs - 1) / cs;
const int chunks_z = (gh + cs - 1) / cs;
CHECK(geo8.terrain_chunks.size() == static_cast<size_t>(chunks_x) * static_cast<size_t>(chunks_z));
size_t total_chunk_idx = 0;
for (const auto& ch : geo8.terrain_chunks) {
CHECK(ch.index_count > 0);
CHECK(ch.first_index + ch.index_count <= geo8.terrain_indices.size());
total_chunk_idx += ch.index_count;
for (uint32_t i = 0; i < ch.index_count; ++i) {
uint32_t vi = geo8.terrain_indices[ch.first_index + i];
const Vec3& p = geo8.terrain_verts[vi].pos;
CHECK(p.x >= ch.min_b.x - 1e-4f && p.x <= ch.max_b.x + 1e-4f);
CHECK(p.y >= ch.min_b.y - 1e-4f && p.y <= ch.max_b.y + 1e-4f);
CHECK(p.z >= ch.min_b.z - 1e-4f && p.z <= ch.max_b.z + 1e-4f);
}
}
CHECK(total_chunk_idx == geo8.terrain_indices.size());
// 2. Refresh bounds reflects terrain height changes cleanly
lvl8.cell_mut(75, 70).height = 4096;
render::update_terrain_region(lvl8, 74, 69, 76, 71, geo8.terrain_verts);
render::refresh_terrain_chunk_bounds(geo8, 74, 69, 76, 71);
const auto& updated_chunk = geo8.terrain_chunks[(70 / cs) * chunks_x + (75 / cs)];
CHECK(updated_chunk.max_b.y >= 2.9f);
// 3. All Bottom (-Y) column quads split along (00)-(11) diagonal matching Top/Terrain
int bottom_quads = 0;
for (size_t i = 0; i + 5 < geo8.column_indices.size(); i += 6) {
const auto& v0 = geo8.column_verts[geo8.column_indices[i + 0]];
if (v0.normal.y > -0.9f) continue;
// For our emitted bottom indices {base+3, base+2, base+1, base+3, base+1, base+0},
// index+0 is p3=(00) and index+2 is p1=(11): shared diagonal has dx*dz > 0.5
const auto& d0 = geo8.column_verts[geo8.column_indices[i + 0]];
const auto& d1 = geo8.column_verts[geo8.column_indices[i + 2]];
CHECK((d1.pos.x - d0.pos.x) * (d1.pos.z - d0.pos.z) > 0.5f);
++bottom_quads;
}
CHECK(bottom_quads > 0);
// 4. Synthetic 2x2 sm=0x02 overpass treats center vertex as overpass (ao=0.88), not solid base (0.72)
assets::LevelData syn;
syn.map.resize(assets::kMapWidth * assets::kMapHeight);
syn.columns[1].shape_mask = 0x02u;
syn.columns[1].blocks[1] = 0;
for (int z = 10; z <= 11; ++z) {
for (int x = 10; x <= 11; ++x) {
syn.cell_mut(x, z).tex_or_col = -1;
}
}
render::WorldGeometry geo_syn = render::build_level_geometry(syn);
const size_t v_base = (static_cast<size_t>(11) * (assets::kMapWidth - 1) + 11) * 4u;
CHECK(std::abs(geo_syn.terrain_verts[v_base].ao - 0.88f) < 1e-4f);
}
std::cout << "[PASS] All 9 Levels & Vehicle 3D Render Geometry validated\n";
return 0;
}