Update .gitignore to exclude TypeScript build info and add dist directory. Expand README with project overview, technology stack, prerequisites, and instructions for running and testing the application.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
|
||||
namespace HSchool.Server.Game;
|
||||
|
||||
/// <summary>Game-loop counters surfaced in the Aspire dashboard.</summary>
|
||||
internal sealed class GameMetrics : IDisposable
|
||||
{
|
||||
public const string MeterName = "HSchool.Server.Game";
|
||||
|
||||
private readonly Meter _meter;
|
||||
private readonly Counter<long> _ticks;
|
||||
private readonly Histogram<double> _tickDuration;
|
||||
private readonly UpDownCounter<long> _connectedPlayers;
|
||||
private readonly Counter<long> _snapshotBytes;
|
||||
|
||||
public GameMetrics(IMeterFactory meterFactory)
|
||||
{
|
||||
_meter = meterFactory.Create(MeterName);
|
||||
_ticks = _meter.CreateCounter<long>("hschool.game.ticks", "{tick}", "Simulation steps executed.");
|
||||
_tickDuration = _meter.CreateHistogram<double>("hschool.game.tick.duration", "ms", "Wall time of one simulation step.");
|
||||
_connectedPlayers = _meter.CreateUpDownCounter<long>("hschool.game.players", "{player}", "Currently connected players.");
|
||||
_snapshotBytes = _meter.CreateCounter<long>("hschool.game.snapshot.bytes", "By", "Snapshot bytes pushed to clients.");
|
||||
}
|
||||
|
||||
public void RecordTick(double durationMs)
|
||||
{
|
||||
_ticks.Add(1);
|
||||
_tickDuration.Record(durationMs);
|
||||
}
|
||||
|
||||
public void PlayerJoined() => _connectedPlayers.Add(1);
|
||||
|
||||
public void PlayerLeft() => _connectedPlayers.Add(-1);
|
||||
|
||||
public void SnapshotSent(int bytes, int recipients) => _snapshotBytes.Add((long)bytes * recipients);
|
||||
|
||||
public void Dispose() => _meter.Dispose();
|
||||
}
|
||||
Reference in New Issue
Block a user