Initial commit

This commit is contained in:
Trevor Slocum 2022-07-25 12:02:24 -07:00
commit 0858f6fbf7
27 changed files with 846 additions and 0 deletions

57
LICENSE Normal file
View File

@ -0,0 +1,57 @@
This repository was copied from the mizu bunnymark example and adapted to use
gohan instead.
Below is the license for the adapted version, followed by the license for the
original version.
---
License for repository code.rocketnine.space/tslocum/gohan-bunnymark
MIT License
Copyright (c) 2022 Trevor Slocum <trevor@rocketnine.space>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
License for repository github.com/sedyh/mizu
MIT License
Copyright (c) 2021 Artem Sedykh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14
README.md Normal file
View File

@ -0,0 +1,14 @@
# Bunnymark Benchmark (gohan)
Bunnymark [benchmark](https://en.wikipedia.org/wiki/Benchmark_(computing)) for the [gohan ECS framework](https://code.rocketnine.space/tslocum/gohan)
# Run
```
go run code.rocketnine.space/tslocum/gohan-bunnymark@main
```
# Note
This repository was copied from the [mizu bunnymark example](https://github.com/sedyh/mizu/tree/master/examples/bunnymark)
and adapted to use gohan instead. See LICENSE.

18
assets/bundle.go Normal file
View File

@ -0,0 +1,18 @@
package assets
import (
"embed"
"image/color"
"code.rocketnine.space/tslocum/gohan-bunnymark/helper"
)
// This is where the images, colors and gradients are loaded.
var (
Background = color.RGBA{R: 41, G: 44, B: 45, A: 255}
Bunny = helper.Image(fs, "data/image/mizu-logo.png")
)
//go:embed data
var fs embed.FS

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

5
component/gravity.go Normal file
View File

@ -0,0 +1,5 @@
package component
type Gravity struct {
Value float64
}

6
component/hue.go Normal file
View File

@ -0,0 +1,6 @@
package component
type Hue struct {
Colorful *bool
Value float64
}

5
component/position.go Normal file
View File

@ -0,0 +1,5 @@
package component
type Position struct {
X, Y float64
}

20
component/settings.go Normal file
View File

@ -0,0 +1,20 @@
package component
import (
"time"
"github.com/hajimehoshi/ebiten/v2"
"code.rocketnine.space/tslocum/gohan-bunnymark/helper"
)
type Settings struct {
Ticker *time.Ticker
Sprite *ebiten.Image
Colorful bool
Amount int
Gpu string
Tps *helper.Plot
Fps *helper.Plot
Objects *helper.Plot
}

7
component/sprite.go Normal file
View File

@ -0,0 +1,7 @@
package component
import "github.com/hajimehoshi/ebiten/v2"
type Sprite struct {
Image *ebiten.Image
}

5
component/velocity.go Normal file
View File

@ -0,0 +1,5 @@
package component
type Velocity struct {
X, Y float64
}

28
go.mod Normal file
View File

@ -0,0 +1,28 @@
module code.rocketnine.space/tslocum/gohan-bunnymark
go 1.17
require (
code.rocketnine.space/tslocum/gohan v1.0.0
github.com/hajimehoshi/ebiten/v2 v2.3.7
github.com/jaypipes/ghw v0.9.0
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539
)
require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/jezek/xgb v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/exp/shiny v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
)

121
go.sum Normal file
View File

@ -0,0 +1,121 @@
code.rocketnine.space/tslocum/gohan v1.0.0 h1:WBcJq7nVfmr1EB8bew6xWlB5Q1714yWJ3a9/q6aBBrY=
code.rocketnine.space/tslocum/gohan v1.0.0/go.mod h1:12yOt5Ygl/RVwnnZSVZRuS1W6gCaHJgezcvg8+THk10=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220320163800-277f93cfa958/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f h1:w3h343WgVLKLITcSpwecCDcq0FO8pAv6A/UG86hhFtY=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220712193148-63cf1f4ef61f/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/hajimehoshi/bitmapfont/v2 v2.2.0 h1:E6vzlchynZj6OVohVKFqWkKW348EmDW62K5zPXDi7A8=
github.com/hajimehoshi/bitmapfont/v2 v2.2.0/go.mod h1:Llj2wTYXMuCTJEw2ATNIO6HbFPOoBYPs08qLdFAxOsQ=
github.com/hajimehoshi/ebiten/v2 v2.3.7 h1:a4AUxBZSnQe3MQAfVLkjnTKA4GvLjnTyASeazq/LcZw=
github.com/hajimehoshi/ebiten/v2 v2.3.7/go.mod h1:vxwpo0q0oSi1cIll0Q3Ui33TVZgeHuFVYzIRk7FwuVk=
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.3/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.1.0/go.mod h1:9i0oYbpJ8BhVGkXDKdXKfFthX1JUNfXjeTp944W8TGM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jaypipes/ghw v0.9.0 h1:TWF4wNIGtZcgDJaiNcFgby5BR8s2ixcUe0ydxNO2McY=
github.com/jaypipes/ghw v0.9.0/go.mod h1:dXMo19735vXOjpIBDyDYSp31sB2u4hrtRCMxInqQ64k=
github.com/jaypipes/pcidb v1.0.0 h1:vtZIfkiCUE42oYbJS0TAq9XSfSmcsgo9IdxSm9qzYU8=
github.com/jaypipes/pcidb v1.0.0/go.mod h1:TnYUvqhPBzCKnH34KrIX22kAeEbDCSRJ9cqLRCuNDfk=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jezek/xgb v1.0.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=
github.com/jezek/xgb v1.0.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/exp/shiny v0.0.0-20220722155223-a9213eeb770e h1:pkl1Ko5DrhA4ezwKwdnmO7H1sKmMy9qLuYKRjS7SlmE=
golang.org/x/exp/shiny v0.0.0-20220722155223-a9213eeb770e/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220321031419-a8550c1d254a/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 h1:/eM0PCrQI2xd471rI+snWuu251/+/jpBpZqir2mPdnU=
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 h1:3vUV5x5+3LfQbgk7paCM6INOaJG9xXQbn79xoNkwfIk=
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
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-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=

20
helper/gpu.go Normal file
View File

@ -0,0 +1,20 @@
package helper
import (
"github.com/jaypipes/ghw"
)
func GpuInfo() (gpu string) {
gpu = "Unknown GPU"
info, err := ghw.GPU()
if err != nil {
return
}
for _, gc := range info.GraphicsCards {
if gc.DeviceInfo != nil {
return gc.DeviceInfo.Product.Name
}
}
return
}

49
helper/graphics.go Normal file
View File

@ -0,0 +1,49 @@
package helper
import (
"bytes"
"embed"
"fmt"
"image"
"image/color"
"image/draw"
_ "image/jpeg"
_ "image/png"
"github.com/hajimehoshi/ebiten/v2"
)
func Image(fs embed.FS, filepath string) *ebiten.Image {
data, err := fs.ReadFile(filepath)
if err != nil {
fmt.Println(err)
return ebiten.NewImageFromImage(Checkerboard(25, 32, 4))
}
m, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
fmt.Println(err)
return ebiten.NewImageFromImage(Checkerboard(25, 32, 4))
}
return ebiten.NewImageFromImage(m)
}
func Checkerboard(w, h, cells int) image.Image {
m := image.NewRGBA(Rect(0, 0, w, h))
cellW, cellH := w/cells, h/cells
for i := 0; i < cells; i++ {
for j := 0; j < cells; j++ {
c := color.RGBA{R: 255, B: 254, A: 255}
if (i+j)%2 == 0 {
c = color.RGBA{A: 255}
}
draw.Draw(m, Rect(i*cellW, j*cellH, cellW, cellH), &image.Uniform{C: c}, image.Point{}, draw.Src)
}
}
return m
}
func Rect(x, y, w, h int) image.Rectangle {
return image.Rect(x, y, x+w, y+h)
}

