Compare commits

...

28 Commits

Author SHA1 Message Date
Bertrand Jung
155c3a41ba
Merge b2a62daea5 into 4267664b8b 2024-07-01 21:01:26 +00:00
Hajime Hoshi
4267664b8b all: update Oto to v3.3.0-alpha.2 2024-07-02 00:06:58 +09:00
Hajime Hoshi
2a22260d14 internal/atlas: backends for unmanaged images were never released
Closes #3030
2024-06-30 23:45:27 +09:00
Hajime Hoshi
3f91d8cdf1 internal/atlas: refactoring 2024-06-30 22:39:25 +09:00
Hajime Hoshi
ec7ef5e6a3 internal/atlas: add comments 2024-06-30 22:22:27 +09:00
Hajime Hoshi
5b8fd9733c internal/atlas: refactoring 2024-06-30 19:21:42 +09:00
Hajime Hoshi
9ff93e3063 all: fix comments 2024-06-30 18:56:07 +09:00
Hajime Hoshi
def82fd5d3 internal/atlas: refactoring: remove ImageTypeVolatile
ImageTypeVolatile was meaningful when Ebitengine had `restorable`
package, but now this doesn't make sense.
2024-06-30 18:50:02 +09:00
Hajime Hoshi
32417353d3 internal/ui: bug fix: the window size callback was not called on macOS
This is basically a revert of e150745598.

As the window size callback was not called, ebiten.WindowSize didn't
work correctly for a while.

Even after this change, the issue #2257 could not be reproduced. This
is mysterious, but probably macOS itself has updated.

