Files
aego/tests/integration/gameplay_events_test.go
sanspie 1030dc9a43
ci-platforms / build (amd64, darwin, macos-15-intel) (push) Skipped
ci-platforms / build (amd64, windows, windows-2022) (push) Skipped
ci-platforms / build (arm64, darwin, macos-15) (push) Skipped
ci / checks (push) Successful in 4m58s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 27m47s
ci / release (push) Successful in 11m57s
Stage 10d2: audio fast path, shutdown order, profiler and monitor sections
2026-10-22 14:41:24 +03:00

68 lines
1.7 KiB
Go

package integration
import (
"testing"
"aego/engine/recorder"
"aego/modules/gameplay"
"aego/scene"
)
func gameplayRecords(r *recorder.Recorder) map[string]int {
out := map[string]int{}
for _, rc := range r.Snapshot(nil) {
if rc.Kind == recorder.Gameplay {
out[rc.Name]++
}
}
return out
}
// Damage and death reach the Event Monitor as gameplay records.
func TestGameplayEventsRecorded(t *testing.T) {
pf := openPlatformer(t)
pf.step(60)
hp, ok := scene.Get[gameplay.Health](pf.app.Scene, pf.enemy)
if !ok {
t.Fatal("EnemyLeft has no Health")
}
if !hp.Damage(hp.Max, pf.player) {
t.Fatal("the enemy took no damage")
}
pf.step(140)
rec := pf.app.Engine.MainWorld().Recorder
got := gameplayRecords(rec)
if got["damage"] == 0 || got["died"] == 0 {
t.Fatalf("gameplay records %v, want damage and died", got)
}
if n := rec.Counts()[recorder.Gameplay]; n == 0 {
t.Fatal("the gameplay count is zero")
}
}
// A tick that records a gameplay event does not allocate; the dummy has no scripts, so only the engine side is measured.
func TestGameplayTickAllocs(t *testing.T) {
pf := openPlatformer(t)
pf.step(120)
sc := pf.app.Scene
dummy := sc.Create(sc.Root(), "Dummy")
hp := scene.Add[gameplay.Health](sc, dummy)
*hp = gameplay.DefaultHealth()
hp.InvulnTime, hp.Max = 0, 1<<30
sc.Flush()
pf.step(2)
hp, _ = scene.Get[gameplay.Health](sc, dummy)
rec := pf.app.Engine.MainWorld().Recorder
before := rec.Counts()[recorder.Gameplay]
a := testing.AllocsPerRun(60, func() {
hp.Damage(1, pf.enemy)
pf.step(1)
})
if rec.Counts()[recorder.Gameplay]-before < 60 {
t.Fatalf("only %d gameplay records over 61 damaged ticks", rec.Counts()[recorder.Gameplay]-before)
}
if a != 0 {
t.Fatalf("a tick with a damage record allocates %v times", a)
}
}