60
helper/plot.go Normal file
View File

@ -0,0 +1,60 @@
package helper
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type Plot struct {
Values []float64
Max float64
Bars int
}
func NewPlot(bars int, max float64) *Plot {
p := &Plot{
Values: make([]float64, bars),
Bars: bars,
Max: max,
}
return p
}
func (p *Plot) Update(value float64) {
p.Values = append(p.Values, value)
if len(p.Values) > p.Bars {
p.Values = p.Values[1:]
}
}
func (p *Plot) Draw(screen *ebiten.Image, x, y, w, h float64) {
ebitenutil.DrawRect(screen, x, y, w, h, color.RGBA{A: 128})
if len(p.Values) < 2 {
return
}
barW := w / float64(p.Bars)
for i := 0; i < p.Bars; i++ {
c := color.RGBA{R: 118, G: 222, B: 211, A: 255}
if i%2 == 0 {
c = color.RGBA{R: 106, G: 196, B: 186, A: 255}
}
height := 0.0
if i < len(p.Values) {
relH := p.Values[i] / p.Max
if relH > 1 {
relH = 1
}
height = relH * h
}
ebitenutil.DrawRect(screen, x+float64(i)*barW, y+h-height+height/2, barW, height/2, c)
}
}
func (p *Plot) Last() float64 {
if len(p.Values) < 1 {
return 0
}
return p.Values[len(p.Values)-1]
}

