Rename shell scripts and implement better frame timing
parent
23a8c400ba
commit
e5892c0fae
42
main.lua
42
main.lua
|
@ -81,7 +81,7 @@ function love.draw()
|
|||
love.graphics.setFont(font_3x5_2)
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.printf(
|
||||
string.format("%.2f", 1 / love.timer.getAverageDelta()) ..
|
||||
string.format("%.2f", 1.0 / love.timer.getAverageDelta()) ..
|
||||
"fps - " .. version, 0, 460, 635, "right"
|
||||
)
|
||||
end
|
||||
|
@ -290,6 +290,7 @@ function love.resize(w, h)
|
|||
end
|
||||
|
||||
local TARGET_FPS = 60
|
||||
local FRAME_DURATION = 1.0 / TARGET_FPS
|
||||
|
||||
function love.run()
|
||||
if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
|
||||
|
@ -299,7 +300,7 @@ function love.run()
|
|||
local dt = 0
|
||||
|
||||
local last_time = love.timer.getTime()
|
||||
local time_accumulator = 0
|
||||
local time_accumulator = 0.0
|
||||
return function()
|
||||
if love.event then
|
||||
love.event.pump()
|
||||
|
@ -319,25 +320,40 @@ function love.run()
|
|||
|
||||
if scene and scene.update and love.timer then
|
||||
scene:update()
|
||||
|
||||
local frame_duration = 1.0 / TARGET_FPS
|
||||
if time_accumulator < frame_duration then
|
||||
|
||||
if time_accumulator < FRAME_DURATION then
|
||||
if love.graphics and love.graphics.isActive() and love.draw then
|
||||
love.graphics.origin()
|
||||
love.graphics.clear(love.graphics.getBackgroundColor())
|
||||
love.draw()
|
||||
love.graphics.present()
|
||||
end
|
||||
local end_time = last_time + frame_duration
|
||||
local time = love.timer.getTime()
|
||||
while time < end_time do
|
||||
love.timer.sleep(0.001)
|
||||
time = love.timer.getTime()
|
||||
|
||||
-- request 1ms delays first but stop short of overshooting, then do "0ms" delays without overshooting (0ms requests generally do a delay of some nonzero amount of time, but maybe less than 1ms)
|
||||
for milliseconds=0.001,0.000,-0.001 do
|
||||
local max_delay = 0.0
|
||||
while max_delay < FRAME_DURATION do
|
||||
local delay_start_time = love.timer.getTime()
|
||||
if delay_start_time - last_time < FRAME_DURATION - max_delay then
|
||||
love.timer.sleep(milliseconds)
|
||||
local last_delay = love.timer.getTime() - delay_start_time
|
||||
if last_delay > max_delay then
|
||||
max_delay = last_delay
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
while love.timer.getTime() - last_time < FRAME_DURATION do
|
||||
-- busy loop, do nothing here until delay is finished; delays above stop short of finishing, so this part can finish it off precisely
|
||||
end
|
||||
time_accumulator = time_accumulator + time - last_time
|
||||
end
|
||||
time_accumulator = time_accumulator - frame_duration
|
||||
|
||||
local finish_delay_time = love.timer.getTime()
|
||||
local real_frame_duration = finish_delay_time - last_time
|
||||
time_accumulator = time_accumulator + real_frame_duration - FRAME_DURATION
|
||||
last_time = finish_delay_time
|
||||
end
|
||||
last_time = love.timer.getTime()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
zip -r cambridge.love libs load res scene tetris conf.lua main.lua scene.lua funcs.lua
|
|
@ -1,4 +1,6 @@
|
|||
./package
|
||||
#!/bin/sh
|
||||
|
||||
./package-love.sh
|
||||
mkdir dist
|
||||
mkdir dist/windows
|
||||
mkdir dist/win32
|
||||
|
@ -8,4 +10,4 @@ zip dist/cambridge-windows.zip dist/windows/* SOURCES.md LICENSE.md
|
|||
cat dist/win32/love.exe cambridge.love > dist/win32/cambridge.exe
|
||||
zip dist/cambridge-win32.zip dist/win32/* SOURCES.md LICENSE.md
|
||||
cp cambridge.love dist/other/
|
||||
zip dist/cambridge-other.zip cambridge.love libs/discord-rpc.* SOURCES.md LICENSE.md
|
||||
zip dist/cambridge-other.zip cambridge.love libs/discord-rpc.* SOURCES.md LICENSE.md
|
Loading…
Reference in New Issue