Skip to content

Commit e66d03a

Browse files
committed
Update AntiChatter to v0.4.2 api and use single precision MathF for faster calculation
1 parent d109828 commit e66d03a

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

DevocubFilters/AntiChatter.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
namespace TabletDriverFilters.Devocub
77
{
8-
using static Math;
8+
using static MathF;
99

1010
[PluginName("TabletDriver AntiChatter Filter")]
1111
public class AntiChatter : IFilter
1212
{
1313
private Vector2 _lastPos;
1414
private float _timerInterval;
15-
private const float _threshold = 0.63f;
16-
private float _latency;
15+
private const float _threshold = 0.9f;
16+
private float _latency = 2.0f;
1717

1818
public Vector2 Filter(Vector2 point)
1919
{
2020
Vector2 calcTarget = new Vector2();
21-
double deltaX, deltaY, distance, weightModifier, predictionModifier;
21+
float deltaX, deltaY, distance, weightModifier, predictionModifier;
2222

2323
if (_lastPos == null)
2424
{
@@ -60,9 +60,9 @@ public Vector2 Filter(Vector2 point)
6060
deltaY = calcTarget.Y - _lastPos.Y;
6161
distance = Sqrt(deltaX * deltaX + deltaY * deltaY);
6262

63-
double stepCount = Latency / TimerInterval;
64-
double target = 1 - _threshold;
65-
double weight = 1.0 - (1.0 / Pow(1.0 / target, 1.0 / stepCount));
63+
float stepCount = Latency / TimerInterval;
64+
float target = 1 - _threshold;
65+
float weight = (float)(1.0 - (1.0 / Pow((float)(1.0 / target), (float)(1.0 / stepCount))));
6666

6767
// Devocub smoothing
6868
// Increase weight of filter in {formula} times
@@ -75,12 +75,10 @@ public Vector2 Filter(Vector2 point)
7575
weightModifier += AntichatterOffsetY;
7676

7777
weightModifier = weight / weightModifier;
78-
weightModifier = Clamp(weightModifier, 0, 1);
78+
weightModifier = Math.Clamp(weightModifier, 0, 1);
7979
_lastPos.X += (float)(deltaX * weightModifier);
8080
_lastPos.Y += (float)(deltaY * weightModifier);
8181

82-
// OTDPlugin 0.3.2 feature
83-
// OpenTabletDriver.Plugin.Log.Write("Antichatter", $"orig: ({point}) new: ({_lastPos}) dist: ({point.DistanceFrom(_lastPos)})", LogLevel.Debug);
8482
return _lastPos;
8583
}
8684

@@ -89,11 +87,11 @@ public Vector2 Filter(Vector2 point)
8987
[SliderProperty("Latency", 0f, 5f, 2f)]
9088
public float Latency
9189
{
92-
set => _latency = Clamp(value, 0, 1000);
90+
set => _latency = Math.Clamp(value, 0, 1000);
9391
get => _latency;
9492
}
9593

96-
[UnitProperty("Timer Interval", "hz")]
94+
[Property("Timer Interval"), Unit("hz")]
9795
public float TimerInterval
9896
{
9997
set => _timerInterval = 1000f / value;
@@ -110,7 +108,7 @@ public float TimerInterval
110108
public float AntichatterOffsetX { set; get; }
111109

112110
[Property("Antichatter Offset Y")]
113-
public float AntichatterOffsetY { set; get; }
111+
public float AntichatterOffsetY { set; get; } = 1;
114112

115113
[BooleanProperty("Prediction", "")]
116114
public bool PredictionEnabled { set; get; }

DevocubFilters/DevocubFilters.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

0 commit comments

Comments
 (0)