11
helper/random.go Normal file
View File

@ -0,0 +1,11 @@
package helper
import "math/rand"
func RangeFloat(min, max float64) float64 {
return min + rand.Float64()*(max-min)
}
func Chance(percent float64) bool {
return rand.Float64() > percent
}

21
main.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"log"
"math/rand"
"time"
"code.rocketnine.space/tslocum/gohan-bunnymark/scene"
"github.com/hajimehoshi/ebiten/v2"
)
func main() {
ebiten.SetWindowSize(800, 600)
ebiten.SetWindowSizeLimits(300, 200, -1, -1)
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMaximum)
ebiten.SetWindowResizable(true)
rand.Seed(time.Now().UTC().UnixNano())
if err := ebiten.RunGame(scene.NewGame()); err != nil {
log.Fatal(err)
}
}

62
scene/game.go Normal file
View File

@ -0,0 +1,62 @@
package scene
import (
"time"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/assets"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"code.rocketnine.space/tslocum/gohan-bunnymark/helper"
"code.rocketnine.space/tslocum/gohan-bunnymark/system"
"code.rocketnine.space/tslocum/gohan-bunnymark/world"
"github.com/hajimehoshi/ebiten/v2"
)
type Game struct {
settings gohan.Entity
}
func NewGame() *Game {
g := &Game{}
// Add systems.
gohan.AddSystem(&system.Background{})
gohan.AddSystem(&system.Velocity{})
gohan.AddSystem(&system.Gravity{})
gohan.AddSystem(&system.Bounce{})
gohan.AddSystem(system.NewRender())
gohan.AddSystem(&system.Metrics{})
gohan.AddSystem(&system.Spawn{})
gohan.AddSystem(&system.Profile{})
// Create Settings entity.
g.settings = gohan.NewEntity()
g.settings.AddComponent(&component.Settings{
Ticker: time.NewTicker(500 * time.Millisecond),
Gpu: helper.GpuInfo(),
Tps: helper.NewPlot(20, 60),
Fps: helper.NewPlot(20, 60),
Objects: helper.NewPlot(20, 60000),
Sprite: assets.Bunny,
Colorful: false,
Amount: 100,
})
return &Game{}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
world.ScreenWidth, world.ScreenHeight = outsideWidth, outsideHeight
return world.ScreenWidth, world.ScreenHeight
}
func (g *Game) Update() error {
return gohan.Update()
}
func (g *Game) Draw(screen *ebiten.Image) {
err := gohan.Draw(screen)
if err != nil {
panic(err)
}
}

21
system/background.go Normal file
View File

@ -0,0 +1,21 @@
package system
import (
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/assets"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"github.com/hajimehoshi/ebiten/v2"
)
type Background struct {
Settings *component.Settings
}
func (b *Background) Update(_ gohan.Entity) error {
return gohan.ErrUnregister
}
func (b *Background) Draw(_ gohan.Entity, screen *ebiten.Image) error {
screen.Fill(assets.Background)
return nil
}

