Implemented basic layer support by sparsex.
This commit is contained in:
parent
eb79fdeedc
commit
c9f8027f81
5 changed files with 56 additions and 7 deletions
3
go.mod
3
go.mod
|
@ -8,7 +8,8 @@ require (
|
|||
github.com/hajimehoshi/ebiten/v2 v2.4.16 // indirect
|
||||
github.com/hajimehoshi/file2byteslice v1.0.0 // indirect
|
||||
github.com/jezek/xgb v1.1.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
||||
github.com/surdeus/godat v0.0.0-20230217130825-eddf2c345cb7 // indirect
|
||||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20230213192124-5e25df0256eb // indirect
|
||||
golang.org/x/image v0.5.0 // indirect
|
||||
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -21,6 +21,8 @@ github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFl
|
|||
github.com/jfreymuth/oggvorbis v1.0.4/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
|
||||
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
|
||||
github.com/surdeus/godat v0.0.0-20230217130825-eddf2c345cb7 h1:Fmoxhb42mS6BEmLF2spRiYlzes+S1VrEw0PnbR1ktUM=
|
||||
github.com/surdeus/godat v0.0.0-20230217130825-eddf2c345cb7/go.mod h1:tQGz8oe6Qig5yjYobaW1O8paXGGhzdukg8nT2bpvfes=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -30,6 +32,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
|||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
||||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w=
|
||||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/exp/shiny v0.0.0-20230213192124-5e25df0256eb h1:gdeQX7xJSkTNF+Sw7++XNIOo4pGL0CjQv3N2Vm1Erxk=
|
||||
golang.org/x/exp/shiny v0.0.0-20230213192124-5e25df0256eb/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
|
|
|
@ -4,6 +4,10 @@ import (
|
|||
"github.com/surdeus/gox/src/gx"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
gx.Object
|
||||
}
|
||||
|
||||
func main() {
|
||||
e := gx.New(&gx.WindowConfig{
|
||||
Title: "Test title",
|
||||
|
@ -11,5 +15,6 @@ func main() {
|
|||
Height: 320,
|
||||
})
|
||||
|
||||
e.Add(0, Player{})
|
||||
e.Run()
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@ package gx
|
|||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/surdeus/godat/src/sparsex"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// The type represents order of drawing.
|
||||
type Layer int
|
||||
|
||||
type WindowConfig struct {
|
||||
Title string
|
||||
Width, Height int
|
||||
|
@ -11,6 +16,8 @@ type WindowConfig struct {
|
|||
|
||||
type Engine struct {
|
||||
wcfg *WindowConfig
|
||||
layers *sparsex.Sparse[Layer, *[]Behaver]
|
||||
behavers []Behaver
|
||||
}
|
||||
|
||||
type engine Engine
|
||||
|
@ -20,13 +27,39 @@ func New(
|
|||
) *Engine {
|
||||
return &Engine{
|
||||
wcfg: cfg,
|
||||
layers: sparsex.New[
|
||||
Layer,
|
||||
*[]Behaver,
|
||||
](true),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) Add(l Layer, b Behaver) {
|
||||
g, ok := e.layers.Get(l)
|
||||
if !ok {
|
||||
e.layers.Set(
|
||||
l,
|
||||
&[]Behaver{b},
|
||||
)
|
||||
} else {
|
||||
set := append(*g, b)
|
||||
*g = set
|
||||
}
|
||||
|
||||
e.behavers = append(e.behavers, b)
|
||||
}
|
||||
|
||||
func (e *engine) Update() error {
|
||||
eng := (*Engine)(e)
|
||||
for _, v := range eng.behavers {
|
||||
v.Update(eng)
|
||||
fmt.Println(v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (e *engine) Draw(s *ebiten.Image) {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package gx
|
||||
|
||||
type Behaver interface {
|
||||
Start()
|
||||
Update()
|
||||
Start(*Engine)
|
||||
Update(*Engine)
|
||||
GetObject() *Object
|
||||
}
|
||||
|
||||
// The object that is drawn by sprite
|
||||
/// based on the transform.
|
||||
type Sprite struct {
|
||||
}
|
||||
|
||||
// The object type represents
|
||||
// basic information for interaction
|
||||
// with the engine.
|
||||
|
@ -13,9 +18,10 @@ type Object struct {
|
|||
T Transform
|
||||
}
|
||||
|
||||
func (o *Object) Start() {}
|
||||
func (o *Object) Update() {}
|
||||
func (o *Object) GetObject() *Object {
|
||||
return o
|
||||
// The functions that
|
||||
func (o Object) Start(e *Engine) {}
|
||||
func (o Object) Update(e *Engine) {}
|
||||
func (o Object) GetObject() *Object {
|
||||
return &o
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue