using Luneraria.Core;
using UnityEngine;
namespace Luneraria.View
{
///
/// Hosts a bot match in the scene (U2C/U2D). Update only hands frame time (times Speed) to the
/// runner's fixed clock; it never decides anything in combat. Seed, start round and extra gold
/// are the public fixtures of the golden scenarios.
///
public sealed class LuneMatchDriver : MonoBehaviour
{
public int Seed = 2;
public int StartRound = 1;
public int ExtraGold;
public string Profile = "";
/// Match speed: simulated seconds per real second.
public float Speed = 1f;
public bool Paused;
public bool RecordTrace = true;
public LuneMatchRunner Runner { get; private set; }
/// Main-thread cost of the last frame's simulation (milliseconds).
public double LastAdvanceMs { get; private set; }
readonly System.Diagnostics.Stopwatch _clock = new System.Diagnostics.Stopwatch();
public void Restart()
{
Runner = new LuneMatchRunner(new MatchOptions { Seed = Seed, HumanSlot = -1 }, StartRound, ExtraGold, Profile);
if (RecordTrace)
Runner.Trace = new LuneTrace();
}
void Awake()
{
if (Runner == null)
Restart();
}
void Update()
{
_clock.Restart();
if (!Paused)
Runner.Advance(Time.deltaTime * Speed);
LastAdvanceMs = _clock.Elapsed.TotalMilliseconds;
}
}
}