45
system/bounce.go Normal file
View File

@ -0,0 +1,45 @@
package system
import (
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"code.rocketnine.space/tslocum/gohan-bunnymark/helper"
"code.rocketnine.space/tslocum/gohan-bunnymark/world"
"github.com/hajimehoshi/ebiten/v2"
)
type Bounce struct {
Position *component.Position
Velocity *component.Velocity
Sprite *component.Sprite
}
func (b *Bounce) Update(e gohan.Entity) error {
sw, sh := float64(world.ScreenWidth), float64(world.ScreenHeight)
iw, ih := float64(b.Sprite.Image.Bounds().Dx()), float64(b.Sprite.Image.Bounds().Dy())
relW, relH := iw/sw, ih/sh
if b.Position.X+relW > 1 {
b.Velocity.X *= -1
b.Position.X = 1 - relW
}
if b.Position.X < 0 {
b.Velocity.X *= -1
b.Position.X = 0
}
if b.Position.Y+relH > 1 {
b.Velocity.Y *= -0.85
b.Position.Y = 1 - relH
if helper.Chance(0.5) {
b.Velocity.Y -= helper.RangeFloat(0, 0.009)
}
}
if b.Position.Y < 0 {
b.Velocity.Y = 0
b.Position.Y = 0
}
return nil
}
func (g *Bounce) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

21
system/gravity.go Normal file
View File

@ -0,0 +1,21 @@
package system
import (
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"github.com/hajimehoshi/ebiten/v2"
)
type Gravity struct {
Velocity *component.Velocity
Gravity *component.Gravity
}
func (g *Gravity) Update(_ gohan.Entity) error {
g.Velocity.Y += g.Gravity.Value
return nil
}
func (g *Gravity) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

58
system/metrics.go Normal file
View File

@ -0,0 +1,58 @@
package system
import (
"fmt"
"image/color"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"code.rocketnine.space/tslocum/gohan-bunnymark/world"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/colornames"
"golang.org/x/image/font/basicfont"
)
type Metrics struct {
Settings *component.Settings
}
func (m *Metrics) Update(_ gohan.Entity) error {
s := m.Settings
select {
case <-s.Ticker.C:
s.Objects.Update(float64(gohan.CurrentEntities()))
s.Tps.Update(ebiten.CurrentTPS())
s.Fps.Update(ebiten.CurrentFPS())
default:
}
return nil
}
func (m *Metrics) Draw(_ gohan.Entity, screen *ebiten.Image) error {
s := m.Settings
str := fmt.Sprintf(
"GPU: %s\nTPS: %.2f, FPS: %.2f, Objects: %.f\nBatching: %t, Amount: %d\nResolution: %dx%d",
s.Gpu, s.Tps.Last(), s.Fps.Last(), s.Objects.Last(),
!s.Colorful, s.Amount,
world.ScreenWidth, world.ScreenHeight,
)
rect := text.BoundString(basicfont.Face7x13, str)
width, height := float64(rect.Dx()), float64(rect.Dy())
padding := 20.0
rectW, rectH := width+padding, height+padding
plotW, plotH := 100.0, 40.0
ebitenutil.DrawRect(screen, 0, 0, rectW, rectH, color.RGBA{A: 128})
text.Draw(screen, str, basicfont.Face7x13, int(padding)/2, 10+int(padding)/2, colornames.White)
s.Tps.Draw(screen, 0, padding+rectH, plotW, plotH)
s.Fps.Draw(screen, 0, padding+rectH*2, plotW, plotH)
s.Objects.Draw(screen, 0, padding+rectH*3, plotW, plotH)
return nil
}

57
system/profile.go Normal file
View File

