Compare commits

...

1 Commits

Author SHA1 Message Date
Francesco Abbate f93c5d0aa9 Adjust animations based on FPS and skipped frames 2021-03-10 10:44:29 +01:00
2 changed files with 12 additions and 3 deletions

View File

@ -414,6 +414,7 @@ function core.init()
core.redraw = true core.redraw = true
core.visited_files = {} core.visited_files = {}
core.restart_request = false core.restart_request = false
core.frames_lost = 0
core.root_view = RootView() core.root_view = RootView()
core.command_view = CommandView() core.command_view = CommandView()
@ -869,7 +870,13 @@ function core.run()
else else
idle_iterations = 0 idle_iterations = 0
local elapsed = system.get_time() - core.frame_start 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 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 if not config.transitions or math.abs(val - dest) < 0.5 then
t[k] = dest t[k] = dest
else else
t[k] = common.lerp(val, dest, rate or 0.5) rate = common.clamp(rate or 0.5, 1e-8, 1 - 1e-8)
end 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 if val ~= dest then
core.redraw = true core.redraw = true
end end