mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
ebiten: remove RunOnMainThread
Unfortunately, there are several issues in RunOnMainThread: * RunOnMainThread cannot be portable: It is impossible to implement this correctly on mobiles. * RunOnMainThread doesn't make sense on mobiles: the rendering works on a different thread (goroutine) on mobiles. * RunOnMainThread can cause deadlocks very easily. Until we find a better solution, let's remove this. Closes #1945
This commit is contained in:
parent
e09c1bf8f1
commit
fcd4453e4f
@ -225,7 +225,7 @@ func (q *commandQueue) Enqueue(command command) {
|
|||||||
|
|
||||||
// Flush flushes the command queue.
|
// Flush flushes the command queue.
|
||||||
func (q *commandQueue) Flush() (err error) {
|
func (q *commandQueue) Flush() (err error) {
|
||||||
RunOnRenderingThread(func() {
|
runOnRenderingThread(func() {
|
||||||
err = q.flush()
|
err = q.flush()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -701,7 +701,7 @@ func (c *newShaderCommand) Exec(indexOffset int) error {
|
|||||||
|
|
||||||
// InitializeGraphicsDriverState initialize the current graphics driver state.
|
// InitializeGraphicsDriverState initialize the current graphics driver state.
|
||||||
func InitializeGraphicsDriverState() (err error) {
|
func InitializeGraphicsDriverState() (err error) {
|
||||||
RunOnRenderingThread(func() {
|
runOnRenderingThread(func() {
|
||||||
err = theGraphicsDriver.Initialize()
|
err = theGraphicsDriver.Initialize()
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -711,7 +711,7 @@ func InitializeGraphicsDriverState() (err error) {
|
|||||||
// If the graphics driver doesn't have an API to reset, ResetGraphicsDriverState does nothing.
|
// If the graphics driver doesn't have an API to reset, ResetGraphicsDriverState does nothing.
|
||||||
func ResetGraphicsDriverState() (err error) {
|
func ResetGraphicsDriverState() (err error) {
|
||||||
if r, ok := theGraphicsDriver.(interface{ Reset() error }); ok {
|
if r, ok := theGraphicsDriver.(interface{ Reset() error }); ok {
|
||||||
RunOnRenderingThread(func() {
|
runOnRenderingThread(func() {
|
||||||
err = r.Reset()
|
err = r.Reset()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -721,7 +721,7 @@ func ResetGraphicsDriverState() (err error) {
|
|||||||
// MaxImageSize returns the maximum size of an image.
|
// MaxImageSize returns the maximum size of an image.
|
||||||
func MaxImageSize() int {
|
func MaxImageSize() int {
|
||||||
var size int
|
var size int
|
||||||
RunOnRenderingThread(func() {
|
runOnRenderingThread(func() {
|
||||||
size = theGraphicsDriver.MaxImageSize()
|
size = theGraphicsDriver.MaxImageSize()
|
||||||
})
|
})
|
||||||
return size
|
return size
|
||||||
|
@ -25,8 +25,8 @@ func SetRenderingThread(thread Thread) {
|
|||||||
theThread = thread
|
theThread = thread
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunOnRenderingThread calls f on the rendering thread, and returns an error if any.
|
// runOnRenderingThread calls f on the rendering thread, and returns an error if any.
|
||||||
func RunOnRenderingThread(f func()) {
|
func runOnRenderingThread(f func()) {
|
||||||
// The thread is nil when 1) GOOS=js or 2) using golang.org/x/mobile/gl.
|
// The thread is nil when 1) GOOS=js or 2) using golang.org/x/mobile/gl.
|
||||||
// When golang.org/x/mobile/gl is used, all the GL functions are called via Context, which already runs on an
|
// When golang.org/x/mobile/gl is used, all the GL functions are called via Context, which already runs on an
|
||||||
// appropriate thread.
|
// appropriate thread.
|
||||||
|
6
run.go
6
run.go
@ -18,7 +18,6 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -162,11 +161,6 @@ func RunGame(game Game) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunOnMainThread calls the given f on the main thread, and blocks until f returns.
|
|
||||||
func RunOnMainThread(f func()) {
|
|
||||||
graphicscommand.RunOnRenderingThread(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isRunGameEnded() bool {
|
func isRunGameEnded() bool {
|
||||||
return atomic.LoadInt32(&isRunGameEnded_) != 0
|
return atomic.LoadInt32(&isRunGameEnded_) != 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user