better setup structure

This commit is contained in:
Baipyrus 2024-04-14 21:29:40 +02:00
parent e57b501178
commit b66f12b7c6

View File

@ -59,17 +59,16 @@ func initGrid(width, height int, parent ...[][]Cell) ([][]Cell, error) {
return cells, nil
}
const FPS = 10
var grid [][]Cell
func setup(callback func([][]Cell), width, height int) {
func setup(callback func([][]Cell), width, height, FPS int) chan bool {
grid, _ = initGrid(width, height)
// Prepare
ticker := time.NewTicker(time.Second / FPS)
// Prepare ticker and finishing flag
ticker := time.NewTicker(time.Second / time.Duration(FPS))
done := make(chan bool)
// Run game loop
go func() {
for {
select {
@ -80,6 +79,9 @@ func setup(callback func([][]Cell), width, height int) {
}
}
}()
// Return flag to be stopped outside
return done
}
func draw(callback func([][]Cell)) {