mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +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).
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,6 @@ import (
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
func IsGopherJS() bool {
|
||||
return runtime.GOOS != "js"
|
||||
}
|
||||
|
||||
func IsBrowser() bool {
|
||||
return true
|
||||
}
|
||||
|
@ -16,10 +16,6 @@
|
||||
|
||||
package web
|
||||
|
||||
func IsGopherJS() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func IsBrowser() bool {
|
||||
return false
|
||||
}
|
||||
|
10
run.go
10
run.go
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user