45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
namespace Hallucinate.UI
|
||
|
|
{
|
||
|
|
public static class MouseMetricsHelper
|
||
|
|
{
|
||
|
|
private static int _reportCount = 0;
|
||
|
|
private static float _timer = 0f;
|
||
|
|
private static int _lastPollingRate = 0;
|
||
|
|
private static float _lastLatency = 0f;
|
||
|
|
private static Vector2 _lastMousePos;
|
||
|
|
|
||
|
|
public static (int pollingRate, float latencyMs) GetMetrics()
|
||
|
|
{
|
||
|
|
Update();
|
||
|
|
return (_lastPollingRate, _lastLatency);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static void Update()
|
||
|
|
{
|
||
|
|
_timer += Time.unscaledDeltaTime;
|
||
|
|
|
||
|
|
// Count "reports" based on position changes (simulated polling rate)
|
||
|
|
Vector2 currentPos = Input.mousePosition;
|
||
|
|
if (currentPos != _lastMousePos)
|
||
|
|
{
|
||
|
|
_reportCount++;
|
||
|
|
_lastMousePos = currentPos;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (_timer >= 1f)
|
||
|
|
{
|
||
|
|
_lastPollingRate = (int)(_reportCount / _timer);
|
||
|
|
_reportCount = 0;
|
||
|
|
_timer = 0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Dummy latency simulation (Input System doesn't expose raw hardware latency easily)
|
||
|
|
// In a real scenario, this would involve timestamping HID reports
|
||
|
|
_lastLatency = (1.0f / (Screen.currentResolution.refreshRateRatio.value > 0 ? (float)Screen.currentResolution.refreshRateRatio.value : 60f)) * 1000f;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|