tune main loop

This commit is contained in:
Luke Meyers 2020-02-08 21:39:53 -08:00
parent ea9f41e581
commit 54301af870
2 changed files with 12 additions and 15 deletions

View File

@ -1,9 +1,5 @@
package game package game
import (
"log"
)
type Command int type Command int
const ( const (
@ -21,7 +17,7 @@ func PollCommands(s State) []Command {
cmds := make([]Command, len(s.Teams)) cmds := make([]Command, len(s.Teams))
for i := range s.Teams { for i := range s.Teams {
cmd := chooseCommand(s, i) 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 cmds[i] = cmd
} }
return cmds return cmds

21
main.go
View File

@ -53,12 +53,21 @@ func run() error {
if !rs.Animating { if !rs.Animating {
sOld = s sOld = s
} }
w.Update()
frames++
select {
case <-second:
w.SetTitle(fmt.Sprintf("%s | FPS: %d", cfg.Title, frames))
frames = 0
default:
}
} else { } else {
switch { switch {
case w.Pressed(pixelgl.KeyQ): case w.Pressed(pixelgl.KeyQ):
return nil return nil
case w.Pressed(pixelgl.KeySpace) || true: case w.Pressed(pixelgl.KeySpace) || true:
log.Printf("TURN %d", turn) //log.Printf("TURN %d", turn)
rs.Animating = true rs.Animating = true
rs.Frame = 0 rs.Frame = 0
@ -72,16 +81,8 @@ func run() error {
} }
go func() { cmdC <- game.PollCommands(s) }() go func() { cmdC <- game.PollCommands(s) }()
} }
}
w.Update() w.UpdateInput()
frames++
select {
case <-second:
w.SetTitle(fmt.Sprintf("%s | FPS: %d", cfg.Title, frames))
frames = 0
default:
} }
} }
return nil return nil