mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Add ebiten/runner; Move glfw -> internal/glfw
This commit is contained in:
parent
00552d91c2
commit
b313578a24
@ -18,9 +18,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/hajimehoshi/ebiten"
|
|
||||||
"github.com/hajimehoshi/ebiten/example/blocks"
|
"github.com/hajimehoshi/ebiten/example/blocks"
|
||||||
"github.com/hajimehoshi/ebiten/glfw"
|
"github.com/hajimehoshi/ebiten/runner"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -44,9 +43,8 @@ func main() {
|
|||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
ui := new(glfw.UI)
|
|
||||||
game := blocks.NewGame()
|
game := blocks.NewGame()
|
||||||
if err := ebiten.Run(ui, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)", 60); err != nil {
|
if err := runner.Run(game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)", 60); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ type canvas struct {
|
|||||||
funcsDone chan struct{}
|
funcsDone chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *canvas) draw(d ebiten.GraphicsContextDrawer) (err error) {
|
func (c *canvas) draw(d GraphicsContextDrawer) (err error) {
|
||||||
c.use(func() {
|
c.use(func() {
|
||||||
c.context.PreUpdate()
|
c.context.PreUpdate()
|
||||||
})
|
})
|
@ -30,6 +30,10 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GraphicsContextDrawer interface {
|
||||||
|
Draw(d ebiten.GraphicsContext) error
|
||||||
|
}
|
||||||
|
|
||||||
type UI struct {
|
type UI struct {
|
||||||
canvas *canvas
|
canvas *canvas
|
||||||
}
|
}
|
||||||
@ -77,7 +81,7 @@ func (u *UI) Terminate() {
|
|||||||
glfw.Terminate()
|
glfw.Terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UI) Draw(drawer ebiten.GraphicsContextDrawer) error {
|
func (u *UI) Draw(drawer GraphicsContextDrawer) error {
|
||||||
return u.canvas.draw(drawer)
|
return u.canvas.draw(drawer)
|
||||||
}
|
}
|
||||||
|
|
@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ebiten
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hajimehoshi/ebiten"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -25,13 +27,14 @@ import (
|
|||||||
|
|
||||||
type Game interface {
|
type Game interface {
|
||||||
Update() error
|
Update() error
|
||||||
Draw(context GraphicsContext) error
|
Draw(context ebiten.GraphicsContext) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the game. Basically, this function executes ui.Start() at the start,
|
// Run runs the game. Basically, this function executes ui.Start() at the start,
|
||||||
// calls ui.DoEvent(), game.Update() and game.Draw() at a regular interval, and finally
|
// calls ui.DoEvent(), game.Update() and game.Draw() at a regular interval, and finally
|
||||||
// calls ui.Terminate().
|
// calls ui.Terminate().
|
||||||
func Run(ui UI, game Game, width, height, scale int, title string, fps int) error {
|
func Run(game Game, width, height, scale int, title string, fps int) error {
|
||||||
|
ui := new(glfw.UI)
|
||||||
if err := ui.Start(width, height, scale, title); err != nil {
|
if err := ui.Start(width, height, scale, title); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
29
ui.go
29
ui.go
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 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 ebiten
|
|
||||||
|
|
||||||
type UI interface {
|
|
||||||
Start(widht, height, scale int, title string) error
|
|
||||||
DoEvents()
|
|
||||||
Terminate()
|
|
||||||
Draw(drawer GraphicsContextDrawer) error
|
|
||||||
IsClosed() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type GraphicsContextDrawer interface {
|
|
||||||
Draw(d GraphicsContext) error
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user