From b385d1f05477c09a5a5dd11829d04375bbd1e3de Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Mon, 11 Nov 2024 15:23:05 +0800 Subject: [PATCH] fix: anim tests and mfp bug --- pkg/anim/anim_test.go | 33 ++++++++++++++++++++++++++ pkg/anim/musicforprogramming/module.go | 11 +++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 pkg/anim/anim_test.go diff --git a/pkg/anim/anim_test.go b/pkg/anim/anim_test.go new file mode 100644 index 00000000..1cb955da --- /dev/null +++ b/pkg/anim/anim_test.go @@ -0,0 +1,33 @@ +package anim + +import ( + "testing" + "time" + + "github.com/cfoust/cy/pkg/geom" + "github.com/cfoust/cy/pkg/geom/image" +) + +// Subject all animations to a few simple smoke tests. +func TestAnims(t *testing.T) { + for name, anim := range Animations { + t.Logf("testing anim %s", name) + + // The most common point of failure for animations is failing + // to do adequate bounds checks. This renders every animation + // at a few different sizes to ensure that doesn't happen. + for _, size := range []geom.Size{ + geom.Size{}, + geom.Size{ + R: 5, + C: 5, + }, + geom.DEFAULT_SIZE, + } { + instance := anim() + instance.Init(image.New(size)) + instance.Update(0) + instance.Update(time.Second) + } + } +} diff --git a/pkg/anim/musicforprogramming/module.go b/pkg/anim/musicforprogramming/module.go index 60a2d362..04fa0912 100644 --- a/pkg/anim/musicforprogramming/module.go +++ b/pkg/anim/musicforprogramming/module.go @@ -376,14 +376,16 @@ func (r *MFP) drawVisualizer(delta time.Duration) { } func (r *MFP) Update(delta time.Duration) image.Image { + size := r.out.Size() + r.drawBackground(delta) image.Copy(geom.Vec2{}, r.out, r.bg) colOffset := 1 rowOffset := 1 - for row := 0; row < r.out.Size().R; row++ { - for col := 0; col < geom.Min(r.out.Size().C-1, PANEL_WIDTH+colOffset); col++ { + for row := 0; row < size.R; row++ { + for col := 0; col < geom.Min(size.C-1, PANEL_WIDTH+colOffset); col++ { r.out[row][col].Char = ' ' } } @@ -404,6 +406,11 @@ func (r *MFP) Update(delta time.Duration) image.Image { for col := 0; col < PANEL_WIDTH; col++ { cellRow := visualRow + VISUAL_HEIGHT cellCol := col + colOffset + + if cellRow >= size.R || cellCol >= size.C { + continue + } + r.out[cellRow][cellCol].Char = TRACK_TITLE[(col+titleIndex)%len(TRACK_TITLE)] r.out[cellRow][cellCol].FG = emu.ANSIColor(8) }