From 96564c52e23d4cd3c0436bc12ac8c31fda05f668 Mon Sep 17 00:00:00 2001 From: Futility Date: Sat, 9 Mar 2019 12:11:23 -0500 Subject: [PATCH 01/18] The btn package in x had a fxn for making TextBoxs that would manipulate the original layers passed in. --- entities/x/btn/textBox.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/entities/x/btn/textBox.go b/entities/x/btn/textBox.go index 84842ba2..cee449fe 100644 --- a/entities/x/btn/textBox.go +++ b/entities/x/btn/textBox.go @@ -35,9 +35,11 @@ func NewTextBox(cid event.CID, x, y, w, h, txtX, txtY float64, b.Text = f.NewStrText("Init", 0, 0) b.Text.Vector = b.Text.Attach(b.Box.Vector, txtX, (-txtY)+b.H) - // Add one to the layer so that the text shows up above the box itself - layers[len(layers)-1]++ - render.Draw(b.Text, layers...) + // We dont want to modify the input's layers but we do want the text to show up on top of the base renderable. + txtLayers := make([]int, len(layers)) + copy(txtLayers, layers) + txtLayers[len(txtLayers)-1]++ + render.Draw(b.Text, txtLayers...) return b } From 943ca08b369a5b3c605cf2597ea42597e5e29fc0 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 9 Mar 2019 12:59:58 -0600 Subject: [PATCH 02/18] Added GoToPtr to scene --- scene/scene.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scene/scene.go b/scene/scene.go index c99015d5..9ad950c3 100644 --- a/scene/scene.go +++ b/scene/scene.go @@ -1,5 +1,9 @@ package scene +import ( + "github.com/oakmound/oak/dlog" +) + // A Scene is a set of functions defining what needs to happen when a scene // starts, loops, and ends. type Scene struct { @@ -47,3 +51,16 @@ func GoTo(nextScene string) End { return nextScene, nil } } + +// GoToPtr returns an End function that, without any other customization possible, +// will change to the input next scene. It takes a pointer so the scene can +// be changed after this function is called. +func GoToPtr(nextScene *string) End { + return func() (string, *Result) { + if nextScene == nil { + dlog.Error("Go To: next scene was nil") + return "", nil + } + return *nextScene, nil + } +} From d77128eb83d90c2e8086057dcf2d33494392533d Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 9 Mar 2019 13:00:24 -0600 Subject: [PATCH 03/18] Refactored some x/move functions to remove hardcoded values --- entities/x/move/topdown.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/entities/x/move/topdown.go b/entities/x/move/topdown.go index 8325f4dd..2e74ffec 100644 --- a/entities/x/move/topdown.go +++ b/entities/x/move/topdown.go @@ -38,7 +38,8 @@ func TopDown(mvr Mover, up, down, left, right string) { } vec.Add(delta) mvr.GetRenderable().SetPos(vec.X(), vec.Y()) - mvr.GetSpace().Update(vec.X(), vec.Y(), 16, 16) + sp := mvr.GetSpace() + sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH()) } // CenterScreenOn will cause the screen to center on the given mover, obeying @@ -58,12 +59,12 @@ func Limit(mvr Mover, rect floatgeom.Rect2) { wf := float64(w) hf := float64(h) if vec.X() < rect.Min.X() { - vec.SetX(0) + vec.SetX(rect.Min.X()) } else if vec.X() > rect.Max.X()-wf { vec.SetX(rect.Max.X() - wf) } if vec.Y() < rect.Min.Y() { - vec.SetY(0) + vec.SetY(rect.Min.Y()) } else if vec.Y() > rect.Max.Y()-hf { vec.SetY(rect.Max.Y() - hf) } From 7b5b13e2ff7fad6b0317bf32e56112d40d427270 Mon Sep 17 00:00:00 2001 From: Futility Date: Sat, 9 Mar 2019 16:20:49 -0500 Subject: [PATCH 04/18] A formerly unhandled panic is now a error in render.NewSheetSequence --- render/sheet.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/render/sheet.go b/render/sheet.go index 7df13ef1..33f2f1b3 100644 --- a/render/sheet.go +++ b/render/sheet.go @@ -42,6 +42,9 @@ func NewSheetSequence(sheet *Sheet, fps float64, frames ...int) (*Sequence, erro mods := make([]Modifiable, len(frames)/2) for i := 0; i < len(frames); i += 2 { + if len(sh) < frames[i] || len(sh[frames[i]]) < frames[i+1] { + return nil, oakerr.InvalidInput{InputName: "Frame requested does not exist"} + } mods[i/2] = NewSprite(0, 0, sh[frames[i]][frames[i+1]]) } return NewSequence(fps, mods...), nil From 7a8fbddb40a1fd6e5b2cacd288bf42fba963442e Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 10 Mar 2019 11:53:43 -0500 Subject: [PATCH 05/18] Correct hurtbox to not depend on lowrez --- .gitignore | 4 +++ Gopkg.lock | 54 +++++++++++++++++++++---------------- Gopkg.toml | 11 +------- entities/x/force/hurtBox.go | 9 +++---- go.mod | 9 +++---- 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index a1338d68..4d69f078 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +# As a library we can't commit our vendor directory if it ever accidentally kept +# around after updating dependencies +vendor/* \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock index 1a026f4f..6e7f3dcb 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,7 +2,6 @@ [[projects]] - branch = "master" digest = "1:b4cf4077e6123e315ad327b9578b6aac5253b74095c9eb16bbb0479b3676805a" name = "github.com/200sc/go-dist" packages = [ @@ -12,6 +11,7 @@ ] pruneopts = "UT" revision = "8bdf90fe4b023f2e176be67c7c27ea31dd89d324" + version = "v1.0.0" [[projects]] digest = "1:7a13753f465bbc2b6c141de05f94dbdcaa066da0f49f226b94b6c46b4bba0ddf" @@ -40,17 +40,32 @@ [[projects]] branch = "master" - digest = "1:130593c6d3a71ec66faec36cbe0017d56755ddc38c638e675b31552b6f1b9708" + digest = "1:5d10efb58e8385c77530e8df60dbb7efcf2f806e1a742f5dfc588f8aeb9e0a96" name = "github.com/BurntSushi/xgb" packages = [ ".", "render", + "shape", "shm", + "xinerama", "xproto", ] pruneopts = "UT" revision = "27f122750802c950b2c869a5b63dafcf590ced95" +[[projects]] + branch = "master" + digest = "1:93698a5b0ee991e62e44f2278c0a5baa3545f9ff64366e67060876aa8753e15d" + name = "github.com/BurntSushi/xgbutil" + packages = [ + ".", + "ewmh", + "xevent", + "xprop", + ] + pruneopts = "UT" + revision = "f7c97cef3b4e6c88280a5a7091c3314e815ca243" + [[projects]] branch = "master" digest = "1:554fc9ace442cb49137a7790fa8d6264d8987c1fb90925cf02899d4663538f9d" @@ -105,23 +120,15 @@ version = "v0.1.1" [[projects]] - branch = "master" digest = "1:0aeaaf2037e67cfb35f8623b2164ca4469cd5c112521b75e19f34fc9e3a287b9" name = "github.com/oakmound/alsa-go" packages = ["."] pruneopts = "UT" revision = "ba5351447e1209bb9726d4330341eb07661e7200" + version = "v1.0.0" [[projects]] - branch = "master" - digest = "1:aef6e035cb47dc2a202386f7599928ecd6525251ad746e6c8e7cc11cea996d5a" - name = "github.com/oakmound/lowrez17" - packages = ["game/layers"] - pruneopts = "UT" - revision = "da6171067fff33956a6af7f46e2226d6acd9cf9d" - -[[projects]] - digest = "1:5946d50a5b3ad30b970c44bfe3d5867c30398f25d95b87c96181dd2cad75e374" + digest = "1:b011f6daff4a9104e16311630be5edffdfb750cb63a0393ccf919108ba447ffa" name = "github.com/oakmound/shiny" packages = [ "driver", @@ -132,23 +139,25 @@ "driver/internal/lifecycler", "driver/internal/swizzle", "driver/internal/win32", + "driver/internal/x11", "driver/internal/x11key", "driver/windriver", "driver/x11driver", "gesture", "screen", + "unit", ] pruneopts = "UT" - revision = "c45f2e40187a7a4659e19f7fcef90086db41801e" - version = "v0.1.0" + revision = "315515c7afb9b9a1a1f519694f2641fef88c65a4" + version = "v0.2.0" [[projects]] - digest = "1:17b5368f859a5ee0bc4521b9cb29b25ab1a69c86eab2ab2883b60efe3a3ad093" + digest = "1:d62ba403cf4b6b331f3be73bbe6a66549b70e3e93f918ec9870badd7f2c242aa" name = "github.com/oakmound/w32" packages = ["."] pruneopts = "UT" - revision = "b7f1cf6a58d56773f641d191180a5d81c5679ab1" - version = "v1.0.0" + revision = "9e34746976a263bb50637c5018561570515aa317" + version = "v2.0.0" [[projects]] branch = "master" @@ -198,7 +207,7 @@ [[projects]] branch = "master" - digest = "1:97b3ccf91aec42b36b53970c65da2f0aaebae2f22f50459eeb7b23a4a56cf71a" + digest = "1:ac6265dc97b72daef957099ec5beba7c0a43bd2f365848444bebf581a0a0d67f" name = "golang.org/x/mobile" packages = [ "event/key", @@ -210,7 +219,7 @@ "gl", ] pruneopts = "UT" - revision = "b8c6dab863a6bb7fceeb28cd882e272336b5d63d" + revision = "d2e1c1c4a691445933af238dcfc2869b0ffa7e91" [[projects]] branch = "master" @@ -221,7 +230,7 @@ "html/atom", ] pruneopts = "UT" - revision = "16b79f2e4e95ea23b2bf9903c9809ff7b013ce85" + revision = "c10a0554eabf8a6a7a6cc3097c9d9f43dcee0a43" [[projects]] branch = "master" @@ -233,11 +242,11 @@ [[projects]] branch = "master" - digest = "1:237e8294fc988c135a81cfce460263ac3806d86ba9faef52130ddcc1ddd22fd4" + digest = "1:ae68415cb4e39b10569bcb1eb4d5c7c4737262fd2a55022b057e5e77e2e7b459" name = "golang.org/x/sys" packages = ["windows"] pruneopts = "UT" - revision = "c2f5717e611cf8e89a852a41081355194d80c943" + revision = "10058d7d4faa7dd5ef860cbd31af00903076e7b8" [solve-meta] analyzer-name = "dep" @@ -258,7 +267,6 @@ "github.com/davecgh/go-spew/spew", "github.com/disintegration/gift", "github.com/golang/freetype/truetype", - "github.com/oakmound/lowrez17/game/layers", "github.com/oakmound/shiny/driver", "github.com/oakmound/shiny/gesture", "github.com/oakmound/shiny/screen", diff --git a/Gopkg.toml b/Gopkg.toml index 26bb8841..f6b7a1b2 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -24,11 +24,6 @@ # go-tests = true # unused-packages = true - -[[constraint]] - branch = "master" - name = "github.com/200sc/go-dist" - [[constraint]] name = "github.com/200sc/klangsynthese" version = "0.1.1" @@ -53,13 +48,9 @@ branch = "master" name = "github.com/golang/freetype" -[[constraint]] - branch = "master" - name = "github.com/oakmound/lowrez17" - [[constraint]] name = "github.com/oakmound/shiny" - version = "0.1.0" + version = "0.2.0" [[constraint]] name = "github.com/stretchr/testify" diff --git a/entities/x/force/hurtBox.go b/entities/x/force/hurtBox.go index a10c5280..2b170cd5 100644 --- a/entities/x/force/hurtBox.go +++ b/entities/x/force/hurtBox.go @@ -4,7 +4,6 @@ import ( "image/color" "time" - "github.com/oakmound/lowrez17/game/layers" "github.com/oakmound/oak/collision" "github.com/oakmound/oak/physics" "github.com/oakmound/oak/render" @@ -28,20 +27,20 @@ func NewHurtBox(x, y, w, h float64, duration time.Duration, l collision.Label, f // NewHurtColor creates a temporary collision space with a given force it should // apply to objects it collides with. The box is rendered as the given color -func NewHurtColor(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, c color.Color) { +func NewHurtColor(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, c color.Color, layers ...int) { cb := render.NewColorBox(int(w), int(h), c) - NewHurtDisplay(x, y, w, h, duration, l, fv, cb) + NewHurtDisplay(x, y, w, h, duration, l, fv, cb, layers...) } // NewHurtDisplay creates a temporary collision space with a given force it should // apply to objects it collides with. The box is rendered as the given renderable. // The input renderable is not copied before it is drawn. -func NewHurtDisplay(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, r render.Renderable) { +func NewHurtDisplay(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, r render.Renderable, layers ...int) { hb := new(hurtBox) hb.DirectionSpace = NewDirectionSpace(collision.NewLabeledSpace(x, y, w, h, l), fv) collision.Add(hb.Space) r.SetPos(x, y) - render.Draw(r, layers.DebugLayer) + render.Draw(r, layers...) go timing.DoAfter(duration, func() { collision.Remove(hb.Space) r.Undraw() diff --git a/go.mod b/go.mod index f177f5f7..c29af0f3 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/oakmound/oak require ( - github.com/200sc/go-dist v0.0.0-20180217184639-8bdf90fe4b02 + github.com/200sc/go-dist v1.0.0 github.com/200sc/klangsynthese v0.1.1 github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 @@ -10,10 +10,9 @@ require ( github.com/disintegration/gift v1.2.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/hajimehoshi/go-mp3 v0.1.1 - github.com/oakmound/alsa-go v0.0.0-20190302183935-ba5351447e12 - github.com/oakmound/lowrez17 v0.0.0-20180207115707-da6171067fff - github.com/oakmound/shiny v0.1.0 - github.com/oakmound/w32 v1.0.0 + github.com/oakmound/alsa-go v1.0.0 + github.com/oakmound/shiny v0.2.0 + github.com/oakmound/w32 v2.0.0 github.com/oov/directsound-go v0.0.0-20141101201356-e53e59c700bf github.com/pkg/errors v0.8.1 github.com/pmezard/go-difflib v1.0.0 From 9d381d87c9fe12140a015678610fdf2b737d5cd3 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 10 Mar 2019 11:53:56 -0500 Subject: [PATCH 06/18] Add ToSprite to CompositeM --- render/compositeM.go | 22 +++++++++++++++++++++- render/sprite.go | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/render/compositeM.go b/render/compositeM.go index dbce8259..a1cb1093 100644 --- a/render/compositeM.go +++ b/render/compositeM.go @@ -93,7 +93,7 @@ func (cs *CompositeM) Undraw() { } } -// GetRGBA does not work on a CompositeM and therefore returns nil +// GetRGBA always returns nil from Composites func (cs *CompositeM) GetRGBA() *image.RGBA { return nil } @@ -113,6 +113,26 @@ func (cs *CompositeM) Filter(fs ...mod.Filter) { } } +// ToSprite draws all of this +func (cs *CompositeM) ToSprite() *Sprite { + var maxW, maxH int + for _, r := range cs.rs { + x, y := int(r.X()), int(r.Y()) + w, h := r.GetDims() + if x+w > maxW { + maxW = x + w + } + if y+h > maxH { + maxH = y + h + } + } + sp := NewEmptySprite(cs.X(), cs.Y(), maxW, maxH) + for _, r := range cs.rs { + r.Draw(sp) + } + return sp +} + // Copy makes a new CompositeM with the same renderables func (cs *CompositeM) Copy() Modifiable { cs2 := new(CompositeM) diff --git a/render/sprite.go b/render/sprite.go index 96980e23..6b268b63 100644 --- a/render/sprite.go +++ b/render/sprite.go @@ -2,6 +2,7 @@ package render import ( "image" + "image/color" "image/draw" "github.com/oakmound/oak/render/mod" @@ -49,6 +50,28 @@ func (s *Sprite) SetRGBA(r *image.RGBA) { s.r = r } +// Bounds is an alternative to GetDims that alows a sprite +// to satisy draw.Image. +func (s *Sprite) Bounds() image.Rectangle { + return s.r.Bounds() +} + +// ColorModel allows sprites to satisfy draw.Image. Returns +// color.RGBA. +func (s *Sprite) ColorModel() color.Model { + return s.r.ColorModel() +} + +// At returns the color of a given pixel location +func (s *Sprite) At(x, y int) color.Color { + return s.r.At(x, y) +} + +// Set sets a color of a given pixel location +func (s *Sprite) Set(x, y int, c color.Color) { + s.r.Set(x, y, c) +} + // DrawOffset draws this sprite at +xOff, +yOff func (s *Sprite) DrawOffset(buff draw.Image, xOff, yOff float64) { ShinyDraw(buff, s.r, int(s.X()+xOff), int(s.Y()+yOff)) From cfabe10ea768b9b4c7607d3c2f94c4223b6a859c Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2019 12:34:13 -0500 Subject: [PATCH 07/18] Add back reactive GetReactiveSpace --- entities/reactive.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entities/reactive.go b/entities/reactive.go index bd5a3d01..c2679bc3 100644 --- a/entities/reactive.go +++ b/entities/reactive.go @@ -66,6 +66,11 @@ func (r *Reactive) GetSpace() *collision.Space { return r.RSpace.Space } +// GetReactiveSpace returns this reactive's RSpace +func (r *Reactive) GetReactiveSpace() *collision.ReactiveSpace { + return r.RSpace +} + // Overwrites // Init satisfies event.Entity From b521832e211586eb2eb28c9fd81ff96221a4bfd0 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2019 15:24:41 -0500 Subject: [PATCH 08/18] Give a bit more information on Switch.Set error --- render/switch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/switch.go b/render/switch.go index 6973e9b9..0df643ae 100644 --- a/render/switch.go +++ b/render/switch.go @@ -55,7 +55,7 @@ func (c *Switch) Add(k string, v Modifiable) (err error) { func (c *Switch) Set(k string) error { c.lock.RLock() if _, ok := c.subRenderables[k]; !ok { - return oakerr.InvalidInput{InputName: "k"} + return oakerr.NotFound{InputName: "k:" + k} } c.lock.RUnlock() c.curRenderable = k From e789443d78ad9d6b0c9dcd2218f2d01056e8f7db Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2019 20:52:28 -0500 Subject: [PATCH 09/18] Fix to sprite Copy --- render/sprite.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/render/sprite.go b/render/sprite.go index 6b268b63..fbd15ca1 100644 --- a/render/sprite.go +++ b/render/sprite.go @@ -86,13 +86,23 @@ func (s *Sprite) Draw(buff draw.Image) { func (s *Sprite) Copy() Modifiable { newS := new(Sprite) if s.r != nil { - newS.r = new(image.RGBA) - *newS.r = *s.r + newS.r = rgbaCopy(s.r) } newS.LayeredPoint = s.LayeredPoint.Copy() return newS } +func rgbaCopy(r *image.RGBA) *image.RGBA { + newRgba := new(image.RGBA) + newRgba.Rect = r.Rect + newRgba.Stride = r.Stride + newRgba.Pix = make([]uint8, len(r.Pix)) + for i, p := range r.Pix { + newRgba.Pix[i] = p + } + return newRgba +} + // IsNil returns whether or not this sprite's rgba is nil. func (s *Sprite) IsNil() bool { return s.r == nil From f50b292290f9c84b973cd96c06d9e8ce87fa2a66 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 12 Mar 2019 07:40:25 -0500 Subject: [PATCH 10/18] Use copy() over a loop for rgbaCopy --- render/sprite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/render/sprite.go b/render/sprite.go index fbd15ca1..dda0b7c6 100644 --- a/render/sprite.go +++ b/render/sprite.go @@ -97,9 +97,7 @@ func rgbaCopy(r *image.RGBA) *image.RGBA { newRgba.Rect = r.Rect newRgba.Stride = r.Stride newRgba.Pix = make([]uint8, len(r.Pix)) - for i, p := range r.Pix { - newRgba.Pix[i] = p - } + copy(newRgba.Pix, r.Pix) return newRgba } From 399d29cc6cc108fe55528af40e9918158f3bfb82 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 12 Mar 2019 15:57:36 -0500 Subject: [PATCH 11/18] Add ShiftY and ShiftX to \x\move --- entities/x/move/shift.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 entities/x/move/shift.go diff --git a/entities/x/move/shift.go b/entities/x/move/shift.go new file mode 100644 index 00000000..cdfe6e7d --- /dev/null +++ b/entities/x/move/shift.go @@ -0,0 +1,21 @@ +package move + +// ShiftX will ShiftX on the vector of the mover and +// set the renderable and space positions to that of the updated vector. +func ShiftX(mvr Mover, x float64) { + vec := mvr.Vec() + vec.ShiftX(x) + mvr.GetRenderable().SetPos(vec.X(), vec.Y()) + sp := mvr.GetSpace() + sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH()) +} + +// ShiftY will ShiftY on the vector of the mover and +// set the renderable and space positions to that of the updated vector. +func ShiftY(mvr Mover, y float64) { + vec := mvr.Vec() + vec.ShiftY(y) + mvr.GetRenderable().SetPos(vec.X(), vec.Y()) + sp := mvr.GetSpace() + sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH()) +} From 9f127f2d6ed7c770d6901a26308d43005dfd0a7c Mon Sep 17 00:00:00 2001 From: Futility Date: Tue, 12 Mar 2019 20:31:11 -0400 Subject: [PATCH 12/18] Updating error in sheets to have even better reporting and actually correct condition. --- render/sheet.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/render/sheet.go b/render/sheet.go index 33f2f1b3..771053d0 100644 --- a/render/sheet.go +++ b/render/sheet.go @@ -3,6 +3,7 @@ package render import ( "image" + "github.com/oakmound/oak/dlog" "github.com/oakmound/oak/oakerr" ) @@ -42,8 +43,9 @@ func NewSheetSequence(sheet *Sheet, fps float64, frames ...int) (*Sequence, erro mods := make([]Modifiable, len(frames)/2) for i := 0; i < len(frames); i += 2 { - if len(sh) < frames[i] || len(sh[frames[i]]) < frames[i+1] { - return nil, oakerr.InvalidInput{InputName: "Frame requested does not exist"} + if len(sh) <= frames[i] || len(sh[frames[i]]) <= frames[i+1] { + dlog.Error("Frame ", frames[i], frames[i+1], "requested but sheet has dimensions ", len(sh), len(sh[frames[i]])) + return nil, oakerr.InvalidInput{InputName: "Frame requested does not exist "} } mods[i/2] = NewSprite(0, 0, sh[frames[i]][frames[i+1]]) } From c2ecbed5523569d9006fae587e14d13a90736a05 Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 12 Mar 2019 20:35:07 -0500 Subject: [PATCH 13/18] Fix some bugs in particle demo since we removed 'c' from commands --- examples/particle-demo/core.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/particle-demo/core.go b/examples/particle-demo/core.go index a5dd5e18..c5463549 100644 --- a/examples/particle-demo/core.go +++ b/examples/particle-demo/core.go @@ -28,8 +28,8 @@ var ( ) func parseShape(args []string) shape.Shape { - if len(args) > 0 { - switch args[0] { + if len(args) > 1 { + switch args[1] { case "heart": return shape.Heart case "square": @@ -289,38 +289,38 @@ func main() { } func parseRGBA(args []string) (r, g, b, a int, err error) { - if len(args) < 5 { + if len(args) < 4 { return } - r, err = strconv.Atoi(args[1]) + r, err = strconv.Atoi(args[0]) if err != nil { return } - g, err = strconv.Atoi(args[2]) + g, err = strconv.Atoi(args[1]) if err != nil { return } - b, err = strconv.Atoi(args[3]) + b, err = strconv.Atoi(args[2]) if err != nil { return } - a, err = strconv.Atoi(args[4]) + a, err = strconv.Atoi(args[3]) return } func parseFloats(args []string) (f1, f2 float64, two bool, err error) { - if len(args) < 2 { + if len(args) < 1 { err = errors.New("No args") return } - f1, err = strconv.ParseFloat(args[1], 64) + f1, err = strconv.ParseFloat(args[0], 64) if err != nil { return } - if len(args) < 3 { + if len(args) < 2 { return } - f2, err = strconv.ParseFloat(args[2], 64) + f2, err = strconv.ParseFloat(args[1], 64) if err != nil { return } @@ -329,18 +329,18 @@ func parseFloats(args []string) (f1, f2 float64, two bool, err error) { } func parseInts(args []string) (i1, i2 int, two bool, err error) { - if len(args) < 2 { + if len(args) < 1 { err = errors.New("No args") return } - i1, err = strconv.Atoi(args[1]) + i1, err = strconv.Atoi(args[0]) if err != nil { return } - if len(args) < 3 { + if len(args) < 2 { return } - i2, err = strconv.Atoi(args[2]) + i2, err = strconv.Atoi(args[1]) if err != nil { return } From 8556c5219b6f8f7ef6b1195bebabe67f152fd6e4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 18 Mar 2019 21:08:33 -0500 Subject: [PATCH 14/18] Correct race condition on updating a non-existant space --- collision/tree.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/collision/tree.go b/collision/tree.go index caae62a8..a75d91f5 100644 --- a/collision/tree.go +++ b/collision/tree.go @@ -83,15 +83,16 @@ func (t *Tree) Remove(sps ...*Space) int { return removed } -// UpdateLabel will set the input space's label in this tree. Modifying a -// space's label without going through a tree's method such as this will -// have no effect. +// UpdateLabel will set the input space's label. DEPRECATED. Just set +// the Label field on the Space pointer. func (t *Tree) UpdateLabel(classtype Label, s *Space) { - t.Remove(s) s.Label = classtype - t.Add(s) } +// ErrNotExist is returned by methods on spaces +// when the space to update or act on did not exist +var ErrNotExist = errors.New("Space did not exist to update") + // UpdateSpace resets a space's location to a given // rtreego.Rect. // This is not an operation on a space because @@ -102,7 +103,11 @@ func (t *Tree) UpdateSpace(x, y, w, h float64, s *Space) error { } loc := NewRect(x, y, w, h) t.Lock() - t.Delete(s) + deleted := t.Delete(s) + if !deleted { + t.Unlock() + return ErrNotExist + } s.Location = loc t.Insert(s) t.Unlock() @@ -116,7 +121,11 @@ func (t *Tree) UpdateSpaceRect(rect floatgeom.Rect3, s *Space) error { return oakerr.NilInput{InputName: "s"} } t.Lock() - t.Delete(s) + deleted := t.Delete(s) + if !deleted { + t.Unlock() + return ErrNotExist + } s.Location = rect t.Insert(s) t.Unlock() @@ -138,8 +147,6 @@ func (t *Tree) ShiftSpace(x, y float64, s *Space) error { // themselves, if they exist in the tree, but self-collision // will not be reported by Hits. func (t *Tree) Hits(sp *Space) []*Space { - // Eventually we'll expose SearchIntersect for use cases where you - // want to see if you intersect yourself results := t.SearchIntersect(sp.Bounds()) hitSelf := -1 i := 0 From dc01c5a8006053689837eeab1da896c132e87ce9 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 18 Mar 2019 21:08:43 -0500 Subject: [PATCH 15/18] Add Size method to Rtree --- collision/rtree.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/collision/rtree.go b/collision/rtree.go index 8bf9a169..49d84616 100644 --- a/collision/rtree.go +++ b/collision/rtree.go @@ -22,6 +22,10 @@ type Rtree struct { height int } +func (tree *Rtree) Size() int { + return tree.size +} + // NewTree creates a new R-tree instance. func newTree(MinChildren, MaxChildren int) *Rtree { rt := Rtree{MinChildren: MinChildren, MaxChildren: MaxChildren} @@ -307,6 +311,7 @@ func (tree *Rtree) Delete(obj *Space) bool { for i, e := range n.entries { if e.obj == obj { ind = i + break } } if ind < 0 { From fd9592f763dd6c6987d52e6e6e0cb3c93cb1ac1f Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 18 Mar 2019 21:09:04 -0500 Subject: [PATCH 16/18] Correct default font generator to use runtime.Caller(0) --- render/font.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/font.go b/render/font.go index c6df1996..2e3368be 100644 --- a/render/font.go +++ b/render/font.go @@ -55,7 +55,7 @@ func (fg *FontGenerator) Generate() *Font { if defaultFontFile != "" { fg.File = defaultFontFile } else { - _, curFile, _, _ := runtime.Caller(1) + _, curFile, _, _ := runtime.Caller(0) dir = filepath.Join(filepath.Dir(curFile), "default_assets", "font") fg.File = "luxisr.ttf" } From 5622f7ac89871f7eb7c1d107bbadc3a84d8e2fca Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 18 Mar 2019 21:09:21 -0500 Subject: [PATCH 17/18] Doc update for NewSequence --- render/sequence.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/sequence.go b/render/sequence.go index 03895bb8..77af9b77 100644 --- a/render/sequence.go +++ b/render/sequence.go @@ -24,7 +24,7 @@ type Sequence struct { } // NewSequence returns a new sequence from the input modifiables, playing at -// fps rate +// the given fps rate. func NewSequence(fps float64, mods ...Modifiable) *Sequence { return &Sequence{ LayeredPoint: NewLayeredPoint(0, 0, 0), From ef2afe524ea1ee5d78e6f9a4a8f179444d6989f5 Mon Sep 17 00:00:00 2001 From: Futility Date: Sat, 23 Mar 2019 12:30:01 -0400 Subject: [PATCH 18/18] Added comment to new exported function rtree.Size --- collision/rtree.go | 1 + 1 file changed, 1 insertion(+) diff --git a/collision/rtree.go b/collision/rtree.go index 49d84616..bf666eeb 100644 --- a/collision/rtree.go +++ b/collision/rtree.go @@ -22,6 +22,7 @@ type Rtree struct { height int } +// Size returns the rtree's size func (tree *Rtree) Size() int { return tree.size }