init commit
This commit is contained in:
commit
15ab48343a
187 files changed
+12644
No files matched your search
@@ -0,0 +1,178 @@
|
||||
#include "assets/flic.hpp"
|
||||
#include "assets/level.hpp"
|
||||
#include "assets/model.hpp"
|
||||
#include "assets/music_bank.hpp"
|
||||
#include "assets/palette.hpp"
|
||||
#include "assets/rnc.hpp"
|
||||
#include "assets/sound_bank.hpp"
|
||||
#include "assets/sprites.hpp"
|
||||
#include "assets/textures.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
using namespace top_octane;
|
||||
using namespace top_octane::assets;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
// 1. Palette & ColorTables (0..5)
|
||||
Palette pal;
|
||||
CHECK(pal.load(vfs));
|
||||
CHECK(pal.colors[1].a == 255);
|
||||
for (int w = 0; w < 6; ++w) {
|
||||
ColorTables tbl;
|
||||
CHECK(tbl.load(vfs, w, pal));
|
||||
WorldTextures wtex;
|
||||
CHECK(wtex.load(vfs, w, pal));
|
||||
CHECK(wtex.tile_rgba.size() == 256u * 64u * 64u * 4u);
|
||||
CHECK(wtex.sky_rgba.size() == 256u * 256u * 4u);
|
||||
}
|
||||
std::cout << "[PASS] Palette, 6 ColorTables, 6 WorldTextures & Skies\n";
|
||||
|
||||
// 2. All 6 Levels (decompression, CRC16, entities, columns, blocks, waypoints, checkpoints)
|
||||
for (int l = 1; l <= 6; ++l) {
|
||||
LevelData lvl;
|
||||
CHECK(lvl.load(vfs, l));
|
||||
CHECK(lvl.map.size() == kMapWidth * kMapHeight);
|
||||
CHECK(!lvl.main_waypoints.empty());
|
||||
CHECK(!lvl.checkpoints.empty());
|
||||
CHECK(lvl.checkpoints[0].index == 0);
|
||||
|
||||
// Verify all referenced columns & floor tiles are within valid bounds
|
||||
int col_cells = 0;
|
||||
float min_h = 1e9f, max_h = -1e9f;
|
||||
for (int z = 0; z < kMapHeight; ++z) {
|
||||
for (int x = 0; x < kMapWidth; ++x) {
|
||||
const auto& cell = lvl.cell(x, z);
|
||||
float h = lvl.cell_height_world(x, z);
|
||||
min_h = std::min(min_h, h);
|
||||
max_h = std::max(max_h, h);
|
||||
if (cell.tex_or_col < 0) {
|
||||
int cidx = -cell.tex_or_col;
|
||||
CHECK(cidx > 0 && cidx < kMaxColumns);
|
||||
++col_cells;
|
||||
} else {
|
||||
CHECK(cell.tex_or_col >= 0 && cell.tex_or_col < 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK(col_cells > 0);
|
||||
CHECK(min_h >= -5.0f && max_h <= 5.0f && max_h > min_h);
|
||||
std::cout << " Level " << l << " (" << lvl.name << "): wps=" << lvl.main_waypoints.size()
|
||||
<< " cps=" << lvl.checkpoints.size() << " cols=" << col_cells
|
||||
<< " pickups=" << lvl.pickups.size()
|
||||
<< " h=[" << min_h << ".." << max_h << "]\n";
|
||||
}
|
||||
std::cout << "[PASS] All 6 Levels parsed & validated\n";
|
||||
|
||||
// 3. Object texture atlases & all 3D models in OBJECTS/DATA/
|
||||
ObjectTextureAtlas obj_atlas;
|
||||
CHECK(obj_atlas.load(vfs, pal));
|
||||
CHECK(obj_atlas.entries.size() == 51);
|
||||
CHECK(obj_atlas.height == 768);
|
||||
|
||||
std::filesystem::path obj_dir = vfs.data_root() / "OBJECTS" / "DATA";
|
||||
int model_count = 0;
|
||||
for (const auto& ent : std::filesystem::directory_iterator(obj_dir)) {
|
||||
std::string fn = ent.path().filename().string();
|
||||
if (fn.size() > 4 && fn.rfind(".DAT") == fn.size() - 4 && fn.rfind("TEX", 0) != 0) {
|
||||
ModelMesh mesh;
|
||||
CHECK(mesh.load(vfs, "OBJECTS/DATA/" + fn, &obj_atlas));
|
||||
CHECK(!mesh.vertices.empty());
|
||||
CHECK(!mesh.triangles.empty());
|
||||
for (const auto& tri : mesh.triangles) {
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
CHECK(tri.v[k] < mesh.vertices.size());
|
||||
if (tri.textured) {
|
||||
CHECK(tri.u[k] >= 0.0f && tri.u[k] <= 1.0f);
|
||||
CHECK(tri.v_coord[k] >= 0.0f && tri.v_coord[k] <= 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
++model_count;
|
||||
}
|
||||
}
|
||||
CHECK(model_count >= 60);
|
||||
std::cout << "[PASS] " << model_count << " 3D Models & TEX0-0 Atlas validated\n";
|
||||
|
||||
// 4. 2D Sprites, Fonts & Raw Screens
|
||||
const char* bank_names[] = {"PANEL0-0", "PANEL0-1", "PFONT0-0", "PFONT0-1",
|
||||
"OLFNT0-0", "OLFNT0-1", "OSFNT0-0", "OSFNT0-1",
|
||||
"LOGO0-0", "LOGO0-1", "TRACK0-0", "TRACK0-1"};
|
||||
for (const char* bn : bank_names) {
|
||||
SpriteBank sb;
|
||||
std::string base = std::string("DATA/") + bn;
|
||||
CHECK(sb.load(vfs, base + ".DAT", base + ".TAB", pal));
|
||||
CHECK(!sb.sprites.empty());
|
||||
}
|
||||
SpriteImage title_img, oscr_img, onet_img;
|
||||
CHECK(load_raw_screen(vfs, "DATA/TITLE.DAT", 320, 200, pal, title_img));
|
||||
CHECK(load_raw_screen(vfs, "DATA/OSCR0-1.DAT", 640, 480, pal, oscr_img));
|
||||
CHECK(load_raw_screen(vfs, "DATA/ONET0-1.DAT", 640, 480, pal, onet_img));
|
||||
std::cout << "[PASS] 12 Sprite/Font Banks & 3 Raw Screens validated\n";
|
||||
|
||||
// 5. Optional Intro FLIC movie (all 548 frames when DATA/INTRO.DAT is present)
|
||||
if (vfs.exists("DATA/INTRO.DAT")) {
|
||||
FlicPlayer flic;
|
||||
CHECK(flic.open(vfs));
|
||||
CHECK(flic.width() == 320 && flic.height() == 200);
|
||||
CHECK(flic.num_frames() == 548);
|
||||
int decoded_frames = 0;
|
||||
while (flic.step_frame()) {
|
||||
++decoded_frames;
|
||||
}
|
||||
CHECK(decoded_frames == 548);
|
||||
std::cout << "[PASS] Intro FLIC decoded all " << decoded_frames << " frames\n";
|
||||
} else {
|
||||
std::cout << "[INFO] Optional DATA/INTRO.DAT not present; skipping intro FLIC check\n";
|
||||
}
|
||||
|
||||
// 6. SOUND.DAT (35 gameplay + 14 intro WAVs)
|
||||
SoundBank sbank;
|
||||
CHECK(sbank.load(vfs));
|
||||
CHECK(sbank.gameplay_sfx.size() == 35);
|
||||
CHECK(sbank.intro_sfx.size() == 14);
|
||||
CHECK(sbank.find_gameplay("ENGINE1.WAV") != nullptr);
|
||||
CHECK(!sbank.find_gameplay("ENGINE1.WAV")->pcm_mono.empty());
|
||||
CHECK(sbank.find_gameplay("MISSILE.WAV") != nullptr);
|
||||
CHECK(sbank.find_intro("TURBO.WAV") != nullptr);
|
||||
std::cout << "[PASS] SOUND.DAT validated (35 gameplay + 14 intro WAVs)\n";
|
||||
|
||||
// 7. MUSIC.DAT (4 banks x 5 XMI tracks), SAMPLE.OPL, BULLFROG.SBK
|
||||
MusicArchive march;
|
||||
CHECK(march.load(vfs));
|
||||
for (int b = 0; b < 4; ++b) {
|
||||
CHECK(march.banks[b].size() == 5);
|
||||
for (const auto& trk : march.banks[b]) {
|
||||
XmiSequence seq;
|
||||
CHECK(parse_xmi_sequence(trk.data.data(), trk.data.size(), trk.name, seq));
|
||||
CHECK(!seq.events.empty());
|
||||
CHECK(seq.total_ticks > 0);
|
||||
}
|
||||
}
|
||||
OplTimbreBank opl_bank;
|
||||
CHECK(opl_bank.load(vfs));
|
||||
CHECK(opl_bank.patches.size() == 162);
|
||||
|
||||
SoundFontBank sf_bank;
|
||||
CHECK(sf_bank.load(vfs));
|
||||
CHECK(sf_bank.samples.size() == 17);
|
||||
CHECK(sf_bank.presets.size() == 17);
|
||||
CHECK(sf_bank.find_preset(0, 0) != nullptr);
|
||||
std::cout << "[PASS] MUSIC.DAT (20 XMI tracks), SAMPLE.OPL (162 timbres), BULLFROG.SBK (17 presets) validated\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "audio/audio_engine.hpp"
|
||||
#include "core/config.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace top_octane;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
GameConfig cfg;
|
||||
audio::AudioEngine eng;
|
||||
CHECK(eng.init(vfs, cfg, /*open_device=*/false));
|
||||
|
||||
struct BufferStats {
|
||||
float peak = 0.0f;
|
||||
float rms = 0.0f;
|
||||
bool finite_ok = true;
|
||||
};
|
||||
|
||||
auto measure_buffer = [](const std::vector<float>& buf, const char* label) -> BufferStats {
|
||||
BufferStats st;
|
||||
double energy = 0.0;
|
||||
for (float s : buf) {
|
||||
if (!std::isfinite(s) || std::abs(s) > 1.05f) {
|
||||
std::cerr << "Bad sample in " << label << ": " << s << "\n";
|
||||
st.finite_ok = false;
|
||||
return st;
|
||||
}
|
||||
st.peak = std::max(st.peak, std::abs(s));
|
||||
energy += static_cast<double>(s) * s;
|
||||
}
|
||||
st.rms = static_cast<float>(std::sqrt(energy / static_cast<double>(buf.size())));
|
||||
std::cout << " " << label << ": peak=" << st.peak << " rms=" << st.rms << "\n";
|
||||
return st;
|
||||
};
|
||||
|
||||
constexpr int kRenderFrames = 48000 * 4; // 4.0 seconds stereo @ 48 kHz (covers lead-in ticks)
|
||||
std::vector<float> pcm(kRenderFrames * 2, 0.0f);
|
||||
|
||||
// 1. OPL3 Backend (SAMPLE.OPL + TGAME1.XMI)
|
||||
eng.play_music(audio::MusicTrackId::Game1, true);
|
||||
eng.mix_offline(pcm.data(), kRenderFrames);
|
||||
BufferStats opl_stats = measure_buffer(pcm, "OPL3 Music (TGAME1.XMI)");
|
||||
CHECK(opl_stats.finite_ok && opl_stats.peak > 0.01f && opl_stats.rms >= 0.025f);
|
||||
|
||||
// 2. SoundFont Backend (BULLFROG.SBK + TGAME1.WTB)
|
||||
cfg.music_backend = MusicBackend::SoundFont;
|
||||
eng.apply_config(cfg, true);
|
||||
eng.mix_offline(pcm.data(), kRenderFrames);
|
||||
BufferStats sf_stats = measure_buffer(pcm, "SoundFont Music (TGAME1.WTB + BULLFROG.SBK)");
|
||||
CHECK(sf_stats.finite_ok && sf_stats.peak > 0.01f && sf_stats.rms >= 0.015f);
|
||||
|
||||
// 3. 3D Spatial SFX + Continuous Engine Mixing + Music Balance Ratio
|
||||
eng.stop_music();
|
||||
eng.set_engine_state(true, 0.85f, true, 0.3f);
|
||||
eng.play_sfx_3d("MISSILE.WAV", Vec3(5, 0, 0), Vec3(0, 0, 0), Vec3(1, 0, 0), 0.48f, 1.0f, 0.18f);
|
||||
eng.play_sfx("EXPLODE.WAV", 0.60f, 1.0f, -0.5f, false, 0.10f);
|
||||
std::vector<float> sfx_pcm(24000 * 2, 0.0f);
|
||||
eng.mix_offline(sfx_pcm.data(), 24000);
|
||||
BufferStats sfx_stats = measure_buffer(sfx_pcm, "3D SFX + Engine Loop");
|
||||
CHECK(sfx_stats.finite_ok && sfx_stats.peak > 0.01f && sfx_stats.rms > 0.002f);
|
||||
CHECK(sfx_stats.rms / opl_stats.rms < 6.0f);
|
||||
CHECK(sfx_stats.rms / sf_stats.rms < 6.0f);
|
||||
|
||||
// 4. Bank 3 WAV loudness normalization spread check
|
||||
{
|
||||
float min_rms = 1e6f;
|
||||
float max_rms = 0.0f;
|
||||
float max_peak = 0.0f;
|
||||
int active_count = 0;
|
||||
for (const auto& smp : eng.sound_bank().gameplay_sfx) {
|
||||
if (smp.name == "NULL.WAV" || smp.pcm_mono.size() < 512) continue;
|
||||
++active_count;
|
||||
CHECK(smp.peak <= 0.90f);
|
||||
CHECK(smp.rms > 0.05f);
|
||||
min_rms = std::min(min_rms, smp.rms);
|
||||
max_rms = std::max(max_rms, smp.rms);
|
||||
max_peak = std::max(max_peak, smp.peak);
|
||||
}
|
||||
float spread = max_rms / std::max(min_rms, 1e-6f);
|
||||
std::cout << " Bank 3 WAV stats: count=" << active_count
|
||||
<< " min_rms=" << min_rms << " max_rms=" << max_rms
|
||||
<< " ratio=" << spread << " max_peak=" << max_peak << "\n";
|
||||
CHECK(active_count >= 25);
|
||||
CHECK(spread < 2.8f);
|
||||
}
|
||||
|
||||
// 5. Spam & SFX bus limiter stress test (cooled slices + uncapped single-buffer burst)
|
||||
{
|
||||
eng.stop_music();
|
||||
eng.set_engine_state(true, 0.85f, true, 0.0f);
|
||||
std::vector<float> stress_pcm;
|
||||
stress_pcm.reserve((10 * 480 + 24000) * 2);
|
||||
std::vector<float> slice(480 * 2, 0.0f);
|
||||
for (int s = 0; s < 10; ++s) {
|
||||
for (int k = 0; k < 6; ++k) {
|
||||
eng.play_sfx("MINISHOT.WAV", 0.35f, 1.0f, 0.0f, false, 0.08f);
|
||||
}
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
eng.play_sfx("EXPLODE.WAV", 0.60f, 1.0f, 0.0f, false, 0.10f);
|
||||
}
|
||||
eng.mix_offline(slice.data(), 480);
|
||||
stress_pcm.insert(stress_pcm.end(), slice.begin(), slice.end());
|
||||
}
|
||||
std::vector<float> tail(24000 * 2, 0.0f);
|
||||
eng.mix_offline(tail.data(), 24000);
|
||||
stress_pcm.insert(stress_pcm.end(), tail.begin(), tail.end());
|
||||
BufferStats cooled_stats = measure_buffer(stress_pcm, "60x Minishot + 30x Explode Stress");
|
||||
CHECK(cooled_stats.finite_ok && cooled_stats.peak <= 0.99f && cooled_stats.rms < 0.45f);
|
||||
|
||||
std::vector<float> burst(24000 * 2, 0.0f);
|
||||
for (int k = 0; k < 30; ++k) {
|
||||
eng.play_sfx("EXPLODE.WAV", 0.60f, 1.0f, 0.0f, false, 0.0f);
|
||||
}
|
||||
eng.mix_offline(burst.data(), 24000);
|
||||
BufferStats burst_stats = measure_buffer(burst, "30x Uncapped Explode Voice-Cap Burst");
|
||||
CHECK(burst_stats.finite_ok && burst_stats.peak <= 0.99f && burst_stats.rms < 0.45f);
|
||||
}
|
||||
|
||||
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
#include "assets/level.hpp"
|
||||
#include "core/clock.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
#include "game/game_modes.hpp"
|
||||
#include "sim/combat.hpp"
|
||||
#include "sim/race_sim.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
using namespace top_octane;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
assets::LevelData lvl1;
|
||||
CHECK(lvl1.load(vfs, 1));
|
||||
float dt = static_cast<float>(FixedStepClock::kFixedDt);
|
||||
|
||||
// 1. Multi-AI Race Simulation (8 racers, 1 lap) + Combat + Pickups
|
||||
sim::RaceSetup setup;
|
||||
setup.mode = sim::GameMode::SingleRace;
|
||||
setup.track_number = 1;
|
||||
setup.total_laps = 1;
|
||||
setup.difficulty = 2; // Hard AI with weapons & boosting
|
||||
setup.num_ai = 7;
|
||||
|
||||
sim::RaceSim sim;
|
||||
CHECK(sim.start_race(lvl1, setup));
|
||||
sim.crafts_mut()[0].autopilot = true;
|
||||
|
||||
int total_shots = 0;
|
||||
for (int t = 0; t < 4000 && !sim.race_finished(); ++t) {
|
||||
CraftInput in;
|
||||
in.fire_minigun = (t % 20 == 0);
|
||||
sim.step(in, CraftInput{}, dt);
|
||||
}
|
||||
for (const auto& c : sim.crafts()) {
|
||||
total_shots += c.shots_fired;
|
||||
}
|
||||
CHECK(sim.crafts()[0].finished);
|
||||
CHECK(total_shots > 0);
|
||||
std::cout << "[PASS] 8-racer AI & combat race finished in " << sim.crafts()[0].race_time
|
||||
<< "s (placement=" << sim.crafts()[0].placement << ", total_shots=" << total_shots << ")\n";
|
||||
|
||||
// 2. Clone Race Ghost Recording & Playback
|
||||
sim::CloneRecording rec = sim.current_recording();
|
||||
CHECK(rec.frames.size() > 100);
|
||||
{
|
||||
sim::RaceSetup csetup;
|
||||
csetup.mode = sim::GameMode::CloneRace;
|
||||
csetup.track_number = 1;
|
||||
csetup.total_laps = 1;
|
||||
sim::RaceSim csim;
|
||||
CHECK(csim.start_race(lvl1, csetup, &rec));
|
||||
CHECK(csim.has_clone_ghost());
|
||||
for (int t = 0; t < 240; ++t) {
|
||||
csim.step(CraftInput{}, CraftInput{}, dt);
|
||||
}
|
||||
sim::CraftPose gpose = csim.interpolated_clone_pose(0.5f);
|
||||
CHECK(gpose.pos.len_sq() > 0.1f);
|
||||
}
|
||||
std::cout << "[PASS] Clone Race ghost recording & playback validated\n";
|
||||
|
||||
// 3. DeathMatch & Recovery Craft Repair Sequence
|
||||
{
|
||||
sim::RaceSetup dm;
|
||||
dm.mode = sim::GameMode::DeathMatch;
|
||||
dm.track_number = 1;
|
||||
dm.num_ai = 3;
|
||||
dm.deathmatch_kill_limit = 2;
|
||||
sim::RaceSim dsim;
|
||||
CHECK(dsim.start_race(lvl1, dm));
|
||||
// Skip countdown
|
||||
for (int t = 0; t < 200; ++t) dsim.step(CraftInput{}, CraftInput{}, dt);
|
||||
// Place victim directly in front of P1 and fire missile/minigun to test kill & recovery craft
|
||||
auto& p1 = dsim.crafts_mut()[0];
|
||||
auto& tgt = dsim.crafts_mut()[1];
|
||||
Vec3 fwd = p1.forward_dir();
|
||||
tgt.curr_pose.pos = p1.curr_pose.pos + fwd * 3.0f;
|
||||
tgt.prev_pose = tgt.curr_pose;
|
||||
tgt.shield = 5.0f;
|
||||
|
||||
for (int t = 0; t < 60; ++t) {
|
||||
CraftInput fire;
|
||||
fire.fire_minigun = true;
|
||||
dsim.step(fire, CraftInput{}, dt);
|
||||
}
|
||||
CHECK(p1.kills >= 1);
|
||||
CHECK(tgt.deaths >= 1);
|
||||
auto rvis = sim::get_recovery_visuals(dsim.crafts());
|
||||
CHECK(!rvis.empty());
|
||||
}
|
||||
std::cout << "[PASS] DeathMatch kill scoring & Recovery Craft dispatch validated\n";
|
||||
|
||||
// 4. Championship Save / Load & Highscore Persistence in temp directory
|
||||
std::filesystem::path tmp_dir = std::filesystem::temp_directory_path() / "top_octane_test_saves";
|
||||
std::filesystem::remove_all(tmp_dir);
|
||||
{
|
||||
game::ChampionshipState ch;
|
||||
ch.start_new("ACE", 3, 7, 1);
|
||||
ch.record_race_results(sim.crafts());
|
||||
CHECK(ch.current_track == 2);
|
||||
CHECK(ch.save_slot(tmp_dir, 0));
|
||||
|
||||
game::ChampionshipState loaded;
|
||||
CHECK(loaded.load_slot(tmp_dir, 0));
|
||||
CHECK(loaded.current_track == 2);
|
||||
CHECK(loaded.player_name == "ACE");
|
||||
CHECK(loaded.drivers[0].points == ch.drivers[0].points);
|
||||
|
||||
game::HighscoreTable hs;
|
||||
hs.clear();
|
||||
int flags = hs.submit_race(1, sim.crafts());
|
||||
CHECK((flags & 3) == 3);
|
||||
CHECK(hs.save(tmp_dir / "hiscores.dat"));
|
||||
|
||||
game::HighscoreTable hs2;
|
||||
CHECK(hs2.load(tmp_dir / "hiscores.dat"));
|
||||
CHECK(hs2.tracks[0].best_lap == hs.tracks[0].best_lap);
|
||||
CHECK(game::save_clone_recording(tmp_dir, rec));
|
||||
|
||||
sim::CloneRecording rec2;
|
||||
CHECK(game::load_clone_recording(tmp_dir, 1, rec2));
|
||||
CHECK(rec2.frames.size() == rec.frames.size());
|
||||
}
|
||||
std::filesystem::remove_all(tmp_dir);
|
||||
std::cout << "[PASS] Championship save/load, Highscores & Clone disk round-trip validated\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
#include "assets/level.hpp"
|
||||
#include "core/clock.hpp"
|
||||
#include "core/math.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
#include "sim/physics.hpp"
|
||||
#include "sim/race_sim.hpp"
|
||||
#include "sim/vehicle_defs.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace top_octane;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
// 1. Verify starting grid across all 6 levels is collision-free and finite
|
||||
for (int l = 1; l <= 6; ++l) {
|
||||
assets::LevelData lvl;
|
||||
CHECK(lvl.load(vfs, l));
|
||||
|
||||
sim::RaceSetup setup;
|
||||
setup.track_number = l;
|
||||
setup.num_ai = 7;
|
||||
|
||||
sim::RaceSim sim;
|
||||
CHECK(sim.start_race(lvl, setup));
|
||||
CHECK(sim.crafts().size() == 8);
|
||||
|
||||
for (const auto& c : sim.crafts()) {
|
||||
CHECK(std::isfinite(c.curr_pose.pos.x));
|
||||
CHECK(std::isfinite(c.curr_pose.pos.y));
|
||||
CHECK(std::isfinite(c.curr_pose.pos.z));
|
||||
CHECK(!lvl.is_cell_solid_at_y(static_cast<int>(std::floor(c.curr_pose.pos.x)),
|
||||
static_cast<int>(std::floor(c.curr_pose.pos.z)),
|
||||
c.curr_pose.pos.y));
|
||||
}
|
||||
for (size_t i = 0; i < sim.crafts().size(); ++i) {
|
||||
for (size_t j = i + 1; j < sim.crafts().size(); ++j) {
|
||||
const auto& ca = sim.crafts()[i];
|
||||
const auto& cb = sim.crafts()[j];
|
||||
float ra = sim::kVehicleSpecs[std::clamp(ca.vehicle_idx, 0, 5)].collision_radius;
|
||||
float rb = sim::kVehicleSpecs[std::clamp(cb.vehicle_idx, 0, 5)].collision_radius;
|
||||
float dx = cb.curr_pose.pos.x - ca.curr_pose.pos.x;
|
||||
float dz = cb.curr_pose.pos.z - ca.curr_pose.pos.z;
|
||||
CHECK(std::hypot(dx, dz) >= ra + rb);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << "[PASS] Start grid valid & collision-free across all 6 tracks\n";
|
||||
|
||||
// 2. Verify fixed-step determinism (running two identical sims produces bit-identical state)
|
||||
assets::LevelData lvl1;
|
||||
CHECK(lvl1.load(vfs, 1));
|
||||
|
||||
auto run_determinism = [&](int steps) -> sim::CraftPose {
|
||||
sim::RaceSetup setup;
|
||||
setup.track_number = 1;
|
||||
setup.num_ai = 0;
|
||||
sim::RaceSim s;
|
||||
s.start_race(lvl1, setup);
|
||||
CraftInput in;
|
||||
in.throttle = 1.0f;
|
||||
for (int i = 0; i < steps; ++i) {
|
||||
in.steer = (i > 220 && i < 260) ? 0.5f : 0.0f;
|
||||
in.boost = (i > 200 && i < 240);
|
||||
s.step(in, CraftInput{}, static_cast<float>(FixedStepClock::kFixedDt));
|
||||
}
|
||||
return s.crafts()[0].curr_pose;
|
||||
};
|
||||
|
||||
sim::CraftPose pa = run_determinism(400);
|
||||
sim::CraftPose pb = run_determinism(400);
|
||||
CHECK(pa.pos.x == pb.pos.x && pa.pos.y == pb.pos.y && pa.pos.z == pb.pos.z);
|
||||
CHECK(pa.yaw == pb.yaw);
|
||||
std::cout << "[PASS] Fixed-timestep 60Hz determinism verified\n";
|
||||
|
||||
// 3. Verify autopilot completes an entire 2-lap race cleanly on Level 1 without getting stuck
|
||||
{
|
||||
sim::RaceSetup setup;
|
||||
setup.track_number = 1;
|
||||
setup.total_laps = 2;
|
||||
setup.num_ai = 0;
|
||||
sim::RaceSim s;
|
||||
CHECK(s.start_race(lvl1, setup));
|
||||
s.crafts_mut()[0].autopilot = true;
|
||||
|
||||
float dt = static_cast<float>(FixedStepClock::kFixedDt);
|
||||
// Simulate up to 180 seconds (10800 ticks)
|
||||
for (int t = 0; t < 10800 && !s.race_finished(); ++t) {
|
||||
s.step(CraftInput{}, CraftInput{}, dt);
|
||||
// Replenish fuel if low so test isolates navigation/physics/checkpoints
|
||||
if (s.crafts()[0].fuel < 20.0f) s.crafts_mut()[0].fuel = 100.0f;
|
||||
}
|
||||
const auto& p1 = s.crafts()[0];
|
||||
std::cout << " Autopilot 2-lap test: finished=" << p1.finished
|
||||
<< " lap=" << p1.lap << " cps=" << p1.checkpoints_passed
|
||||
<< " time=" << p1.race_time << "s\n";
|
||||
CHECK(p1.finished);
|
||||
CHECK(p1.best_lap_time > 5.0f && p1.best_lap_time < 80.0f);
|
||||
}
|
||||
std::cout << "[PASS] Autopilot hover physics, checkpoints & 2-lap completion verified\n";
|
||||
|
||||
// 4. Verify wall containment (steering straight into a boundary/column never tunnels out of map)
|
||||
{
|
||||
sim::RaceSetup setup;
|
||||
setup.track_number = 1;
|
||||
setup.num_ai = 0;
|
||||
sim::RaceSim s;
|
||||
CHECK(s.start_race(lvl1, setup));
|
||||
CraftInput ram;
|
||||
ram.throttle = 1.0f;
|
||||
ram.steer = 1.0f;
|
||||
ram.boost = true;
|
||||
for (int t = 0; t < 600; ++t) {
|
||||
s.step(ram, CraftInput{}, static_cast<float>(FixedStepClock::kFixedDt));
|
||||
const auto& pos = s.crafts()[0].curr_pose.pos;
|
||||
CHECK(pos.x >= 1.0f && pos.x <= assets::kMapWidth - 2.0f);
|
||||
CHECK(pos.z >= 1.0f && pos.z <= assets::kMapHeight - 2.0f);
|
||||
}
|
||||
}
|
||||
std::cout << "[PASS] Map boundary & column containment verified\n";
|
||||
|
||||
// 5. Seam-free multi-tile wall sliding & 2-craft column squeeze containment
|
||||
assets::LevelData syn;
|
||||
syn.map.resize(assets::kMapWidth * assets::kMapHeight);
|
||||
for (auto& m : syn.map) {
|
||||
m.height = 2048;
|
||||
m.tex_or_col = 0;
|
||||
}
|
||||
syn.columns[1].shape_mask = 0x03;
|
||||
for (int x = 10; x <= 19; ++x) {
|
||||
syn.cell_mut(x, 20).tex_or_col = -1;
|
||||
}
|
||||
|
||||
{
|
||||
sim::CraftState car;
|
||||
car.id = 0;
|
||||
car.vehicle_idx = 0; // CAR0- (r = 0.48)
|
||||
car.curr_pose.pos = Vec3(11.0f, 0.28f, 19.45f);
|
||||
car.curr_pose.yaw = kHalfPi;
|
||||
car.prev_pose = car.curr_pose;
|
||||
car.vel = Vec3(12.0f, 0.0f, 2.5f);
|
||||
car.fuel = car.max_fuel = 100.0f;
|
||||
car.shield = car.max_shield = 100.0f;
|
||||
|
||||
CraftInput neutral{};
|
||||
float dt = static_cast<float>(FixedStepClock::kFixedDt);
|
||||
for (int t = 0; t < 30; ++t) {
|
||||
sim::step_craft_physics(car, neutral, syn, dt);
|
||||
}
|
||||
CHECK(car.curr_pose.pos.z <= 20.0f - 0.48f + 0.02f);
|
||||
CHECK(car.curr_pose.pos.x > 14.5f);
|
||||
CHECK(car.vel.x > 4.5f);
|
||||
}
|
||||
std::cout << "[PASS] Seam-free multi-tile wall sliding verified\n";
|
||||
|
||||
{
|
||||
sim::CraftState a;
|
||||
a.id = 0;
|
||||
a.vehicle_idx = 2; // JUGGA (r = 0.60)
|
||||
a.curr_pose.pos = Vec3(15.0f, 0.28f, 19.38f);
|
||||
a.prev_pose = a.curr_pose;
|
||||
a.vel = Vec3(0.0f, 0.0f, 0.0f);
|
||||
a.fuel = a.max_fuel = 125.0f;
|
||||
|
||||
sim::CraftState b;
|
||||
b.id = 1;
|
||||
b.vehicle_idx = 1; // TANK (r = 0.56)
|
||||
b.curr_pose.pos = Vec3(15.0f, 0.28f, 18.4f);
|
||||
b.prev_pose = b.curr_pose;
|
||||
b.vel = Vec3(0.0f, 0.0f, 12.0f);
|
||||
b.fuel = b.max_fuel = 110.0f;
|
||||
|
||||
CraftInput neutral{};
|
||||
float dt = static_cast<float>(FixedStepClock::kFixedDt);
|
||||
for (int t = 0; t < 30; ++t) {
|
||||
sim::step_craft_physics(a, neutral, syn, dt);
|
||||
sim::step_craft_physics(b, neutral, syn, dt);
|
||||
for (int iter = 0; iter < 2; ++iter) {
|
||||
float rel = 0.0f;
|
||||
sim::resolve_craft_pair_collision(a, b, rel);
|
||||
float imp = 0.0f;
|
||||
bool scr = false;
|
||||
sim::resolve_world_collisions(a, syn, imp, scr);
|
||||
sim::resolve_world_collisions(b, syn, imp, scr);
|
||||
}
|
||||
}
|
||||
CHECK(!syn.is_cell_solid_at_y(static_cast<int>(std::floor(a.curr_pose.pos.x)),
|
||||
static_cast<int>(std::floor(a.curr_pose.pos.z)),
|
||||
a.curr_pose.pos.y));
|
||||
CHECK(!syn.is_cell_solid_at_y(static_cast<int>(std::floor(b.curr_pose.pos.x)),
|
||||
static_cast<int>(std::floor(b.curr_pose.pos.z)),
|
||||
b.curr_pose.pos.y));
|
||||
CHECK(a.curr_pose.pos.z <= 20.0f - sim::kVehicleSpecs[a.vehicle_idx].collision_radius + 0.02f);
|
||||
CHECK(b.curr_pose.pos.z <= 20.0f - sim::kVehicleSpecs[b.vehicle_idx].collision_radius + 0.02f);
|
||||
float sep = std::hypot(b.curr_pose.pos.x - a.curr_pose.pos.x,
|
||||
b.curr_pose.pos.z - a.curr_pose.pos.z);
|
||||
CHECK(sep >= 0.60f + 0.56f - 0.05f);
|
||||
}
|
||||
std::cout << "[PASS] 2-craft column squeeze containment verified\n";
|
||||
|
||||
// 6. Track 1 gantry overpass clearance & ceiling clamp
|
||||
{
|
||||
int gx = -1, gz = -1;
|
||||
for (int z = 0; z < assets::kMapHeight && gx < 0; ++z) {
|
||||
for (int x = 0; x < assets::kMapWidth; ++x) {
|
||||
const auto& m = lvl1.cell(x, z);
|
||||
if (m.tex_or_col < 0) {
|
||||
int cidx = -m.tex_or_col;
|
||||
if (cidx > 0 && cidx < assets::kMaxColumns) {
|
||||
uint16_t mask = lvl1.columns[cidx].shape_mask;
|
||||
if ((mask & 1u) == 0 && (mask & 0xFEu) != 0) {
|
||||
gx = x;
|
||||
gz = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK(gx >= 0 && gz >= 0);
|
||||
float gy = lvl1.cell_height_world(gx, gz);
|
||||
CHECK(!lvl1.is_cell_solid_at_y(gx, gz, gy + 0.28f));
|
||||
|
||||
float floor_y = 0.0f, ceil_y = 1e6f;
|
||||
lvl1.sample_surface_and_ceiling(gx + 0.5f, gz + 0.5f, gy + 0.28f, floor_y, ceil_y);
|
||||
CHECK(ceil_y < 1e5f && ceil_y >= gy + 0.95f);
|
||||
|
||||
sim::CraftState c;
|
||||
c.vehicle_idx = 0;
|
||||
c.curr_pose.pos = Vec3(gx + 0.5f, ceil_y - 0.10f, gz + 0.5f);
|
||||
c.prev_pose = c.curr_pose;
|
||||
c.vel = Vec3(0.0f, 5.0f, 0.0f);
|
||||
float imp = 0.0f;
|
||||
bool scr = false;
|
||||
sim::resolve_world_collisions(c, lvl1, imp, scr);
|
||||
CHECK(c.curr_pose.pos.y <= ceil_y - 0.45f);
|
||||
CHECK(c.vel.y <= 0.0f);
|
||||
}
|
||||
std::cout << "[PASS] Overhead gantry overpass & ceiling clamping verified\n";
|
||||
|
||||
// 7. All 6 tracks 1-lap autopilot completion
|
||||
for (int l = 1; l <= 6; ++l) {
|
||||
assets::LevelData lvl;
|
||||
CHECK(lvl.load(vfs, l));
|
||||
sim::RaceSetup setup;
|
||||
setup.track_number = l;
|
||||
setup.total_laps = 1;
|
||||
setup.num_ai = 0;
|
||||
sim::RaceSim s;
|
||||
CHECK(s.start_race(lvl, setup));
|
||||
s.crafts_mut()[0].autopilot = true;
|
||||
|
||||
float dt = static_cast<float>(FixedStepClock::kFixedDt);
|
||||
for (int t = 0; t < 9000 && !s.race_finished(); ++t) {
|
||||
s.step(CraftInput{}, CraftInput{}, dt);
|
||||
if (s.crafts()[0].fuel < 20.0f) s.crafts_mut()[0].fuel = 100.0f;
|
||||
}
|
||||
const auto& p1 = s.crafts()[0];
|
||||
std::cout << " Track " << l << " 1-lap autopilot: finished=" << p1.finished
|
||||
<< " time=" << p1.race_time << "s\n";
|
||||
CHECK(p1.finished);
|
||||
}
|
||||
std::cout << "[PASS] 1-lap autopilot completion verified across all 6 tracks\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
#include "assets/level.hpp"
|
||||
#include "assets/model.hpp"
|
||||
#include "assets/palette.hpp"
|
||||
#include "assets/sprites.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
#include "render/world_geometry.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace top_octane;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
assets::Palette pal;
|
||||
CHECK(pal.load(vfs));
|
||||
|
||||
// Verify CPU geometry generation for all 6 tracks
|
||||
for (int l = 1; l <= 6; ++l) {
|
||||
assets::LevelData lvl;
|
||||
CHECK(lvl.load(vfs, l));
|
||||
|
||||
render::WorldGeometry geo = render::build_level_geometry(lvl);
|
||||
CHECK(geo.terrain_verts.size() == (assets::kMapWidth - 1) * (assets::kMapHeight - 1) * 4u);
|
||||
CHECK(geo.terrain_indices.size() == (assets::kMapWidth - 1) * (assets::kMapHeight - 1) * 6u);
|
||||
CHECK(!geo.column_verts.empty());
|
||||
CHECK(!geo.column_indices.empty());
|
||||
CHECK(geo.column_indices.size() % 6 == 0);
|
||||
|
||||
for (const auto& v : geo.terrain_verts) {
|
||||
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.light >= 0.25f && v.light <= 1.5f);
|
||||
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
||||
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
||||
}
|
||||
for (const auto& v : geo.column_verts) {
|
||||
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);
|
||||
}
|
||||
|
||||
// Verify strict outward counter-clockwise triangle winding on terrain (+Y) & 3D columns
|
||||
auto check_winding = [&](const std::vector<render::WorldVertex>& verts,
|
||||
const std::vector<uint32_t>& indices,
|
||||
bool heightmap_up) -> bool {
|
||||
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
||||
const auto& v0 = verts[indices[i + 0]];
|
||||
const auto& v1 = verts[indices[i + 1]];
|
||||
const auto& v2 = verts[indices[i + 2]];
|
||||
Vec3 tri_n = (v1.pos - v0.pos).cross(v2.pos - v0.pos);
|
||||
if (tri_n.len_sq() <= 1e-8f) {
|
||||
return false;
|
||||
}
|
||||
if (heightmap_up) {
|
||||
if (tri_n.y <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Vec3 avg_n = v0.normal + v1.normal + v2.normal;
|
||||
if (tri_n.dot(avg_n) <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
CHECK(check_winding(geo.terrain_verts, geo.terrain_indices, true));
|
||||
CHECK(check_winding(geo.column_verts, geo.column_indices, false));
|
||||
|
||||
// Verify partial morph region update stays valid
|
||||
render::update_terrain_region(lvl, 10, 80, 15, 85, geo.terrain_verts);
|
||||
|
||||
std::cout << " Level " << l << " geo: terrain_tris=" << geo.terrain_indices.size() / 3
|
||||
<< " column_tris=" << geo.column_indices.size() / 3 << "\n";
|
||||
}
|
||||
|
||||
// Verify TRACK0-1 full track silhouette preview sprites for all 6 tracks
|
||||
{
|
||||
assets::SpriteBank track_bank;
|
||||
CHECK(track_bank.load(vfs, "DATA/TRACK0-1.DAT", "DATA/TRACK0-1.TAB", pal));
|
||||
static constexpr int kPreviewIndices[6] = {1, 3, 6, 7, 9, 11};
|
||||
for (int idx : kPreviewIndices) {
|
||||
CHECK(static_cast<size_t>(idx) < track_bank.sprites.size());
|
||||
const auto& sp = track_bank.sprites[idx];
|
||||
CHECK(sp.width >= 50 && sp.height >= 90);
|
||||
CHECK(!sp.rgba.empty());
|
||||
}
|
||||
}
|
||||
|
||||
// Verify 3D model GPU geometry conversion
|
||||
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));
|
||||
render::ModelGeometry mg = render::build_model_geometry(mesh, pal);
|
||||
CHECK(!mg.verts.empty());
|
||||
CHECK(mg.indices.size() == mesh.triangles.size() * 3u);
|
||||
}
|
||||
|
||||
std::cout << "[PASS] All 6 Levels & Vehicle 3D Render Geometry validated\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user