Ooops
September 18, 2021, 04:57:26

Author Topic: display fps on screen  (Read 436 times)

Offline zelda64bit

  • Jr. Member
  • **
  • Posts: 54
display fps on screen
« on: August 07, 2021, 20:20:50 »
Hello.

there is some way to get the fps from the game so that you can display them on the screen.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: display fps on screen
« Reply #1 on: August 08, 2021, 01:35:14 »
Code: BlitzMax
  1. SuperStrict
  2. Graphics 800,600
  3. Print GraphicsHertz()
  4.  
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline zelda64bit

  • Jr. Member
  • **
  • Posts: 54
Re: display fps on screen
« Reply #2 on: August 08, 2021, 15:04:15 »
Thank you Midimaster. ;) Although it does not do what I wanted, I give example to explain myself.
Code: [Select]
SuperStrict
AutoMidHandle(True) 'centra origen en el medio

Type Tjugador
Field x:Int
Field y:Int
Field rotacion:Int
Field imagen:TImage = LoadImage("00.png")

Function Create:Tjugador()
Local jugador:Tjugador = New Tjugador
SeedRnd(MilliSecs()) 
jugador.x = Rand(32, 608)
jugador.y = Rand(100, 450)
Return jugador
EndFunction

Method pintar()
rotacion:+ 1
SetScale(0.5,0.5)
SetRotation(rotacion)
DrawImage(imagen,x,y)
EndMethod

EndType

Global objetos:Int

Graphics(640,480)


Global lista_jugador:TList = CreateList()

While Not KeyDown(key_escape)
SetScale(2,2)
SetRotation(0)
DrawText("frames: "+GraphicsHertz(),100,32)
DrawText("objetos: "+objetos,320,32)

If(GraphicsHertz() > 58) Then
Local jugador:Tjugador = Tjugador.Create()
ListAddLast(lista_jugador,jugador)
objetos:+1
EndIf

For Local j:Tjugador = EachIn lista_jugador
j.pintar()
Next

Flip()
Cls()
EndWhile


In the example I create objects while it is greater than 58 fps, what happens is that the fps do not go down for more objects that appear on the screen and I can not see the performance that bliztmax has on my computer.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: display fps on screen
« Reply #3 on: August 08, 2021, 18:56:39 »
As long as you do games in a window the GraphicsHertz() is related to the Vsync that Window uses. It does not go down but is constant 60Hz.

Every time when you use the command Flip() your screen will be sent to the window. With only the word Flip() this happens too at 60Hz. Means, that independent of what msec you used before the next While/Wend-loop will start 16msec later. Flip() without parameter pauses your app until the vsync comes.

You could use a Flip 0 to speed up your performance. This means sent your screen to the window, but dont wait for the vsync.

If you want to know how often the While/Wend iterated simply use a counter:Int in combination with a Millisecs()-time.
Code: BlitzMax
  1. While Not KeyDown(key_escape)
  2.         Global Counter:Int, TimeStamp:Int
  3.         If TimeStamp<Millisecs()
  4.                 TimeStamp = Millisecs()+1000
  5.                 Print "FPS=" + Counter
  6.                 Counter=0
  7.         Endif
  8.         Counter = Counter +1
  9.         SetRotation(0)
  10.         DrawText("frames: "+GraphicsHertz(),100,32)
  11.         DrawText("objetos: "+objetos,320,32)
  12. .....
  13.  


Another way would be to measure the time between While-command and Wend command:
Code: BlitzMax
  1. While Not KeyDown(key_escape)
  2.         Local  TimeStamp:Int =  Millisecs()
  3.         ' now your code:
  4.         SetRotation(0)
  5.         DrawText("frames: "+GraphicsHertz(),100,32)
  6.         DrawText("objetos: "+objetos,320,32)
  7. .....
  8.         Print "Time needed:" + (Millisecs()-TimeStamp)
  9.         Flip()
  10. Wend
  11.  

If you need it more precise you could use my MicroTimer code snipplet I pubished here last week. This enables measurments below 1msec. So it is possible to get usefull result when you try only to find out the performance of a single function or a hand full of code lines. See here:

https://www.syntaxbomb.com/blitzmax-blitzmax-ng/usleep/msg347051757/#msg347051757
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline zelda64bit

  • Jr. Member
  • **
  • Posts: 54
Re: display fps on screen
« Reply #4 on: August 08, 2021, 20:38:51 »
Thanks for the help,I'll try it to see if it works. ;)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal