next try to enhance performance: now using uint9 again and no pointers

This commit is contained in:
2024-07-15 14:21:21 +02:00
parent 89d25db9e7
commit e8ed283233
2 changed files with 49 additions and 34 deletions

View File

@@ -163,14 +163,14 @@ func (scene *ScenePlay) UpdateCells() {
defer wg.Done()
for x := 0; x < scene.Config.Width; x++ {
state := scene.Grids[scene.Index].Data[y][x].State // 0|1 == dead or alive
state := scene.Grids[scene.Index].Data[y][x] // 0|1 == dead or alive
neighbors := scene.Grids[scene.Index].CountNeighbors(x, y)
// actually apply the current rules
nextstate := scene.RuleCheckFunc(state, neighbors)
// change state of current cell in next grid
scene.Grids[next].Data[y][x].State = nextstate
scene.Grids[next].Data[y][x] = nextstate
if scene.Config.ShowEvolution {
// set history to current generation so we can infer the
@@ -418,7 +418,7 @@ func (scene *ScenePlay) SaveRectRLE() {
grid[y] = make([]uint8, width)
for x := 0; x < width; x++ {
grid[y][x] = scene.Grids[scene.Index].Data[y+starty][x+startx].State
grid[y][x] = scene.Grids[scene.Index].Data[y+starty][x+startx]
}
}
@@ -471,7 +471,7 @@ func (scene *ScenePlay) ToggleCellOnCursorPos() {
y := int(worldY) / scene.Config.Cellsize
if x > -1 && y > -1 && x < scene.Config.Width && y < scene.Config.Height {
scene.Grids[scene.Index].Data[y][x].State ^= 1
scene.Grids[scene.Index].Data[y][x] ^= 1
scene.History.Age[y][x] = 1
}
}
@@ -497,7 +497,7 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
if scene.Config.ShowEvolution {
scene.DrawEvolution(screen, x, y, op)
} else {
if scene.Grids[scene.Index].Data[y][x].State == 1 {
if scene.Grids[scene.Index].Data[y][x] == 1 {
scene.World.DrawImage(scene.Theme.Tile(ColLife), op)
}
}
@@ -514,7 +514,7 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) {
age := scene.Generations - scene.History.Age[y][x]
switch scene.Grids[scene.Index].Data[y][x].State {
switch scene.Grids[scene.Index].Data[y][x] {
case Alive:
if age > 50 && scene.Config.ShowEvolution {
scene.World.DrawImage(scene.Theme.Tile(ColOld), op)