init commit
This commit is contained in:
commit
15ab48343a
187 files changed
+12644
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user