From 78a73aa0c7d2dc1974ace5fb2c2147898cd02c16 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 22 May 2024 14:35:33 +0200 Subject: [PATCH] default speed: 10, added mem usage to stats debug print --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1d15f2a..1fa7440 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "math/rand" "os" + "runtime" "strconv" "strings" @@ -287,12 +288,19 @@ func (game *Game) Draw(screen *ebiten.Image) { ebitenutil.DebugPrint( screen, - fmt.Sprintf("FPS: %d, TPG: %d, Generations: %d %s", - game.Speed, game.TPG, game.Generations, paused), + fmt.Sprintf("FPS: %0.2f, TPG: %d, Mem: %0.2f MB, Generations: %d %s", + ebiten.ActualTPS(), game.TPG, GetMem(), game.Generations, paused), ) } } +func GetMem() float64 { + var m runtime.MemStats + runtime.ReadMemStats(&m) + + return float64(m.Alloc) / 1024 / 1024 +} + func (game *Game) InitGrid() { grid := &Grid{Data: make([][]int, game.Height)} gridb := &Grid{Data: make([][]int, game.Height)} @@ -398,7 +406,7 @@ func main() { pflag.IntVarP(&game.Height, "height", "H", 40, "grid height in cells") pflag.IntVarP(&game.Cellsize, "cellsize", "c", 8, "cell size in pixels") pflag.IntVarP(&game.Density, "density", "D", 10, "density of random cells") - pflag.IntVarP(&game.TPG, "ticks-per-generation", "t", 1, "game speed: the higher the slower (default: 1)") + pflag.IntVarP(&game.TPG, "ticks-per-generation", "t", 10, "game speed: the higher the slower (default: 10)") pflag.StringVarP(&rule, "rule", "r", "B3/S23", "game rule")