FPS onscreen

Posted By: NL_3DGS_n00b

FPS onscreen - 07/13/06 14:55

How can I display the FPS speed?
I have knowledge for making panels, but I have no idea if there is a variable to display the FPS speed etc...
Posted By: ulillillia

Re: FPS onscreen - 07/13/06 14:59

Using time_fac is one way (multiply it by 16), but it's an abandoned variable.

Using this simple computation is another:

fps_display = pow(time_step, -1)*16;

This takes the reciprocal of the time_step variable and multiplies it by 16. This gives the frame rate. Then, just add a panel to point to this.
Posted By: Excessus

Re: FPS onscreen - 07/13/06 15:00

16 / time_step

EDIT: Too late, but I think my formula is easyer to understand. pow(time_step, -1)* 16 = (time_step ^(-1)) * 16 = (1/time_step)*16 = 16 / time_step.

I don't know about speed or accuracy..
Posted By: NL_3DGS_n00b

Re: FPS onscreen - 07/13/06 15:03

@Excessus,

Do I have to add / time_step behind *16 in 'uli's script?

(@Ulillillia, thanks, I'll try it out)
Posted By: Excessus

Re: FPS onscreen - 07/13/06 15:05

no, just use fps_display = 16 / time_step. Then display fps_display in a panel.
Posted By: NL_3DGS_n00b

Re: FPS onscreen - 07/13/06 15:08

Do I have to define time_step somewhere before I use it? If so, what kind of value does it need?
Posted By: ulillillia

Re: FPS onscreen - 07/13/06 15:12

Whoops! I forgot to simplify the formula, but it's still the same thing.

time_step is a predefined variable available in the 6.40.5 update. For those using older versions, use "time" instead. You do, however, have to define fps_display (or whatever you want to call it), as that isn't a predefined variable.
Posted By: NL_3DGS_n00b

Re: FPS onscreen - 07/13/06 15:25

I placed fps_display = 16 / time; inside a while(1){ } with a wait(64); inside a function so it won't refresh to fast.
Now I see it switches from 200 to 256. So I think it works?
Posted By: Excessus

Re: FPS onscreen - 07/13/06 15:29

Yes that should do it, although it's never a good idea to use wait(x) for a timed interval. Better use wait(-x) to wait x seconds instead of x frames because the time of a frame is variable.

If you want to check if the value of your calculated fps is correct, press f11 to bring up the debug panel and compare the values (they may slightly differ because of limited var accuracy)
Posted By: NL_3DGS_n00b

Re: FPS onscreen - 07/13/06 15:33

Thanks, I'll check it out.

EDIT:

This is the script I'm using now, it works fine now:

Code:
function fps_show{
if(FPS.visible == off){
FPS.visible = on;
while(FPS.visible == on){
fps_display = 16 / time;
wait(1);
}
}else{
FPS.visible = off;
}
}

on_f = fps_show;


Posted By: ulillillia

Re: FPS onscreen - 07/13/06 15:58

A better way to get the frame rate is to add it up over time then take the average. Averaging it over 10 to 20 frames is sufficient enough. For this, just create an array of ten objects, and do this:

Code:

var fps_logs[16]; // more means slower changes but less randomness

function get_framerate()
{
var main_array_index = 0;
var temp_array_index = 0;
var fps_average;

while(1)
{
fps_logs[main_array_index] = 16/time;
main_array_index += 1;
main_array_index %= 16; // always from 0 to 15, change if another array index is used
fps_average = 0;

while(temp_array_index < 16) // change 16 to your limit
{
fps_average += fps_logs[temp_array_index]; // adds up all this
}

fps_average /= 16;
fps_display = 16/(fps_average/16); // this can be just "fps_average" as is
temp_array_index = 0;
wait(1);
}
}



Then just let this code run. You may want to change the condition for the while loop, but this gives a decent idea. The code seems rather messy, but I don't know how else to simplify it, if possible.
© 2023 lite-C Forums