Skip to content

Commit

Permalink
reduce background CPU use by using 12fps main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Nov 3, 2023
1 parent 1f96a69 commit 8725463
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (d *gLDriver) drawSingleFrame() {
}

func (d *gLDriver) runGL() {
eventTick := time.NewTicker(time.Second / 60)
//eventTick := time.NewTicker(time.Second / 60)

run.L.Lock()
run.flag = true
Expand All @@ -114,7 +114,7 @@ func (d *gLDriver) runGL() {
for {
select {
case <-d.done:
eventTick.Stop()
//eventTick.Stop()
d.drawDone <- nil // wait for draw thread to stop
d.Terminate()
fyne.CurrentApp().Lifecycle().(*app.Lifecycle).TriggerStopped()
Expand All @@ -124,8 +124,9 @@ func (d *gLDriver) runGL() {
if f.done != nil {
f.done <- struct{}{}
}
case <-eventTick.C:
d.tryPollEvents()
//case <-eventTick.C:
default:
d.tryWaitEventsTimeout(0.08333)
newWindows := []fyne.Window{}
reassign := false
for _, win := range d.windowList() {
Expand Down
10 changes: 10 additions & 0 deletions internal/driver/glfw/loop_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func (d *gLDriver) initGLFW() {
})
}

func (d *gLDriver) tryWaitEventsTimeout(timeoutSeconds float64) {
defer func() {
if r := recover(); r != nil {
fyne.LogError(fmt.Sprint("GLFW waitEvents error: ", r), nil)
}
}()

glfw.WaitEventsTimeout(timeoutSeconds)
}

func (d *gLDriver) tryPollEvents() {

Check failure on line 37 in internal/driver/glfw/loop_desktop.go

View workflow job for this annotation

GitHub Actions / static_analysis

func (*gLDriver).tryPollEvents is unused (U1000)
defer func() {
if r := recover(); r != nil {
Expand Down

0 comments on commit 8725463

Please sign in to comment.