Update
This commit is contained in:
44
Assets/Scripts/UI/MouseMetricsHelper.cs
Normal file
44
Assets/Scripts/UI/MouseMetricsHelper.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user