I am working on an old project.
I noticed our Frames Per Second counter is not working.
We have a “Module” below which takes care of FPS counter display:
FPS counter stays locked at whatever “set_update_frequency” is set to.
(even when I know the game is not running full speed like on a Raspberry Pi)
Code is below. hope someone knows how to fix it:
Thanks!
Jesse
local UFPSAMXY = {}
function UFPSAMXY.UpdateFPSandMouseXY(dt)
local frames = {}
local frame_sum = 0
local frame_index = 1
local MAX_SAMPLES = 10
UFPSAMXY.average_ms = 0
UFPSAMXY.raw_average_time = 0
UFPSAMXY.fps = 0
if frames[frame_index] then frame_sum = frame_sum - frames[frame_index] end
frame_sum = frame_sum + dt
frames[frame_index] = dt
frame_index = math.fmod(frame_index + 1, MAX_SAMPLES)
UFPSAMXY.raw_average_time = frame_sum / MAX_SAMPLES
UFPSAMXY.average_ms = math.floor(UFPSAMXY.raw_average_time * 10000) / 100
UFPSAMXY.fps = math.floor(1.0 / UFPSAMXY.raw_average_time * 100) / 1000 + 1
if (SecretCode[0] == 2 and SecretCode[1] == 7 and SecretCode[2] == 7 and SecretCode[3] == 7) then
label.set_text( "#MouseXY", "FPS=" .. tostring( math.floor(UFPSAMXY.fps) ) .. " [" .. tostring( math.floor( mX * (360/WindowWidthTrue) ) ) .. "," .. tostring( math.floor( mY * (640/WindowHeightTrue) ) ) .. "]" )
end
end
return UFPSAMXY
Sadly actual FPS calculations based on dt do not work due to the way the engine is currently setup. I thought it was working at some point, but somewhere there was a change that broke it. If a user’s vsync is messed up it will also still display 60FPS even if animations are going a few hundred FPS. And in your case vsync is also probably still messed up but since hardware is slow you see slower animations but the engine wants to say it’s going at 60FPS because of the consistent dt value.
You will have to get the actual system time to do time diffs on.
You can use socket.gettime() which returns a Unix timestamp with milliseconds. Then you subtract the previous from the current timestamp to get the actual ms time between frames.