Jump to content

Calculating FPS per frame


H!tman

Recommended Posts

for every time GTA lead a new frame i want to know what is my frames can be loaded in 1 second, i want update it not after 1 second i want it like fraps.

if you didn't understand what i'm talking about, a lot of us know the fraps and you know the yellow numbers at the corners of the screen(FPS), fraps calculating it about 20 times per second!

i don't know what i should say.

thats all in my mind

Link to comment

onClientPreRender event has a timeslice parameter. It's time in miliseconds between last two frames. So you can divide 1000 (one second) by one frame duration and you will have FPS based on the length of that frame. However, I noticed that every frame is a lot shorter or longer than previous frame. I mean, every other frame has something what takes more time to process (maybe game physics?). Because of that, you will see FPS increasing and decreasing every frame.

Link to comment

FPS - Frames per second, meaning 1 second.

And you want FPS counter to update 20 times a second, but show how many frames per 1 second a player has?

I tried doing that just now, however the fps jumps too much, which i think is because of time lag somewhere.

Link to comment
addEventHandler ( "onClientRender" , root , 
    function ( ) 
        if not startTick then 
            startTick = getTickCount ( ) 
        end 
        if not frames then 
            frames = 0 
        end 
        frames = frames + 1 
        currentTick = getTickCount ( ) 
        if currentTick - startTick >= 1000 then 
            setElementData ( localPlayer , "fps" , frames ) 
            startTick = nil 
            frames = nil 
        end 
    end 
) 

Now it sets the localPlayer's element data 'fps' to the current FPS, updates every second.

You should probably add a scoreboard column.

Link to comment
FPSLimit = 37 
FPSMax = 1 
  
function onClientResourceStart ( resource ) 
    if ( guiFPSLabel == nil ) then 
        FPSLimit = 255 / FPSLimit 
        guiFPSLabel = guiCreateLabel ( 0.03, 0.94, 0.5, 0.1, "FPS: 0", true ) 
        guiSetFont ( guiFPSLabel, "sa-header" ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
        addEventHandler ( "onClientRender", getRootElement (), onClientRender ) 
    end 
end 
addEventHandler ( "onClientResourceStart", getRootElement (), onClientResourceStart ) 
  
function onClientRender ( ) 
    if ( getTickCount() < FPSTime ) then 
        FPSCalc = FPSCalc + 1 
    else 
        if ( FPSCalc > FPSMax ) then FPSLimit = 255 / FPSCalc FPSMax = FPSCalc end 
        guiSetText ( guiFPSLabel, "FPS: "..FPSCalc.." Max: "..FPSMax ) 
        guiLabelSetColor ( guiFPSLabel, 255 - math.ceil ( FPSCalc * FPSLimit ), math.ceil ( FPSCalc * FPSLimit ), 0 ) 
        FPSCalc = 0 
        FPSTime = getTickCount() + 1000 
    end 
end 

mybe this ?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...