mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-19 05:21:04 +01:00
Compare commits
1 Commits
shader
...
dimensions
| Author | SHA1 | Date | |
|---|---|---|---|
| 01eeab86f7 |
@@ -8,7 +8,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/repr"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/tlinden/golsky/rle"
|
"github.com/tlinden/golsky/rle"
|
||||||
)
|
)
|
||||||
@@ -67,14 +66,8 @@ func (config *Config) ParseGeom(geom string) error {
|
|||||||
// fit into window
|
// fit into window
|
||||||
config.ScreenWidth = width - (width % config.Width)
|
config.ScreenWidth = width - (width % config.Width)
|
||||||
config.ScreenHeight = height - (height % config.Height)
|
config.ScreenHeight = height - (height % config.Height)
|
||||||
|
|
||||||
if config.ScreenWidth == 0 || config.ScreenHeight == 0 {
|
|
||||||
return errors.New("the number of requested cells don't fit into the requested window size")
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Cellsize = config.ScreenWidth / config.Width
|
config.Cellsize = config.ScreenWidth / config.Width
|
||||||
|
|
||||||
repr.Println(config)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
game.go
4
game.go
@@ -7,16 +7,14 @@ type Game struct {
|
|||||||
Scenes map[SceneName]Scene
|
Scenes map[SceneName]Scene
|
||||||
CurrentScene SceneName
|
CurrentScene SceneName
|
||||||
Config *Config
|
Config *Config
|
||||||
Shader *ebiten.Shader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame(config *Config, shader *ebiten.Shader, startscene SceneName) *Game {
|
func NewGame(config *Config, startscene SceneName) *Game {
|
||||||
game := &Game{
|
game := &Game{
|
||||||
Config: config,
|
Config: config,
|
||||||
Scenes: map[SceneName]Scene{},
|
Scenes: map[SceneName]Scene{},
|
||||||
ScreenWidth: config.ScreenWidth,
|
ScreenWidth: config.ScreenWidth,
|
||||||
ScreenHeight: config.ScreenHeight,
|
ScreenHeight: config.ScreenHeight,
|
||||||
Shader: shader,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup scene[s]
|
// setup scene[s]
|
||||||
|
|||||||
32
main.go
32
main.go
@@ -12,22 +12,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Shader string = `
|
|
||||||
//kage:unit pixels
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
var Alife int
|
|
||||||
|
|
||||||
func Fragment(_ vec4, pos vec2, _ vec4) vec4 {
|
|
||||||
if Alife == 1 {
|
|
||||||
return vec4(0.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return vec4(1.0)
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config, err := ParseCommandline()
|
config, err := ParseCommandline()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -39,13 +23,7 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
shader, err := ebiten.NewShader([]byte(Shader))
|
game := NewGame(config, Play)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(Shader)
|
|
||||||
log.Fatalf("failed to compile shader: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
game := NewGame(config, shader, Play)
|
|
||||||
|
|
||||||
if config.ProfileFile != "" {
|
if config.ProfileFile != "" {
|
||||||
// enable cpu profiling and use fake game loop
|
// enable cpu profiling and use fake game loop
|
||||||
@@ -66,14 +44,6 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fd, err := os.Create("cpu.profile")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
pprof.StartCPUProfile(fd)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
// main loop
|
// main loop
|
||||||
if err := ebiten.RunGame(game); err != nil {
|
if err := ebiten.RunGame(game); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
@@ -409,10 +409,7 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
// we fill the whole screen with a background color, the cells
|
// we fill the whole screen with a background color, the cells
|
||||||
// themselfes will be 1px smaller as their nominal size, producing
|
// themselfes will be 1px smaller as their nominal size, producing
|
||||||
// a nice grey grid with grid lines
|
// a nice grey grid with grid lines
|
||||||
//op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
shaderop := &ebiten.DrawRectShaderOptions{}
|
|
||||||
|
|
||||||
fmt.Println(ebiten.ActualFPS())
|
|
||||||
|
|
||||||
if scene.Config.NoGrid {
|
if scene.Config.NoGrid {
|
||||||
scene.World.Fill(scene.White)
|
scene.World.Fill(scene.White)
|
||||||
@@ -422,25 +419,11 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
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()
|
||||||
// op.GeoM.Translate(float64(x*scene.Config.Cellsize), float64(y*scene.Config.Cellsize))
|
op.GeoM.Translate(float64(x*scene.Config.Cellsize), float64(y*scene.Config.Cellsize))
|
||||||
// age := scene.Generations - scene.History.Data[y][x]
|
|
||||||
|
|
||||||
shaderop.GeoM.Reset()
|
age := scene.Generations - scene.History.Data[y][x]
|
||||||
shaderop.Uniforms = map[string]any{
|
|
||||||
"Alife": scene.Grids[scene.Index].Data[y][x],
|
|
||||||
}
|
|
||||||
|
|
||||||
shaderop.GeoM.Translate(float64(x*scene.Config.Cellsize), float64(y*scene.Config.Cellsize))
|
|
||||||
|
|
||||||
scene.World.DrawRectShader(
|
|
||||||
scene.Config.Cellsize,
|
|
||||||
scene.Config.Cellsize,
|
|
||||||
scene.Game.Shader,
|
|
||||||
shaderop,
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
switch scene.Grids[scene.Index].Data[y][x] {
|
switch scene.Grids[scene.Index].Data[y][x] {
|
||||||
case 1:
|
case 1:
|
||||||
if age > 50 && scene.Config.ShowEvolution {
|
if age > 50 && scene.Config.ShowEvolution {
|
||||||
@@ -464,8 +447,6 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
scene.World.DrawImage(scene.Tiles.White, op)
|
scene.World.DrawImage(scene.Tiles.White, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user