I trying to code a 'fps calculator', but I have some problems.
FPS counter does not show correctly, and when I change the frames per second limit (MaxFPS var), the FPS counter exceeds the limit.
Any feedback is appreciated.
Code: Select all
@Echo Off
SetLocal EnableDelayedExpansion
:Tick
Rem Get the 'scale', how many 'calls' is required for get a milliseconds?
Set "T=!Time!"
For /L %%T in (1,1,1000) Do (
Call
If "!Time:~-2!" Equ "01" Set Scale=%%T
)
Set __T[1]=-1
Set __T[2]=-1
Set __Cnt=0
Set FPS=0
Set MaxFPS=20
:Main
For /L %%! in (1,1,20055) Do (
Cls & Echo; FPS: !FPS! Percent: !AVG!%% - No implemented-
for /l %%a in (1,1,1220) do call
%== FPS compute ==%
Set /a __Cnt+=1
For /F "Tokens=* Delims=0" %%A in ("!Time:~-2!") Do Set "__T[!__Cnt!]=%%A!Random:~0,1!" & Set T[!__Cnt!]=!Time!
If !__Cnt! Geq 2 (
Rem Milliseconds roll over
If !__T[1]! Gtr !__T[2]! (
Set /a "TimeCoef=1000 - (__T[1] - __T[2])"
) Else Set /a "TimeCoef=__T[2] - __T[1]"
If !__T[1]! Neq !__T[2]! (
Set /a "FPS=1000 / TimeCoef"
)
Set "__Cnt=0"
If !FPS! LSS !MaxFPS! Cls & Echo; FPS: !FPS!
)
If !FPS! Gtr !MaxFPS! (
Rem MaxCOEF - FPSCOEF
Rem Calculate milliseconds from FPS limit (60) and calculate milliseconds from current frame
Rem then subtract this values
Set /a "__ScaleLimit=((1000 / MaxFPS) - (1000 / FPS))"
Rem slowdown the code for x milliseconds
For /L %%` in (0,1,!__ScaleLimit!) Do For /L %%' in (0,1,!Scale!) Do Call
)
rem echo;!T[1]!____!__T[1]! !T[2]!_____!__T[2]! -- !__Cnt! ------ !__ScaleLimit!
rem pause
)
Goto :Main