1
0
Fork 0

Plumbed Delta and the IdGenerator back through

Dieser Commit ist enthalten in:
Stephen McQuay 2014-03-31 22:54:30 -07:00
Ursprung 8b52f93ca5
Commit a956162205
5 geänderte Dateien mit 27 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -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))

Datei anzeigen

@ -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
}

Datei anzeigen

@ -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")

Datei anzeigen

@ -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)

Datei anzeigen

@ -461,6 +461,7 @@ func (r *Robot) fire(g *Game) *Projectile {
Radius: r.Stats.WeaponRadius,
Speed: r.Stats.WeaponSpeed,
Owner: r,
Delta: r.Delta,
}
}