mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
Refactoring: isRunning -> isImageAvailable
This commit is contained in:
parent
a42b5274df
commit
ef56d0a535
4
image.go
4
image.go
@ -496,7 +496,7 @@ func (i *Image) ColorModel() color.Model {
|
|||||||
//
|
//
|
||||||
// At can't be called outside the main loop (ebiten.Run's updating function) starts (as of version 1.4.0-alpha).
|
// At can't be called outside the main loop (ebiten.Run's updating function) starts (as of version 1.4.0-alpha).
|
||||||
func (i *Image) At(x, y int) color.Color {
|
func (i *Image) At(x, y int) color.Color {
|
||||||
if atomic.LoadInt32(&isRunning) == 0 {
|
if atomic.LoadInt32(&isImageAvailable) == 0 {
|
||||||
panic("ebiten: (*Image).At is not available outside the main loop so far")
|
panic("ebiten: (*Image).At is not available outside the main loop so far")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +519,7 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
//
|
//
|
||||||
// If the image is disposed, Set does nothing.
|
// If the image is disposed, Set does nothing.
|
||||||
func (img *Image) Set(x, y int, clr color.Color) {
|
func (img *Image) Set(x, y int, clr color.Color) {
|
||||||
if atomic.LoadInt32(&isRunning) == 0 {
|
if atomic.LoadInt32(&isImageAvailable) == 0 {
|
||||||
panic("ebiten: (*Image).Set is not available outside the main loop so far")
|
panic("ebiten: (*Image).Set is not available outside the main loop so far")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,6 @@ import (
|
|||||||
"syscall/js"
|
"syscall/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsGopherJS() bool {
|
|
||||||
return runtime.GOOS != "js"
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package web
|
package web
|
||||||
|
|
||||||
func IsGopherJS() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
10
run.go
10
run.go
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/uidriver"
|
"github.com/hajimehoshi/ebiten/internal/uidriver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/web"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = __EBITEN_REQUIRES_GO_VERSION_1_12_OR_LATER__
|
var _ = __EBITEN_REQUIRES_GO_VERSION_1_12_OR_LATER__
|
||||||
@ -47,7 +46,7 @@ func CurrentFPS() float64 {
|
|||||||
var (
|
var (
|
||||||
isDrawingSkipped = int32(0)
|
isDrawingSkipped = int32(0)
|
||||||
currentMaxTPS = int32(DefaultTPS)
|
currentMaxTPS = int32(DefaultTPS)
|
||||||
isRunning = int32(0)
|
isImageAvailable = int32(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
func setDrawingSkipped(skipped bool) {
|
func setDrawingSkipped(skipped bool) {
|
||||||
@ -133,12 +132,6 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e
|
|||||||
c := newUIContext(f)
|
c := newUIContext(f)
|
||||||
theUIContext.Store(c)
|
theUIContext.Store(c)
|
||||||
|
|
||||||
atomic.StoreInt32(&isRunning, 1)
|
|
||||||
// On GopherJS, run returns immediately.
|
|
||||||
if !web.IsGopherJS() {
|
|
||||||
defer atomic.StoreInt32(&isRunning, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := uidriver.Get().Run(width, height, scale, title, c, graphicsdriver.Get()); err != nil {
|
if err := uidriver.Get().Run(width, height, scale, title, c, graphicsdriver.Get()); err != nil {
|
||||||
if err == driver.RegularTermination {
|
if err == driver.RegularTermination {
|
||||||
return nil
|
return nil
|
||||||
@ -160,7 +153,6 @@ func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64,
|
|||||||
c := newUIContext(f)
|
c := newUIContext(f)
|
||||||
theUIContext.Store(c)
|
theUIContext.Store(c)
|
||||||
|
|
||||||
atomic.StoreInt32(&isRunning, 1)
|
|
||||||
return uidriver.Get().RunWithoutMainLoop(width, height, scale, title, c, graphicsdriver.Get())
|
return uidriver.Get().RunWithoutMainLoop(width, height, scale, title, c, graphicsdriver.Get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ package ebiten
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
@ -96,6 +97,10 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
|
|||||||
if err := shareable.BeginFrame(); err != nil {
|
if err := shareable.BeginFrame(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Images are available after shareable is initialized.
|
||||||
|
atomic.StoreInt32(&isImageAvailable, 1)
|
||||||
|
|
||||||
for i := 0; i < updateCount; i++ {
|
for i := 0; i < updateCount; i++ {
|
||||||
c.offscreen.Clear()
|
c.offscreen.Clear()
|
||||||
// Mipmap images should be disposed by fill.
|
// Mipmap images should be disposed by fill.
|
||||||
|
Loading…
Reference in New Issue
Block a user