default speed: 10, added mem usage to stats debug print

This commit is contained in:
2024-05-22 14:35:33 +02:00
parent ed5eeb8525
commit 78a73aa0c7

14
main.go
View File

@@ -6,6 +6,7 @@ import (
"log" "log"
"math/rand" "math/rand"
"os" "os"
"runtime"
"strconv" "strconv"
"strings" "strings"
@@ -287,12 +288,19 @@ func (game *Game) Draw(screen *ebiten.Image) {
ebitenutil.DebugPrint( ebitenutil.DebugPrint(
screen, screen,
fmt.Sprintf("FPS: %d, TPG: %d, Generations: %d %s", fmt.Sprintf("FPS: %0.2f, TPG: %d, Mem: %0.2f MB, Generations: %d %s",
game.Speed, game.TPG, game.Generations, paused), 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() { func (game *Game) InitGrid() {
grid := &Grid{Data: make([][]int, game.Height)} grid := &Grid{Data: make([][]int, game.Height)}
gridb := &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.Height, "height", "H", 40, "grid height in cells")
pflag.IntVarP(&game.Cellsize, "cellsize", "c", 8, "cell size in pixels") 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.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") pflag.StringVarP(&rule, "rule", "r", "B3/S23", "game rule")