180 lines
4.8 KiB
C++
180 lines
4.8 KiB
C++
#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;
|
||
|
|
Vec3 pos{0, 0, 0};
|
||
|
|
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
|
||
|
|
};
|
||
|
|
|
||
|
|
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;
|
||
|
|
};
|
||
|
|
|
||
|
|
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_; }
|
||
|
|
|
||
|
|
// Checks if morph triggers fired and changed terrain heights
|
||
|
|
bool consume_terrain_dirty(int& x0, int& z0, int& x1, int& z1);
|
||
|
|
|
||
|
|
private:
|
||
|
|
void compute_start_grid(int count, std::vector<CraftPose>& out_poses) const;
|
||
|
|
void update_checkpoints_and_laps(CraftState& c);
|
||
|
|
void update_recharge_pads(CraftState& c, float dt);
|
||
|
|
void update_triggers(CraftState& c);
|
||
|
|
void update_standings();
|
||
|
|
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;
|
||
|
|
int winner_id_ = -1;
|
||
|
|
|
||
|
|
// Trigger/morph tracking
|
||
|
|
std::vector<bool> trigger_fired_;
|
||
|
|
bool terrain_dirty_ = false;
|
||
|
|
int dirty_x0_ = 0, dirty_z0_ = 0, dirty_x1_ = 0, dirty_z1_ = 0;
|
||
|
|
|
||
|
|
// Clone race recording & playback
|
||
|
|
CloneRecording recording_;
|
||
|
|
CloneRecording playback_clone_;
|
||
|
|
bool clone_active_ = false;
|
||
|
|
size_t clone_tick_ = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace top_octane::sim
|