/*
 * MIT License
 * Author: Mark Allyn
 *
 * simulator.h — Thread 4: generates simulated marine targets in
 * Bellingham Bay for the Marine PPI scope.
 *
 * The Simulator is polled by TrafficCop (Thread 2) at ~4 Hz.
 * On each poll it advances all target positions, applies the
 * marine radar equation, and returns a snapshot array.
 *
 * No mutex is needed inside the Simulator itself — it only shares
 * data when TrafficCop calls poll(), and TrafficCop serialises those
 * calls from its own thread.
 */

#pragma once
#include <array>
#include <cstdint>
#include "target_buffer.h"
#include "settings.h"

struct SimTarget {
    uint64_t id;
    float    latDeg;       // WGS84 latitude, degrees
    float    lonDeg;       // WGS84 longitude, degrees
    float    speedMps;     // metres per second
    float    headingDeg;   // true heading, CW from north
    float    sigmaM2;      // RCS in m²
    float    sizeM;        // physical blob half-radius in metres
};

class Simulator {
public:
    Simulator();

    // Advance simulation by dt seconds and fill output array.
    // Returns the number of valid targets written.
    int poll(float dt, std::array<TargetState, MAX_TARGETS>& out);

private:
    static float computeBrightness(float sigmaM2, float rangeM);

    std::array<SimTarget, MAX_TARGETS> targets_{};
    int targetCount_ = 0;
};
