sdl2-life

Conway's Game of Life with go-sdl2
git clone https://www.brianlane.com/git/sdl2-life
Log | Files | Refs | README

commit e90286b9da18a66398ed061f21a04014e18a2f7e
parent 513af793ccde5a9069b1b3f36e23101b6775bd54
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Wed, 27 Nov 2019 17:24:11 -0800

Add -fps option to control the speed

Diffstat:
Mmain.go | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go @@ -15,7 +15,6 @@ import ( const ( threshold = 0.15 - fps = 10 ) /* commandline flags */ @@ -29,6 +28,7 @@ type cmdlineArgs struct { Font string // Path to TTF to use for status bar FontSize int // Size of font in points Rule string // Rulestring to use + Fps int // Frames per Second } /* commandline defaults */ @@ -42,6 +42,7 @@ var cfg = cmdlineArgs{ Font: "/usr/share/fonts/liberation/LiberationMono-Regular.ttf", FontSize: 14, Rule: "B3/S23", + Fps: 10, } /* parseArgs handles parsing the cmdline args and setting values in the global cfg struct */ @@ -55,6 +56,7 @@ func parseArgs() { flag.StringVar(&cfg.Font, "font", cfg.Font, "Path to TTF to use for status bar") flag.IntVar(&cfg.FontSize, "font-size", cfg.FontSize, "Size of font in points") flag.StringVar(&cfg.Rule, "rule", cfg.Rule, "Rulestring Bn.../Sn... (B3/S23)") + flag.IntVar(&cfg.Fps, "fps", cfg.Fps, "Frames per Second update rate (10fps)") flag.Parse() } @@ -313,7 +315,7 @@ func (g *LifeGame) Run() { } // Delay a small amount time.Sleep(1 * time.Millisecond) - if sdl.GetTicks() > fpsTime+(1000/fps) { + if sdl.GetTicks() > fpsTime+(1000/uint32(cfg.Fps)) { if !pause || oneStep { g.NextFrame() fpsTime = sdl.GetTicks()