Compare commits

...

25 Commits

Author SHA1 Message Date
Bertrand Jung
01d3e1f032
Merge 30157b5dea into 72f50c389b 2024-08-05 18:41:10 +00:00
Hajime Hoshi
72f50c389b Revert "all: update Oto"
This reverts commit 8f36a479a3.

Reason: crash on tests
https://github.com/ebitengine/oto/actions/runs/10253513865/job/28366298117
2024-08-06 03:11:48 +09:00
Hajime Hoshi
8f36a479a3 all: update Oto
Updates ebitengine/oto#242
2024-08-06 02:45:09 +09:00
Hajime Hoshi
2a34d1d47b internal/graphicsdriver/opengl/gl: use PureGo version for Android again
This is basically a revert for 297efea68b.
This updates PureGo for the Android issue.

Updates #3052
Updates ebitengine/purego#262
2024-08-05 23:34:56 +09:00
Hajime Hoshi
1e3ab9e5fc all: update dependencies 2024-08-05 21:23:03 +09:00
Hajime Hoshi
aba652c323 internal/graphicsdriver/playstation5: add DrawTriangles 2024-08-04 19:13:36 +09:00
Hajime Hoshi
6555375b06 all: add .clang-format 2024-08-04 19:06:59 +09:00
Hajime Hoshi
9bd17de2d3 internal/graphicsdriver/opengl: remove unused members 2024-08-04 04:26:53 +09:00
Hajime Hoshi
37a6057230 internal/ui: bug fix: increase maxSkipCount
Closes #3055
2024-08-04 04:16:01 +09:00
Hajime Hoshi
af6072c1b4 internal/shader: add more tests
Updates #3011
2024-08-03 19:08:03 +09:00
Hajime Hoshi
7c4f532b83 internal/shader: bug fix: an index must be a constant for vectors
Updates #3011
2024-08-03 19:03:42 +09:00
Hajime Hoshi
719838b7ab .github/workflows: update wasmbrowsertest to fix timeout issue
The issue agnivade/wasmbrowsertest#60 was fixed.

Updates #1313
2024-08-02 23:03:01 +09:00
Hajime Hoshi
1fc2dedaaa all: update gomobile 2024-08-02 13:33:55 +09:00
Hajime Hoshi
297efea68b internal/graphicsdriver/opengl/gl: use C version for Android
Unfortunately PureGo's dlopen didn't work on some Android devices.
Use the Cgo version instead in the same way as v2.7.

Closes #3052
2024-08-01 11:52:07 +09:00
Hajime Hoshi
856b339298 internal/ui: bug fix: show a black dot at the red button when needed
When SetWindowClosingHandled(true) is called, a black dot should be
shown at the red button to close the window.

Closes #3020
2024-07-31 23:54:18 +09:00
Hajime Hoshi
3106f98b52 internal/graphicsdriver/opengl/gl: add more error messages to load libraries 2024-07-31 21:35:24 +09:00
Hajime Hoshi
1843f6acc1 internal/ui: bug fix: dropping multiple files didn't work on Firefox and Safari
Closes #3045
2024-07-31 11:50:30 +09:00
Hajime Hoshi
95ad1b158c internal/file: refactoring
Updates #3045
2024-07-31 11:21:35 +09:00
Hajime Hoshi
47b8af554c all: update Oto to v3.3.0-alpha.3 2024-07-31 00:15:04 +09:00
Hajime Hoshi
c8aea2df16 examples/blocks: bug fix: do not ignore error 2024-07-29 17:37:30 +09:00
Hajime Hoshi
0281ac7bd2 all: use bufio.NewWriter to improve writing speed 2024-07-29 16:29:57 +09:00
Hajime Hoshi
ef5ac4175d all: use bufio.Reader to improve reading speed 2024-07-29 02:28:37 +09:00
Hajime Hoshi
563f2e0e0b all: update Oto 2024-07-28 20:20:13 +09:00
Hajime Hoshi
09b41846f9 all: update Oto (bug fix) 2024-07-28 17:13:13 +09:00
Hajime Hoshi
b6d5b8a1a6 all: update Oto (use AudioWorklet)
Updates ebitengine/oto#241
2024-07-28 16:34:01 +09:00
31 changed files with 436 additions and 154 deletions

