mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Revert "ui: Bug fix: SetVsyncEnabled before Run didn't work on macOS"
This reverts commit 042b30a516
.
This commit is contained in:
parent
7956e0ebbc
commit
c76ce28065
@ -233,11 +233,10 @@ type Driver struct {
|
||||
src *Image
|
||||
dst *Image
|
||||
|
||||
vsync bool
|
||||
maxImageSize int
|
||||
}
|
||||
|
||||
var theDriver = Driver{vsync: true}
|
||||
var theDriver Driver
|
||||
|
||||
func Get() *Driver {
|
||||
return &theDriver
|
||||
@ -396,7 +395,7 @@ func (d *Driver) Reset() error {
|
||||
// MTLPixelFormatBGRA10_XR_sRGB.
|
||||
d.ml.SetPixelFormat(mtl.PixelFormatBGRA8UNorm)
|
||||
d.ml.SetMaximumDrawableCount(3)
|
||||
d.ml.SetDisplaySyncEnabled(d.vsync)
|
||||
d.ml.SetDisplaySyncEnabled(true)
|
||||
|
||||
replaces := map[string]string{
|
||||
"{{.FilterNearest}}": fmt.Sprintf("%d", graphics.FilterNearest),
|
||||
@ -571,11 +570,7 @@ func (d *Driver) ResetSource() {
|
||||
}
|
||||
|
||||
func (d *Driver) SetVsyncEnabled(enabled bool) {
|
||||
mainthread.Run(func() error {
|
||||
d.ml.SetDisplaySyncEnabled(enabled)
|
||||
d.vsync = enabled
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Driver) VDirection() graphicsdriver.VDirection {
|
||||
|
@ -14,39 +14,16 @@
|
||||
|
||||
package mainthread
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
funcs chan func()
|
||||
running bool
|
||||
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
runtime.LockOSThread()
|
||||
}
|
||||
var funcs = make(chan func())
|
||||
|
||||
// Loop starts the main-thread loop.
|
||||
//
|
||||
// Loop must be called on the main thread.
|
||||
func Loop(ch <-chan error) error {
|
||||
m.Lock()
|
||||
funcs = make(chan func())
|
||||
m.Unlock()
|
||||
for {
|
||||
select {
|
||||
case f := <-funcs:
|
||||
m.Lock()
|
||||
running = true
|
||||
m.Unlock()
|
||||
f()
|
||||
m.Lock()
|
||||
running = false
|
||||
m.Unlock()
|
||||
case err := <-ch:
|
||||
// ch returns a value not only when an error occur but also it is closed.
|
||||
return err
|
||||
@ -55,19 +32,7 @@ func Loop(ch <-chan error) error {
|
||||
}
|
||||
|
||||
// Run calls f on the main thread.
|
||||
//
|
||||
// Run can be called even before Loop is called.
|
||||
//
|
||||
// Run can be called recursively: Run can be called from the function that are called via Run.
|
||||
func Run(f func() error) error {
|
||||
// Even if funcs is nil, Run is called from the main thread (e.g. init)
|
||||
m.Lock()
|
||||
now := funcs == nil || running
|
||||
m.Unlock()
|
||||
if now {
|
||||
return f()
|
||||
}
|
||||
|
||||
ch := make(chan struct{})
|
||||
var err error
|
||||
funcs <- func() {
|
||||
|
@ -76,6 +76,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
runtime.LockOSThread()
|
||||
hideConsoleWindowOnWindows()
|
||||
if err := initialize(); err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user