66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System.Text;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace FloodSWE.Debugging
|
|
{
|
|
public sealed class SweStatsOverlay : MonoBehaviour
|
|
{
|
|
public SweTileSimulator simulator;
|
|
public TextMeshProUGUI targetText;
|
|
public float updateInterval = 0.25f;
|
|
|
|
private float elapsed;
|
|
private readonly StringBuilder builder = new StringBuilder(256);
|
|
|
|
private void Update()
|
|
{
|
|
if (targetText == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
elapsed += Time.deltaTime;
|
|
if (elapsed < updateInterval)
|
|
{
|
|
return;
|
|
}
|
|
|
|
elapsed = 0.0f;
|
|
targetText.text = BuildStats();
|
|
}
|
|
|
|
private string BuildStats()
|
|
{
|
|
builder.Clear();
|
|
|
|
if (simulator == null)
|
|
{
|
|
builder.AppendLine("SWE: simulator not set");
|
|
return builder.ToString();
|
|
}
|
|
|
|
builder.AppendLine("SWE Stats");
|
|
builder.Append("Grid: ").Append(simulator.gridRes).Append(" ");
|
|
builder.Append("Tile: ").Append(simulator.tileSizeMeters.ToString("F0")).Append("m ");
|
|
builder.Append("dx: ").Append(simulator.CellSizeMeters.ToString("F3")).Append("m");
|
|
builder.AppendLine();
|
|
builder.Append("Depth: ").Append(simulator.LastMaxDepth.ToString("F3")).Append("m ");
|
|
builder.Append("Speed: ").Append(simulator.LastMaxSpeed.ToString("F3")).Append("m/s");
|
|
builder.AppendLine();
|
|
builder.Append("TotalDepth: ").Append(simulator.LastTotalDepth.ToString("F3")).Append("m ");
|
|
builder.Append("Volume: ").Append(simulator.LastTotalVolume.ToString("F3")).Append("m^3");
|
|
builder.AppendLine();
|
|
builder.Append("Clamped: ").Append(simulator.LastClampedCells);
|
|
builder.Append(" (").Append((simulator.LastClampedRatio * 100.0f).ToString("F1")).Append("%)");
|
|
builder.Append(" NaN: ").Append(simulator.LastNanCells);
|
|
builder.AppendLine();
|
|
builder.Append("dtMax: ").Append(simulator.LastDtMax.ToString("F4")).Append("s ");
|
|
builder.Append("substeps: ").Append(simulator.LastSubsteps).Append(" ");
|
|
builder.Append("dt: ").Append(simulator.LastDt.ToString("F4")).Append("s");
|
|
|
|
return builder.ToString();
|
|
}
|
|
}
|
|
}
|