From b31c294d4d59159ea272652a7a16f5bc8a0f0098 Mon Sep 17 00:00:00 2001 From: Jacob Stewart Date: Sun, 27 Dec 2020 11:54:34 -0500 Subject: [PATCH 1/5] Added input event tracking to prevent missed inputs --- pixelgl/input.go | 18 ++++++++++++++---- pixelgl/window.go | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pixelgl/input.go b/pixelgl/input.go index 22468ef..75060ae 100644 --- a/pixelgl/input.go +++ b/pixelgl/input.go @@ -13,14 +13,14 @@ func (w *Window) Pressed(button Button) bool { return w.currInp.buttons[button] } -// JustPressed returns whether the Button has just been pressed down. +// JustPressed returns whether the Button has been pressed in the last frame. func (w *Window) JustPressed(button Button) bool { - return w.currInp.buttons[button] && !w.prevInp.buttons[button] + return w.pressEvents[button] } -// JustReleased returns whether the Button has just been released up. +// JustReleased returns whether the Button has been released in the last frame. func (w *Window) JustReleased(button Button) bool { - return !w.currInp.buttons[button] && w.prevInp.buttons[button] + return w.releaseEvents[button] } // Repeated returns whether a repeat event has been triggered on button. @@ -362,8 +362,10 @@ func (w *Window) initInput() { w.window.SetMouseButtonCallback(func(_ *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) { switch action { case glfw.Press: + w.tempPressEvents[Button(button)] = true w.tempInp.buttons[Button(button)] = true case glfw.Release: + w.tempReleaseEvents[Button(button)] = true w.tempInp.buttons[Button(button)] = false } }) @@ -374,8 +376,10 @@ func (w *Window) initInput() { } switch action { case glfw.Press: + w.tempPressEvents[Button(key)] = true w.tempInp.buttons[Button(key)] = true case glfw.Release: + w.tempReleaseEvents[Button(key)] = true w.tempInp.buttons[Button(key)] = false case glfw.Repeat: w.tempInp.repeat[Button(key)] = true @@ -431,6 +435,12 @@ func (w *Window) doUpdateInput() { w.prevInp = w.currInp w.currInp = w.tempInp + w.pressEvents = w.tempPressEvents + w.releaseEvents = w.tempReleaseEvents + + // Clear last frame's temporary status + w.tempPressEvents = [KeyLast + 1]bool{} + w.tempReleaseEvents = [KeyLast + 1]bool{} w.tempInp.repeat = [KeyLast + 1]bool{} w.tempInp.scroll = pixel.ZV w.tempInp.typed = "" diff --git a/pixelgl/window.go b/pixelgl/window.go index af1f1a7..566cf8f 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -100,6 +100,9 @@ type Window struct { typed string } + pressEvents, tempPressEvents [KeyLast + 1]bool + releaseEvents, tempReleaseEvents [KeyLast + 1]bool + prevJoy, currJoy, tempJoy joystickState } From 063b8952f9e7b1c62a786102c0e0c6b6ad3bc00e Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Mon, 21 Jun 2021 08:42:27 -0400 Subject: [PATCH 2/5] Adding Clipboard get/set functions to window --- pixelgl/window.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pixelgl/window.go b/pixelgl/window.go index f237c0b..ffdc02c 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -205,6 +205,17 @@ func (w *Window) Update() { w.UpdateInput() } +// ClipboardText returns the current value of the systems clipboard. +func (w *Window) ClipboardText() string { + return w.window.GetClipboardString() +} + +// SetClipboardText passes the given string to the underlying glfw window to set the +// systems clipboard. +func (w *Window) SetClipboardText(text string) { + w.window.SetClipboardString(text) +} + // SwapBuffers swaps buffers. Call this to swap buffers without polling window events. // Note that Update invokes SwapBuffers. func (w *Window) SwapBuffers() { From aae9927b584702260badb52190cb312ba6560c3f Mon Sep 17 00:00:00 2001 From: Alexandru-Paul Copil Date: Fri, 9 Jul 2021 10:43:10 +0300 Subject: [PATCH 3/5] Apply gofumpt and basic styling changes --- data.go | 16 +++++++-------- geometry_test.go | 3 ++- imdraw/imdraw.go | 4 ++-- pixel_test.go | 50 ++++++++++++++++++++++----------------------- pixelgl/canvas.go | 2 +- pixelgl/glshader.go | 8 ++++---- pixelgl/window.go | 2 +- text/text_test.go | 2 +- 8 files changed, 43 insertions(+), 44 deletions(-) diff --git a/data.go b/data.go index a195969..35630f8 100644 --- a/data.go +++ b/data.go @@ -8,15 +8,13 @@ import ( "math" ) -var ( - // zeroValueTriangleData is the default value of a TriangleData element - zeroValueTriangleData = struct { - Position Vec - Color RGBA - Picture Vec - Intensity float64 - }{Color: RGBA{1, 1, 1, 1}} -) +// zeroValueTriangleData is the default value of a TriangleData element +var zeroValueTriangleData = struct { + Position Vec + Color RGBA + Picture Vec + Intensity float64 +}{Color: RGBA{1, 1, 1, 1}} // TrianglesData specifies a list of Triangles vertices with three common properties: // TrianglesPosition, TrianglesColor and TrianglesPicture. diff --git a/geometry_test.go b/geometry_test.go index 328bd46..3599244 100644 --- a/geometry_test.go +++ b/geometry_test.go @@ -1236,7 +1236,8 @@ func TestLine_Intersect(t *testing.T) { args: args{k: pixel.L(pixel.V(0, 1), pixel.V(10, 11))}, want: pixel.ZV, want1: false, - }, { + }, + { name: "Lines intersect", fields: fields{A: pixel.V(600, 600), B: pixel.V(925, 150)}, args: args{k: pixel.L(pixel.V(740, 255), pixel.V(925, 255))}, diff --git a/imdraw/imdraw.go b/imdraw/imdraw.go index 9de21c9..d371d54 100644 --- a/imdraw/imdraw.go +++ b/imdraw/imdraw.go @@ -128,9 +128,9 @@ func (imd *IMDraw) Draw(t pixel.Target) { // Push adds some points to the IM queue. All Pushed points will have the same properties except for // the position. func (imd *IMDraw) Push(pts ...pixel.Vec) { - //Assert that Color is of type pixel.RGBA, + // Assert that Color is of type pixel.RGBA, if _, ok := imd.Color.(pixel.RGBA); !ok { - //otherwise cast it + // otherwise cast it imd.Color = pixel.ToRGBA(imd.Color) } opts := point{ diff --git a/pixel_test.go b/pixel_test.go index 8fa3fe8..01b3ae5 100644 --- a/pixel_test.go +++ b/pixel_test.go @@ -12,31 +12,31 @@ import ( "github.com/faiface/pixel/pixelgl" ) -var ( - // onePixelImage is the byte representation of a 1x1 solid white png file - onePixelImage = []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, - 0, 0, 0, 144, 119, 83, 222, 0, 0, 1, 130, 105, 67, 67, 80, 73, 67, 67, 32, 112, 114, 111, 102, 105, 108, 101, 0, - 0, 40, 145, 125, 145, 59, 72, 3, 65, 20, 69, 143, 73, 68, 17, 37, 133, 41, 68, 44, 182, 80, 43, 5, 81, 17, 75, - 141, 66, 16, 34, 132, 168, 96, 212, 194, 221, 141, 137, 66, 118, 13, 187, 9, 54, 150, 130, 109, 192, 194, 79, - 227, 175, 176, 177, 214, 214, 194, 86, 16, 4, 63, 32, 54, 182, 86, 138, 54, 18, 214, 55, 73, 32, 65, 140, 3, - 195, 28, 238, 188, 123, 121, 243, 6, 124, 71, 25, 211, 114, 3, 3, 96, 217, 57, 39, 30, 9, 107, 243, 137, 5, 173, - 233, 149, 0, 65, 90, 104, 0, 221, 116, 179, 227, 177, 88, 148, 186, 235, 235, 94, 213, 193, 93, 191, 202, 170, - 95, 247, 231, 106, 75, 174, 184, 38, 52, 104, 194, 99, 102, 214, 201, 9, 47, 11, 143, 108, 228, 178, 138, 247, - 132, 67, 230, 170, 158, 20, 62, 23, 238, 115, 164, 65, 225, 71, 165, 27, 101, 126, 83, 156, 46, 177, 79, 101, - 134, 156, 217, 248, 132, 112, 72, 88, 75, 215, 176, 81, 195, 230, 170, 99, 9, 15, 11, 119, 39, 45, 91, 242, 125, - 243, 101, 78, 42, 222, 84, 108, 101, 242, 102, 165, 79, 245, 194, 214, 21, 123, 110, 70, 233, 178, 187, 136, 48, - 197, 52, 49, 52, 12, 242, 172, 145, 33, 71, 191, 156, 182, 40, 46, 113, 185, 15, 215, 241, 119, 150, 252, 49, - 113, 25, 226, 90, 195, 20, 199, 36, 235, 88, 232, 37, 63, 234, 15, 126, 207, 214, 77, 13, 13, 150, 147, 90, 195, - 208, 248, 226, 121, 31, 61, 208, 180, 3, 197, 130, 231, 125, 31, 123, 94, 241, 4, 252, 207, 112, 101, 87, 253, - 235, 71, 48, 250, 41, 122, 161, 170, 117, 31, 66, 112, 11, 46, 174, 171, 154, 177, 11, 151, 219, 208, 241, 148, - 213, 29, 189, 36, 249, 101, 251, 82, 41, 120, 63, 147, 111, 74, 64, 251, 45, 180, 44, 150, 231, 86, 185, 231, - 244, 1, 102, 101, 86, 209, 27, 216, 63, 128, 222, 180, 100, 47, 213, 121, 119, 115, 237, 220, 254, 173, 169, - 204, 239, 7, 178, 211, 114, 90, 10, 150, 157, 65, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 46, 35, 0, 0, 46, 35, 1, - 120, 165, 63, 118, 0, 0, 0, 7, 116, 73, 77, 69, 7, 227, 4, 15, 10, 5, 36, 189, 4, 224, 88, 0, 0, 0, 25, 116, 69, - 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, - 73, 77, 80, 87, 129, 14, 23, 0, 0, 0, 12, 73, 68, 65, 84, 8, 215, 99, 120, 241, 226, 61, 0, 5, 123, 2, 192, 194, - 77, 211, 95, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130} -) +// onePixelImage is the byte representation of a 1x1 solid white png file +var onePixelImage = []byte{ + 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, + 0, 0, 0, 144, 119, 83, 222, 0, 0, 1, 130, 105, 67, 67, 80, 73, 67, 67, 32, 112, 114, 111, 102, 105, 108, 101, 0, + 0, 40, 145, 125, 145, 59, 72, 3, 65, 20, 69, 143, 73, 68, 17, 37, 133, 41, 68, 44, 182, 80, 43, 5, 81, 17, 75, + 141, 66, 16, 34, 132, 168, 96, 212, 194, 221, 141, 137, 66, 118, 13, 187, 9, 54, 150, 130, 109, 192, 194, 79, + 227, 175, 176, 177, 214, 214, 194, 86, 16, 4, 63, 32, 54, 182, 86, 138, 54, 18, 214, 55, 73, 32, 65, 140, 3, + 195, 28, 238, 188, 123, 121, 243, 6, 124, 71, 25, 211, 114, 3, 3, 96, 217, 57, 39, 30, 9, 107, 243, 137, 5, 173, + 233, 149, 0, 65, 90, 104, 0, 221, 116, 179, 227, 177, 88, 148, 186, 235, 235, 94, 213, 193, 93, 191, 202, 170, + 95, 247, 231, 106, 75, 174, 184, 38, 52, 104, 194, 99, 102, 214, 201, 9, 47, 11, 143, 108, 228, 178, 138, 247, + 132, 67, 230, 170, 158, 20, 62, 23, 238, 115, 164, 65, 225, 71, 165, 27, 101, 126, 83, 156, 46, 177, 79, 101, + 134, 156, 217, 248, 132, 112, 72, 88, 75, 215, 176, 81, 195, 230, 170, 99, 9, 15, 11, 119, 39, 45, 91, 242, 125, + 243, 101, 78, 42, 222, 84, 108, 101, 242, 102, 165, 79, 245, 194, 214, 21, 123, 110, 70, 233, 178, 187, 136, 48, + 197, 52, 49, 52, 12, 242, 172, 145, 33, 71, 191, 156, 182, 40, 46, 113, 185, 15, 215, 241, 119, 150, 252, 49, + 113, 25, 226, 90, 195, 20, 199, 36, 235, 88, 232, 37, 63, 234, 15, 126, 207, 214, 77, 13, 13, 150, 147, 90, 195, + 208, 248, 226, 121, 31, 61, 208, 180, 3, 197, 130, 231, 125, 31, 123, 94, 241, 4, 252, 207, 112, 101, 87, 253, + 235, 71, 48, 250, 41, 122, 161, 170, 117, 31, 66, 112, 11, 46, 174, 171, 154, 177, 11, 151, 219, 208, 241, 148, + 213, 29, 189, 36, 249, 101, 251, 82, 41, 120, 63, 147, 111, 74, 64, 251, 45, 180, 44, 150, 231, 86, 185, 231, + 244, 1, 102, 101, 86, 209, 27, 216, 63, 128, 222, 180, 100, 47, 213, 121, 119, 115, 237, 220, 254, 173, 169, + 204, 239, 7, 178, 211, 114, 90, 10, 150, 157, 65, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 46, 35, 0, 0, 46, 35, 1, + 120, 165, 63, 118, 0, 0, 0, 7, 116, 73, 77, 69, 7, 227, 4, 15, 10, 5, 36, 189, 4, 224, 88, 0, 0, 0, 25, 116, 69, + 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, + 73, 77, 80, 87, 129, 14, 23, 0, 0, 0, 12, 73, 68, 65, 84, 8, 215, 99, 120, 241, 226, 61, 0, 5, 123, 2, 192, 194, + 77, 211, 95, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130, +} func TestMain(m *testing.M) { pixelgl.Run(func() { diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index 2cb310b..720aa72 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -135,7 +135,7 @@ func (c *Canvas) SetBounds(bounds pixel.Rect) { c.sprite = pixel.NewSprite(nil, pixel.Rect{}) } c.sprite.Set(c, c.Bounds()) - //c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center())) + // c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center())) } // Bounds returns the rectangular bounds of the Canvas. diff --git a/pixelgl/glshader.go b/pixelgl/glshader.go index d472cca..3d10aa0 100644 --- a/pixelgl/glshader.go +++ b/pixelgl/glshader.go @@ -40,10 +40,10 @@ const ( ) var defaultCanvasVertexFormat = glhf.AttrFormat{ - canvasPosition: {Name: "aPosition", Type: glhf.Vec2}, - canvasColor: {Name: "aColor", Type: glhf.Vec4}, - canvasTexCoords: {Name: "aTexCoords", Type: glhf.Vec2}, - canvasIntensity: {Name: "aIntensity", Type: glhf.Float}, + canvasPosition: glhf.Attr{Name: "aPosition", Type: glhf.Vec2}, + canvasColor: glhf.Attr{Name: "aColor", Type: glhf.Vec4}, + canvasTexCoords: glhf.Attr{Name: "aTexCoords", Type: glhf.Vec2}, + canvasIntensity: glhf.Attr{Name: "aIntensity", Type: glhf.Float}, } // Sets up a base shader with everything needed for a Pixel diff --git a/pixelgl/window.go b/pixelgl/window.go index 00dafa8..836ed2b 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -100,7 +100,7 @@ type Window struct { typed string } - pressEvents, tempPressEvents [KeyLast + 1]bool + pressEvents, tempPressEvents [KeyLast + 1]bool releaseEvents, tempReleaseEvents [KeyLast + 1]bool prevJoy, currJoy, tempJoy joystickState diff --git a/text/text_test.go b/text/text_test.go index d3184a5..a5f30af 100644 --- a/text/text_test.go +++ b/text/text_test.go @@ -76,7 +76,7 @@ func BenchmarkTextWrite(b *testing.B) { b.Run(fmt.Sprintf("%d", len(chunk)), func(b *testing.B) { txt := text.New(pixel.ZV, atlas) for i := 0; i < b.N; i++ { - txt.Write(chunk) + _, _ = txt.Write(chunk) } }) } From bb0a0f485e5937df16b3d21c6ac97ea5719367eb Mon Sep 17 00:00:00 2001 From: Alexandru-Paul Copil Date: Fri, 9 Jul 2021 10:44:48 +0300 Subject: [PATCH 4/5] Optimize *GLShader.Update() by allocating array before for loop --- pixelgl/glshader.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pixelgl/glshader.go b/pixelgl/glshader.go index 3d10aa0..c76c9a3 100644 --- a/pixelgl/glshader.go +++ b/pixelgl/glshader.go @@ -68,13 +68,14 @@ func NewGLShader(fragmentShader string) *GLShader { // Update reinitialize GLShader data and recompile the underlying gl shader object func (gs *GLShader) Update() { - gs.uf = nil - for _, u := range gs.uniforms { - gs.uf = append(gs.uf, glhf.Attr{ - Name: u.Name, - Type: u.Type, - }) + gs.uf = make([]glhf.Attr, len(gs.uniforms)) + for idx := range gs.uniforms { + gs.uf[idx] = glhf.Attr{ + Name: gs.uniforms[idx].Name, + Type: gs.uniforms[idx].Type, + } } + var shader *glhf.Shader mainthread.Call(func() { var err error From 4ec3c64512c2d6bf4c03b2540b837cd85ecb4c79 Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Sun, 15 Aug 2021 23:12:03 -0600 Subject: [PATCH 5/5] add spriteplus and pixelutils to README.md under "Related repos" --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5118169..5a954ab 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,9 @@ Here's the list of the main features in Pixel. Although Pixel is still under hea ## Related repositories Here are some packages which use Pixel: - - [TilePix](https://github.com/bcvery1/tilepix) Makes handling TMX files built with [Tiled](https://www.mapeditor.org/) - trivially easy to work with using Pixel. + - [TilePix](https://github.com/bcvery1/tilepix) Makes handling TMX files built with [Tiled](https://www.mapeditor.org/) trivially easy to work with using Pixel. + - [spriteplus](https://github.com/cebarks/spriteplus) Basic `SpriteSheet` and `Animation` implementations + - [pixelutils](https://github.com/dusk125/pixelutils) Variety of game related utilities (sprite packer, id generator, ticker, sprite loader, voronoia diagrams) ## Missing features