Merge branch 'master' into clipTris

This commit is contained in:
Allen Ray 2021-08-16 09:55:30 -04:00 committed by GitHub
commit 6c717101a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 58 deletions

View File

@ -108,8 +108,9 @@ Here's the list of the main features in Pixel. Although Pixel is still under hea
## Related repositories ## Related repositories
Here are some packages which use Pixel: Here are some packages which use Pixel:
- [TilePix](https://github.com/bcvery1/tilepix) Makes handling TMX files built with [Tiled](https://www.mapeditor.org/) - [TilePix](https://github.com/bcvery1/tilepix) Makes handling TMX files built with [Tiled](https://www.mapeditor.org/) trivially easy to work with using Pixel.
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 ## Missing features

View File

@ -8,9 +8,8 @@ import (
"math" "math"
) )
var (
// zeroValueTriangleData is the default value of a TriangleData element // zeroValueTriangleData is the default value of a TriangleData element
zeroValueTriangleData = struct { var zeroValueTriangleData = struct {
Position Vec Position Vec
Color RGBA Color RGBA
Picture Vec Picture Vec
@ -18,7 +17,6 @@ var (
ClipRect Rect ClipRect Rect
IsClipped bool IsClipped bool
}{Color: RGBA{1, 1, 1, 1}} }{Color: RGBA{1, 1, 1, 1}}
)
// TrianglesData specifies a list of Triangles vertices with three common properties: // TrianglesData specifies a list of Triangles vertices with three common properties:
// TrianglesPosition, TrianglesColor and TrianglesPicture. // TrianglesPosition, TrianglesColor and TrianglesPicture.

View File

@ -1236,7 +1236,8 @@ func TestLine_Intersect(t *testing.T) {
args: args{k: pixel.L(pixel.V(0, 1), pixel.V(10, 11))}, args: args{k: pixel.L(pixel.V(0, 1), pixel.V(10, 11))},
want: pixel.ZV, want: pixel.ZV,
want1: false, want1: false,
}, { },
{
name: "Lines intersect", name: "Lines intersect",
fields: fields{A: pixel.V(600, 600), B: pixel.V(925, 150)}, 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))}, args: args{k: pixel.L(pixel.V(740, 255), pixel.V(925, 255))},

View File

@ -12,9 +12,9 @@ import (
"github.com/faiface/pixel/pixelgl" "github.com/faiface/pixel/pixelgl"
) )
var (
// onePixelImage is the byte representation of a 1x1 solid white png file // 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, 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, 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, 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, 141, 66, 16, 34, 132, 168, 96, 212, 194, 221, 141, 137, 66, 118, 13, 187, 9, 54, 150, 130, 109, 192, 194, 79,
@ -35,8 +35,8 @@ var (
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, 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, 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, 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} 77, 211, 95, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130,
) }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
pixelgl.Run(func() { pixelgl.Run(func() {

View File

@ -42,11 +42,11 @@ const (
) )
var defaultCanvasVertexFormat = glhf.AttrFormat{ var defaultCanvasVertexFormat = glhf.AttrFormat{
canvasPosition: {Name: "aPosition", Type: glhf.Vec2}, canvasPosition: glhf.Attr{Name: "aPosition", Type: glhf.Vec2},
canvasColor: {Name: "aColor", Type: glhf.Vec4}, canvasColor: glhf.Attr{Name: "aColor", Type: glhf.Vec4},
canvasTexCoords: {Name: "aTexCoords", Type: glhf.Vec2}, canvasTexCoords: glhf.Attr{Name: "aTexCoords", Type: glhf.Vec2},
canvasIntensity: {Name: "aIntensity", Type: glhf.Float}, canvasIntensity: glhf.Attr{Name: "aIntensity", Type: glhf.Float},
canvasClip: {Name: "aClipRect", Type: glhf.Vec4}, canvasClip: glhf.Attr{Name: "aClipRect", Type: glhf.Vec4},
} }
// Sets up a base shader with everything needed for a Pixel // Sets up a base shader with everything needed for a Pixel
@ -71,13 +71,14 @@ func NewGLShader(fragmentShader string) *GLShader {
// Update reinitialize GLShader data and recompile the underlying gl shader object // Update reinitialize GLShader data and recompile the underlying gl shader object
func (gs *GLShader) Update() { func (gs *GLShader) Update() {
gs.uf = nil gs.uf = make([]glhf.Attr, len(gs.uniforms))
for _, u := range gs.uniforms { for idx := range gs.uniforms {
gs.uf = append(gs.uf, glhf.Attr{ gs.uf[idx] = glhf.Attr{
Name: u.Name, Name: gs.uniforms[idx].Name,
Type: u.Type, Type: gs.uniforms[idx].Type,
})
} }
}
var shader *glhf.Shader var shader *glhf.Shader
mainthread.Call(func() { mainthread.Call(func() {
var err error var err error

View File

@ -13,14 +13,14 @@ func (w *Window) Pressed(button Button) bool {
return w.currInp.buttons[button] 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 { 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 { 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. // 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) { w.window.SetMouseButtonCallback(func(_ *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
switch action { switch action {
case glfw.Press: case glfw.Press:
w.tempPressEvents[Button(button)] = true
w.tempInp.buttons[Button(button)] = true w.tempInp.buttons[Button(button)] = true
case glfw.Release: case glfw.Release:
w.tempReleaseEvents[Button(button)] = true
w.tempInp.buttons[Button(button)] = false w.tempInp.buttons[Button(button)] = false
} }
}) })
@ -374,8 +376,10 @@ func (w *Window) initInput() {
} }
switch action { switch action {
case glfw.Press: case glfw.Press:
w.tempPressEvents[Button(key)] = true
w.tempInp.buttons[Button(key)] = true w.tempInp.buttons[Button(key)] = true
case glfw.Release: case glfw.Release:
w.tempReleaseEvents[Button(key)] = true
w.tempInp.buttons[Button(key)] = false w.tempInp.buttons[Button(key)] = false
case glfw.Repeat: case glfw.Repeat:
w.tempInp.repeat[Button(key)] = true w.tempInp.repeat[Button(key)] = true
@ -431,6 +435,12 @@ func (w *Window) doUpdateInput() {
w.prevInp = w.currInp w.prevInp = w.currInp
w.currInp = w.tempInp 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.repeat = [KeyLast + 1]bool{}
w.tempInp.scroll = pixel.ZV w.tempInp.scroll = pixel.ZV
w.tempInp.typed = "" w.tempInp.typed = ""

View File

@ -100,6 +100,9 @@ type Window struct {
typed string typed string
} }
pressEvents, tempPressEvents [KeyLast + 1]bool
releaseEvents, tempReleaseEvents [KeyLast + 1]bool
prevJoy, currJoy, tempJoy joystickState prevJoy, currJoy, tempJoy joystickState
} }
@ -205,6 +208,17 @@ func (w *Window) Update() {
w.UpdateInput() 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. // SwapBuffers swaps buffers. Call this to swap buffers without polling window events.
// Note that Update invokes SwapBuffers. // Note that Update invokes SwapBuffers.
func (w *Window) SwapBuffers() { func (w *Window) SwapBuffers() {

View File

@ -76,7 +76,7 @@ func BenchmarkTextWrite(b *testing.B) {
b.Run(fmt.Sprintf("%d", len(chunk)), func(b *testing.B) { b.Run(fmt.Sprintf("%d", len(chunk)), func(b *testing.B) {
txt := text.New(pixel.ZV, atlas) txt := text.New(pixel.ZV, atlas)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
txt.Write(chunk) _, _ = txt.Write(chunk)
} }
}) })
} }