internal/atlas: resolve deferred every frame instead of every tick

Resolving defferred functions doesn't have to be done every tick. Rather,
this should be done every frame as this is related to rendering.
This commit is contained in:
Hajime Hoshi 2022-02-14 03:45:56 +09:00
parent 4949c49cd0
commit f17d222a4b

View File

@ -23,7 +23,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/affine"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
"github.com/hajimehoshi/ebiten/v2/internal/packing"
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
)
@ -103,16 +102,6 @@ func min(a, b int) int {
return b
}
func init() {
hooks.AppendHookOnBeforeUpdate(func() error {
backendsM.Lock()
defer backendsM.Unlock()
resolveDeferred()
return putImagesOnAtlas()
})
}
func resolveDeferred() {
deferredM.Lock()
fs := deferred
@ -823,6 +812,11 @@ func BeginFrame() error {
return err
}
resolveDeferred()
if err := putImagesOnAtlas(); err != nil {
return err
}
return restorable.RestoreIfNeeded()
}