Skip to content

Commit b9c45c3

Browse files
committed
fold entities into engine
1 parent dabd47a commit b9c45c3

41 files changed

Lines changed: 196 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.fat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dist/demo/atlas.webp 1432 1457
22
dist/demo/index.css 69 94
3-
dist/demo/index.html 151834 74488
4-
dist/demo/index.js 146753 69430
5-
dist/demo/index.wasm 85239 45979
3+
dist/demo/index.html 140760 68914
4+
dist/demo/index.js 135679 63809
5+
dist/demo/index.wasm 76930 41268

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ levels are a higher-level app composition that selects a board and wires gamepla
2727

2828
### Ents and Hooks
2929

30-
ents are a single data and behavior instance. low-count demo ents implement `Update(game.Game)` and register directly with `gam.Register()`. hooks operate on high-count or coordinated ent vectors efficiently.
30+
ents are a single data and behavior instance. low-count demo ents implement `Update(*engine.Eng)` and register directly with `gam.Register()`. hooks operate on high-count or coordinated ent vectors efficiently.
3131

3232
ents with an update hook return whether they have been updated and so request a new frame. this is important for lo energy apps.
3333

src/internal/demo/app/app_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/oidoid/void/src/internal/demo/engine"
7-
"github.com/oidoid/void/src/internal/demo/entities"
87
"github.com/oidoid/void/src/internal/demo/gfx"
98
"github.com/oidoid/void/src/void/vgeo"
109
"github.com/oidoid/void/src/void/vgfx"
@@ -64,7 +63,7 @@ func newGame(camX, camY float32, superballCount int) *engine.Eng {
6463
gam.Cam().Y = camY
6564
gam.Poll().DeltaMillis = 1000. / fps
6665
for i := range superballCount {
67-
superball := entities.NewSuperballEnt(
66+
superball := engine.NewSuperballEnt(
6867
gam.Random,
6968
vgeo.NewXY(float32(i%benchCanvasSize), float32(i/benchCanvasSize)),
7069
)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package entities
1+
package engine
22

33
import (
44
"github.com/oidoid/void/src/internal/demo/gfx"
55
"github.com/oidoid/void/src/internal/demo/tags"
6+
"github.com/oidoid/void/src/void/vengine"
67
"github.com/oidoid/void/src/void/ventities"
7-
game "github.com/oidoid/void/src/void/vgame"
88
"github.com/oidoid/void/src/void/vgeo"
99
"github.com/oidoid/void/src/void/vgfx"
1010
)
@@ -14,7 +14,7 @@ const (
1414
buttonMinW = 16
1515
)
1616

17-
func NewDrawToggleButton(gam game.Game) *ventities.ButtonEnt {
17+
func NewDrawToggleButton(gam *Eng) *ventities.ButtonEnt {
1818
this := newButtonEnt("draw", ventities.ButtonTypeToggle)
1919
this.ClipAnchor = ventities.HUDEnt{
2020
Anchor: vgeo.DirNE,
@@ -30,7 +30,7 @@ func NewDrawToggleButton(gam game.Game) *ventities.ButtonEnt {
3030
return this
3131
}
3232

33-
func NewDrawOnBlurToggle(gam game.Game) *ventities.ButtonEnt {
33+
func NewDrawOnBlurToggle(gam *Eng) *ventities.ButtonEnt {
3434
this := newButtonEnt("blur", ventities.ButtonTypeToggle)
3535
this.OnUpdate = func(ent *ventities.ButtonEnt) {
3636
ent.On = gam.DrawOnBlur()
@@ -41,32 +41,32 @@ func NewDrawOnBlurToggle(gam game.Game) *ventities.ButtonEnt {
4141
return this
4242
}
4343

44-
func NewContextLossButton(gam game.Game) *ventities.ButtonEnt {
44+
func NewContextLossButton(gam *Eng) *ventities.ButtonEnt {
4545
this := newButtonEnt("!gl", ventities.ButtonTypeButton)
4646
this.OnClick = func(*ventities.ButtonEnt) {
4747
gam.ReqContextLoss()
4848
}
4949
return this
5050
}
5151

52-
func NewScreenshotButton(gam game.Game) *ventities.ButtonEnt {
52+
func NewScreenshotButton(gam *Eng) *ventities.ButtonEnt {
5353
this := newButtonEnt("pic", ventities.ButtonTypeButton)
5454
this.OnClick = func(*ventities.ButtonEnt) {
5555
gam.ReqScreenshot()
5656
}
5757
return this
5858
}
5959

60-
func NewFullscreenToggle(gam game.Game) *ventities.ButtonEnt {
60+
func NewFullscreenToggle(gam *Eng) *ventities.ButtonEnt {
6161
this := newButtonEnt("window", ventities.ButtonTypeToggle)
6262
this.OnUpdate = func(ent *ventities.ButtonEnt) {
6363
ent.On = !gam.FullscreenEnabled()
6464
}
6565
this.OnClick = func(ent *ventities.ButtonEnt) {
6666
if ent.On {
67-
gam.ReqFullscreen(game.FullscreenReqExit)
67+
gam.ReqFullscreen(vengine.FullscreenReqExit)
6868
} else {
69-
gam.ReqFullscreen(game.FullscreenReqEnter)
69+
gam.ReqFullscreen(vengine.FullscreenReqEnter)
7070
}
7171
}
7272
return this

src/internal/demo/entities/cam_status_ent.go renamed to src/internal/demo/engine/cam_status_ent.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package entities
1+
package engine
22

33
import (
4-
"github.com/oidoid/void/src/internal/demo/game"
54
"github.com/oidoid/void/src/internal/demo/gfx"
65
"github.com/oidoid/void/src/void/vatlas"
6+
"github.com/oidoid/void/src/void/vengine"
77
"github.com/oidoid/void/src/void/ventities"
8-
"github.com/oidoid/void/src/void/vgame"
98
"github.com/oidoid/void/src/void/vgeo"
109
"github.com/oidoid/void/src/void/vgfx"
1110
"github.com/oidoid/void/src/void/vtext"
@@ -39,7 +38,7 @@ func NewCamStatusEnt(fillTag vatlas.Tag, z vgfx.Z) CamStatusEnt {
3938
return this
4039
}
4140

42-
func (this *CamStatusEnt) Update(gam game.Game) vgame.Status {
41+
func (this *CamStatusEnt) Update(gam *Eng) vengine.Status {
4342
font := gam.Font()
4443
layer := gam.Layer(this.Z.Layer())
4544
sprs := &layer.Sprs
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package entities
1+
package engine
22

33
import (
4-
"github.com/oidoid/void/src/internal/demo/game"
54
"github.com/oidoid/void/src/internal/demo/gfx"
5+
"github.com/oidoid/void/src/void/vengine"
66
"github.com/oidoid/void/src/void/ventities"
7-
"github.com/oidoid/void/src/void/vgame"
87
"github.com/oidoid/void/src/void/vgeo"
98
"github.com/oidoid/void/src/void/vtext"
109
)
@@ -23,7 +22,7 @@ func NewClockEnt() ClockEnt {
2322
return this
2423
}
2524

26-
func (this *ClockEnt) Update(gam game.Game) vgame.Status {
25+
func (this *ClockEnt) Update(gam *Eng) vengine.Status {
2726
layer := gam.Layer(gfx.LayerUI)
2827
font := gam.Font()
2928
clip := layer.Clip
@@ -34,14 +33,14 @@ func (this *ClockEnt) Update(gam game.Game) vgame.Status {
3433
)
3534
this.TextEnt.Update(font, &layer.Sprs, clip)
3635
gam.ReqUpdateInMillis(millisToNextMin(gam.UtcMillis()))
37-
return vgame.Pause
36+
return vengine.Pause
3837
}
3938

4039
func millisToNextMin(millis uint64) uint64 {
4140
return 60_000 - millis%60_000
4241
}
4342

44-
func timeString(time vgame.TimeFormat) string {
43+
func timeString(time vengine.TimeFormat) string {
4544
hour := int(time.Hour) % 12
4645
if hour == 0 {
4746
hour = 12

src/internal/demo/entities/clock_ent_test.go renamed to src/internal/demo/engine/clock_ent_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package entities
1+
package engine
22

33
import (
44
"testing"
55

6-
"github.com/oidoid/void/src/void/vgame"
6+
"github.com/oidoid/void/src/void/vengine"
77
)
88

99
func TestTimeString(t *testing.T) {
@@ -22,7 +22,7 @@ func TestTimeString(t *testing.T) {
2222
{"late night", 23, 59, 0, "11:59:00"},
2323
} {
2424
t.Run(test.name, func(t *testing.T) {
25-
time := vgame.TimeFormat{
25+
time := vengine.TimeFormat{
2626
Hour: uint8(test.hour), Minute: uint8(test.min), Second: uint8(test.sec),
2727
}
2828
if got := timeString(time); got != test.want {

src/internal/demo/entities/draw_status_ent.go renamed to src/internal/demo/engine/draw_status_ent.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package entities
1+
package engine
22

33
import (
4-
"github.com/oidoid/void/src/internal/demo/game"
54
"github.com/oidoid/void/src/internal/demo/gfx"
65
"github.com/oidoid/void/src/void/vatlas"
6+
"github.com/oidoid/void/src/void/vengine"
77
"github.com/oidoid/void/src/void/ventities"
8-
"github.com/oidoid/void/src/void/vgame"
98
"github.com/oidoid/void/src/void/vgeo"
109
"github.com/oidoid/void/src/void/vgfx"
1110
"github.com/oidoid/void/src/void/vtext"
@@ -49,7 +48,7 @@ func NewDrawStatusEnt(
4948
return this
5049
}
5150

52-
func (this *DrawStatusEnt) Update(gam game.Game) vgame.Status {
51+
func (this *DrawStatusEnt) Update(gam *Eng) vengine.Status {
5352
font := gam.Font()
5453
layer := gam.Layer(this.Z.Layer())
5554
sprs := &layer.Sprs

src/internal/demo/engine/eng.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import (
44
"math"
55

66
"github.com/oidoid/void/src/internal/demo/assets"
7-
"github.com/oidoid/void/src/internal/demo/entities"
8-
"github.com/oidoid/void/src/internal/demo/game"
97
"github.com/oidoid/void/src/internal/demo/gfx"
108
"github.com/oidoid/void/src/internal/demo/tags"
119
"github.com/oidoid/void/src/void/vatlas"
1210
"github.com/oidoid/void/src/void/vboards"
1311
"github.com/oidoid/void/src/void/vengine"
1412
"github.com/oidoid/void/src/void/ventities"
15-
"github.com/oidoid/void/src/void/vgame"
1613
"github.com/oidoid/void/src/void/vgeo"
1714
"github.com/oidoid/void/src/void/vgfx"
1815
"github.com/oidoid/void/src/void/vgrid"
@@ -23,7 +20,7 @@ import (
2320

2421
type Eng struct {
2522
*vengine.Eng[*Eng]
26-
Superballs ventities.EntVec[*Eng, entities.SuperballEnt]
23+
Superballs ventities.EntVec[*Eng, SuperballEnt]
2724
HitSuperballs bool
2825
BeepSuperballs bool
2926
SuperballGrid vgrid.Grid
@@ -36,16 +33,8 @@ type Eng struct {
3633
CamZoomOn bool
3734
}
3835

39-
type entUpdater struct {
40-
ent ventities.Updater[game.Game]
41-
}
42-
43-
func (this entUpdater) Update(gam *Eng) vgame.Status {
44-
return this.ent.Update(gam)
45-
}
46-
4736
var Version string
48-
var _ vgame.Game = (*Eng)(nil)
37+
var _ vengine.Game = (*Eng)(nil)
4938

5039
const (
5140
lvlScaleMin = float32(1)
@@ -81,7 +70,7 @@ func New() *Eng {
8170
this.Layer(gfx.LayerCursor).CamMode = vgfx.LayerCamModeFixed
8271
this.Layer(gfx.LayerGrid).CamMode = vgfx.LayerCamModeFixed
8372
this.Layer(gfx.LayerGrid).BlendMode = vgfx.LayerBlendModeMultiply
84-
this.ReqFullscreen(vgame.FullscreenReqEnter)
73+
this.ReqFullscreen(vengine.FullscreenReqEnter)
8574
this.In().MapDefaults()
8675
*this.Texts() = *ventities.NewEntVec(vhooks.UpdateTexts[*Eng])
8776
this.RegisterUpdate(this.Texts())
@@ -102,8 +91,8 @@ func (this *Eng) SetBoard(board *vboards.Board) {
10291
this.SuperballGrid = vgrid.New(bounds, diameter, 2*1024*1024)
10392
}
10493

105-
func (this *Eng) Register(ent ventities.Updater[game.Game]) {
106-
this.RegisterUpdate(entUpdater{ent})
94+
func (this *Eng) Register(ent ventities.Updater[*Eng]) {
95+
this.RegisterUpdate(ent)
10796
}
10897

10998
func (this *Eng) SuperballCount() int { return this.Superballs.Len() }
@@ -230,13 +219,13 @@ func (this *Eng) Boing(dx, dy float32) {
230219
this.LastBoingMs = this.NowMillis()
231220
speed := float32(math.Hypot(float64(dx), float64(dy)))
232221
hz := 100 * (0.5 + this.Random()) * min(max(speed/80, 2), 5)
233-
this.Beep(vgame.Beep{
222+
this.Beep(vengine.Beep{
234223
StartHz: hz, EndHz: hz * 0.9, DurationMs: 120,
235224
})
236225
}
237226

238227
// to-do: separate method for resizing cam or whatever.
239-
func (this *Eng) Update() vgame.Status {
228+
func (this *Eng) Update() vengine.Status {
240229
stat := this.Eng.BeginTick()
241230
dpr := this.Poll().DevicePixelRatio
242231
this.Layer(gfx.LayerUI).AutoscaleMaxScale = uint8(vmath.Round(3 * dpr))

src/internal/demo/engine/eng_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@ import (
44
"math"
55
"testing"
66

7-
"github.com/oidoid/void/src/internal/demo/entities"
87
"github.com/oidoid/void/src/internal/demo/gfx"
98
"github.com/oidoid/void/src/void/vatlas"
109
"github.com/oidoid/void/src/void/vboards"
11-
"github.com/oidoid/void/src/void/vgame"
10+
"github.com/oidoid/void/src/void/vengine"
1211
"github.com/oidoid/void/src/void/vgeo"
1312
"github.com/oidoid/void/src/void/vgfx"
1413
)
1514

1615
// applies the window URL override before the demo submits its fullscreen req.
1716
func TestFullscreenURLDisable(t *testing.T) {
1817
gam := New()
19-
gam.Router().Update = func(*Eng) vgame.Status { return vgame.Pause }
20-
gam.Poll().FullscreenReq = vgame.FullscreenReqExit
18+
gam.Router().Update = func(*Eng) vengine.Status { return vengine.Pause }
19+
gam.Poll().FullscreenReq = vengine.FullscreenReqExit
2120
gam.Update()
2221
if gam.FullscreenEnabled() {
2322
t.Error("FullscreenEnabled() = true, want false")
2423
}
25-
if got := gam.FullscreenReq(); got != int32(vgame.FullscreenReqExit) {
24+
if got := gam.FullscreenReq(); got != int32(vengine.FullscreenReqExit) {
2625
t.Errorf("FullscreenReq() = %v, want exit", got)
2726
}
2827
}
2928

3029
// requests windowed mode from the default fullscreen setting.
3130
func TestFullscreenToggle(t *testing.T) {
3231
gam := New()
33-
toggle := entities.NewFullscreenToggle(gam)
32+
toggle := NewFullscreenToggle(gam)
3433
toggle.OnUpdate(toggle)
3534
if toggle.On {
3635
t.Error("toggle.On = true, want false")
@@ -40,7 +39,7 @@ func TestFullscreenToggle(t *testing.T) {
4039
if gam.FullscreenEnabled() {
4140
t.Error("FullscreenEnabled() = true, want false")
4241
}
43-
if got := gam.FullscreenReq(); got != int32(vgame.FullscreenReqExit) {
42+
if got := gam.FullscreenReq(); got != int32(vengine.FullscreenReqExit) {
4443
t.Errorf("FullscreenReq() = %v, want exit", got)
4544
}
4645
}
@@ -59,7 +58,7 @@ func TestP1EntDrawsWhenSpriteHitsClip(t *testing.T) {
5958
gam := New()
6059
gam.Eng.SetBoard(&vboards.Board{WH: vgeo.NewWH[int32](10, 10)})
6160
gam.Layer(gfx.LayerP1).Clip = clip
62-
ent := entities.NewP1Ent(
61+
ent := NewP1Ent(
6362
vgeo.NewXY(test.x, float32(0)), vatlas.Anim{W: 8, H: 13},
6463
)
6564
ent.Update(gam)
@@ -171,12 +170,12 @@ func TestAdjustLvlScaleAt(t *testing.T) {
171170
// starts fullscreen by default.
172171
func TestDefaults(t *testing.T) {
173172
gam := New()
174-
gam.Router().Update = func(*Eng) vgame.Status { return vgame.Pause }
173+
gam.Router().Update = func(*Eng) vengine.Status { return vengine.Pause }
175174
gam.Update()
176175
if !gam.FullscreenEnabled() {
177176
t.Error("FullscreenEnabled() = false, want true")
178177
}
179-
if got := gam.FullscreenReq(); got != int32(vgame.FullscreenReqEnter) {
178+
if got := gam.FullscreenReq(); got != int32(vengine.FullscreenReqEnter) {
180179
t.Errorf("FullscreenReq() = %v, want enter", got)
181180
}
182181
}

0 commit comments

Comments
 (0)