1
.clang-format Normal file
View File

@ -0,0 +1 @@
CommentPragmas: '^go:build'

View File

@ -44,7 +44,7 @@ jobs:
- name: Install wasmbrowsertest
run: |
wasmbrowsertest_version=6e494bb3a5ddfe6cccb449250dbdcaa5777b593d
wasmbrowsertest_version=6e5bbb88049c42eb62e19d10e5be9940b9271aab
go install github.com/agnivade/wasmbrowsertest@${wasmbrowsertest_version}
mv $(go env GOPATH)/bin/wasmbrowsertest${{ runner.os == 'Windows' && '.exe' || '' }} $(go env GOPATH)/bin/go_js_wasm_exec${{ runner.os == 'Windows' && '.exe' || '' }}
go install github.com/agnivade/wasmbrowsertest/cmd/cleanenv@${wasmbrowsertest_version}

View File

@ -17,7 +17,6 @@ package audio_test
import (
"bytes"
"io"
"os"
"runtime"
"testing"
"time"
@ -36,14 +35,6 @@ func teardown() {
context = nil
}
func TestMain(m *testing.M) {
code := m.Run()
// 200[ms] should be enough all the players are consumed.
// TODO: This is a dirty hack. Would it be possible to use virtual time?
time.Sleep(200 * time.Millisecond)
os.Exit(code)
}
// Issue #746
func TestGC(t *testing.T) {
setup()

View File

@ -18,22 +18,12 @@ import (
"bytes"
"io"
"math/rand" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22.
"os"
"testing"
"time"
"unsafe"
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
)
func TestMain(m *testing.M) {
code := m.Run()
// Tests in this package often fails on GitHub Actions due to unfinished goroutines.
// That's mysterious, but to avoid this, sleep for a while before exiting.
time.Sleep(200 * time.Millisecond)
os.Exit(code)
}
func randInt16s(n int) []int16 {
r := make([]int16, n)
for i := range r {

View File

@ -17,6 +17,7 @@
package main
import (
"bufio"
"fmt"
"image"
"image/color"
@ -77,7 +78,11 @@ func run() error {
}
defer f.Close()
if err := png.Encode(f, dst); err != nil {
w := bufio.NewWriter(f)
if err := png.Encode(w, dst); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}

View File

@ -15,6 +15,7 @@
package main
import (
"bufio"
"flag"
"log"
"os"
@ -33,9 +34,15 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := pprof.StartCPUProfile(f); err != nil {
w := bufio.NewWriter(f)
if err := pprof.StartCPUProfile(w); err != nil {
log.Fatal(err)
}
defer func() {
if err := w.Flush(); err != nil {
log.Fatal(err)
}
}()
defer pprof.StopCPUProfile()
}

View File

@ -17,6 +17,7 @@
package main
import (
"bufio"
"bytes"
"image"
"image/png"
@ -220,7 +221,11 @@ func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
}
defer out.Close()
if err := png.Encode(out, img); err != nil {
w := bufio.NewWriter(out)
if err := png.Encode(w, img); err != nil {
return nil, err
}
if err := w.Flush(); err != nil {
return nil, err
}
@ -278,10 +283,17 @@ func outputKeyRectsGo(k map[ebiten.Key]image.Rectangle) error {
if err != nil {
return err
}
return tmpl.Execute(f, map[string]any{
w := bufio.NewWriter(f)
if err := tmpl.Execute(w, map[string]any{
"License": license,
"KeyRectsMap": k,
})
}); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}
return nil
}
type game struct {

View File

@ -20,6 +20,7 @@
package main
import (
"bufio"
"errors"
"fmt"
"os"
@ -88,7 +89,15 @@ func generateHSLSFiles(source *shaderprecomp.ShaderSource, index int, tmpdir str
}
defer psf.Close()
if err := shaderprecomp.CompileToHLSL(vsf, psf, source); err != nil {
vsfw := bufio.NewWriter(vsf)
psfw := bufio.NewWriter(psf)
if err := shaderprecomp.CompileToHLSL(vsfw, psfw, source); err != nil {
return "", "", err
}
if err := vsfw.Flush(); err != nil {
return "", "", err
}
if err := psfw.Flush(); err != nil {
return "", "", err
}

View File

@ -20,6 +20,7 @@
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
@ -68,10 +69,11 @@ func compile(source *shaderprecomp.ShaderSource, index int, tmpdir string) error
}
defer f.Close()
if err := shaderprecomp.CompileToMSL(f, source); err != nil {
w := bufio.NewWriter(f)
if err := shaderprecomp.CompileToMSL(w, source); err != nil {
return err
}
if err := f.Sync(); err != nil {
if err := w.Flush(); err != nil {
return err
}

View File

@ -15,6 +15,7 @@
package main
import (
"bufio"
"bytes"
_ "embed"
"fmt"
@ -81,7 +82,7 @@ func main() {
fmt.Println("Play the default video. You can specify a video file as an argument.")
}
player, err := newMPEGPlayer(in)
player, err := newMPEGPlayer(bufio.NewReader(in))
if err != nil {
log.Fatal(err)
}

View File

@ -19,6 +19,7 @@
package main
import (
"bufio"
"log"
"os"
"path/filepath"
@ -809,7 +810,8 @@ func main() {
buildConstraints = "//go:build !android && !ios && !js && !nintendosdk && !playstation5"
}
// NOTE: According to godoc, maps are automatically sorted by key.
if err := tmpl.Execute(f, struct {
w := bufio.NewWriter(f)
if err := tmpl.Execute(w, struct {
License string
DoNotEdit string
BuildConstraints string
@ -840,5 +842,9 @@ func main() {
}); err != nil {
log.Fatal(err)
}
if err := w.Flush(); err != nil {
log.Fatal(err)
}
}
}

10
go.mod
View File

@ -3,10 +3,10 @@ module github.com/hajimehoshi/ebiten/v2
go 1.19
require (
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc
github.com/ebitengine/hideconsole v1.0.0
github.com/ebitengine/oto/v3 v3.3.0-alpha.2
github.com/ebitengine/purego v0.8.0-alpha.3
github.com/ebitengine/oto/v3 v3.3.0-alpha.3
github.com/ebitengine/purego v0.8.0-alpha.3.0.20240805123034-6cc30db8f187
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.3
@ -16,8 +16,8 @@ require (
github.com/jfreymuth/oggvorbis v1.0.5
github.com/kisielk/errcheck v1.7.0
golang.org/x/image v0.18.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.22.0
golang.org/x/sync v0.8.0
golang.org/x/sys v0.23.0
golang.org/x/text v0.16.0
golang.org/x/tools v0.23.0
)

19
go.sum
View File

@ -1,11 +1,11 @@
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895 h1:48bCqKTuD7Z0UovDfvpCn7wZ0GUZ+yosIteNDthn3FU=
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895/go.mod h1:XZdLv05c5hOZm3fM2NlJ92FyEZjnslcMcNRrhxs8+8M=
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc h1:76TYsaP1F48tiQRlrr71NsbfxBcFM9/8bEHS9/JbsQg=
github.com/ebitengine/gomobile v0.0.0-20240802043200-192f051f4fcc/go.mod h1:RM/c3pvru6dRqgGEW7RCTb6czFXYAa3MxbXu3u8/dcI=
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.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/ebitengine/oto/v3 v3.3.0-alpha.3 h1:L8Odh8gVr4F+0CzSfqOfw/nEnXXWkB+UhGOKUYrP+Nk=
github.com/ebitengine/oto/v3 v3.3.0-alpha.3/go.mod h1:yYvXK7mgNwsFawY5RsvGI6yhMHtD+0MfaPkDTl9/uv8=
github.com/ebitengine/purego v0.8.0-alpha.3.0.20240805123034-6cc30db8f187 h1:vXEgFw8Ni26tlWLmeI8nFXa7pMLKUTR9hfXcQPCYpQg=
github.com/ebitengine/purego v0.8.0-alpha.3.0.20240805123034-6cc30db8f187/go.mod h1:SQ56/omnSL8DdaBSKswoBvsMjgaWQyxyeMtb48sOskI=
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=
@ -59,8 +59,9 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -73,8 +74,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
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=

View File

@ -24,13 +24,24 @@ import (
)
type FileEntryFS struct {
rootEntry js.Value
rootEntries []js.Value
}
func NewFileEntryFS(root js.Value) *FileEntryFS {
return &FileEntryFS{
rootEntry: root,
func NewFileEntryFS(rootEntries []js.Value) (*FileEntryFS, error) {
// Check all the full paths are the same.
var fullpath string
for _, ent := range rootEntries {
if fullpath == "" {
fullpath = ent.Get("fullPath").String()
continue
}
if fullpath != ent.Get("fullPath").String() {
return nil, errors.New("file: all the full paths must be the same")
}
}
return &FileEntryFS{
rootEntries: rootEntries,
}, nil
}
func (f *FileEntryFS) Open(name string) (fs.File, error) {
@ -43,33 +54,55 @@ func (f *FileEntryFS) Open(name string) (fs.File, error) {
}
if name == "." {
return &dir{entry: f.rootEntry}, nil
var dirName string
for _, ent := range f.rootEntries {
if dirName == "" {
dirName = ent.Get("name").String()
continue
}
if dirName != ent.Get("name").String() {
return nil, &fs.PathError{
Op: "open",
Path: name,
Err: errors.New("invalid directory"),
}
}
}
return &dir{
name: dirName,
dirEntries: f.rootEntries,
}, nil
}
var chEntry chan js.Value
cbSuccess := js.FuncOf(func(this js.Value, args []js.Value) any {
chEntry <- args[0]
close(chEntry)
return nil
})
defer cbSuccess.Release()
for _, ent := range f.rootEntries {
var chEntry chan js.Value
cbSuccess := js.FuncOf(func(this js.Value, args []js.Value) any {
chEntry <- args[0]
close(chEntry)
return nil
})
defer cbSuccess.Release()
cbFailure := js.FuncOf(func(this js.Value, args []js.Value) any {
close(chEntry)
return nil
})
defer cbFailure.Release()
cbFailure := js.FuncOf(func(this js.Value, args []js.Value) any {
close(chEntry)
return nil
})
defer cbFailure.Release()
chEntry = make(chan js.Value)
f.rootEntry.Call("getFile", name, nil, cbSuccess, cbFailure)
if entry := <-chEntry; entry.Truthy() {
return &file{entry: entry}, nil
}
chEntry = make(chan js.Value)
ent.Call("getFile", name, nil, cbSuccess, cbFailure)
if entry := <-chEntry; entry.Truthy() {
return &file{entry: entry}, nil
}
chEntry = make(chan js.Value)
f.rootEntry.Call("getDirectory", name, nil, cbSuccess, cbFailure)
if entry := <-chEntry; entry.Truthy() {
return &dir{entry: entry}, nil
chEntry = make(chan js.Value)
ent.Call("getDirectory", name, nil, cbSuccess, cbFailure)
if entry := <-chEntry; entry.Truthy() {
return &dir{
name: entry.Get("name").String(),
dirEntries: []js.Value{entry},
}, nil
}
}
return nil, &fs.PathError{
@ -109,8 +142,8 @@ func (f *file) ensureFile() js.Value {
func (f *file) Stat() (fs.FileInfo, error) {
return &fileInfo{
entry: f.entry,
file: f.ensureFile(),
name: f.entry.Get("name").String(),
file: f.ensureFile(),
}, nil
}
@ -163,21 +196,22 @@ func (f *file) Close() error {
}
type dir struct {
entry js.Value
entries []js.Value
offset int
name string
dirEntries []js.Value
fileEntries []js.Value
offset int
}
func (d *dir) Stat() (fs.FileInfo, error) {
return &fileInfo{
entry: d.entry,
name: d.name,
}, nil
}
func (d *dir) Read(buf []byte) (int, error) {
return 0, &fs.PathError{
Op: "read",
Path: d.entry.Get("name").String(),
Path: d.name,
Err: errors.New("is a directory"),
}
}
@ -187,43 +221,52 @@ func (d *dir) Close() error {
}
func (d *dir) ReadDir(count int) ([]fs.DirEntry, error) {
if d.entries == nil {
ch := make(chan struct{})
var rec js.Func
cb := js.FuncOf(func(this js.Value, args []js.Value) any {
entries := args[0]
if entries.Length() == 0 {
close(ch)
if d.fileEntries == nil {
names := map[string]struct{}{}
for _, dirEntry := range d.dirEntries {
ch := make(chan struct{})
var rec js.Func
cb := js.FuncOf(func(this js.Value, args []js.Value) any {
entries := args[0]
if entries.Length() == 0 {
close(ch)
return nil
}
for i := 0; i < entries.Length(); i++ {
ent := entries.Index(i)
name := ent.Get("name").String()
// A name can be empty when this directory is a root directory.
if name == "" {
continue
}
// Avoid entry duplications. Entry duplications happen when multiple files are dropped on Chrome.
if _, ok := names[name]; ok {
continue
}
if !ent.Get("isFile").Bool() && !ent.Get("isDirectory").Bool() {
continue
}
d.fileEntries = append(d.fileEntries, ent)
names[name] = struct{}{}
}
rec.Value.Call("call")
return nil
}
for i := 0; i < entries.Length(); i++ {
ent := entries.Index(i)
// A name can be empty when this directory is a root directory.
if ent.Get("name").String() == "" {
continue
}
if !ent.Get("isFile").Bool() && !ent.Get("isDirectory").Bool() {
continue
}
d.entries = append(d.entries, ent)
}
})
defer cb.Release()
reader := dirEntry.Call("createReader")
rec = js.FuncOf(func(this js.Value, args []js.Value) any {
reader.Call("readEntries", cb)
return nil
})
defer rec.Release()
rec.Value.Call("call")
return nil
})
defer cb.Release()
reader := d.entry.Call("createReader")
rec = js.FuncOf(func(this js.Value, args []js.Value) any {
reader.Call("readEntries", cb)
return nil
})
defer rec.Release()
rec.Value.Call("call")
<-ch
<-ch
}
}
n := len(d.entries) - d.offset
n := len(d.fileEntries) - d.offset
if n == 0 {
if count <= 0 {
@ -238,11 +281,12 @@ func (d *dir) ReadDir(count int) ([]fs.DirEntry, error) {
ents := make([]fs.DirEntry, n)
for i := range ents {
entry := d.fileEntries[d.offset+i]
fi := &fileInfo{
entry: d.entries[d.offset+i],
name: entry.Get("name").String(),
}
if fi.entry.Get("isFile").Bool() {
fi.file = getFile(fi.entry)
if entry.Get("isFile").Bool() {
fi.file = getFile(entry)
}
ents[i] = fs.FileInfoToDirEntry(fi)
}
@ -252,12 +296,12 @@ func (d *dir) ReadDir(count int) ([]fs.DirEntry, error) {
}
type fileInfo struct {
entry js.Value
file js.Value
name string
file js.Value
}
func (f *fileInfo) Name() string {
return f.entry.Get("name").String()
return f.name
}
func (f *fileInfo) Size() int64 {

View File

@ -155,7 +155,8 @@ func run() error {
}
defer f.Close()
if err := tmpl.Execute(f, struct {
w := bufio.NewWriter(f)
if err := tmpl.Execute(w, struct {
License string
DoNotEdit string
BuildConstraints string
@ -170,6 +171,9 @@ func run() error {
}); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}
}
return nil

View File

@ -15,6 +15,7 @@
package mtl_test
import (
"bufio"
"fmt"
"image"
"image/color"
@ -147,7 +148,7 @@ func readPNG(name string) (image.Image, error) {
defer func() {
_ = f.Close()
}()
return png.Decode(f)
return png.Decode(bufio.NewReader(f))
}
// imageEq reports whether images m, n are considered equivalent. Two images are considered

View File

@ -90,7 +90,6 @@ type (
type (
uniformLocation int32
attribLocation int32
)
const (
@ -111,8 +110,6 @@ type context struct {
lastBlend graphicsdriver.Blend
maxTextureSize int
maxTextureSizeOnce sync.Once
highp bool
highpOnce sync.Once
initOnce sync.Once
}

View File

@ -45,6 +45,9 @@ func (c *defaultContext) init() error {
}
}
// TODO: Use multiple %w-s as of Go 1.20.
var errors []string
// Try OpenGL first. OpenGL is preferable as this doesn't cause context losses.
if !preferES {
// Usually libGL.so or libGL.so.1 is used. libGL.so.2 might exist only on NetBSD.
@ -57,6 +60,7 @@ func (c *defaultContext) init() error {
libGL = lib
return nil
}
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
}
}
@ -68,9 +72,10 @@ func (c *defaultContext) init() error {
c.isES = true
return nil
}
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
}
return fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so")
return fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so: %s", strings.Join(errors, ", "))
}
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {

View File

@ -18,24 +18,28 @@
#include "graphics_playstation5.h"
extern "C" ebitengine_Error ebitengine_InitializeGraphics(void) {
extern "C" ebitengine_Error ebitengine_InitializeGraphics(void) { return {}; }
extern "C" ebitengine_Error ebitengine_NewImage(int *image, int width,
int height) {
return {};
}
extern "C" ebitengine_Error ebitengine_NewImage(int* image, int width, int height) {
extern "C" ebitengine_Error
ebitengine_NewScreenFramebufferImage(int *image, int width, int height) {
return {};
}
extern "C" ebitengine_Error ebitengine_NewScreenFramebufferImage(int* image, int width, int height) {
extern "C" void ebitengine_DisposeImage(int id) {}
extern "C" ebitengine_Error
ebitengine_DrawTriangles(ebitengine_DrawTrianglesArgs *args) {
return {};
}
extern "C" void ebitengine_DisposeImage(int id) {
}
extern "C" ebitengine_Error ebitengine_NewShader(int* shader, const char* source) {
extern "C" ebitengine_Error ebitengine_NewShader(int *shader,
const char *source) {
return {};
}
extern "C" void ebitengine_DisposeShader(int id) {
}
extern "C" void ebitengine_DisposeShader(int id) {}

View File

@ -21,6 +21,7 @@ import "C"
import (
"fmt"
"runtime"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
@ -117,6 +118,52 @@ func (g *Graphics) NewShader(program *shaderir.Program) (graphicsdriver.Shader,
}
func (g *Graphics) DrawTriangles(dst graphicsdriver.ImageID, srcs [graphics.ShaderSrcImageCount]graphicsdriver.ImageID, shader graphicsdriver.ShaderID, dstRegions []graphicsdriver.DstRegion, indexOffset int, blend graphicsdriver.Blend, uniforms []uint32, fillRule graphicsdriver.FillRule) error {
csrcs := make([]C.int, len(srcs))
for i, src := range srcs {
csrcs[i] = C.int(src)
}
cDstRegions := make([]C.ebitengine_DstRegion, len(dstRegions))
for i, r := range dstRegions {
cDstRegions[i] = C.ebitengine_DstRegion{
Region: C.ebitengine_Rectangle{
MinX: C.int(r.Region.Min.X),
MinY: C.int(r.Region.Min.Y),
MaxX: C.int(r.Region.Max.X),
MaxY: C.int(r.Region.Max.Y),
},
IndexCount: C.int(r.IndexCount),
}
}
cUniforms := make([]C.uint32_t, len(uniforms))
for i, u := range uniforms {
cUniforms[i] = C.uint32_t(u)
}
cBlend := C.ebitengine_Blend{
BlendFactorSourceRGB: C.uint8_t(blend.BlendFactorSourceRGB),
BlendFactorSourceAlpha: C.uint8_t(blend.BlendFactorSourceAlpha),
BlendFactorDestinationRGB: C.uint8_t(blend.BlendFactorDestinationRGB),
BlendFactorDestinationAlpha: C.uint8_t(blend.BlendFactorDestinationAlpha),
BlendOperationRGB: C.uint8_t(blend.BlendOperationRGB),
BlendOperationAlpha: C.uint8_t(blend.BlendOperationAlpha),
}
args := C.ebitengine_DrawTrianglesArgs{
Dst: C.int(dst),
Srcs: &csrcs[0],
SrcCount: C.int(len(csrcs)),
Shader: C.int(shader),
DstRegions: &cDstRegions[0],
DstRegionCount: C.int(len(cDstRegions)),
IndexOffset: C.int(indexOffset),
Blend: cBlend,
Uniforms: &cUniforms[0],
UniformCount: C.int(len(cUniforms)),
FillRule: C.int(fillRule),
}
if err := C.ebitengine_DrawTriangles(&args); !C.ebitengine_IsErrorNil(&err) {
return newPlaystation5Error("(*playstation5.Graphics).DrawTriangles", err)
}
runtime.KeepAlive(args)
return nil
}

View File

@ -19,26 +19,64 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
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) {
static bool ebitengine_IsErrorNil(ebitengine_Error *err) {
return err->Message == NULL && err->Code == 0;
}
ebitengine_Error ebitengine_InitializeGraphics(void);
ebitengine_Error ebitengine_NewImage(int* image, int width, int height);
ebitengine_Error ebitengine_NewScreenFramebufferImage(int* image, int width, int height);
void ebitengine_DisposeImage(int id);
typedef struct ebitengine_Rectangle {
int MinX;
int MinY;
int MaxX;
int MaxY;
} ebitengine_Rectangle;
ebitengine_Error ebitengine_NewShader(int* shader, const char* source);
typedef struct ebitengine_DstRegion {
ebitengine_Rectangle Region;
int IndexCount;
} ebitengine_DstRegion;
typedef struct ebitengine_Blend {
uint8_t BlendFactorSourceRGB;
uint8_t BlendFactorSourceAlpha;
uint8_t BlendFactorDestinationRGB;
uint8_t BlendFactorDestinationAlpha;
uint8_t BlendOperationRGB;
uint8_t BlendOperationAlpha;
} ebitengine_Blend;
typedef struct ebitengine_DrawTrianglesArgs {
int Dst;
int *Srcs;
int SrcCount;
int Shader;
ebitengine_DstRegion *DstRegions;
int DstRegionCount;
int IndexOffset;
ebitengine_Blend Blend;
uint32_t *Uniforms;
int UniformCount;
int FillRule;
} ebitengine_DrawTrianglesArgs;
ebitengine_Error ebitengine_InitializeGraphics(void);
ebitengine_Error ebitengine_NewImage(int *image, int width, int height);
ebitengine_Error ebitengine_NewScreenFramebufferImage(int *image, int width,
int height);
void ebitengine_DisposeImage(int id);
ebitengine_Error ebitengine_DrawTriangles(ebitengine_DrawTrianglesArgs *args);
ebitengine_Error ebitengine_NewShader(int *shader, const char *source);
void ebitengine_DisposeShader(int id);
#ifdef __cplusplus

View File

@ -17,6 +17,7 @@
package main
import (
"bufio"
"fmt"
"go/ast"
"go/format"
@ -93,6 +94,8 @@ func run() error {
}
defer out.Close()
w := bufio.NewWriter(out)
// TODO: Remove call of RegisterDecoder
data, err := os.ReadFile(filepath.Join(dir, f))
@ -129,14 +132,14 @@ func run() error {
return true
}, nil)
fmt.Fprintln(out, "// Code generated by gen.go. DO NOT EDIT.")
fmt.Fprintln(out)
format.Node(out, fset, tree)
fmt.Fprintln(w, "// Code generated by gen.go. DO NOT EDIT.")
fmt.Fprintln(w)
format.Node(w, fset, tree)
if f == "reader.go" {
// The min function was removed as of Go 1.22, but this is needed for old Go.
// TODO: Remove this when Go 1.21 is the minimum supported version.
fmt.Fprintln(out, `
fmt.Fprintln(w, `
func min(a, b int) int {
if a < b {
return a
@ -144,6 +147,10 @@ func min(a, b int) int {
return b
}`)
}
if err := w.Flush(); err != nil {
return err
}
}
return nil
}

View File

@ -1150,6 +1150,11 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
x := exprs[0]
t := ts[0]
if (t.IsFloatVector() || t.IsIntVector()) && idx.Const == nil {
cs.addError(e.Pos(), fmt.Sprintf("index must be a constant for the type %s", t.String()))
return nil, nil, nil, false
}
var typ shaderir.Type
switch t.Main {
case shaderir.Vec2, shaderir.Vec3, shaderir.Vec4:

View File

@ -21,7 +21,6 @@ import (
"runtime"
"strings"
"testing"
"time"
"github.com/hajimehoshi/ebiten/v2/internal/shader"
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
@ -30,13 +29,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/msl"
)
func TestMain(m *testing.M) {
code := m.Run()
// The Wasm tests on GitHub CI often fail due to some remaining functions. Wait for a while to finish them.
time.Sleep(100 * time.Millisecond)
os.Exit(code)
}
func glslVertexNormalize(str string) string {
p := glsl.VertexPrelude(glsl.GLSLVersionDefault)
if strings.HasPrefix(str, p) {

View File

@ -4363,3 +4363,67 @@ func Foo() int {
t.Error(err)
}
}
func TestSyntaxIndex(t *testing.T) {
// Issue #3011
if _, err := compileToIR([]byte(`package main
func Foo() float {
var a int
var b vec4
return b[a]
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
if _, err := compileToIR([]byte(`package main
func Foo() int {
var a int
var b ivec4
return b[a]
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
if _, err := compileToIR([]byte(`package main
func Foo() float {
var a int
var b mat4
return b[a][0]
}
`)); err != nil {
t.Error(err)
}
if _, err := compileToIR([]byte(`package main
func Foo() float {
const a = 0
var b vec4
return b[a]
}
`)); err != nil {
t.Error(err)
}
if _, err := compileToIR([]byte(`package main
func Foo() int {
const a = 0
var b ivec4
return b[a]
}
`)); err != nil {
t.Error(err)
}
if _, err := compileToIR([]byte(`package main
func Foo() float {
const a = 0
var b mat4
return b[a][0]
}
`)); err != nil {
t.Error(err)
}
}

View File

@ -192,7 +192,7 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, ui *UserInter
return err
}
const maxSkipCount = 3
const maxSkipCount = 4
if !forceDraw && !c.isOffscreenModified {
if c.skipCount < maxSkipCount {

View File

@ -238,6 +238,7 @@ var (
sel_origResizable = objc.RegisterName("isOrigResizable")
sel_setCollectionBehavior = objc.RegisterName("setCollectionBehavior:")
sel_setDelegate = objc.RegisterName("setDelegate:")
sel_setDocumentEdited = objc.RegisterName("setDocumentEdited:")
sel_setOrigDelegate = objc.RegisterName("setOrigDelegate:")
sel_setOrigResizable = objc.RegisterName("setOrigResizable:")
sel_toggleFullScreen = objc.RegisterName("toggleFullScreen:")
@ -433,3 +434,13 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
func (u *UserInterface) skipTaskbar() error {
return nil
}
// setDocumentEdited must be called from the main thread.
func (u *UserInterface) setDocumentEdited(edited bool) error {
w, err := u.window.GetCocoaWindow()
if err != nil {
return err
}
objc.ID(w).Send(sel_setDocumentEdited, edited)
return nil
}

View File

@ -568,6 +568,22 @@ func (u *UserInterface) setWindowClosingHandled(handled bool) {
u.m.Lock()
u.windowClosingHandled = handled
u.m.Unlock()
if !u.isRunning() {
return
}
if u.isTerminated() {
return
}
u.mainThread.Call(func() {
if u.isTerminated() {
return
}
if err := u.setDocumentEdited(handled); err != nil {
u.setError(err)
return
}
})
}
// isFullscreen must be called from the main thread.
@ -874,6 +890,13 @@ func (u *UserInterface) createWindow() error {
return err
}
u.m.Lock()
closingHandled := u.windowClosingHandled
u.m.Unlock()
if err := u.setDocumentEdited(closingHandled); err != nil {
return err
}
return nil
}

View File

@ -707,14 +707,21 @@ func (u *UserInterface) appendDroppedFiles(data js.Value) {
defer u.dropFileM.Unlock()
items := data.Get("items")
var entries []js.Value
for i := 0; i < items.Length(); i++ {
kind := items.Index(i).Get("kind").String()
switch kind {
case "file":
fs := items.Index(i).Call("webkitGetAsEntry").Get("filesystem").Get("root")
u.inputState.DroppedFiles = file.NewFileEntryFS(fs)
entries = append(entries, items.Index(i).Call("webkitGetAsEntry").Get("filesystem").Get("root"))
}
}
if len(entries) > 0 {
fs, err := file.NewFileEntryFS(entries)
if err != nil {
u.setError(err)
return
}
u.inputState.DroppedFiles = fs
}
}

View File

@ -200,3 +200,7 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
func (u *UserInterface) skipTaskbar() error {
return nil
}
func (u *UserInterface) setDocumentEdited(edited bool) error {
return nil
}

View File

@ -242,6 +242,10 @@ func (u *UserInterface) skipTaskbar() error {
return nil
}
func (u *UserInterface) setDocumentEdited(edited bool) error {
return nil
}
func init() {
if microsoftgdk.IsXbox() {
// TimeBeginPeriod might not be defined in Xbox.