Jump to content

FPS Calculator


Recommended Posts

Hello everyone, well I tried to make an FPS Calculator and tried to tweak This resource with dxDrawText but it doesn't create any text.

Code

--Client-side 
local player = getLocalPlayer() 
local counter = 0 
local starttick 
local currenttick 
  
addEventHandler("onClientRender", root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter + 1 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
        dxDrawText(""..counter.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
            counter = 0 
            starttick = false 
    end 
    end 
) 
  

Link to comment
local root = getRootElement() 
local player = getLocalPlayer() 
local counter = 0 
local starttick 
local currenttick 
addEventHandler("onClientRender",root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter + 1 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
            setElementData(player,"fps",counter) 
            counter = 0 
            starttick = false 
        end 
 dxDrawText(""..counter.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
) 

This should work

Link to comment

this is better..

  
local fps;  
local updateTick; 
addEventHandler ("onClientPreRender", getRootElement (), 
    function (dt)  
       if (not updateTick) or ((getTickCount () - updateTick)>1000) then 
             fps = math.floor ( 1000 / dt ); 
             updateTick = getTickCount ();  
       end;  
    end);  
addEventHandler ("onClientRender", getRootElement (), 
    function ()  
        dxDrawText ("FPS: " .. tostring(fps) , 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false); 
    end);  
  

Link to comment
  • Moderators
this is better..

It isn't, more handlers give more lagg.

onClientRender is just fine, you don't need to calculate so much, for so little improvements with the correct timing.

But it is nice that there is another way of doing.

Link to comment
  • Moderators
ok. I don´t know that.

i said it´s best because its a more clear solution.

Not really precisely, cause you only check the amount of fps from one pre-frame, not from a second.

But the good thing about it, that it shows us direct big fps drops, I tried that part of you.

It jumps from 66 t/m 56, my fps is stable and it makes changes with 10 fps.

but it detect big fps drops directly:(I tried this)

local updateTick,lastFPSUpdate = 0,0 
addEventHandler ("onClientPreRender", root, 
function (dt) 
    local fps = math.floor ( 1000 / dt ) 
    if lastFPSUpdate-fps > 30 and (not updateTick or getTickCount () - updateTick > 500) then 
        updateTick = getTickCount () 
        outputChatBox("big fps drop") 
   end 
   lastFPSUpdate = fps 
end) 

@abxf,

  
local counter = 0 
local starttick 
local fps =0 
addEventHandler("onClientRender",root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter+1 
        if getTickCount() - starttick >= 1000 then 
            fps = counter 
            starttick,counter = false,0 
        end 
        dxDrawText(""..fps.."", 898, 689, 1018, 736, tocolor(0, 255, 0, 255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
) 

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...