Problem - Calculate fps and regulating this.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Honguito98
Posts: 1
Joined: 24 Nov 2014 21:30

Problem - Calculate fps and regulating this.

#1 Post by Honguito98 » 24 Nov 2014 21:45

Hi at all.
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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problem - Calculate fps and regulating this.

#2 Post by aGerman » 25 Nov 2014 14:33

The Frames Per Second of what are you trying to calculate?

To be honest neither do I understand on what your calculation is based nor do I understand your code at all.

Code: Select all

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
)

The last 2 digits of the %time% variable show up as centiseconds not as milliseconds.
And you do not know the initial value of %time%. It could happen the last 2 digits are already 01 in the first iteration of your loop as well as they could be 01 several times during 1000 iterations where 'Scale' would be changed several times. Thus, the value of %Scale% is more or less random and probably completely different each time you run the code.
Further more: what has the time that the CALL command takes to do with your calculation of FPS?

Regards
aGerman

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Problem - Calculate fps and regulating this.

#3 Post by einstein1969 » 02 Dec 2014 15:29

Hi Honguito98,

the TIME variable is instable.

I have studied for time this variable form gaming porpouse...

1) the variable on windows 7 depend on "timer coaleshing" and i thinks the same on windows 8.x

2) the variable skip some value.

3) the variable depend on internal timer that have a resolution variable.

But i think there are solution for these problems.

first you need analyze the timer resolution of OS:

Code: Select all

C:\Windows\system32>powercfg -energy -xml duration 1
Attivazione della traccia per 1 secondi in corso...
Analisi del comportamento del sistema in corso...
Analisi dei dati di traccia in corso...
Analisi completata.


will produce "energy-report.xml"

search 843c944e-9fc2-4e58-9e58-9bfdf0ea25b2 and e5ba7e97-57dd-4378-a022-0b5b3fff3d22

Code: Select all

    <Name>Risoluzione timer di piattaforma</Name>
    <AnalysisLog>
      <LogEntry guid="843c944e-9fc2-4e58-9e58-9bfdf0ea25b2">
        <Name>Risoluzione timer di piattaforma</Name>
        <Severity>Informational</Severity>
        <Description>La risoluzione predefinita del timer di piattaforma è 15,6 ms (15625000 ns) e deve essere utilizzata ogni volta che il sistema è inattivo. Se la risoluzione del timer aumenta, le tecnologie di risparmio energia del processore potrebbero non essere efficaci. La risoluzione del timer può aumentare in caso di riproduzione multimediale o di animazioni grafiche.</Description>
        <Details>
          <Detail guid="e5ba7e97-57dd-4378-a022-0b5b3fff3d22">
            <Name>Risoluzione timer corrente (unità di 100 ns)</Name>
            <Value>156000</Value>
          </Detail>
        </Details>
      </LogEntry>


on my machine the current timer is 15600000 ns (or 15625000 ns)

the variable %TIME% get the value from this timer!

this explain why there are GAP on the variable TIME.

ref : http://www.dostips.com/forum/viewtopic.php?p=31740#p31740
ref : http://www.dostips.com/forum/viewtopic.php?p=30206#p30206


The TIME variable don't increment by 1 cs but 1.56 cs and then produce 100/1.56=64 values (the max frequency)

einstein1969

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Problem - Calculate fps and regulating this.

#4 Post by einstein1969 » 07 Dec 2014 08:21

This is a sample for the same functionality.

Code: Select all

@echo off

cls
SetLocal EnableDelayedExpansion

Rem Empty environment for best set-set/A performance.
For /F "delims==" %%v in ('set') do if /I Not "%%v"=="TMP" if /I Not "%%v"=="Temp" set "%%v="

call :pre_game1
set N=0
set k=0

set /A maxFPS=4
set /A cs=100/maxFPS
set t=!time: =0!

:loop
(
       rem do some stuff/game
       rem call :game2
       call :game1


:delay
(     
       set tc=!time: =0!

       for /F "tokens=1-8 delims=:.," %%a in ("!t!:!tc!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"

       if !a! lss !cs! goto :delay
       if !a! gtr !cs! set /a a-=1

       set t=!tc!
       if !a! neq 0 (set /A fps=100/a) else set fps=?
       title FPS:!fps!/s
)
goto :loop

:game2
   set /A N+=1
   if !N! equ 1 set/P "=!time!" <nul
   set/P "=." <nul
   if !N! equ !maxFPS! (set N=0 & echo()
goto :eof

:game1
   cls&for /F %%k in ("!K!") do for /L %%N in (1,1,4) do echo(!L[%%k,%%N]!
   set /a k=k+1 & if !k! gtr 5 set k=0
goto :eof

:pre_game1
set L[0,1]=
set L[0,2]=           _o
set L[0,3]=         _^< \_
set L[0,4]=        (_)^>(_)
set L[1,1]=
set L[1,2]=           _o
set L[1,3]=         _^< \_
set L[1,4]=        (_)^>(_)
set L[2,1]=         o
set L[2,2]=         /\_
set L[2,3]=         _^>(_)
set L[2,4]=        (_)
set L[3,1]=         _
set L[3,2]=       _ \\o
set L[3,3]=        (_)/^<_
set L[3,4]=           (_)
set L[4,1]=         _
set L[4,2]=        (_)\__/o
set L[4,3]=             \_^| \
set L[4,4]=           (_)
set L[5,1]=         _
set L[5,2]=        (_)
set L[5,3]=            _^|/' \/
set L[5,4]=        (_)'  _\o_

goto :eof


Edit: Correct some flaw

einstein1969
Last edited by einstein1969 on 12 Dec 2014 10:12, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem - Calculate fps and regulating this.

#5 Post by foxidrive » 07 Dec 2014 09:26

einstein1969 wrote:

Code: Select all

Rem Empty environment for best set-set/A performance.
For /F "delims==" %%v in ('set') do if Not "%%v"=="TMP" set "%%v="



Your routine above has some flaws Einstein.

A) The temp variable is used most often.
B) Your comparison is case sensitive.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Problem - Calculate fps and regulating this.

#6 Post by Squashman » 08 Dec 2014 07:56

Einstein,
Is this batch suppose to work? Didn't do anything but spew code onto my screen.

penpen
Expert
Posts: 1997
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Problem - Calculate fps and regulating this.

#7 Post by penpen » 08 Dec 2014 12:08

Just add the first line:

Code: Select all

@echo off
:: ...

penpen

lmstearn
Posts: 47
Joined: 07 Dec 2014 15:15
Location: Australia
Contact:

Re: Problem - Calculate fps and regulating this.

#8 Post by lmstearn » 09 Dec 2014 02:47

This looks ambitious. Hope it will continue to be developed, for once the FPS is calculated within a tolerance then calibrating it is trivial. Problem will then be hooking into popular games so the info is captured in game screen.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Problem - Calculate fps and regulating this.

#9 Post by Squashman » 09 Dec 2014 15:13

Would be cooler to simulate the wheels turning.

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Problem - Calculate fps and regulating this.

#10 Post by einstein1969 » 12 Dec 2014 10:25

thanks foxidrive, thanks penpen : i have added your suggestion

@squashman : you are right :oops:

I have probed to get the millisecond but it is difficult to syncronize. It is easy calculate a average value.

einstein1969

Post Reply