mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Remove 'Pause'
This commit is contained in:
parent
eb8e8b6034
commit
f71dcd3466
@ -89,17 +89,6 @@ func (c *graphicsContext) Update() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Pause() error {
|
||||
if err := theImages.evacuatePixels(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := graphics.Finalize(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
ui.GLContext().Pause()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Resume() error {
|
||||
ui.GLContext().Resume()
|
||||
if !c.imageTasksDone {
|
||||
|
52
image.go
52
image.go
@ -99,21 +99,6 @@ func (i *images) isEvacuated() bool {
|
||||
return i.evacuated
|
||||
}
|
||||
|
||||
func (i *images) evacuatePixels() error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if i.evacuated {
|
||||
return errors.New("ebiten: images must not be evacuated")
|
||||
}
|
||||
i.evacuated = true
|
||||
for img := range i.images {
|
||||
if err := img.evacuatePixels(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *images) restorePixels() error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
@ -323,43 +308,6 @@ func (i *imageImpl) At(x, y int) color.Color {
|
||||
return color.RGBA{r, g, b, a}
|
||||
}
|
||||
|
||||
func (i *imageImpl) evacuatePixels() error {
|
||||
imageM.Lock()
|
||||
defer imageM.Unlock()
|
||||
defer func() {
|
||||
i.evacuated = true
|
||||
}()
|
||||
if i.defaultFramebuffer {
|
||||
return nil
|
||||
}
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if i.evacuated {
|
||||
return errors.New("ebiten: image must not be evacuated")
|
||||
}
|
||||
if i.pixels == nil {
|
||||
var err error
|
||||
i.pixels, err = i.framebuffer.Pixels(ui.GLContext())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if i.framebuffer != nil {
|
||||
if err := i.framebuffer.Dispose(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
i.framebuffer = nil
|
||||
}
|
||||
if i.texture != nil {
|
||||
if err := i.texture.Dispose(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
i.texture = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *imageImpl) restorePixels() error {
|
||||
imageM.Lock()
|
||||
defer imageM.Unlock()
|
||||
|
@ -96,7 +96,6 @@ func (c *runContext) setRunningSlowly(isRunningSlowly bool) {
|
||||
type GraphicsContext interface {
|
||||
SetSize(width, height, scale int) error
|
||||
Update() error
|
||||
Pause() error
|
||||
Resume() error
|
||||
}
|
||||
|
||||
@ -166,11 +165,6 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
|
||||
frames = 0
|
||||
}
|
||||
e.Done <- struct{}{}
|
||||
case ui.PauseEvent:
|
||||
if err := g.Pause(); err != nil {
|
||||
return err
|
||||
}
|
||||
e.Done <- struct{}{}
|
||||
case ui.ResumeEvent:
|
||||
if err := g.Resume(); err != nil {
|
||||
return err
|
||||
|
@ -37,12 +37,6 @@ func Render(chError <-chan error) error {
|
||||
}
|
||||
// TODO: Check this is called on the rendering thread
|
||||
select {
|
||||
case <-chPauseStart:
|
||||
if err := doGLWorks(chError, chPauseEnd); err != nil {
|
||||
return err
|
||||
}
|
||||
chPauseEnd2 <- struct{}{}
|
||||
return nil
|
||||
case <-chResumeStart:
|
||||
if err := doGLWorks(chError, chResumeEnd); err != nil {
|
||||
return err
|
||||
@ -51,7 +45,7 @@ func Render(chError <-chan error) error {
|
||||
case chRender <- struct{}{}:
|
||||
return doGLWorks(chError, chRenderEnd)
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
// This function must not be blocked so we need to break after a while.
|
||||
// This function must not be blocked. We need to break for timeout.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -82,23 +76,16 @@ type userInterface struct {
|
||||
height int
|
||||
scale int
|
||||
sizeChanged bool
|
||||
paused bool
|
||||
}
|
||||
|
||||
var (
|
||||
// TODO: Rename these channels
|
||||
chRender = make(chan struct{})
|
||||
chRenderEnd = make(chan struct{})
|
||||
chPause = make(chan struct{})
|
||||
chPauseStart = make(chan struct{})
|
||||
chPauseEnd = make(chan struct{})
|
||||
chPauseEnd2 = make(chan struct{})
|
||||
chResume = make(chan struct{})
|
||||
chResumeStart = make(chan struct{})
|
||||
chResumeEnd = make(chan struct{})
|
||||
currentUI = &userInterface{
|
||||
sizeChanged: true,
|
||||
paused: false,
|
||||
}
|
||||
)
|
||||
|
||||
@ -130,21 +117,12 @@ func (u *userInterface) Update() (interface{}, error) {
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
if u.paused {
|
||||
select {
|
||||
case <-chResume:
|
||||
u.paused = false
|
||||
chResumeStart <- struct{}{}
|
||||
return ResumeEvent{chResumeEnd}, nil
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-chPause:
|
||||
u.paused = true
|
||||
chPauseStart <- struct{}{}
|
||||
return PauseEvent{chPauseEnd}, nil
|
||||
case <-chRender:
|
||||
return RenderEvent{chRenderEnd}, nil
|
||||
case <-chResume:
|
||||
chResumeStart <- struct{}{}
|
||||
return ResumeEvent{chResumeEnd}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,13 +148,6 @@ func (u *userInterface) actualScreenScale() int {
|
||||
return u.scale
|
||||
}
|
||||
|
||||
func Pause() error {
|
||||
// Pause must be done in the current GL context.
|
||||
chPause <- struct{}{}
|
||||
<-chPauseEnd2
|
||||
return nil
|
||||
}
|
||||
|
||||
func Resume() error {
|
||||
chResume <- struct{}{}
|
||||
// Don't have to wait for resumeing done.
|
||||
|
@ -29,7 +29,6 @@ type EventDispatcher interface {
|
||||
SetScreenSize(width, height int)
|
||||
SetScreenScale(scale int)
|
||||
Render() error
|
||||
Pause()
|
||||
Resume()
|
||||
TouchDown(id int, x, y int)
|
||||
TouchMove(id int, x, y int)
|
||||
@ -70,10 +69,6 @@ func (e *eventDispatcher) Render() error {
|
||||
return ui.Render(chError)
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) Pause() {
|
||||
ui.Pause()
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) Resume() {
|
||||
ui.Resume()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user