From 54301af870f971faec54abf2555a8775df0a04bf Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Sat, 8 Feb 2020 21:39:53 -0800 Subject: [PATCH] tune main loop --- game/commands.go | 6 +----- main.go | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/game/commands.go b/game/commands.go index 4688053..4e7c164 100644 --- a/game/commands.go +++ b/game/commands.go @@ -1,9 +1,5 @@ package game -import ( - "log" -) - type Command int const ( @@ -21,7 +17,7 @@ func PollCommands(s State) []Command { cmds := make([]Command, len(s.Teams)) for i := range s.Teams { cmd := chooseCommand(s, i) - log.Printf("team %d chose to %v", i, cmd) + //log.Printf("team %d chose to %v", i, cmd) cmds[i] = cmd } return cmds diff --git a/main.go b/main.go index 374b3ef..73cc309 100644 --- a/main.go +++ b/main.go @@ -53,12 +53,21 @@ func run() error { if !rs.Animating { sOld = s } + w.Update() + frames++ + + select { + case <-second: + w.SetTitle(fmt.Sprintf("%s | FPS: %d", cfg.Title, frames)) + frames = 0 + default: + } } else { switch { case w.Pressed(pixelgl.KeyQ): return nil case w.Pressed(pixelgl.KeySpace) || true: - log.Printf("TURN %d", turn) + //log.Printf("TURN %d", turn) rs.Animating = true rs.Frame = 0 @@ -72,16 +81,8 @@ func run() error { } go func() { cmdC <- game.PollCommands(s) }() } - } - w.Update() - frames++ - - select { - case <-second: - w.SetTitle(fmt.Sprintf("%s | FPS: %d", cfg.Title, frames)) - frames = 0 - default: + w.UpdateInput() } } return nil