mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
loop: Remove package loop
This commit is contained in:
parent
0913adc1e2
commit
14737df60f
@ -1,48 +0,0 @@
|
|||||||
// Copyright 2016 Hajime Hoshi
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package loop
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
|
||||||
)
|
|
||||||
|
|
||||||
const FPS = clock.FPS
|
|
||||||
|
|
||||||
func CurrentFPS() float64 {
|
|
||||||
return clock.CurrentFPS()
|
|
||||||
}
|
|
||||||
|
|
||||||
type runContext struct{}
|
|
||||||
|
|
||||||
var (
|
|
||||||
theRunContext *runContext
|
|
||||||
contextInitCh = make(chan struct{})
|
|
||||||
)
|
|
||||||
|
|
||||||
func Start() error {
|
|
||||||
// TODO: Need lock here?
|
|
||||||
if theRunContext != nil {
|
|
||||||
return errors.New("loop: The game is already running")
|
|
||||||
}
|
|
||||||
theRunContext = &runContext{}
|
|
||||||
close(contextInitCh)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func End() {
|
|
||||||
theRunContext = nil
|
|
||||||
}
|
|
15
run.go
15
run.go
@ -18,12 +18,11 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/internal/loop"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FPS represents how many times game updating happens in a second (60).
|
// FPS represents how many times game updating happens in a second (60).
|
||||||
const FPS = loop.FPS
|
const FPS = clock.FPS
|
||||||
|
|
||||||
// CurrentFPS returns the current number of frames per second of rendering.
|
// CurrentFPS returns the current number of frames per second of rendering.
|
||||||
//
|
//
|
||||||
@ -34,7 +33,7 @@ const FPS = loop.FPS
|
|||||||
// Note that logical game updating is assured to happen 60 times in a second
|
// Note that logical game updating is assured to happen 60 times in a second
|
||||||
// as long as the screen is active.
|
// as long as the screen is active.
|
||||||
func CurrentFPS() float64 {
|
func CurrentFPS() float64 {
|
||||||
return loop.CurrentFPS()
|
return clock.CurrentFPS()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -114,15 +113,10 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e
|
|||||||
|
|
||||||
g := newGraphicsContext(f)
|
g := newGraphicsContext(f)
|
||||||
theGraphicsContext.Store(g)
|
theGraphicsContext.Store(g)
|
||||||
if err := loop.Start(); err != nil {
|
|
||||||
ch <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := run(width, height, scale, title, g); err != nil {
|
if err := run(width, height, scale, title, g); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loop.End()
|
|
||||||
}()
|
}()
|
||||||
// TODO: Use context in Go 1.7?
|
// TODO: Use context in Go 1.7?
|
||||||
if err := ui.RunMainThreadLoop(ch); err != nil {
|
if err := ui.RunMainThreadLoop(ch); err != nil {
|
||||||
@ -145,15 +139,10 @@ func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64,
|
|||||||
|
|
||||||
g := newGraphicsContext(f)
|
g := newGraphicsContext(f)
|
||||||
theGraphicsContext.Store(g)
|
theGraphicsContext.Store(g)
|
||||||
if err := loop.Start(); err != nil {
|
|
||||||
ch <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := run(width, height, scale, title, g); err != nil {
|
if err := run(width, height, scale, title, g); err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loop.End()
|
|
||||||
}()
|
}()
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user