mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: refactoring
This commit is contained in:
parent
3f753b7086
commit
fa4916d063
@ -14,7 +14,11 @@
|
||||
|
||||
package graphicscommand
|
||||
|
||||
var theThread Thread
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
|
||||
var theThread Thread = thread.NewNoopThread()
|
||||
|
||||
type Thread interface {
|
||||
Call(f func())
|
||||
@ -29,12 +33,5 @@ func SetRenderingThread(thread Thread) {
|
||||
|
||||
// runOnRenderingThread calls f on the rendering thread, and returns an error if any.
|
||||
func runOnRenderingThread(f func()) {
|
||||
// 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
|
||||
// appropriate thread.
|
||||
if theThread == nil {
|
||||
f()
|
||||
return
|
||||
}
|
||||
theThread.Call(f)
|
||||
}
|
||||
|
@ -18,12 +18,6 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Thread defines threading behavior in Ebitengine.
|
||||
type Thread interface {
|
||||
Call(func())
|
||||
Loop(context.Context) error
|
||||
}
|
||||
|
||||
// OSThread represents an OS thread.
|
||||
type OSThread struct {
|
||||
funcs chan func()
|
||||
|
@ -17,6 +17,7 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
stdcontext "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
@ -32,7 +33,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
|
||||
func driverCursorModeToGLFWCursorMode(mode CursorMode) int {
|
||||
@ -108,10 +108,15 @@ type userInterfaceImpl struct {
|
||||
defaultFramebufferSizeCallback glfw.FramebufferSizeCallback
|
||||
framebufferSizeCallbackCh chan struct{}
|
||||
|
||||
mainThread thread.Thread
|
||||
mainThread threadInterface
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
type threadInterface interface {
|
||||
Loop(ctx stdcontext.Context) error
|
||||
Call(f func())
|
||||
}
|
||||
|
||||
const (
|
||||
maxInt = int(^uint(0) >> 1)
|
||||
minInt = -maxInt - 1
|
||||
|
Loading…
Reference in New Issue
Block a user