2026-11-30 22:31:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "assets/level.hpp"
|
|
|
|
|
#include "core/math.hpp"
|
|
|
|
|
#include "input/input_manager.hpp"
|
|
|
|
|
#include "sim/physics.hpp"
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace top_octane::sim {
|
|
|
|
|
|
|
|
|
|
enum class GameMode {
|
|
|
|
|
SingleRace = 0,
|
|
|
|
|
DeathMatch = 1,
|
|
|
|
|
CloneRace = 2,
|
|
|
|
|
Championship = 3,
|
|
|
|
|
SplitScreen = 4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class SimSoundCue {
|
|
|
|
|
None = 0,
|
|
|
|
|
StartBeep,
|
|
|
|
|
StartGo,
|
|
|
|
|
MinigunShot,
|
|
|
|
|
MissileLaunch,
|
|
|
|
|
Explosion,
|
|
|
|
|
Impact,
|
|
|
|
|
Scrape,
|
|
|
|
|
Boost,
|
|
|
|
|
Pickup,
|
|
|
|
|
Powerup,
|
|
|
|
|
Refuel,
|
|
|
|
|
LockOn,
|
|
|
|
|
Warning,
|
|
|
|
|
Stunt180,
|
|
|
|
|
Stunt360,
|
|
|
|
|
Stunt720,
|
|
|
|
|
SwitchTrigger,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SimEvent {
|
|
|
|
|
SimSoundCue sound = SimSoundCue::None;
|
|
|
|
|
Vec3 pos{0, 0, 0};
|
|
|
|
|
int target_player = -1; // -1 = global, 0 = P1, 1 = P2
|
|
|
|
|
std::string banner_text;
|
|
|
|
|
float rumble_intensity = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Projectile {
|
|
|
|
|
bool active = false;
|
|
|
|
|
bool is_missile = false;
|
|
|
|
|
int owner_id = -1;
|
|
|
|
|
int target_id = -1;
|
|
|
|
|
Vec3 pos{0, 0, 0};
|
|
|
|
|
Vec3 vel{0, 0, 0};
|
|
|
|
|
float yaw = 0.0f;
|
|
|
|
|
float damage = 10.0f;
|
|
|
|
|
float life = 2.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PickupItem {
|
|
|
|
|
uint16_t entity_id = 0;
|
|
|
|
|
uint8_t subtype = 0;
|
2026-12-01 08:05:04 +02:00
|
|
|
uint16_t group = 1;
|
2026-11-30 22:31:51 +02:00
|
|
|
Vec3 pos{0, 0, 0};
|
2026-12-01 08:05:04 +02:00
|
|
|
bool group_unlocked = true;
|
2026-11-30 22:31:51 +02:00
|
|
|
bool active = true;
|
|
|
|
|
float respawn_timer = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PropObject {
|
|
|
|
|
uint16_t entity_id = 0;
|
|
|
|
|
uint8_t subtype = 0;
|
|
|
|
|
std::string model_key;
|
|
|
|
|
Vec3 pos{0, 0, 0};
|
|
|
|
|
float yaw = 0.0f;
|
|
|
|
|
float hp = 25.0f;
|
|
|
|
|
bool alive = true;
|
|
|
|
|
float respawn_timer = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ParticleBurst {
|
|
|
|
|
Vec3 pos{0, 0, 0};
|
|
|
|
|
Vec3 vel{0, 0, 0};
|
|
|
|
|
float size = 0.4f;
|
|
|
|
|
Vec4 color{1.0f, 0.7f, 0.2f, 1.0f};
|
|
|
|
|
float life = 0.5f;
|
|
|
|
|
float max_life = 0.5f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CloneRecording {
|
|
|
|
|
int track_number = 1;
|
|
|
|
|
int vehicle_idx = 0;
|
|
|
|
|
int team_idx = 7;
|
|
|
|
|
float best_race_time = 1e9f;
|
|
|
|
|
std::vector<CraftPose> frames; // 60 Hz sampled poses
|
|
|
|
|
};
|
|
|
|
|
|
2026-12-01 08:05:04 +02:00
|
|
|
struct DirtyRect {
|
|
|
|
|
int x0 = 0, z0 = 0, x1 = 0, z1 = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ProjectileTrace {
|
|
|
|
|
Vec3 p0{0, 0, 0};
|
|
|
|
|
Vec3 p1{0, 0, 0};
|
|
|
|
|
int owner_player = -1;
|
|
|
|
|
bool is_missile = false;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
struct RaceSetup {
|
|
|
|
|
GameMode mode = GameMode::SingleRace;
|
|
|
|
|
int track_number = 1; // 1..6
|
|
|
|
|
int total_laps = 3;
|
|
|
|
|
int difficulty = 1; // 0=Easy, 1=Medium, 2=Hard
|
|
|
|
|
int num_ai = 7; // 0..7
|
|
|
|
|
int p1_vehicle = 0;
|
|
|
|
|
int p1_team = 7;
|
|
|
|
|
std::string p1_name = "PLAYER";
|
|
|
|
|
int p2_vehicle = 3;
|
|
|
|
|
int p2_team = 1;
|
|
|
|
|
std::string p2_name = "PLAYER 2";
|
|
|
|
|
int deathmatch_kill_limit = 5;
|
2026-11-30 23:57:29 +02:00
|
|
|
bool fuel_enabled = true;
|
|
|
|
|
bool damage_enabled = true;
|
|
|
|
|
bool weapons_enabled = true;
|
|
|
|
|
bool pickups_enabled = true;
|
|
|
|
|
bool track_morphing_enabled = true;
|
2026-11-30 22:31:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RaceSim {
|
|
|
|
|
public:
|
|
|
|
|
bool start_race(const assets::LevelData& level, const RaceSetup& setup,
|
|
|
|
|
const CloneRecording* existing_clone = nullptr);
|
|
|
|
|
|
|
|
|
|
// Advances 1 fixed 60 Hz tick
|
|
|
|
|
void step(const CraftInput& p1_input, const CraftInput& p2_input, float dt);
|
|
|
|
|
|
|
|
|
|
const RaceSetup& setup() const { return setup_; }
|
|
|
|
|
const assets::LevelData& level() const { return level_; }
|
|
|
|
|
const std::vector<CraftState>& crafts() const { return crafts_; }
|
|
|
|
|
std::vector<CraftState>& crafts_mut() { return crafts_; }
|
|
|
|
|
const std::vector<Projectile>& projectiles() const { return projectiles_; }
|
|
|
|
|
const std::vector<PickupItem>& pickups() const { return pickups_; }
|
|
|
|
|
const std::vector<PropObject>& props() const { return props_; }
|
|
|
|
|
const std::vector<ParticleBurst>& particles() const { return particles_; }
|
|
|
|
|
const std::vector<SimEvent>& events() const { return events_; }
|
|
|
|
|
void clear_events() { events_.clear(); }
|
|
|
|
|
|
|
|
|
|
bool countdown_active() const { return countdown_timer_ > 0.0f; }
|
|
|
|
|
float countdown_timer() const { return countdown_timer_; }
|
|
|
|
|
bool race_finished() const { return race_over_; }
|
|
|
|
|
int winner_id() const { return winner_id_; }
|
|
|
|
|
|
|
|
|
|
bool has_clone_ghost() const { return clone_active_; }
|
|
|
|
|
CraftPose interpolated_clone_pose(float alpha) const;
|
|
|
|
|
const CloneRecording& current_recording() const { return recording_; }
|
2026-12-01 08:33:48 +02:00
|
|
|
const CloneRecording& playback_clone() const { return playback_clone_; }
|
2026-11-30 22:31:51 +02:00
|
|
|
|
2026-12-01 08:05:04 +02:00
|
|
|
// Checks if morph triggers fired and changed terrain heights or columns
|
2026-11-30 22:31:51 +02:00
|
|
|
bool consume_terrain_dirty(int& x0, int& z0, int& x1, int& z1);
|
2026-12-01 08:05:04 +02:00
|
|
|
bool consume_world_dirty(std::vector<DirtyRect>& out_terrain_rects, bool& out_columns_dirty);
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
private:
|
2026-12-01 08:05:04 +02:00
|
|
|
struct TriggerRuntime {
|
|
|
|
|
bool armed = false;
|
|
|
|
|
bool fired = false;
|
|
|
|
|
bool pending = false;
|
|
|
|
|
float timer = 0.0f;
|
|
|
|
|
int hit_accum = 0;
|
|
|
|
|
int pending_player = -1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ActiveMorph {
|
|
|
|
|
size_t morph_idx = 0;
|
|
|
|
|
float elapsed = 0.0f;
|
|
|
|
|
float duration = 0.50f;
|
|
|
|
|
std::vector<assets::MapEntry> orig_dst;
|
|
|
|
|
std::vector<assets::MapEntry> orig_src;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
void compute_start_grid(int count, std::vector<CraftPose>& out_poses) const;
|
2026-12-01 08:33:48 +02:00
|
|
|
void update_checkpoints_and_laps(CraftState& c, float dt);
|
2026-11-30 22:31:51 +02:00
|
|
|
void update_recharge_pads(CraftState& c, float dt);
|
|
|
|
|
void update_triggers(CraftState& c);
|
2026-12-01 08:05:04 +02:00
|
|
|
void update_timed_triggers(float dt);
|
|
|
|
|
void update_rocket_triggers(const std::vector<ProjectileTrace>& traces);
|
|
|
|
|
void update_active_morphs(float dt);
|
|
|
|
|
void apply_morph_fraction(const ActiveMorph& am, float s);
|
|
|
|
|
void push_dirty_rect(int x0, int z0, int x1, int z1);
|
|
|
|
|
void activate_group(uint16_t group, int actor_player, bool allow_banner, bool fast_morph = false);
|
2026-11-30 22:31:51 +02:00
|
|
|
void update_standings();
|
2026-12-01 08:33:48 +02:00
|
|
|
void finalize_unfinished_times(const std::vector<size_t>& order);
|
2026-11-30 22:31:51 +02:00
|
|
|
void update_particles(float dt);
|
|
|
|
|
|
|
|
|
|
RaceSetup setup_{};
|
|
|
|
|
assets::LevelData level_{};
|
|
|
|
|
std::vector<CraftState> crafts_;
|
|
|
|
|
std::vector<Projectile> projectiles_;
|
|
|
|
|
std::vector<PickupItem> pickups_;
|
|
|
|
|
std::vector<PropObject> props_;
|
|
|
|
|
std::vector<ParticleBurst> particles_;
|
|
|
|
|
std::vector<SimEvent> events_;
|
|
|
|
|
|
|
|
|
|
float countdown_timer_ = 3.0f;
|
|
|
|
|
int last_countdown_int_ = 4;
|
|
|
|
|
float elapsed_time_ = 0.0f;
|
|
|
|
|
bool race_over_ = false;
|
2026-12-01 08:33:48 +02:00
|
|
|
bool times_finalized_ = false;
|
2026-11-30 22:31:51 +02:00
|
|
|
int winner_id_ = -1;
|
|
|
|
|
|
|
|
|
|
// Trigger/morph tracking
|
2026-12-01 08:05:04 +02:00
|
|
|
std::vector<TriggerRuntime> trigger_states_;
|
|
|
|
|
std::vector<bool> morph_is_repeating_;
|
|
|
|
|
std::vector<bool> morph_fired_once_;
|
|
|
|
|
std::vector<ActiveMorph> active_morphs_;
|
|
|
|
|
std::vector<DirtyRect> dirty_rects_;
|
|
|
|
|
bool columns_dirty_ = false;
|
|
|
|
|
float morph_banner_cd_ = 0.0f;
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
// Clone race recording & playback
|
|
|
|
|
CloneRecording recording_;
|
|
|
|
|
CloneRecording playback_clone_;
|
|
|
|
|
bool clone_active_ = false;
|
|
|
|
|
size_t clone_tick_ = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace top_octane::sim
|