Files
top-octane/src/sim/physics.hpp
T
Luxferre db788a2739 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
2026-12-01 18:50:29 +02:00

157 lines
4.6 KiB
C++

#pragma once
#include "assets/level.hpp"
#include "core/math.hpp"
#include "input/input_manager.hpp"
#include "sim/vehicle_defs.hpp"
#include <string>
#include <vector>
namespace top_octane::sim {
struct CraftPose {
Vec3 pos{0.0f, 0.0f, 0.0f};
float yaw = 0.0f;
float pitch = 0.0f;
float roll = 0.0f;
};
enum class RecoveryState {
Active = 0,
CallingRepair,
AwaitingRepair,
Repairing,
Destroyed,
};
struct CraftState {
int id = 0;
bool is_human = false;
int player_index = -1; // 0 = P1, 1 = P2, -1 = AI
int vehicle_idx = 0;
int team_idx = 7;
std::string pilot_name;
CraftPose prev_pose{};
CraftPose curr_pose{};
Vec3 vel{0.0f, 0.0f, 0.0f};
float yaw_rate = 0.0f;
bool airborne = false;
float airtime = 0.0f;
float air_spin_accum = 0.0f;
// Resources & upgrades
float fuel = 100.0f;
float max_fuel = 100.0f;
float shield = 100.0f;
float max_shield = 100.0f;
float ammo = 100.0f;
float max_ammo = 100.0f;
int minigun_level = 1;
int missile_level = 1;
int booster_level = 1;
// Timers & weapons
float minigun_cd = 0.0f;
float missile_cd = 0.0f;
float boost_timer = 0.0f;
float boost_cooldown = 0.0f;
float invincible_timer = 0.0f;
float invisible_timer = 0.0f;
float damage_flash = 0.0f;
int lock_target_id = -1;
float lock_progress = 0.0f;
float scrape_intensity = 0.0f;
float refuel_sound_cd = 0.0f;
uint8_t active_recharge_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo
uint8_t on_pit_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo (present on bay even if full)
float pit_fill_ratio = 1.0f; // [0..1] fill ratio of active charging resource(s)
bool autopilot = false;
// Recovery / repair
RecoveryState recovery_state = RecoveryState::Active;
float recovery_timer = 0.0f;
Vec3 recovery_pos{0.0f, 0.0f, 0.0f};
bool recovery_refill = true;
float recovery_duration = 3.2f;
float recovery_cooldown = 0.0f;
float pit_stuck_timer = 0.0f;
bool stuck_in_pit_hint = false;
// Race / Deathmatch progression
int lap = 1;
int next_checkpoint = 1;
int checkpoints_passed = 0;
int current_wp = 0;
bool wrong_way = false;
bool finished = false;
float race_time = 0.0f;
float current_lap_time = 0.0f;
float best_lap_time = 0.0f;
int placement = 1;
int kills = 0;
int deaths = 0;
float fuel_used = 0.0f;
float armour_used = 0.0f;
int shots_fired = 0;
int shots_hit = 0;
std::string killed_by;
// AI state
int ai_target_wp = 0;
float ai_fire_delay = 0.0f;
bool ai_seeking_pit = false;
int ai_pit_pad_idx = -1;
float ai_stuck_timer = 0.0f;
float ai_unstuck_timer = 0.0f;
float ai_unstuck_steer = 1.0f;
float ai_pit_cooldown = 0.0f;
float ai_pit_stay_timer = 0.0f;
Vec3 ai_progress_anchor{0.0f, 0.0f, 0.0f};
float ai_progress_timer = 0.0f;
bool ai_anchor_init = false;
float ai_wp_best_dist = 1e9f;
float ai_wp_stall_timer = 0.0f;
float speed_horizontal() const {
return std::sqrt(vel.x * vel.x + vel.z * vel.z);
}
Vec3 forward_dir() const {
return Vec3(std::sin(curr_pose.yaw), 0.0f, std::cos(curr_pose.yaw));
}
};
struct CraftStepFeedback {
bool collided_wall = false;
float impact_speed = 0.0f;
bool scraping = false;
bool boosting = false;
int stunt_degrees = 0; // 180, 360, or 720 on landing
bool out_of_fuel = false;
};
// Pure deterministic 60 Hz hover physics step for one active craft
CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
const assets::LevelData& level, float dt,
bool fuel_enabled = true);
// Resolves world boundary, column AABB, ceiling, and cliff collisions for one active craft
bool resolve_world_collisions(CraftState& craft, const assets::LevelData& level,
float& out_impact_speed, bool& out_scraping);
// Resolves sphere-sphere bounce between two active crafts
bool resolve_craft_pair_collision(CraftState& a, CraftState& b, float& out_rel_speed);
// Safely places a craft on the nearest clear, drivable main track waypoint
bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
const std::vector<CraftState>& all_crafts,
bool restrict_to_checkpoint_arc = true);
// Interpolates craft pose for smooth rendering at arbitrary refresh rate
CraftPose interpolate_pose(const CraftState& craft, float alpha);
} // namespace top_octane::sim