Refactoring: isRunning -> isImageAvailable

This commit is contained in:
Hajime Hoshi 2019-08-25 00:14:37 +09:00
parent a42b5274df
commit ef56d0a535
5 changed files with 8 additions and 19 deletions

View File

@ -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).
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")
}
@ -519,7 +519,7 @@ func (i *Image) At(x, y int) color.Color {
//
// If the image is disposed, Set does nothing.
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")
}

View File

@ -22,10 +22,6 @@ import (
"syscall/js"
)
func IsGopherJS() bool {
return runtime.GOOS != "js"
}
func IsBrowser() bool {
return true
}

View File

@ -16,10 +16,6 @@
package web
func IsGopherJS() bool {
return false
}
func IsBrowser() bool {
return false
}

10
run.go
View File

@ -22,7 +22,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/internal/uidriver"
"github.com/hajimehoshi/ebiten/internal/web"
)
var _ = __EBITEN_REQUIRES_GO_VERSION_1_12_OR_LATER__
@ -47,7 +46,7 @@ func CurrentFPS() float64 {
var (
isDrawingSkipped = int32(0)
currentMaxTPS = int32(DefaultTPS)
isRunning = int32(0)
isImageAvailable = int32(0)
)
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)
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 == driver.RegularTermination {
return nil
@ -160,7 +153,6 @@ func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64,
c := newUIContext(f)
theUIContext.Store(c)
atomic.StoreInt32(&isRunning, 1)
return uidriver.Get().RunWithoutMainLoop(width, height, scale, title, c, graphicsdriver.Get())
}

View File

@ -17,6 +17,7 @@ package ebiten
import (
"fmt"
"math"
"sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/driver"
@ -96,6 +97,10 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
if err := shareable.BeginFrame(); err != nil {
return err
}
// Images are available after shareable is initialized.
atomic.StoreInt32(&isImageAvailable, 1)
for i := 0; i < updateCount; i++ {
c.offscreen.Clear()
// Mipmap images should be disposed by fill.