Browse Source

Plumbed Delta and the IdGenerator back through

Stephen McQuay 5 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() {
49 49
 
50 50
 	sm := http.NewServeMux()
51 51
 
52
-	c := botserv.Controller{
53
-		Idg:  botserv.NewIdGenerator(),
54
-		Conf: conf,
55
-		Games: botserv.MapLock{
56
-			M: make(map[string]*botserv.Game),
57
-		},
58
-		Memprofile: *mprofile,
59
-		Profile:    *profile,
60
-	}
52
+	c := botserv.NewController(conf, *mprofile, *profile)
53
+	go c.Run()
61 54
 
62 55
 	sm.Handle("/", botserv.JsonHandler(c.Index))
63 56
 	sm.Handle("/ws/", websocket.Handler(c.AddPlayer))

+ 2
- 0
config.go View File

@@ -14,6 +14,7 @@ import (
14 14
 type Config struct {
15 15
 	Tick      int     `json:"tick"` // ms
16 16
 	Timescale float32 `json:"timescale"`
17
+	Delta     float32 `json:"delta"`
17 18
 	Width     int     `json:"width"`
18 19
 	Height    int     `json:"height"`
19 20
 	Obstacles int     `json:"obstacles"`
@@ -61,6 +62,7 @@ func LoadConfig(filename string) (Config, error) {
61 62
 			return c, errors.New(fmt.Sprintf("config parse error: %s", err))
62 63
 		}
63 64
 	}
65
+	c.Delta = (float32(c.Tick) / 1000.0) * float32(c.Timescale)
64 66
 	log.Printf("final config: %+v", c)
65 67
 	return c, nil
66 68
 }

+ 18
- 0
control.go View File

@@ -28,6 +28,24 @@ type Controller struct {
28 28
 	Profile    string
29 29
 }
30 30
 
31
+func NewController(conf Config, mprof, pprof string) *Controller {
32
+	idg := NewIdGenerator()
33
+	return &Controller{
34
+		Idg:  idg,
35
+		Conf: conf,
36
+		Games: MapLock{
37
+			M: make(map[string]*Game),
38
+		},
39
+		Memprofile: mprof,
40
+		Profile:    pprof,
41
+	}
42
+}
43
+
44
+// TODO Eventually this thing will have a select loop for dealing with game access in a more lock-free manner?
45
+func (c *Controller) Run() {
46
+	c.Idg.Run()
47
+}
48
+
31 49
 func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
32 50
 	log.Println("asked to create a game")
33 51
 

+ 4
- 1
protocol.go View File

@@ -288,7 +288,10 @@ encodingLoops:
288 288
 				Name:     name,
289 289
 				Health:   10,
290 290
 				Heading:  v.Vector2d{1, 0},
291
-				Scanners: make([]Scanner, 0)}
291
+				Scanners: make([]Scanner, 0),
292
+				Delta:    c.Conf.Delta,
293
+				idg:      c.Idg,
294
+			}
292 295
 			r.Health = r.Stats.Hp
293 296
 			log.Printf("%s: adding robot: %s", p.Id, r.Id)
294 297
 			r.reset(game)

+ 1
- 0
robot.go View File

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

Loading…
Cancel
Save