mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-18 04:51:05 +01:00
put evolutioin drawing out of Draw(), handle history only if enabled
This commit is contained in:
6
TODO.md
6
TODO.md
@@ -1,14 +1,10 @@
|
|||||||
- add all other options like size etc
|
- add all other options like size etc
|
||||||
- do not process history if turned off
|
|
||||||
- add gif export
|
- add gif export
|
||||||
- add toolbar
|
- add toolbar
|
||||||
- turn input ifs to switch
|
- turn input ifs to switch
|
||||||
- add insert mode for edit like vi
|
- only draw visible part of the world
|
||||||
- use left mouse to drag grid unless insert mode is active
|
|
||||||
- keep supporting middle mouse to drag so that dragging is possible in insert mode
|
|
||||||
- print current mode to the bottom like pause, insert and mark
|
- print current mode to the bottom like pause, insert and mark
|
||||||
- add https://www.ibiblio.org/lifepatterns/october1970.html
|
- add https://www.ibiblio.org/lifepatterns/october1970.html
|
||||||
- use uint8 or bool, history needs not be larger than 256 anyway
|
|
||||||
- history: dont count age but do calc to get index to age tile based on cell age
|
- history: dont count age but do calc to get index to age tile based on cell age
|
||||||
- maybe pre calc neighbors as 8 slice of pointers to neighboring cells to faster do the count
|
- maybe pre calc neighbors as 8 slice of pointers to neighboring cells to faster do the count
|
||||||
- https://mattnakama.com/blog/go-branchless-coding/
|
- https://mattnakama.com/blog/go-branchless-coding/
|
||||||
|
|||||||
44
src/play.go
44
src/play.go
@@ -131,6 +131,7 @@ func (scene *ScenePlay) UpdateCells() {
|
|||||||
// change state of current cell in next grid
|
// change state of current cell in next grid
|
||||||
scene.Grids[next].Data[y][x] = nextstate
|
scene.Grids[next].Data[y][x] = nextstate
|
||||||
|
|
||||||
|
if scene.Config.ShowEvolution {
|
||||||
// set history to current generation so we can infer the
|
// set history to current generation so we can infer the
|
||||||
// age of the cell's state during rendering and use it to
|
// age of the cell's state during rendering and use it to
|
||||||
// deduce the color to use if evolution tracing is enabled
|
// deduce the color to use if evolution tracing is enabled
|
||||||
@@ -143,6 +144,7 @@ func (scene *ScenePlay) UpdateCells() {
|
|||||||
//scene.History.Data[y][x] = (state ^ (1 ^ nextstate)) * (scene.Generations - scene.History.Data[y][x])
|
//scene.History.Data[y][x] = (state ^ (1 ^ nextstate)) * (scene.Generations - scene.History.Data[y][x])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// switch grid for rendering
|
// switch grid for rendering
|
||||||
scene.Index ^= 1
|
scene.Index ^= 1
|
||||||
@@ -459,8 +461,6 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
op.GeoM.Translate(0, 0)
|
op.GeoM.Translate(0, 0)
|
||||||
scene.World.DrawImage(scene.Cache, op)
|
scene.World.DrawImage(scene.Cache, op)
|
||||||
|
|
||||||
var age int64
|
|
||||||
|
|
||||||
for y := 0; y < scene.Config.Height; y++ {
|
for y := 0; y < scene.Config.Height; y++ {
|
||||||
for x := 0; x < scene.Config.Width; x++ {
|
for x := 0; x < scene.Config.Width; x++ {
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
@@ -469,14 +469,35 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
float64(y*scene.Config.Cellsize),
|
float64(y*scene.Config.Cellsize),
|
||||||
)
|
)
|
||||||
|
|
||||||
//age = scene.Generations - scene.History.Data[y][x]
|
if scene.Config.ShowEvolution {
|
||||||
age = scene.History[y][x]
|
scene.DrawEvolution(screen, x, y, op)
|
||||||
|
} else {
|
||||||
|
if scene.Grids[scene.Index].Data[y][x] {
|
||||||
|
scene.World.DrawImage(scene.Tiles.Black, op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scene.DrawMark(scene.World)
|
||||||
|
|
||||||
|
scene.Camera.Render(scene.World, screen)
|
||||||
|
|
||||||
|
scene.DrawDebug(screen)
|
||||||
|
|
||||||
|
op.GeoM.Reset()
|
||||||
|
op.GeoM.Translate(0, 0)
|
||||||
|
|
||||||
|
scene.Game.Screen.DrawImage(screen, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) {
|
||||||
|
age := scene.Generations - scene.History[y][x]
|
||||||
|
|
||||||
switch scene.Grids[scene.Index].Data[y][x] {
|
switch scene.Grids[scene.Index].Data[y][x] {
|
||||||
case Alive:
|
case Alive:
|
||||||
if age > 50 && scene.Config.ShowEvolution {
|
if age > 50 && scene.Config.ShowEvolution {
|
||||||
scene.World.DrawImage(scene.Tiles.Old, op)
|
scene.World.DrawImage(scene.Tiles.Old, op)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
scene.World.DrawImage(scene.Tiles.Black, op)
|
scene.World.DrawImage(scene.Tiles.Black, op)
|
||||||
}
|
}
|
||||||
@@ -496,19 +517,6 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
scene.DrawMark(scene.World)
|
|
||||||
|
|
||||||
scene.Camera.Render(scene.World, screen)
|
|
||||||
|
|
||||||
scene.DrawDebug(screen)
|
|
||||||
|
|
||||||
op.GeoM.Reset()
|
|
||||||
op.GeoM.Translate(0, 0)
|
|
||||||
|
|
||||||
scene.Game.Screen.DrawImage(screen, op)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (scene *ScenePlay) DrawMark(screen *ebiten.Image) {
|
func (scene *ScenePlay) DrawMark(screen *ebiten.Image) {
|
||||||
if scene.Config.Markmode && scene.MarkTaken {
|
if scene.Config.Markmode && scene.MarkTaken {
|
||||||
|
|||||||
Reference in New Issue
Block a user