revert history=>struct, but evolution doesn't work anymore anyway

This commit is contained in:
2024-06-15 13:15:22 +02:00
committed by T.v.Dein
parent 6dec8c74ef
commit 41da9b8536

View File

@@ -22,21 +22,6 @@ const (
DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s" DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s"
) )
type History struct {
Age [][]int64
}
func NewHistory(height, width int) History {
hist := History{}
hist.Age = make([][]int64, height)
for y := 0; y < height; y++ {
hist.Age[y] = make([]int64, width)
}
return hist
}
type ScenePlay struct { type ScenePlay struct {
Game *Game Game *Game
Config *Config Config *Config
@@ -47,7 +32,7 @@ type ScenePlay struct {
Clear bool Clear bool
Grids []*Grid // 2 grids: one current, one next Grids []*Grid // 2 grids: one current, one next
History History // holds state of past dead cells for evolution traces History [][]int64 // holds state of past dead cells for evolution traces
Index int // points to current grid Index int // points to current grid
Generations int64 // Stats Generations int64 // Stats
TicksElapsed int // tick counter for game speed TicksElapsed int // tick counter for game speed
@@ -157,7 +142,7 @@ func (scene *ScenePlay) UpdateCells() {
// deduce the color to use if evolution tracing is enabled // deduce the color to use if evolution tracing is enabled
// 60FPS: // 60FPS:
if state != nextstate { if state != nextstate {
scene.History.Age[y][x] = scene.Generations scene.History[y][x] = scene.Generations
} }
} }
} }
@@ -453,7 +438,7 @@ func (scene *ScenePlay) ToggleCellOnCursorPos(alive uint8) {
if x > -1 && y > -1 && x < scene.Config.Width && y < scene.Config.Height { if x > -1 && y > -1 && x < scene.Config.Width && y < scene.Config.Height {
scene.Grids[scene.Index].Data[y][x].State = alive scene.Grids[scene.Index].Data[y][x].State = alive
scene.History.Age[y][x] = 1 scene.History[y][x] = 1
} }
} }
@@ -493,7 +478,7 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
} }
func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) { func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) {
age := scene.Generations - scene.History.Age[y][x] age := scene.Generations - scene.History[y][x]
switch scene.Grids[scene.Index].Data[y][x].State { switch scene.Grids[scene.Index].Data[y][x].State {
case Alive: case Alive:
@@ -614,7 +599,10 @@ func (scene *ScenePlay) InitGrid() {
gridb, gridb,
} }
scene.History = NewHistory(scene.Config.Height, scene.Config.Width) scene.History = make([][]int64, scene.Config.Height)
for y := 0; y < scene.Config.Height; y++ {
scene.History[y] = make([]int64, scene.Config.Width)
}
} }
func (scene *ScenePlay) Init() { func (scene *ScenePlay) Init() {