Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

added 30 fps throttle to renderloop #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,26 @@ function pollwindow(window)
sleep(1/60)
end
end

# nanoseconds between each frame
const _ns_per_frame = round(UInt64, 1e9 / parse(Float64, get(ENV, "GLVISUALIZE_FPS", "60")))

"""
Blocking renderloop
"""
function renderloop(window::Screen)
nw = time_ns()
while isopen(window)
render_frame(window)
GLFW.PollEvents()

# if we've gone too fast, sleep for the remaining time
ns_diff = time_ns() - nw
nw += ns_diff
if ns_diff < _ns_per_frame
secs = (_ns_per_frame - ns_diff) * 1e-9
sleep(secs)
end
end
empty!(window)
yield()
Expand Down