Bunnymark benchmark for the gohan ECS framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

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)
}
}