Updates #2257
Closes #3029
2024-06-30 15:59:15 +09:00
Hajime Hoshi
f6fbb3ddea all: update Oto 2024-06-29 15:47:20 +09:00
dependabot[bot]
4061742067
build(deps): bump golang.org/x/image from 0.17.0 to 0.18.0 (#3028)
Bumps [golang.org/x/image](https://github.com/golang/image) from 0.17.0 to 0.18.0.
- [Commits](https://github.com/golang/image/compare/v0.17.0...v0.18.0)

---
updated-dependencies:
- dependency-name: golang.org/x/image
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-27 13:25:42 +09:00
Hajime Hoshi
b749976a84 examples/resources/images: update the licenses for the Gopher images 2024-06-23 12:09:40 +09:00
Hajime Hoshi
0c3b4a2d91 examples/resources/images: update the license URLs for ebiten.png 2024-06-23 12:07:51 +09:00
Hajime Hoshi
c86874b506 all: update PureGo to v0.8.0-alpha.3 2024-06-23 01:23:32 +09:00
Hajime Hoshi
7524f990ba .github/workflows: add Go v1.23.0 to tests 2024-06-22 13:53:25 +09:00
Hajime Hoshi
b7015c4354 .github/workflows: bug fix: wrong version was specified 2024-06-22 02:45:29 +09:00
Hajime Hoshi
96984210e1 .github/workflows: update action versions 2024-06-22 02:43:36 +09:00
Hajime Hoshi
1cd6a1f10c examples/wav: add -bits option to specify 8bits 2024-06-22 01:25:04 +09:00
Hajime Hoshi
0eb2b9980d all: update purego 2024-06-20 21:08:12 +09:00
Hajime Hoshi
76a170eecf examples/resources/images: update the licenses 2024-06-20 03:25:39 +09:00
Hajime Hoshi
941aec5f51 ebitenutil: update documentation for DebugPrint
Closes #2977
2024-06-19 03:10:51 +09:00
Hajime Hoshi
a6d7cadab7 internal/graphicsdriver/playstation5: change struct member names 2024-06-17 03:04:18 +09:00
Ikko Eltociear Ashimine
dc8dfae3bf
examples/windowsize: fix typo (#3022) 2024-06-16 03:42:42 +09:00
Hajime Hoshi
ffb77757f0 all: update dependencies 2024-06-13 01:06:09 +09:00
Hajime Hoshi
60f0a03749 all: go mod tidy 2024-06-13 01:04:05 +09:00
Hajime Hoshi
22339c2510 all: update dependencies 2024-06-13 00:56:35 +09:00
Hajime Hoshi
96e0fd7a50 exp/textinput: bug fix: pressing enter key was often ignored on iOS Safari
Closes #3015
2024-06-12 02:44:51 +09:00
Hajime Hoshi
546c47878d exp/textinput: bug fix: issues on browsers
This change addresses on these issues on browsers:

* Pressing cursor keys didn't work well.
  This is fixed by calling trySend with true on desktops (not mobiles).
* Inputting failed just after moving a cursor.
  This is fixed by resetting a session correctly.
* Sometimes pressing the enter key inserted a new line unexpectedly.
  This is fixed by calling `preventDefault`.

Closes #3014
2024-06-12 01:31:15 +09:00
25 changed files with 182 additions and 119 deletions

View File

@ -21,14 +21,14 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./.github/workflows/site
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
deploy:
environment:
@ -39,4 +39,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4

View File

@ -13,7 +13,7 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Docker build (amd64)
run: |

View File

@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ['1.19.x', '1.20.x', '1.21.x', '1.22.x']
go: ['1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.0-rc.1']
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
@ -23,15 +23,15 @@ jobs:
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'

View File

@ -39,10 +39,10 @@ jobs:
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

View File

@ -41,7 +41,7 @@ func init() {
debugPrintTextImage = ebiten.NewImageFromImage(img)
}
// DebugPrint draws the string str on the image on left top corner.
// DebugPrint draws the string str on the image at (0, 0) position (the upper-left corner in most cases).
//
// The available runes are in U+0000 to U+00FF, which is C0 Controls and Basic Latin and C1 Controls and Latin-1 Supplement.
func DebugPrint(image *ebiten.Image, str string) {

View File

@ -22,6 +22,9 @@ var (
//go:embed jab.wav
Jab_wav []byte
//go:embed jab8.wav
Jab8_wav []byte
//go:embed jump.ogg
Jump_ogg []byte

Binary file not shown.

View File

@ -3,24 +3,35 @@
## ebiten.png
```
http://www.sozai-page.com/02_sozai/b/b04/b04_002/b04_002.html
https://web.archive.org/web/20200110174435/http://www.sozai-page.com/02_sozai/b/b04/b04_002/b04_002.html
https://web.archive.org/web/20191229033100/http://www.sozai-page.com/rule/rule1.html
● 商用・個人使用を問わず自由に使用できます。
● 画像の内容、画質、状態などにより生じた結果に当方は一切責任を負いません。
● 全ての画像は自由に加工・修正できます。
  ただし、加工により生じた結果に当方は一切責任を負いません。
● 加工・修正に関わらず、許可無く画像として再配布・販売することを禁止します。
これはあくまで「お願い」なのですが、出版・放送等メディア関係の方は使用の際にご連絡いただけると助かります。印刷物やテレビ放送での使用に制限はありませんが、書名、雑誌名、番組名、また発売日・放送日が決まっているようでしたらお知らせいただけないでしょうか。
当サイトの画像がどのように利用されたのか、今後の参考にいたします。
```
## fiveyears.jpg
```
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The design is licensed under the Creative Commons 4.0 Attributions license.
Read this article for more details: https://blog.golang.org/gopher
```
## gophers.jpg
```
http://blog.golang.org/go-programming-language-turns-two
https://go.dev/blog/2years
https://go.dev/copyright
Photograph by Chris Nokleberg
the Creative Commons Attribution 3.0 License
The Creative Commons Attribution 4.0 License
```
## runner.png
@ -106,7 +117,7 @@ CC0 1.0
```
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The design is licensed under the Creative Commons 4.0 Attributions license.
Read this article for more details: https://blog.golang.org/gopher
```
@ -128,7 +139,7 @@ MIT License
```
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The design is licensed under the Creative Commons 4.0 Attributions license.
Read this article for more details: https://blog.golang.org/gopher
```
@ -136,7 +147,7 @@ Read this article for more details: https://blog.golang.org/gopher
```
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The design is licensed under the Creative Commons 4.0 Attributions license.
Read this article for more details: https://blog.golang.org/gopher
```
@ -150,7 +161,7 @@ https://corvussg.itch.io/2d-game-backgrounds
```
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
The design is licensed under the Creative Commons 4.0 Attributions license.
Read this article for more details: https://blog.golang.org/gopher
```
@ -175,5 +186,5 @@ MIT License
```
Copyright 2014 Hajime Hoshi
the Creative Commons Attribution 3.0 License
The Creative Commons Attribution 4.0 License
```

View File

@ -16,6 +16,8 @@ package main
import (
"bytes"
"flag"
"io"
"log"
"github.com/hajimehoshi/ebiten/v2"
@ -32,6 +34,10 @@ const (
sampleRate = 48000
)
var (
flagBitsPerSample = flag.Int("bits", 16, "bits per sample")
)
type Game struct {
audioContext *audio.Context
audioPlayer *audio.Player
@ -59,7 +65,14 @@ func NewGame() (*Game, error) {
// ...
// Decode wav-formatted data and retrieve decoded PCM stream.
d, err := wav.DecodeWithoutResampling(bytes.NewReader(raudio.Jab_wav))
var r io.Reader
switch *flagBitsPerSample {
case 8:
r = bytes.NewReader(raudio.Jab8_wav)
default:
r = bytes.NewReader(raudio.Jab_wav)
}
d, err := wav.DecodeWithoutResampling(r)
if err != nil {
return nil, err
}
@ -99,6 +112,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
}
func main() {
flag.Parse()
g, err := NewGame()
if err != nil {
log.Fatal(err)

View File

@ -47,7 +47,7 @@ var (
flagAutoRestore = flag.Bool("autorestore", false, "restore the window automatically")
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
flagMinWindowSize = flag.String("minwindowsize", "", "minimum window size (e.g., 100x200)")
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximium window size (e.g., 1920x1080)")
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximum window size (e.g., 1920x1080)")
flagGraphicsLibrary = flag.String("graphicslibrary", "", "graphics library (e.g. opengl)")
flagRunnableOnUnfocused = flag.Bool("runnableonunfocused", true, "whether the app is runnable even on unfocused")
)

View File

@ -106,7 +106,7 @@ func (f *Field) HandleInput(x, y int) (handled bool, err error) {
f.ch, f.end = Start(x, y)
// Start returns nil for non-supported envrionments.
if f.ch == nil {
return true, nil
return false, nil
}
}

View File

@ -79,7 +79,10 @@ func (t *textInput) init() {
e.Call("preventDefault")
}
if e.Get("code").String() == "Enter" || e.Get("key").String() == "Enter" {
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true, especially for iOS Safari.
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true.
e.Call("preventDefault")
ui.Get().UpdateInputFromEvent(e)
t.trySend(true)
return nil
}
if !e.Get("isComposing").Bool() {
@ -96,6 +99,11 @@ func (t *textInput) init() {
}))
t.textareaElement.Call("addEventListener", "input", js.FuncOf(func(this js.Value, args []js.Value) any {
e := args[0]
// On iOS Safari, `isComposing` can be undefined.
if e.Get("isComposing").IsUndefined() {
t.trySend(false)
return nil
}
if e.Get("isComposing").Bool() {
t.trySend(false)
return nil
@ -109,9 +117,13 @@ func (t *textInput) init() {
t.trySend(true)
return nil
}
// Though `isComposing` is false, send the text as being not committed for text completion on mobile browsers.
// Though `isComposing` is false, send the text as being not committed for text completion with a virtual keyboard.
if ui.IsVirtualKeyboard() {
t.trySend(false)
return nil
}
t.trySend(true)
return nil
}))
t.textareaElement.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
t.trySend(true)
@ -172,7 +184,13 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
s := newSession()
t.session = s
}
return t.session.ch, t.session.end
return t.session.ch, func() {
if t.session != nil {
t.session.end()
// Reset the session explictly, or a new session cannot be created above.
t.session = nil
}
}
}
if t.session != nil {
@ -193,6 +211,10 @@ func (t *textInput) trySend(committed bool) {
}
textareaValue := t.textareaElement.Get("value").String()
if textareaValue == "" {
return
}
start := t.textareaElement.Get("selectionStart").Int()
end := t.textareaElement.Get("selectionEnd").Int()
startInBytes := convertUTF16CountToByteCount(textareaValue, start)

View File

@ -66,10 +66,6 @@ func (g *gameForUI) NewOffscreenImage(width, height int) *ui.Image {
// An image on an atlas is surrounded by a transparent edge,
// and the shader program unexpectedly picks the pixel on the edges.
imageType := atlas.ImageTypeUnmanaged
if ui.Get().IsScreenClearedEveryFrame() {
// A volatile image is also always isolated.
imageType = atlas.ImageTypeVolatile
}
g.offscreen = newImage(image.Rect(0, 0, width, height), imageType)
return g.offscreen.image
}

16
go.mod
View File

@ -5,24 +5,24 @@ go 1.19
require (
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895
github.com/ebitengine/hideconsole v1.0.0
github.com/ebitengine/oto/v3 v3.3.0-alpha.1
github.com/ebitengine/purego v0.8.0-alpha.2
github.com/ebitengine/oto/v3 v3.3.0-alpha.2
github.com/ebitengine/purego v0.8.0-alpha.3
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
github.com/go-text/typesetting v0.1.1
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2
github.com/hajimehoshi/go-mp3 v0.3.4
github.com/jakecoffman/cp v1.2.1
github.com/jezek/xgb v1.1.1
github.com/jfreymuth/oggvorbis v1.0.5
github.com/kisielk/errcheck v1.7.0
golang.org/x/image v0.16.0
golang.org/x/image v0.18.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/text v0.15.0
golang.org/x/tools v0.21.0
golang.org/x/sys v0.21.0
golang.org/x/text v0.16.0
golang.org/x/tools v0.22.0
)
require (
github.com/jfreymuth/vorbis v1.0.2 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/mod v0.18.0 // indirect
)

32
go.sum
View File

@ -2,17 +2,17 @@ github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895 h1:48bCqKTuD7Z
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895/go.mod h1:XZdLv05c5hOZm3fM2NlJ92FyEZjnslcMcNRrhxs8+8M=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
github.com/ebitengine/purego v0.8.0-alpha.2 h1:+Kyr9n4eXAGMzhtWJxfdQ7AzGn0+6ZWihfCCxul3Dso=
github.com/ebitengine/purego v0.8.0-alpha.2/go.mod h1:w5fARo4H5UrAgQTz0yqDfZ6bjstTQwUFmO+TN+nHlWE=
github.com/ebitengine/oto/v3 v3.3.0-alpha.2 h1:ex2UbULSPuLt76yyaR2JBXICx83Ph6Oz5ugN7h1Jo/I=
github.com/ebitengine/oto/v3 v3.3.0-alpha.2/go.mod h1:yYvXK7mgNwsFawY5RsvGI6yhMHtD+0MfaPkDTl9/uv8=
github.com/ebitengine/purego v0.8.0-alpha.3 h1:qoFlpGuVwJ6J85kuj6Qpyp0DBgxsNYfSY9efidSNFgA=
github.com/ebitengine/purego v0.8.0-alpha.3/go.mod h1:b94LtM1jUWDZPKDyENVhB0WsLdLWFApjbNw5AyxmKyI=
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk=
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38=
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1 h1:GLoMNCbvXOd39tFkqk9w/MI0xSLJaDzEOOl8mT1ILtI=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2 h1:3x/UYntkuEcDN8kjSohmR+ddDSFEB8Bsvm/QFug+teA=
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
@ -31,12 +31,12 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
@ -54,8 +54,8 @@ golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@ -64,12 +64,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -69,3 +69,9 @@ func DeferredFuncCountForTesting() int {
defer deferredM.Unlock()
return len(deferred)
}
func BackendCountForTesting() int {
backendsM.Lock()
defer backendsM.Unlock()
return len(theBackends)
}

View File

@ -89,7 +89,7 @@ func putImagesOnSourceBackend() {
if i.usedAsSourceCount < math.MaxInt {
i.usedAsSourceCount++
}
if int64(i.usedAsSourceCount) >= int64(baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31)))) {
if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<<uint(min(i.usedAsDestinationCount, 31))) {
i.putOnSourceBackend()
i.usedAsSourceCount = 0
}
@ -97,6 +97,8 @@ func putImagesOnSourceBackend() {
imagesToPutOnSourceBackend.clear()
}
// backend is a big texture atlas that can have multiple images.
// backend is a texture in GPU.
type backend struct {
// image is an atlas on which there might be multiple images.
image *graphicscommand.Image
@ -109,6 +111,7 @@ type backend struct {
page *packing.Page
// source reports whether this backend is mainly used a rendering source, but this is not 100%.
//
// If a non-source (destination) image is used as a source many times,
// the image's backend might be turned into a source backend to optimize draw calls.
source bool
@ -144,8 +147,6 @@ func (b *backend) extendIfNeeded(width, height int) {
// Assume that the screen image is never extended.
newImg := newClearedImage(width, height, false)
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
// information.
srcs := [graphics.ShaderSrcImageCount]*graphicscommand.Image{b.image}
sw, sh := b.image.InternalSize()
vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
@ -220,12 +221,18 @@ var (
deferredM sync.Mutex
)
// ImageType represents the type of an image.
type ImageType int
const (
// ImageTypeRegular is a regular image, that can be on a big texture atlas (backend).
ImageTypeRegular ImageType = iota
// ImageTypeScreen is a screen image that is not on an atlas.
// A screen image is also unmanaged.
ImageTypeScreen
ImageTypeVolatile
// ImageTypeUnmanaged is an unmanaged image that is not on an atlas.
ImageTypeUnmanaged
)
@ -245,11 +252,13 @@ type Image struct {
// In the current implementation, if an image is being modified by DrawTriangles, the image is separated from
// a graphicscommand.Image on an atlas by ensureIsolatedFromSource.
//
// The type is int64 instead of int to avoid overflow when comparing the limitation.
//
// usedAsSourceCount is increased if the image is used as a rendering source, or set to 0 if the image is
// modified.
//
// WritePixels doesn't affect this value since WritePixels can be done on images on an atlas.
usedAsSourceCount int
usedAsSourceCount int64
// usedAsDestinationCount represents how many times an image is used as a rendering destination at DrawTriangles.
// usedAsDestinationCount affects the calculation when to put the image onto a texture atlas again.
@ -810,12 +819,7 @@ func (i *Image) deallocate() {
return
}
if !i.isOnAtlas() {
i.backend.image.Dispose()
i.backend.image = nil
return
}
if i.isOnAtlas() {
i.backend.page.Free(i.node)
if !i.backend.page.IsEmpty() {
// As this part can be reused, this should be cleared explicitly.
@ -823,6 +827,7 @@ func (i *Image) deallocate() {
i.backend.clearPixels(r)
return
}
}
i.backend.image.Dispose()
i.backend.image = nil
@ -878,20 +883,6 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
runtime.SetFinalizer(i, (*Image).finalize)
if i.imageType == ImageTypeScreen {
if asSource {
panic("atlas: a screen image cannot be created as a source")
}
// A screen image doesn't have a padding.
i.backend = &backend{
image: newClearedImage(i.width, i.height, true),
width: i.width,
height: i.height,
}
theBackends = append(theBackends, i.backend)
return
}
wp := i.width + i.paddingSize()
hp := i.height + i.paddingSize()
@ -901,7 +892,7 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
}
i.backend = &backend{
image: newClearedImage(wp, hp, false),
image: newClearedImage(wp, hp, i.imageType == ImageTypeScreen),
width: wp,
height: hp,
source: asSource && i.imageType == ImageTypeRegular,

View File

@ -177,8 +177,8 @@ func TestReputOnSourceBackend(t *testing.T) {
}
img2.WritePixels(pix, image.Rect(0, 0, size, size))
// Create a volatile image. This should always be on a non-source backend.
img3 := atlas.NewImage(size, size, atlas.ImageTypeVolatile)
// Create an unmanaged image. This should always be on a non-source backend.
img3 := atlas.NewImage(size, size, atlas.ImageTypeUnmanaged)
defer img3.Deallocate()
img3.WritePixels(make([]byte, 4*size*size), image.Rect(0, 0, size, size))
if got, want := img3.IsOnSourceBackendForTesting(), false; got != want {
@ -296,7 +296,7 @@ func TestReputOnSourceBackend(t *testing.T) {
t.Errorf("got: %v, want: %v", got, want)
}
// Use img3 as a render source. As img3 is volatile, img3 is never on an atlas.
// Use img3 as a render source. As img3 is unmanaged, img3 is never on an atlas.
for i := 0; i < atlas.BaseCountToPutOnSourceBackend*2; i++ {
atlas.PutImagesOnSourceBackendForTesting()
vs := quadVertices(size, size, 0, 0, 1)
@ -688,7 +688,7 @@ func TestImageIsNotReputOnSourceBackendWithoutUsingAsSource(t *testing.T) {
}
func TestImageWritePixelsModify(t *testing.T) {
for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeVolatile, atlas.ImageTypeUnmanaged} {
for _, typ := range []atlas.ImageType{atlas.ImageTypeRegular, atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged} {
const size = 16
img := atlas.NewImage(size, size, typ)
defer img.Deallocate()
@ -881,4 +881,26 @@ func TestGC(t *testing.T) {
}
}
func TestDallocateUnmanagedImageBackends(t *testing.T) {
const w, h = 16, 16
img0 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
img1 := atlas.NewImage(w, h, atlas.ImageTypeUnmanaged)
// Call DrawTriangles to ensure the images are on backends.
vs := quadVertices(w, h, 0, 0, 1)
is := graphics.QuadIndices()
dr := image.Rect(0, 0, w, h)
img0.DrawTriangles([graphics.ShaderSrcImageCount]*atlas.Image{img1}, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll)
// Get the difference of the number of backends before and after the images are deallocated.
c := atlas.BackendCountForTesting()
img0.Deallocate()
img1.Deallocate()
diff := c - atlas.BackendCountForTesting()
if got, want := diff, 2; got != want {
t.Errorf("got: %d, want: %d", got, want)
}
}
// TODO: Add tests to extend image on an atlas out of the main loop

View File

@ -36,8 +36,8 @@ type playstation5Error struct {
func newPlaystation5Error(name string, err C.ebitengine_Error) *playstation5Error {
return &playstation5Error{
name: name,
code: int(err.code),
message: C.GoString(err.message),
code: int(err.Code),
message: C.GoString(err.Message),
}
}

View File

@ -25,12 +25,12 @@ extern "C" {
#endif
typedef struct ebitengine_Error {
const char* message;
int code;
const char* Message;
int Code;
} ebitengine_Error;
static bool ebitengine_IsErrorNil(ebitengine_Error* err) {
return err->message == NULL && err->code == 0;
return err->Message == NULL && err->Code == 0;
}
ebitengine_Error ebitengine_InitializeGraphics(void);

View File

@ -71,7 +71,6 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Mipmap, verti
}
level := 0
// TODO: Do we need to check all the sources' states of being volatile?
if !canSkipMipmap && srcs[0] != nil && canUseMipmap(srcs[0].imageType) {
level = math.MaxInt32
for i := 0; i < len(indices)/3; i++ {
@ -215,7 +214,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
}
if !canUseMipmap(m.imageType) {
panic("mipmap: mipmap images for a volatile or a screen image is not implemented yet")
panic("mipmap: mipmap images for a screen image is not implemented yet")
}
if img, ok := m.imgs[level]; ok {

View File

@ -178,12 +178,6 @@ func (c *context) newOffscreenImage(w, h int) *Image {
}
func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, ui *UserInterface, forceDraw bool) error {
if (c.offscreen.imageType == atlas.ImageTypeVolatile) != ui.IsScreenClearedEveryFrame() {
w, h := c.offscreen.width, c.offscreen.height
c.offscreen.Deallocate()
c.offscreen = c.newOffscreenImage(w, h)
}
// isOffscreenModified is updated when an offscreen's modifyCallback.
c.isOffscreenModified = false

View File

@ -15,7 +15,6 @@
package ui
import (
"fmt"
"image"
"math"
@ -86,16 +85,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
if antialias {
if i.bigOffscreenBuffer == nil {
var imageType atlas.ImageType
switch i.imageType {
case atlas.ImageTypeRegular, atlas.ImageTypeUnmanaged:
imageType = atlas.ImageTypeUnmanaged
case atlas.ImageTypeScreen, atlas.ImageTypeVolatile:
imageType = atlas.ImageTypeVolatile
default:
panic(fmt.Sprintf("ui: unexpected image type: %d", imageType))
}
i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, imageType)
i.bigOffscreenBuffer = i.ui.newBigOffscreenImage(i, atlas.ImageTypeUnmanaged)
}
i.bigOffscreenBuffer.drawTriangles(srcs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, fillRule, canSkipMipmap)

View File

@ -16,6 +16,7 @@ package ui
import (
"math"
"strings"
"syscall/js"
"unicode"
)
@ -64,6 +65,11 @@ var codeToMouseButton = map[int]MouseButton{
func eventToKeys(e js.Value) (key0, key1 Key, fromKeyProperty bool) {
id := jsCodeToID(e.Get("code"))
// On mobile browsers, treat enter key as if this is from a `key` property.
if IsVirtualKeyboard() && id == KeyEnter {
return KeyEnter, -1, true
}
if id >= 0 {
return id, -1, false
}
@ -426,3 +432,15 @@ func (i *InputState) resetForBlur() {
}
i.Touches = i.Touches[:0]
}
func IsVirtualKeyboard() bool {
// Detect a virtual keyboard by the user agent.
// Note that this is not a correct way to detect a virtual keyboard.
// In the future, we should use the `navigator.virtualKeyboard` API.
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/virtualKeyboard
ua := js.Global().Get("navigator").Get("userAgent").String()
if strings.Contains(ua, "Android") || strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod") {
return true
}
return false
}

View File

@ -905,13 +905,10 @@ func (u *UserInterface) registerWindowCloseCallback() error {
// registerWindowFramebufferSizeCallback must be called from the main thread.
func (u *UserInterface) registerWindowFramebufferSizeCallback() error {
if u.defaultFramebufferSizeCallback == nil && runtime.GOOS != "darwin" {
if u.defaultFramebufferSizeCallback == nil {
// When the window gets resized (either by manual window resize or a window
// manager), glfw sends a framebuffer size callback which we need to handle (#1960).
// This event is the only way to handle the size change at least on i3 window manager.
//
// When a decorating state changes, the callback of arguments might be an unexpected value on macOS (#2257)
// Then, do not register this callback on macOS.
u.defaultFramebufferSizeCallback = func(_ *glfw.Window, w, h int) {
f, err := u.isFullscreen()
if err != nil {