mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
shareable: Refactoring: reduce sync.Once
This commit is contained in:
parent
b53279b1e1
commit
7907bb43ce
@ -47,26 +47,10 @@ func min(a, b int) int {
|
||||
}
|
||||
|
||||
func init() {
|
||||
var once sync.Once
|
||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
once.Do(func() {
|
||||
if len(theBackends) != 0 {
|
||||
panic("shareable: all the images must be not-shared before the game starts")
|
||||
}
|
||||
if graphicsDriver.HasHighPrecisionFloat() {
|
||||
minSize = 1024
|
||||
// Use 4096 as a maximum size whatever size the graphics driver accepts. There are
|
||||
// not enough evidences that bigger textures works correctly.
|
||||
maxSize = min(4096, graphicsDriver.MaxImageSize())
|
||||
} else {
|
||||
minSize = 512
|
||||
maxSize = 512
|
||||
}
|
||||
})
|
||||
|
||||
resolveDeferred()
|
||||
makeImagesShared()
|
||||
return nil
|
||||
@ -612,6 +596,21 @@ func BeginFrame() error {
|
||||
var err error
|
||||
initOnce.Do(func() {
|
||||
err = restorable.InitializeGraphicsDriverState()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(theBackends) != 0 {
|
||||
panic("shareable: all the images must be not-shared before the game starts")
|
||||
}
|
||||
if graphicsDriver.HasHighPrecisionFloat() {
|
||||
minSize = 1024
|
||||
// Use 4096 as a maximum size whatever size the graphics driver accepts. There are
|
||||
// not enough evidences that bigger textures works correctly.
|
||||
maxSize = min(4096, graphicsDriver.MaxImageSize())
|
||||
} else {
|
||||
minSize = 512
|
||||
maxSize = 512
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user