1515using WinAPI ;
1616using Microsoft . Extensions . Configuration ;
1717using SharedLib . NpcFinder ;
18+ using Cyotek . Collections . Generic ;
1819
1920namespace Core
2021{
@@ -34,7 +35,7 @@ public sealed class BotController : IBotController, IDisposable
3435
3536 public Thread ? screenshotThread { get ; set ; }
3637
37- private const int screenshotTickMs = 150 ;
38+ private const int screenshotTickMs = 200 ;
3839 private DateTime lastScreenshot ;
3940
4041 public Thread addonThread { get ; set ; }
@@ -74,6 +75,34 @@ public sealed class BotController : IBotController, IDisposable
7475 private readonly AutoResetEvent addonAutoResetEvent = new ( false ) ;
7576 private readonly AutoResetEvent npcNameFinderAutoResetEvent = new ( false ) ;
7677
78+ public double AvgScreenLatency
79+ {
80+ get
81+ {
82+ double avg = 0 ;
83+ for ( int i = 0 ; i < ScreenLatencys . Size ; i ++ )
84+ {
85+ avg += ScreenLatencys . PeekAt ( i ) ;
86+ }
87+ return avg /= ScreenLatencys . Size ;
88+ }
89+ }
90+ private readonly CircularBuffer < double > ScreenLatencys ;
91+
92+ public double AvgNPCLatency
93+ {
94+ get
95+ {
96+ double avg = 0 ;
97+ for ( int i = 0 ; i < NPCLatencys . Size ; i ++ )
98+ {
99+ avg += NPCLatencys . PeekAt ( i ) ;
100+ }
101+ return avg /= NPCLatencys . Size ;
102+ }
103+ }
104+ private readonly CircularBuffer < double > NPCLatencys ;
105+
77106 public BotController ( ILogger logger , IPPather pather , DataConfig dataConfig , IConfiguration configuration )
78107 {
79108 this . logger = logger ;
@@ -112,6 +141,9 @@ public BotController(ILogger logger, IPPather pather, DataConfig dataConfig, ICo
112141 minimapNodeFinder = new MinimapNodeFinder ( WowScreen , new PixelClassifier ( ) ) ;
113142 MinimapImageFinder = minimapNodeFinder as IImageProvider ;
114143
144+ ScreenLatencys = new CircularBuffer < double > ( 5 ) ;
145+ NPCLatencys = new CircularBuffer < double > ( 5 ) ;
146+
115147 addonThread = new Thread ( AddonRefreshThread ) ;
116148 addonThread . Start ( ) ;
117149
@@ -157,14 +189,21 @@ public void AddonRefreshThread()
157189 public void ScreenshotRefreshThread ( )
158190 {
159191 var nodeFound = false ;
192+ var stopWatch = new Stopwatch ( ) ;
160193 while ( this . Enabled )
161194 {
162195 if ( ( DateTime . UtcNow - lastScreenshot ) . TotalMilliseconds > screenshotTickMs )
163196 {
164197 if ( this . WowScreen . Enabled )
165198 {
199+ stopWatch . Restart ( ) ;
166200 this . WowScreen . UpdateScreenshot ( ) ;
201+ ScreenLatencys . Put ( stopWatch . ElapsedMilliseconds ) ;
202+
203+ stopWatch . Restart ( ) ;
167204 this . npcNameFinder . Update ( ) ;
205+ NPCLatencys . Put ( stopWatch . ElapsedMilliseconds ) ;
206+
168207 this . WowScreen . PostProcess ( ) ;
169208 }
170209 else
@@ -189,11 +228,10 @@ public void ScreenshotRefreshThread()
189228 MapId = this . AddonReader . UIMapId . Value ,
190229 Spot = this . AddonReader . PlayerReader . PlayerLocation
191230 } ) ;
192- updatePlayerPostion . Reset ( ) ;
193231 updatePlayerPostion . Restart ( ) ;
194232 }
195233
196- Thread . Sleep ( 10 ) ;
234+ Thread . Sleep ( 5 ) ;
197235 }
198236 this . logger . LogInformation ( "Screenshot thread stoppped!" ) ;
199237 }
0 commit comments