NaaLaa
Performance - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: NaaLaa 7 Questions (https://www.naalaa.com/forum/forum-3.html)
+--- Thread: Performance (/thread-247.html)



Performance - johnno56 - 05-19-2025

Quick question.

I understand the purpose of the "fwait" command and it use to control the "speed" (for want of a better word) of the program. What I would like to know is... is there a way for N7 to display the current FPS? For example: If I wanted to check the performance impact by moving more and more sprites on the screen... Or even like an FPS counter when running stress tests... that kind of thing...  I hope that I am making sense... Just curious...

J


RE: Performance - 1micha.elok - 05-19-2025

(05-19-2025, 02:29 AM)johnno56 Wrote: Quick question.

I understand the purpose of the "fwait" command and it use to control the "speed" (for want of a better word) of the program. What I would like to know is... is there a way for N7 to display the current FPS? For example: If I wanted to check the performance impact by moving more and more sprites on the screen... Or even like an FPS counter when running stress tests... that kind of thing...  I hope that I am making sense... Just curious...

J

Perhaps like this one .....

Code:
set window "FPS Checker",400,300

set redraw off

' Variables to calculate FPS
time_start = time()
frame_count = 0
fps = 0
fw = 60

'Main Loop
while not keydown(KEY_ESCAPE,true)
    ' Clear screen
    set color 32,32,32
    cls

    ' Frame counting
    frame_count = frame_count +1
    time_now = time()

    ' Calculate FPS every second
    if time_now - time_start >= 1 then
        fps = (frame_count) / (time_now - time_start)
        time_start = time_now
        frame_count = 0
    endif

    ' Display FPS
    set caret width()/2, height()/2
    set color 255,255,255
    center "Current FPS: " + fps

    ' Update screen
    redraw
   
    if keydown(KEY_UP,true) then fw = fw + 10
    if keydown(KEY_DOWN,true) then fw = fw - 10
   
    fwait fw

wend



RE: Performance - johnno56 - 05-19-2025

Excellent! Thank you!


RE: Performance - kevin - 05-20-2025

(05-19-2025, 04:59 AM)johnno56 Wrote: Excellent! Thank you!

Great example. 

I would just add the following to it, to make it easier to switch between max fps and 60 fps - I find that this really helps when you are trying to check fps, but still easily see how the game is running when the fps is set to a "normal" rate. You can retain the smaller increments/decrements in fw by amalgamating the key up and key down actions within this code, if desired.

Code:
if keydown(KEY_SPACE)
        fw = 1000
else
        fw = 60
endif