#pragma once

// Discrete simulation time, measured in ticks since t=0.
using Tick = long long;

// Fixed simulation tick rate. See architecture.md "Fixed-Timestep Tick-Based Simulation".
constexpr int kTickRateHz = 30;
constexpr double kTickDurationMs = 1000.0 / kTickRateHz;
constexpr double kTickDurationSeconds = 1.0 / kTickRateHz;

// Delay between a tool activating (emitting its beam) and its effect being
// applied — half the 0.3 s beam duration. Shared by weapons, repair tools, and
// salvage modules so all three apply their effect mid-beam (REQ-SHP-FIRING,
// REQ-SHP-FIRING-BEAM).
constexpr Tick kBeamImpactDelayTicks = 5;

// Converts a wall-clock duration (in seconds, as it appears in config TOML) to
// an integer tick count. Rounds to nearest to avoid systematic drift from
// repeated conversions.
constexpr Tick secondsToTicks(double seconds)
{
    return static_cast<Tick>(seconds * kTickRateHz + 0.5);
}

// Inverse of secondsToTicks; useful for logging and UI display.
constexpr double ticksToSeconds(Tick ticks)
{
    return static_cast<double>(ticks) / kTickRateHz;
}
