Счётчик FPS + правильное измерение производительности

Теперь учитывается и время обновления экрана тоже
This commit is contained in:
MrPixel92 2023-04-29 19:56:56 +03:00 committed by GitHub
parent 4df37fcc35
commit aa77c8ee72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,14 @@ local inputX = 0
local inputY = 0 local inputY = 0
local inputYaw = 0 local inputYaw = 0
local holdingFire = 0 local holdingFire = 0
---------------------------------------------------- Переменные ------------------------------------------------------------------
local startRenderClock = os.clock()
local endRenderClock = os.clock()
local frameCount = 0
local fps = 0
local lastFPSCheck = os.clock()
---------------------------------------------------- Константы ------------------------------------------------------------------ ---------------------------------------------------- Константы ------------------------------------------------------------------
local rayEngine = {} local rayEngine = {}
@ -558,8 +566,8 @@ function rayEngine.drawWorld()
end end
function rayEngine.update() function rayEngine.update()
local frameRenderClock = os.clock()
local frameRenderClock = os.clock()
rayEngine.rotate(rayEngine.player.rotationSpeed * inputYaw) rayEngine.rotate(rayEngine.player.rotationSpeed * inputYaw)
rayEngine.move(rayEngine.player.moveSpeed * inputY, rayEngine.player.moveSpeed * inputX) rayEngine.move(rayEngine.player.moveSpeed * inputY, rayEngine.player.moveSpeed * inputX)
@ -577,13 +585,23 @@ function rayEngine.update()
if rayEngine.debugInformationEnabled then if rayEngine.debugInformationEnabled then
rayEngine.drawDebugInformation(3, 2 + (rayEngine.minimapEnabled and 12 or 0), 24, 0.6, rayEngine.drawDebugInformation(3, 2 + (rayEngine.minimapEnabled and 12 or 0), 24, 0.6,
"renderTime: " .. string.format("%.2f", (os.clock() - frameRenderClock) * 1000) .. " ms", "renderTime: " .. string.format("%.2f", ((os.clock() - frameRenderClock) + (endRenderClock-startRenderClock)) * 1000) .. " ms",
"FPS: " .. string.format("%.2f",fps),
"freeRAM: " .. string.format("%.2f", computer.freeMemory() / 1024) .. " KB", "freeRAM: " .. string.format("%.2f", computer.freeMemory() / 1024) .. " KB",
"pos: " .. string.format("%.2f", rayEngine.player.position.x) .. " x " .. string.format("%.2f", rayEngine.player.position.y) "pos: " .. string.format("%.2f", rayEngine.player.position.x) .. " x " .. string.format("%.2f", rayEngine.player.position.y)
) )
end end
startRenderClock = os.clock()
screen.update() screen.update()
frameCount = frameCount + 1
if (os.clock() - lastFPSCheck) > 1 then
fps = frameCount
frameCount = 0
lastFPSCheck = os.clock()
end
endRenderClock = os.clock()
end end
---------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------