Plumbed Delta and the IdGenerator back through
This commit is contained in:
parent
8b52f93ca5
commit
a956162205
@ -49,15 +49,8 @@ func main() {
|
|||||||
|
|
||||||
sm := http.NewServeMux()
|
sm := http.NewServeMux()
|
||||||
|
|
||||||
c := botserv.Controller{
|
c := botserv.NewController(conf, *mprofile, *profile)
|
||||||
Idg: botserv.NewIdGenerator(),
|
go c.Run()
|
||||||
Conf: conf,
|
|
||||||
Games: botserv.MapLock{
|
|
||||||
M: make(map[string]*botserv.Game),
|
|
||||||
},
|
|
||||||
Memprofile: *mprofile,
|
|
||||||
Profile: *profile,
|
|
||||||
}
|
|
||||||
|
|
||||||
sm.Handle("/", botserv.JsonHandler(c.Index))
|
sm.Handle("/", botserv.JsonHandler(c.Index))
|
||||||
sm.Handle("/ws/", websocket.Handler(c.AddPlayer))
|
sm.Handle("/ws/", websocket.Handler(c.AddPlayer))
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Tick int `json:"tick"` // ms
|
Tick int `json:"tick"` // ms
|
||||||
Timescale float32 `json:"timescale"`
|
Timescale float32 `json:"timescale"`
|
||||||
|
Delta float32 `json:"delta"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
Obstacles int `json:"obstacles"`
|
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))
|
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)
|
log.Printf("final config: %+v", c)
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
18
control.go
18
control.go
@ -28,6 +28,24 @@ type Controller struct {
|
|||||||
Profile string
|
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) {
|
func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
|
||||||
log.Println("asked to create a game")
|
log.Println("asked to create a game")
|
||||||
|
|
||||||
|
@ -288,7 +288,10 @@ encodingLoops:
|
|||||||
Name: name,
|
Name: name,
|
||||||
Health: 10,
|
Health: 10,
|
||||||
Heading: v.Vector2d{1, 0},
|
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
|
r.Health = r.Stats.Hp
|
||||||
log.Printf("%s: adding robot: %s", p.Id, r.Id)
|
log.Printf("%s: adding robot: %s", p.Id, r.Id)
|
||||||
r.reset(game)
|
r.reset(game)
|
||||||
|
Loading…
Reference in New Issue
Block a user