From a956162205f3b83c7b5576da2102915868a58ad1 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Mon, 31 Mar 2014 22:54:30 -0700 Subject: [PATCH] Plumbed Delta and the IdGenerator back through --- bserv/main.go | 11 ++--------- config.go | 2 ++ control.go | 18 ++++++++++++++++++ protocol.go | 5 ++++- robot.go | 1 + 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bserv/main.go b/bserv/main.go index 2b0fdc2..69b5497 100644 --- a/bserv/main.go +++ b/bserv/main.go @@ -49,15 +49,8 @@ func main() { sm := http.NewServeMux() - c := botserv.Controller{ - Idg: botserv.NewIdGenerator(), - Conf: conf, - Games: botserv.MapLock{ - M: make(map[string]*botserv.Game), - }, - Memprofile: *mprofile, - Profile: *profile, - } + c := botserv.NewController(conf, *mprofile, *profile) + go c.Run() sm.Handle("/", botserv.JsonHandler(c.Index)) sm.Handle("/ws/", websocket.Handler(c.AddPlayer)) diff --git a/config.go b/config.go index 7e12d15..b176314 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ import ( type Config struct { Tick int `json:"tick"` // ms Timescale float32 `json:"timescale"` + Delta float32 `json:"delta"` Width int `json:"width"` Height int `json:"height"` Obstacles int `json:"obstacles"` @@ -61,6 +62,7 @@ func LoadConfig(filename string) (Config, error) { return c, errors.New(fmt.Sprintf("config parse error: %s", err)) } } + c.Delta = (float32(c.Tick) / 1000.0) * float32(c.Timescale) log.Printf("final config: %+v", c) return c, nil } diff --git a/control.go b/control.go index 1b2794b..3b10c26 100644 --- a/control.go +++ b/control.go @@ -28,6 +28,24 @@ type Controller struct { Profile string } +func NewController(conf Config, mprof, pprof string) *Controller { + idg := NewIdGenerator() + return &Controller{ + Idg: idg, + Conf: conf, + Games: MapLock{ + M: make(map[string]*Game), + }, + Memprofile: mprof, + Profile: pprof, + } +} + +// TODO Eventually this thing will have a select loop for dealing with game access in a more lock-free manner? +func (c *Controller) Run() { + c.Idg.Run() +} + func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) { log.Println("asked to create a game") diff --git a/protocol.go b/protocol.go index 62cfdd9..18da165 100644 --- a/protocol.go +++ b/protocol.go @@ -288,7 +288,10 @@ encodingLoops: Name: name, Health: 10, Heading: v.Vector2d{1, 0}, - Scanners: make([]Scanner, 0)} + Scanners: make([]Scanner, 0), + Delta: c.Conf.Delta, + idg: c.Idg, + } r.Health = r.Stats.Hp log.Printf("%s: adding robot: %s", p.Id, r.Id) r.reset(game) diff --git a/robot.go b/robot.go index 66542e5..8ad7c22 100644 --- a/robot.go +++ b/robot.go @@ -461,6 +461,7 @@ func (r *Robot) fire(g *Game) *Projectile { Radius: r.Stats.WeaponRadius, Speed: r.Stats.WeaponSpeed, Owner: r, + Delta: r.Delta, } }