UNTESTED: ebiten v2

This commit is contained in:
2020-11-21 19:27:09 +00:00
parent c5e6abb798
commit 92fa0fc5d6
22 changed files with 92 additions and 132 deletions

View File

@@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
"code.ur.gs/lupine/ordoor/internal/config"
"code.ur.gs/lupine/ordoor/internal/data"

View File

@@ -3,7 +3,7 @@ package assetstore
import (
"image"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
// These are just offsets into the Cursors.cur file

View File

@@ -4,7 +4,7 @@ import (
"image"
"os"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
_ "github.com/samuel/go-pcx/pcx" // PCX support
)
@@ -32,10 +32,7 @@ func (a *AssetStore) Image(name string) (*ebiten.Image, error) {
return nil, err
}
img, err := ebiten.NewImageFromImage(rawImg, ebiten.FilterDefault)
if err != nil {
return nil, err
}
img := ebiten.NewImageFromImage(rawImg)
a.images[name] = img
return img, nil

View File

@@ -3,7 +3,7 @@ package assetstore
import (
"log"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
"code.ur.gs/lupine/ordoor/internal/menus"
)

View File

@@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
"code.ur.gs/lupine/ordoor/internal/data"
)
@@ -117,10 +117,7 @@ func (o *Object) Sprite(idx int) (*Sprite, error) {
}
raw := o.raw.Sprites[idx]
img, err := ebiten.NewImageFromImage(raw.ToImage(o.assets.Palette), ebiten.FilterDefault)
if err != nil {
return nil, err
}
img := ebiten.NewImageFromImage(raw.ToImage(o.assets.Palette))
rect := image.Rect(
int(raw.XOffset),

View File

@@ -4,8 +4,8 @@ import (
"log"
"os"
"github.com/hajimehoshi/ebiten/audio"
"github.com/hajimehoshi/ebiten/audio/vorbis"
"github.com/hajimehoshi/ebiten/v2/audio"
"github.com/hajimehoshi/ebiten/v2/audio/vorbis"
)
type Sound struct {
@@ -57,7 +57,7 @@ func (s *Sound) InfinitePlayer() (*audio.Player, error) {
return nil, err
}
infinite := audio.NewInfiniteLoop(decoder, decoder.Size())
infinite := audio.NewInfiniteLoop(decoder, decoder.Length())
return audio.NewPlayer(audio.CurrentContext(), infinite)
}

View File

@@ -6,8 +6,8 @@ import (
"log"
"strings"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/inpututil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"code.ur.gs/lupine/ordoor/internal/assetstore"
"code.ur.gs/lupine/ordoor/internal/config"

View File

@@ -9,8 +9,8 @@ import (
"log"
"time"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/audio"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/audio"
"code.ur.gs/lupine/ordoor/internal/assetstore"
"code.ur.gs/lupine/ordoor/internal/config"
@@ -61,9 +61,7 @@ func Run(configFile string, overrideX, overrideY int) error {
}
}
if _, err := audio.NewContext(48000); err != nil {
return fmt.Errorf("Failed to set up audio context: %v", err)
}
_ = audio.NewContext(48000)
ordoor := &Ordoor{
assets: assets,
@@ -188,7 +186,8 @@ func (o *Ordoor) Draw(screen *ebiten.Image) error {
do := &ebiten.DrawImageOptions{}
do.GeoM.Scale(scaleX, scaleY)
return screen.DrawImage(pic, do)
screen.DrawImage(pic, do)
return nil
}
return o.flow.Draw(screen)

View File

@@ -5,8 +5,8 @@ import (
"image"
"sort"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type CartPt struct {
@@ -118,9 +118,7 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
op.GeoM.Scale(s.Zoom, s.Zoom)
if err := screen.DrawImage(spr.Image, &op); err != nil {
return err
}
screen.DrawImage(spr.Image, &op)
x1, y1 := geo.Apply(0, 0)
ebitenutil.DebugPrintAt(
@@ -187,9 +185,7 @@ func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter *int) e
// Zoom has to come last
op.GeoM.Scale(s.Zoom, s.Zoom)
if err := screen.DrawImage(spr.Image, &op); err != nil {
return err
}
screen.DrawImage(spr.Image, &op)
}
return nil

View File

@@ -1,7 +1,7 @@
package ui
import (
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
var (

View File

@@ -5,8 +5,8 @@ import (
"image"
"runtime/debug"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"code.ur.gs/lupine/ordoor/internal/assetstore"
)
@@ -137,9 +137,7 @@ func (d *Driver) Draw(screen *ebiten.Image) error {
do.GeoM = d.orig2native
do.GeoM.Translate(x, y)
if err := screen.DrawImage(region.image, &do); err != nil {
return err
}
screen.DrawImage(region.image, &do)
}
}

View File

@@ -3,7 +3,7 @@ package ui
import (
"image"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
type region struct {

View File

@@ -8,9 +8,9 @@ import (
"runtime/debug"
"runtime/pprof"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/inpututil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Game interface {
@@ -53,8 +53,6 @@ type Window struct {
//
// ebiten assumes a single window, so only call this once...
func NewWindow(game Game, title string, xRes int, yRes int) (*Window, error) {
ebiten.SetRunnableInBackground(true)
return &Window{
Title: title,
debug: true,
@@ -109,10 +107,12 @@ func (w *Window) drawCursor(screen *ebiten.Image) error {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
return screen.DrawImage(cursor, op)
screen.DrawImage(cursor, op)
return nil
}
func (w *Window) Update(screen *ebiten.Image) (outErr error) {
func (w *Window) Update() (outErr error) {
// Ebiten does not like it if we panic inside its main loop
defer func() {
if panicErr := recover(); panicErr != nil {
@@ -124,7 +124,8 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
}()
if err := w.game.Update(screen.Size()); err != nil {
// FIXME: remove need for update generally
if err := w.game.Update(w.xRes, w.yRes); err != nil {
return err
}
@@ -157,13 +158,11 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
}
if ebiten.IsDrawingSkipped() {
return nil
}
return nil
}
if err := w.game.Draw(screen); err != nil {
return err
}
func (w *Window) Draw(screen *ebiten.Image) {
w.game.Draw(screen)
if w.debug {
// Draw FPS, etc, to the screen
@@ -172,7 +171,7 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
// Draw the cursor last
return w.drawCursor(screen)
w.drawCursor(screen)
}
// TODO: a stop or other cancellation mechanism