@ -0,0 +1,57 @@
package system
import (
"fmt"
"log"
"os"
"path"
"runtime"
"runtime/pprof"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Profile struct {
Settings *component.Settings
cpuProfile *os.File
}
func (s *Profile) Update(_ gohan.Entity) error {
if inpututil.IsKeyJustPressed(ebiten.KeyP) {
if s.cpuProfile != nil {
pprof.StopCPUProfile()
s.cpuProfile.Close()
s.cpuProfile = nil
log.Println("Stopped profiling")
} else {
log.Println("Starting profiling...")
runtime.SetCPUProfileRate(10000)
homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to determine home directory: %s", err)
}
s.cpuProfile, err = os.Create(path.Join(homeDir, "gohan.prof"))
if err != nil {
return fmt.Errorf("failed to create cpu profile: %s", err)
}
err = pprof.StartCPUProfile(s.cpuProfile)
if err != nil {
return fmt.Errorf("failed to start cpu profile: %s", err)
}
}
}
return nil
}
func (s *Profile) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

41
system/render.go Normal file
View File

@ -0,0 +1,41 @@
package system
import (
"code.rocketnine.space/tslocum/gohan-bunnymark/world"
"github.com/hajimehoshi/ebiten/v2"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
)
type Render struct {
Position *component.Position
Sprite *component.Sprite
Hue *component.Hue
op *ebiten.DrawImageOptions
}
func NewRender() *Render {
return &Render{
op: &ebiten.DrawImageOptions{},
}
}
func (r *Render) Update(_ gohan.Entity) error {
return gohan.ErrUnregister
}
func (r *Render) Draw(_ gohan.Entity, screen *ebiten.Image) error {
op := r.op
op.GeoM.Reset()
op.ColorM.Reset()
sw, sh := float64(world.ScreenWidth), float64(world.ScreenHeight)
op.GeoM.Translate(r.Position.X*sw, r.Position.Y*sh)
if *r.Hue.Colorful {
op.ColorM.RotateHue(r.Hue.Value)
}
screen.DrawImage(r.Sprite.Image, op)
return nil
}

66
system/spawn.go Normal file
View File

@ -0,0 +1,66 @@
package system
import (
"math"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"code.rocketnine.space/tslocum/gohan-bunnymark/helper"
)
type Spawn struct {
Settings *component.Settings
}
func (s *Spawn) Update(e gohan.Entity) error {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
s.addBunnies()
}
if ids := ebiten.AppendTouchIDs(nil); len(ids) > 0 {
s.addBunnies() // not accurate, cause no input manager for this
}
if _, offset := ebiten.Wheel(); offset != 0 {
s.Settings.Amount += int(offset * 10)
if s.Settings.Amount < 0 {
s.Settings.Amount = 0
}
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
s.Settings.Colorful = !s.Settings.Colorful
}
return nil
}
func (s *Spawn) addBunnies() {
numEntities := len(gohan.AllEntities())
// Spawns specific amount of bunnies at the edges of the screen
// It will alternately add bunnies to the left and right corners of the screen
for i := 0; i < s.Settings.Amount; i++ {
e := gohan.NewEntity()
e.AddComponent(&component.Position{
X: float64(numEntities % 2), // Alternate screen edges
})
e.AddComponent(&component.Velocity{
X: helper.RangeFloat(0, 0.005),
Y: helper.RangeFloat(0.0025, 0.005)})
e.AddComponent(&component.Hue{
Colorful: &s.Settings.Colorful,
Value: helper.RangeFloat(0, 2*math.Pi),
})
e.AddComponent(&component.Gravity{Value: 0.00095})
e.AddComponent(&component.Sprite{Image: s.Settings.Sprite})
numEntities++
}
}
func (s *Spawn) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

22
system/velocity.go Normal file
View File

@ -0,0 +1,22 @@
package system
import (
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan-bunnymark/component"
"github.com/hajimehoshi/ebiten/v2"
)
type Velocity struct {
Position *component.Position
Velocity *component.Velocity
}
func (v *Velocity) Update(_ gohan.Entity) error {
v.Position.X += v.Velocity.X
v.Position.Y += v.Velocity.Y
return nil
}
func (v *Velocity) Draw(_ gohan.Entity, _ *ebiten.Image) error {
return gohan.ErrUnregister
}

6
world/world.go Normal file
View File

@ -0,0 +1,6 @@
package world
var (
ScreenWidth int
ScreenHeight int
)