Skip to content
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
12 changes: 10 additions & 2 deletions win/win.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/go-gl/glfw/v3.2/glfw"
)

// FrameDelay - usualy 1/60th of a second.
const FrameDelay time.Duration = time.Duration(int64(time.Second) / 60)

// Option is a functional option to the window constructor New.
type Option func(*options)

Expand Down Expand Up @@ -262,14 +265,19 @@ func (w *Win) eventThread() {
r := w.img.Bounds()
w.eventsIn <- gui.Resize{Rectangle: r}

t := time.Now()
for {
select {
case <-w.finish:
close(w.eventsIn)
w.w.Destroy()
return
default:
glfw.WaitEventsTimeout(1.0 / 30)
dif := time.Now().Sub(t)
if dif > FrameDelay {
glfw.WaitEventsTimeout(1.0 / 30)
t = time.Now()
}
}
}
}
Expand Down Expand Up @@ -302,7 +310,7 @@ loop:

for {
select {
case <-time.After(time.Second / 960):
case <-time.After(FrameDelay):
w.openGLFlush(totalR)
totalR = image.ZR
continue loop
Expand Down