Adjust animations based on FPS and skipped frames

This commit is contained in:
Francesco Abbate 2021-03-10 10:44:29 +01:00
parent 3af6af654b
commit f93c5d0aa9
2 changed files with 12 additions and 3 deletions

View File

@ -414,6 +414,7 @@ function core.init()
core.redraw = true
core.visited_files = {}
core.restart_request = false
core.frames_lost = 0
core.root_view = RootView()
core.command_view = CommandView()
@ -869,7 +870,13 @@ function core.run()
else
idle_iterations = 0
local elapsed = system.get_time() - core.frame_start
system.sleep(math.max(0, frame_duration - elapsed))
local remaining = frame_duration - elapsed
if remaining > 0 then
core.frames_lost = 0
system.sleep(remaining)
else
core.frames_lost = math.ceil(elapsed / frame_duration) - 1
end
end
end
end

View File

@ -24,8 +24,10 @@ function View:move_towards(t, k, dest, rate)
if not config.transitions or math.abs(val - dest) < 0.5 then
t[k] = dest
else
t[k] = common.lerp(val, dest, rate or 0.5)
end
rate = common.clamp(rate or 0.5, 1e-8, 1 - 1e-8)
local alpha = math.log(1 - rate)
local dt = (60 / config.fps) * (1 + core.frames_lost)
t[k] = common.lerp(val, dest, 1 - math.exp(alpha * dt)) end
if val ~= dest then
core.redraw = true
end