mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
4 Commits
df33bc3e27
...
4bccf9d009
Author | SHA1 | Date | |
---|---|---|---|
|
4bccf9d009 | ||
|
a4bfa6cb15 | ||
|
a36f6210c0 | ||
|
c346c1d75b |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -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', '1.23.x']
|
||||
go: ['1.22.x', '1.23.x']
|
||||
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
|
@ -188,14 +188,7 @@ func (c *Context) addPlayingPlayer(p *playerImpl) {
|
||||
defer c.m.Unlock()
|
||||
c.playingPlayers[p] = struct{}{}
|
||||
|
||||
// (reflect.Type).Comparable() is enough here, as reflect.TypeOf should always return a dynamic (non-interface) type.
|
||||
// If reflect.TypeOf returned an interface type, this check would be meaningless.
|
||||
// See these for more details:
|
||||
// * https://pkg.go.dev/reflect#TypeOf
|
||||
// * https://pkg.go.dev/reflect#Type.Comparable
|
||||
//
|
||||
// (*reflect.Value).Comparable() is more intuitive but this was introduced in Go 1.20.
|
||||
if !reflect.TypeOf(p.sourceIdent()).Comparable() {
|
||||
if !reflect.ValueOf(p.sourceIdent()).Comparable() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -93,10 +93,3 @@ func (r *float32BytesReader) Seek(offset int64, whence int) (int64, error) {
|
||||
}
|
||||
return n / 2 * 4, nil
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ package convert_test
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math/rand" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22.
|
||||
"math/rand/v2"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
@ -27,7 +27,7 @@ import (
|
||||
func randInt16s(n int) []int16 {
|
||||
r := make([]int16, n)
|
||||
for i := range r {
|
||||
r[i] = int16(rand.Intn(1<<16) - (1 << 15))
|
||||
r[i] = int16(rand.IntN(1<<16) - (1 << 15))
|
||||
}
|
||||
return r
|
||||
}
|
||||
@ -69,15 +69,14 @@ func TestFloat32(t *testing.T) {
|
||||
name = "seek"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// Note that unsafe.SliceData is available as of Go 1.20.
|
||||
var in, out []byte
|
||||
if len(c.In) > 0 {
|
||||
outF32 := make([]float32, len(c.In))
|
||||
for i := range c.In {
|
||||
outF32[i] = float32(c.In[i]) / (1 << 15)
|
||||
}
|
||||
in = unsafe.Slice((*byte)(unsafe.Pointer(&c.In[0])), len(c.In)*2)
|
||||
out = unsafe.Slice((*byte)(unsafe.Pointer(&outF32[0])), len(outF32)*4)
|
||||
in = unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(c.In))), len(c.In)*2)
|
||||
out = unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(outF32))), len(outF32)*4)
|
||||
}
|
||||
r := convert.NewFloat32BytesReaderFromInt16BytesReader(bytes.NewReader(in)).(io.ReadSeeker)
|
||||
var got []byte
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/rand" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22.
|
||||
"math/rand/v2"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
||||
|
@ -17,8 +17,8 @@ package convert_test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22.
|
||||
"math/rand"
|
||||
"io"
|
||||
"math/rand/v2"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
||||
@ -101,7 +101,7 @@ func TestStereoI16(t *testing.T) {
|
||||
func randBytes(n int) []byte {
|
||||
r := make([]byte, n)
|
||||
for i := range r {
|
||||
r[i] = byte(rand.Intn(256))
|
||||
r[i] = byte(rand.IntN(256))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
@ -34,13 +34,6 @@ type int16BytesReader struct {
|
||||
fbuf []float32
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (r *int16BytesReader) Read(buf []byte) (int, error) {
|
||||
if r.eof {
|
||||
return 0, io.EOF
|
||||
|
@ -15,16 +15,9 @@
|
||||
package twenty48
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
ScreenWidth = 420
|
||||
ScreenHeight = 600
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
@ -261,9 +261,9 @@ func addRandomTile(tiles map[*Tile]struct{}, size int) error {
|
||||
if len(availableCells) == 0 {
|
||||
return errors.New("twenty48: there is no space to add a new tile")
|
||||
}
|
||||
c := availableCells[rand.Intn(len(availableCells))]
|
||||
c := availableCells[rand.IntN(len(availableCells))]
|
||||
v := 2
|
||||
if rand.Intn(10) == 0 {
|
||||
if rand.IntN(10) == 0 {
|
||||
v = 4
|
||||
}
|
||||
x := c % size
|
||||
|
@ -163,19 +163,9 @@ func loadImage(data []byte) (*ebiten.Image, error) {
|
||||
}
|
||||
|
||||
// max returns the largest of x or y.
|
||||
func max(x, y int) int {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// maxSide returns the largest side of a or b images.
|
||||
func maxSide(a, b *ebiten.Image) int {
|
||||
return max(
|
||||
max(a.Bounds().Dx(), b.Bounds().Dx()),
|
||||
max(a.Bounds().Dy(), b.Bounds().Dy()),
|
||||
)
|
||||
return max(a.Bounds().Dx(), b.Bounds().Dx(), a.Bounds().Dy(), b.Bounds().Dy())
|
||||
}
|
||||
|
||||
// drawCenteredText is a util function for drawing blend mode description.
|
||||
|
@ -187,13 +187,6 @@ func (f *Field) Update() {
|
||||
}
|
||||
}
|
||||
|
||||
func min(a, b float64) float64 {
|
||||
if a > b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func flushingColor(rate float64) colorm.ColorM {
|
||||
var clr colorm.ColorM
|
||||
alpha := min(1, rate*2)
|
||||
|
@ -20,9 +20,8 @@ import (
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/colorm"
|
||||
@ -139,10 +138,6 @@ type GameScene struct {
|
||||
gameover bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func NewGameScene() *GameScene {
|
||||
return &GameScene{
|
||||
field: &Field{},
|
||||
@ -194,7 +189,7 @@ const (
|
||||
|
||||
func (s *GameScene) choosePiece() *Piece {
|
||||
num := int(BlockTypeMax)
|
||||
blockType := BlockType(rand.Intn(num) + 1)
|
||||
blockType := BlockType(rand.IntN(num) + 1)
|
||||
return Pieces[blockType]
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
|
@ -17,8 +17,7 @@ package main
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
@ -102,7 +101,7 @@ func (g *Game) updateFireIntensityPerPixel(currentPixelIndex int) {
|
||||
return
|
||||
}
|
||||
|
||||
d := rand.Intn(3)
|
||||
d := rand.IntN(3)
|
||||
newI := int(g.indices[below]) - d
|
||||
if newI < 0 {
|
||||
newI = 0
|
||||
@ -139,8 +138,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
ebiten.SetWindowSize(screenWidth*6, screenHeight*6)
|
||||
ebiten.SetWindowTitle("Doom Fire (Ebitengine Demo)")
|
||||
if err := ebiten.RunGame(NewGame()); err != nil {
|
||||
|
@ -20,8 +20,7 @@ import (
|
||||
"image/color"
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -29,10 +28,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
screenWidth = 640
|
||||
screenHeight = 480
|
||||
@ -196,8 +191,8 @@ func NewGame() *Game {
|
||||
s := &Sprite{
|
||||
image: ebitenImage,
|
||||
alphaImage: ebitenAlphaImage,
|
||||
x: rand.Intn(screenWidth - w),
|
||||
y: rand.Intn(screenHeight - h),
|
||||
x: rand.IntN(screenWidth - w),
|
||||
y: rand.IntN(screenHeight - h),
|
||||
}
|
||||
sprites = append(sprites, s)
|
||||
}
|
||||
|
@ -24,8 +24,7 @@ import (
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||
@ -44,10 +43,6 @@ var flagCRT = flag.Bool("crt", false, "enable the CRT effect")
|
||||
//go:embed crt.go
|
||||
var crtGo []byte
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func floorDiv(x, y int) int {
|
||||
d := x / y
|
||||
if d*y == x || x >= 0 {
|
||||
@ -150,7 +145,7 @@ func (g *Game) init() {
|
||||
g.cameraY = 0
|
||||
g.pipeTileYs = make([]int, 256)
|
||||
for i := range g.pipeTileYs {
|
||||
g.pipeTileYs[i] = rand.Intn(6) + 2
|
||||
g.pipeTileYs[i] = rand.IntN(6) + 2
|
||||
}
|
||||
|
||||
if g.audioContext == nil {
|
||||
|
@ -19,8 +19,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||
@ -94,10 +93,6 @@ func init() {
|
||||
mplusFaceSource = s
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
counter int
|
||||
kanjiText string
|
||||
@ -110,14 +105,14 @@ func (g *Game) Update() error {
|
||||
g.kanjiText = ""
|
||||
for j := 0; j < 6; j++ {
|
||||
for i := 0; i < 12; i++ {
|
||||
g.kanjiText += string(jaKanjis[rand.Intn(len(jaKanjis))])
|
||||
g.kanjiText += string(jaKanjis[rand.IntN(len(jaKanjis))])
|
||||
}
|
||||
g.kanjiText += "\n"
|
||||
}
|
||||
|
||||
g.kanjiTextColor.R = 0x80 + uint8(rand.Intn(0x7f))
|
||||
g.kanjiTextColor.G = 0x80 + uint8(rand.Intn(0x7f))
|
||||
g.kanjiTextColor.B = 0x80 + uint8(rand.Intn(0x7f))
|
||||
g.kanjiTextColor.R = 0x80 + uint8(rand.IntN(0x7f))
|
||||
g.kanjiTextColor.G = 0x80 + uint8(rand.IntN(0x7f))
|
||||
g.kanjiTextColor.B = 0x80 + uint8(rand.IntN(0x7f))
|
||||
g.kanjiTextColor.A = 0xff
|
||||
}
|
||||
g.counter++
|
||||
|
@ -16,8 +16,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
)
|
||||
|
||||
// Level represents a Game level.
|
||||
@ -56,9 +55,6 @@ func NewLevel() (*Level, error) {
|
||||
return nil, fmt.Errorf("failed to load embedded spritesheet: %s", err)
|
||||
}
|
||||
|
||||
// Generate a unique permutation each time.
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
|
||||
// Fill each tile with one or more sprites randomly.
|
||||
l.tiles = make([][]*Tile, l.h)
|
||||
for y := 0; y < l.h; y++ {
|
||||
@ -66,7 +62,7 @@ func NewLevel() (*Level, error) {
|
||||
for x := 0; x < l.w; x++ {
|
||||
t := &Tile{}
|
||||
isBorderSpace := x == 0 || y == 0 || x == l.w-1 || y == l.h-1
|
||||
val := r.Intn(1000)
|
||||
val := rand.IntN(1000)
|
||||
switch {
|
||||
case isBorderSpace || val < 275:
|
||||
t.AddSprite(ss.Wall)
|
||||
|
@ -8,16 +8,11 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// World represents the game state.
|
||||
type World struct {
|
||||
area []bool
|
||||
@ -39,8 +34,8 @@ func NewWorld(width, height int, maxInitLiveCells int) *World {
|
||||
// init inits world with a random state.
|
||||
func (w *World) init(maxLiveCells int) {
|
||||
for i := 0; i < maxLiveCells; i++ {
|
||||
x := rand.Intn(w.width)
|
||||
y := rand.Intn(w.height)
|
||||
x := rand.IntN(w.width)
|
||||
y := rand.IntN(w.height)
|
||||
w.area[y*w.width+x] = true
|
||||
}
|
||||
}
|
||||
@ -96,20 +91,6 @@ func (w *World) Draw(pix []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// neighbourCount calculates the Moore neighborhood of (x, y).
|
||||
func neighbourCount(a []bool, width, height, x, y int) int {
|
||||
c := 0
|
||||
|
@ -27,13 +27,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
func min(x, y int) int {
|
||||
if x < y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
var (
|
||||
whiteImage = ebiten.NewImage(3, 3)
|
||||
|
||||
|
@ -21,8 +21,7 @@ import (
|
||||
"image"
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
rmascot "github.com/hajimehoshi/ebiten/v2/examples/resources/images/mascot"
|
||||
@ -60,10 +59,6 @@ func init() {
|
||||
gopher3 = ebiten.NewImageFromImage(img3)
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
type mascot struct {
|
||||
x16 int
|
||||
y16 int
|
||||
@ -105,8 +100,8 @@ func (m *mascot) Update() error {
|
||||
}
|
||||
|
||||
// If the mascto is on the ground, cause an action in random.
|
||||
if rand.Intn(60) == 0 && m.y16 == 0 {
|
||||
switch rand.Intn(2) {
|
||||
if rand.IntN(60) == 0 && m.y16 == 0 {
|
||||
switch rand.IntN(2) {
|
||||
case 0:
|
||||
// Jump.
|
||||
m.vy16 = -240
|
||||
|
@ -145,20 +145,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
return screenWidth, screenHeight
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func main() {
|
||||
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||
ebiten.SetWindowTitle("Masking (Ebitengine Demo)")
|
||||
|
@ -23,18 +23,13 @@ import (
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
screenWidth = 640
|
||||
screenHeight = 480
|
||||
@ -110,7 +105,7 @@ func (s *sprite) draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
func newSprite(img *ebiten.Image) *sprite {
|
||||
c := rand.Intn(50) + 300
|
||||
c := rand.IntN(50) + 300
|
||||
dir := rand.Float64() * 2 * math.Pi
|
||||
a := rand.Float64() * 2 * math.Pi
|
||||
s := rand.Float64()*0.1 + 0.4
|
||||
@ -136,7 +131,7 @@ func (g *Game) Update() error {
|
||||
g.sprites = list.New()
|
||||
}
|
||||
|
||||
if g.sprites.Len() < 500 && rand.Intn(4) < 3 {
|
||||
if g.sprites.Len() < 500 && rand.IntN(4) < 3 {
|
||||
// Emit
|
||||
g.sprites.PushBack(newSprite(smokeImage))
|
||||
}
|
||||
|
@ -18,8 +18,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -30,10 +29,6 @@ const (
|
||||
screenHeight = 240
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
offscreen *ebiten.Image
|
||||
}
|
||||
@ -46,12 +41,12 @@ func NewGame() *Game {
|
||||
|
||||
func (g *Game) Update() error {
|
||||
s := g.offscreen.Bounds().Size()
|
||||
x := rand.Intn(s.X)
|
||||
y := rand.Intn(s.Y)
|
||||
x := rand.IntN(s.X)
|
||||
y := rand.IntN(s.Y)
|
||||
c := color.RGBA{
|
||||
byte(rand.Intn(256)),
|
||||
byte(rand.Intn(256)),
|
||||
byte(rand.Intn(256)),
|
||||
byte(rand.IntN(256)),
|
||||
byte(rand.IntN(256)),
|
||||
byte(rand.IntN(256)),
|
||||
byte(0xff),
|
||||
}
|
||||
g.offscreen.Set(x, y, c)
|
||||
|
@ -18,8 +18,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -59,10 +58,6 @@ type Game struct {
|
||||
level int
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func (g *Game) collidesWithApple() bool {
|
||||
return g.snakeBody[0].X == g.apple.X &&
|
||||
g.snakeBody[0].Y == g.apple.Y
|
||||
@ -130,8 +125,8 @@ func (g *Game) Update() error {
|
||||
}
|
||||
|
||||
if g.collidesWithApple() {
|
||||
g.apple.X = rand.Intn(xGridCountInScreen - 1)
|
||||
g.apple.Y = rand.Intn(yGridCountInScreen - 1)
|
||||
g.apple.X = rand.IntN(xGridCountInScreen - 1)
|
||||
g.apple.Y = rand.IntN(yGridCountInScreen - 1)
|
||||
g.snakeBody = append(g.snakeBody, Position{
|
||||
X: g.snakeBody[len(g.snakeBody)-1].X,
|
||||
Y: g.snakeBody[len(g.snakeBody)-1].Y,
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -119,9 +119,9 @@ func (g *Game) init() {
|
||||
g.sprites.num = 500
|
||||
for i := range g.sprites.sprites {
|
||||
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
|
||||
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
||||
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
|
||||
a := rand.Intn(maxAngle)
|
||||
x, y := rand.IntN(screenWidth-w), rand.IntN(screenHeight-h)
|
||||
vx, vy := 2*rand.IntN(2)-1, 2*rand.IntN(2)-1
|
||||
a := rand.IntN(maxAngle)
|
||||
g.sprites.sprites[i] = &Sprite{
|
||||
imageWidth: w,
|
||||
imageHeight: h,
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
_ "image/png"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -117,9 +117,9 @@ func (g *Game) init() {
|
||||
g.sprites.num = 500
|
||||
for i := range g.sprites.sprites {
|
||||
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
|
||||
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
||||
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
|
||||
a := rand.Intn(maxAngle)
|
||||
x, y := rand.IntN(screenWidth-w), rand.IntN(screenHeight-h)
|
||||
vx, vy := 2*rand.IntN(2)-1, 2*rand.IntN(2)-1
|
||||
a := rand.IntN(maxAngle)
|
||||
g.sprites.sprites[i] = &Sprite{
|
||||
imageWidth: w,
|
||||
imageHeight: h,
|
||||
|
@ -20,8 +20,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -127,8 +126,8 @@ type squiral struct {
|
||||
func (s *squiral) spawn(game *Game) {
|
||||
s.dead = false
|
||||
|
||||
rx := rand.Intn(width-4) + 2
|
||||
ry := rand.Intn(height-4) + 2
|
||||
rx := rand.IntN(width-4) + 2
|
||||
ry := rand.IntN(height-4) + 2
|
||||
|
||||
for dx := -2; dx <= 2; dx++ {
|
||||
for dy := -2; dy <= 2; dy++ {
|
||||
@ -140,15 +139,15 @@ func (s *squiral) spawn(game *Game) {
|
||||
}
|
||||
}
|
||||
|
||||
s.speed = rand.Intn(5) + 1
|
||||
s.speed = rand.IntN(5) + 1
|
||||
s.pos.x = rx
|
||||
s.pos.y = ry
|
||||
s.dir = rand.Intn(4)
|
||||
s.dir = rand.IntN(4)
|
||||
|
||||
game.colorCycle = (game.colorCycle + 1) % len(palettes[game.selectedPalette].colors)
|
||||
s.col = palettes[game.selectedPalette].colors[game.colorCycle]
|
||||
|
||||
s.rot = rand.Intn(2)
|
||||
s.rot = rand.IntN(2)
|
||||
}
|
||||
|
||||
func (s *squiral) step(game *Game) {
|
||||
@ -157,7 +156,7 @@ func (s *squiral) step(game *Game) {
|
||||
}
|
||||
x, y := s.pos.x, s.pos.y // shorthands
|
||||
|
||||
change := rand.Intn(1000)
|
||||
change := rand.IntN(1000)
|
||||
if change < 2 {
|
||||
// On 0.2% of iterations, switch rotation direction.
|
||||
s.rot = (s.rot + 1) % 2
|
||||
@ -267,10 +266,6 @@ func (a *automaton) step(game *Game) {
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
selectedPalette int
|
||||
colorCycle int
|
||||
|
@ -17,8 +17,7 @@ package main
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
"math/rand/v2"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
@ -97,7 +96,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
ebiten.SetWindowSize(screenWidth, screenHeight)
|
||||
ebiten.SetWindowTitle("Stars (Ebitengine Demo)")
|
||||
if err := ebiten.RunGame(NewGame()); err != nil {
|
||||
|
@ -22,12 +22,11 @@ import (
|
||||
_ "image/jpeg"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
@ -55,7 +54,6 @@ var (
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
@ -71,9 +69,9 @@ var (
|
||||
func createRandomIconImage() image.Image {
|
||||
const size = 32
|
||||
|
||||
rf := float64(rand.Intn(0x100))
|
||||
gf := float64(rand.Intn(0x100))
|
||||
bf := float64(rand.Intn(0x100))
|
||||
rf := float64(rand.IntN(0x100))
|
||||
gf := float64(rand.IntN(0x100))
|
||||
bf := float64(rand.IntN(0x100))
|
||||
img := ebiten.NewImage(size, size)
|
||||
pix := make([]byte, 4*size*size)
|
||||
for j := 0; j < size; j++ {
|
||||
|
12
go.mod
12
go.mod
@ -1,9 +1,9 @@
|
||||
module github.com/hajimehoshi/ebiten/v2
|
||||
|
||||
go 1.19
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911013058-19d2b8b92254
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325
|
||||
github.com/ebitengine/hideconsole v1.0.0
|
||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.4
|
||||
github.com/ebitengine/purego v0.8.0-alpha.5
|
||||
@ -15,15 +15,15 @@ require (
|
||||
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.19.0
|
||||
golang.org/x/image v0.20.0
|
||||
golang.org/x/sync v0.8.0
|
||||
golang.org/x/sys v0.25.0
|
||||
golang.org/x/text v0.17.0
|
||||
golang.org/x/tools v0.24.0
|
||||
golang.org/x/text v0.18.0
|
||||
golang.org/x/tools v0.25.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jfreymuth/vorbis v1.0.2 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.21 // indirect
|
||||
golang.org/x/mod v0.20.0 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
)
|
||||
|
19
go.sum
19
go.sum
@ -1,5 +1,5 @@
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911013058-19d2b8b92254 h1:4gZw/SDMJtxpPh+lMpXLZ63LWWna0mZgtEBuvizRmdo=
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911013058-19d2b8b92254/go.mod h1:n2NbB/F4d9wOXFzC7FT1ipERidmYWC5I4YNOYRs5N7I=
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325 h1:Gk1XUEttOk0/hb6Tq3WkmutWa0ZLhNn/6fc6XZpM7tM=
|
||||
github.com/ebitengine/gomobile v0.0.0-20240911145611-4856209ac325/go.mod h1:ulhSQcbPioQrallSuIzF8l1NKQoD7xmMZc5NxzibUMY=
|
||||
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.4 h1:w9SD7kK4GgJULkh5pWVTToMA5Ia1bP7VxD4rIjQqb8M=
|
||||
@ -11,6 +11,7 @@ github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRR
|
||||
github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496 h1:zgx3rOyOdRoA2GXWpfJkH7Zg248ookseRifdn9VSp5g=
|
||||
github.com/go-text/typesetting v0.1.1-0.20240522210117-2c045476f496/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.5 h1:gtIcN2INlD2qlfUiECuvbI0moNIoANgIY7MwgW4cFGE=
|
||||
@ -37,15 +38,16 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
|
||||
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
|
||||
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
|
||||
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
|
||||
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.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
|
||||
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
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=
|
||||
@ -92,14 +94,15 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
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.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
|
||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
|
||||
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -22,10 +22,9 @@ import (
|
||||
"image/draw"
|
||||
_ "image/png"
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
|
||||
@ -37,10 +36,6 @@ import (
|
||||
// maxImageSize is a maximum image size that should work in almost every environment.
|
||||
const maxImageSize = 4096 - 2
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func skipTooSlowTests(t *testing.T) bool {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
@ -348,26 +343,6 @@ func TestImageDeallocate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type ordered interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
|
||||
}
|
||||
|
||||
// TODO: Use the built-in function min from Go 1.21.
|
||||
func min[T ordered](a, b T) T {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// TODO: Use the built-in function max from Go 1.21.
|
||||
func max[T ordered](a, b T) T {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func TestImageBlendLighter(t *testing.T) {
|
||||
img0, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
@ -4292,7 +4267,7 @@ func TestImageAntiAlias(t *testing.T) {
|
||||
ebiten.BlendXor,
|
||||
ebiten.BlendLighter,
|
||||
} {
|
||||
rnd := rand.New(rand.NewSource(0))
|
||||
rnd := rand.New(rand.NewPCG(0, 0))
|
||||
max := func(x, y, z byte) byte {
|
||||
if x >= y && x >= z {
|
||||
return x
|
||||
|
@ -16,7 +16,7 @@ package affine_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
|
@ -35,13 +35,6 @@ var (
|
||||
maxSize = 0
|
||||
)
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func appendDeferred(f func()) {
|
||||
deferredM.Lock()
|
||||
defer deferredM.Unlock()
|
||||
|
@ -314,8 +314,5 @@ func (i *Image) syncPixelsIfNeeded() {
|
||||
blend := graphicsdriver.BlendCopy
|
||||
i.img.DrawTriangles(srcs, vs, is, blend, dr, [graphics.ShaderSrcImageCount]image.Rectangle{sr}, atlas.NearestFilterShader, nil, graphicsdriver.FillRuleFillAll, restorable.HintNone)
|
||||
|
||||
// TODO: Use clear if Go 1.21 is available.
|
||||
for pos := range i.dotsBuffer {
|
||||
delete(i.dotsBuffer, pos)
|
||||
}
|
||||
clear(i.dotsBuffer)
|
||||
}
|
||||
|
@ -64,13 +64,6 @@ func ActualTPS() float64 {
|
||||
return actualTPS
|
||||
}
|
||||
|
||||
func max(a, b int64) int64 {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func calcCountFromTPS(tps int64, now int64) int {
|
||||
if tps == 0 {
|
||||
return 0
|
||||
|
@ -616,6 +616,5 @@ func bytePtrToString(p *byte) string {
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
}
|
||||
|
||||
// unsafe.String(p, n) is available as of Go 1.20.
|
||||
return string(unsafe.Slice(p, n))
|
||||
return unsafe.String(p, n)
|
||||
}
|
||||
|
@ -507,13 +507,6 @@ func roundUpPower2(x int) int {
|
||||
return p2
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (b *uint32sBuffer) alloc(n int) []uint32 {
|
||||
buf := b.buf
|
||||
if len(buf)+n > cap(buf) {
|
||||
|
@ -38,8 +38,7 @@ func (c *defaultContext) init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Use multiple %w-s as of Go 1.20
|
||||
return fmt.Errorf("gl: failed to load: OpenGL.framework: %v, OpenGLES.framework: %v", errGL, errGLES)
|
||||
return fmt.Errorf("gl: failed to load: OpenGL.framework: %w, OpenGLES.framework: %w", errGL, errGLES)
|
||||
}
|
||||
|
||||
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {
|
||||
|
@ -17,8 +17,8 @@
|
||||
package gl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
)
|
||||
@ -29,8 +29,7 @@ var (
|
||||
)
|
||||
|
||||
func (c *defaultContext) init() error {
|
||||
// TODO: Use multiple %w-s as of Go 1.20.
|
||||
var errors []string
|
||||
var errs []error
|
||||
|
||||
// Try OpenGL ES first. Some machines like Android and Raspberry Pi might work only with OpenGL ES.
|
||||
for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
|
||||
@ -40,7 +39,7 @@ func (c *defaultContext) init() error {
|
||||
c.isES = true
|
||||
return nil
|
||||
}
|
||||
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
|
||||
errs = append(errs, fmt.Errorf("gl: Dlopen failed: name: %s: %w", name, err))
|
||||
}
|
||||
|
||||
// Try OpenGL next.
|
||||
@ -54,10 +53,11 @@ func (c *defaultContext) init() error {
|
||||
libGL = lib
|
||||
return nil
|
||||
}
|
||||
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
|
||||
errs = append(errs, fmt.Errorf("gl: Dlopen failed: name: %s: %w", name, err))
|
||||
}
|
||||
|
||||
return fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so: %s", strings.Join(errors, ", "))
|
||||
errs = append([]error{fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so: ")}, errs...)
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {
|
||||
|
@ -136,18 +136,6 @@ func run() error {
|
||||
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(w, `
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}`)
|
||||
}
|
||||
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1054,10 +1054,3 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user