mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-03-19 19:24:37 +01:00
Use high-precision timer for DeltaTime
This commit is contained in:
parent
68f51ff4f0
commit
9a286691f4
|
|
@ -17,7 +17,7 @@ namespace SteamController
|
|||
public List<Profiles.Profile> Profiles { get; } = new List<Profiles.Profile>();
|
||||
public List<Managers.Manager> Managers { get; } = new List<Managers.Manager>();
|
||||
|
||||
public List<Profiles.Profile>? orderedProfiles;
|
||||
private List<Profiles.Profile>? orderedProfiles;
|
||||
|
||||
public bool RequestEnable { get; set; } = true;
|
||||
public bool RequestDesktopMode { get; set; } = true;
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ namespace SteamController.Devices
|
|||
/// This is action controlled by Lizard mode
|
||||
public bool LizardButton { get; internal set; }
|
||||
public bool LizardMouse { get; internal set; }
|
||||
public DateTime LastUpdated { get; protected set; } = DateTime.Now;
|
||||
public double DeltaTime { get; protected set; }
|
||||
|
||||
internal abstract void Reset();
|
||||
internal abstract bool BeforeUpdate(byte[] buffer);
|
||||
|
|
@ -23,13 +21,6 @@ namespace SteamController.Devices
|
|||
{
|
||||
}
|
||||
|
||||
protected void UpdateTime()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
DeltaTime = (now - LastUpdated).TotalSeconds;
|
||||
LastUpdated = now;
|
||||
}
|
||||
|
||||
protected bool ValueCanBeUsed
|
||||
{
|
||||
get
|
||||
|
|
@ -202,7 +193,6 @@ namespace SteamController.Devices
|
|||
{
|
||||
rawLastValue = rawValue;
|
||||
rawValue = newValue;
|
||||
UpdateTime();
|
||||
|
||||
if (!rawLastValue && rawValue)
|
||||
{
|
||||
|
|
@ -330,7 +320,7 @@ namespace SteamController.Devices
|
|||
case DeltaValueMode.AbsoluteTime:
|
||||
if (Math.Abs(Value) < Deadzone)
|
||||
return 0.0;
|
||||
value = (int)(Value * DeltaTime);
|
||||
value = (int)(Value * (Controller?.DeltaTime ?? 0.0));
|
||||
break;
|
||||
|
||||
case DeltaValueMode.Delta:
|
||||
|
|
@ -343,7 +333,7 @@ namespace SteamController.Devices
|
|||
value = Value - LastValue;
|
||||
if (Math.Abs(Value) < MinChange)
|
||||
return 0.0;
|
||||
value = (int)(value * DeltaTime);
|
||||
value = (int)(value * (Controller?.DeltaTime ?? 0.0));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -364,7 +354,6 @@ namespace SteamController.Devices
|
|||
{
|
||||
rawLastValue = rawValue;
|
||||
rawValue = newValue;
|
||||
UpdateTime();
|
||||
|
||||
// first time pressed, reset value as this is a Pad
|
||||
if (ActiveButton is not null && ActiveButton.JustPressed())
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Diagnostics;
|
||||
using CommonHelpers;
|
||||
using hidapi;
|
||||
using PowerControl.External;
|
||||
|
|
@ -12,6 +13,9 @@ namespace SteamController.Devices
|
|||
private const int ReadTimeout = 50;
|
||||
|
||||
private hidapi.HidDevice neptuneDevice;
|
||||
private Stopwatch stopwatch = new Stopwatch();
|
||||
private TimeSpan? lastUpdate;
|
||||
public double DeltaTime { get; private set; }
|
||||
|
||||
internal SteamController()
|
||||
{
|
||||
|
|
@ -20,6 +24,8 @@ namespace SteamController.Devices
|
|||
|
||||
neptuneDevice = new hidapi.HidDevice(VendorID, ProductID, 64);
|
||||
neptuneDevice.OpenDevice();
|
||||
|
||||
stopwatch.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -42,6 +48,11 @@ namespace SteamController.Devices
|
|||
|
||||
internal void BeforeUpdate()
|
||||
{
|
||||
var ts = stopwatch.Elapsed;
|
||||
DeltaTime = lastUpdate is not null ? (ts - lastUpdate.Value).TotalSeconds : 0.0;
|
||||
DeltaTime = Math.Min(DeltaTime, 0.1); // max update is 100ms
|
||||
lastUpdate = ts;
|
||||
|
||||
LizardButtons = true;
|
||||
LizardMouse = true;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue