Browse Source

Plumbed Delta and the IdGenerator back through

master
Stephen McQuay 6 years ago
parent
commit
a956162205
5 changed files with 27 additions and 10 deletions
  1. +2
    -9
      bserv/main.go
  2. +2
    -0
      config.go
  3. +18
    -0
      control.go
  4. +4
    -1
      protocol.go
  5. +1
    -0
      robot.go

+ 2
- 9
bserv/main.go View File

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

+ 2
- 0
config.go View File

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

+ 18
- 0
control.go View File

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

+ 4
- 1
protocol.go View File

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

+ 1
- 0
robot.go View File

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

Loading…
Cancel
Save