This commit is contained in:
Josh Deprez 2021-08-01 20:28:33 +10:00 committed by Josh Deprez
parent 64d44d9caf
commit 92ed1f1a89
3 changed files with 24 additions and 4 deletions

View file

@ -1,5 +1,11 @@
package engine package engine
import (
"unsafe"
"github.com/hajimehoshi/ebiten/v2"
)
// ID implements Identifier directly (as a string value). // ID implements Identifier directly (as a string value).
type ID string type ID string
@ -11,3 +17,16 @@ type ZPos float64
// Z returns z as a float64. // Z returns z as a float64.
func (z ZPos) Z() float64 { return float64(z) } func (z ZPos) Z() float64 { return float64(z) }
// GeoMDef is a serialisable form of GeoM.
type GeoMDef [6]float64 // Assumption: this has identical memory layout to GeoM
// ToGeoMDef translates a GeoM to a GeoMDef using unsafe.Pointer.
func ToGeoMDef(m *ebiten.GeoM) *GeoMDef {
return (*GeoMDef)(unsafe.Pointer(m))
}
// GeoM translates a GeoMDef to a GeoM using unsafe.Pointer.
func (d *GeoMDef) GeoM() *ebiten.GeoM {
return (*ebiten.GeoM)(unsafe.Pointer(d))
}

View file

@ -32,7 +32,7 @@ type Scene struct {
Components []interface{} Components []interface{}
Hidden bool Hidden bool
ID ID
Transform ebiten.GeoM Transform GeoMDef
ZPos ZPos
} }
@ -41,7 +41,8 @@ func (s *Scene) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
if s.Hidden { if s.Hidden {
return return
} }
geom.Concat(s.Transform) geom.Concat(*s.Transform.GeoM())
for _, i := range s.Components { for _, i := range s.Components {
if d, ok := i.(Drawer); ok { if d, ok := i.(Drawer); ok {
d.Draw(screen, geom) d.Draw(screen, geom)

View file

@ -20,7 +20,7 @@ type Tilemap struct {
Map [][]Tile Map [][]Tile
Src ImageRef // must be a horizontal tile set Src ImageRef // must be a horizontal tile set
TileSize int TileSize int
Transform ebiten.GeoM Transform GeoMDef
ZPos ZPos
} }
@ -29,7 +29,7 @@ func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
if t.Hidden { if t.Hidden {
return return
} }
geom.Concat(t.Transform) geom.Concat(*t.Transform.GeoM())
for j, row := range t.Map { for j, row := range t.Map {
for i, tile := range row { for i, tile := range row {
var op ebiten.DrawImageOptions var op ebiten.DrawImageOptions