loop: Remove package loop

This commit is contained in:
Hajime Hoshi 2017-08-06 02:17:26 +09:00
parent 0913adc1e2
commit 14737df60f
2 changed files with 2 additions and 61 deletions

View File

@ -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
View File

@ -18,12 +18,11 @@ import (
"sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/loop"
"github.com/hajimehoshi/ebiten/internal/ui"
)
// 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.
//
@ -34,7 +33,7 @@ const FPS = loop.FPS
// Note that logical game updating is assured to happen 60 times in a second
// as long as the screen is active.
func CurrentFPS() float64 {
return loop.CurrentFPS()
return clock.CurrentFPS()
}
var (
@ -114,15 +113,10 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e
g := newGraphicsContext(f)
theGraphicsContext.Store(g)
if err := loop.Start(); err != nil {
ch <- err
return
}
if err := run(width, height, scale, title, g); err != nil {
ch <- err
return
}
loop.End()
}()
// TODO: Use context in Go 1.7?
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)
theGraphicsContext.Store(g)
if err := loop.Start(); err != nil {
ch <- err
return
}
if err := run(width, height, scale, title, g); err != nil {
ch <- err
return
}
loop.End()
}()
return ch
}