From 9e1cd272f750babb61ef125fdbc01fa604aa4f47 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Mon, 14 Apr 2014 00:39:42 -0700 Subject: [PATCH] Fixed warnings generated by go vet --- control.go | 2 +- game.go | 1 - obstacle.go | 4 ++-- protocol.go | 2 +- robot.go | 6 +++--- robot_test.go | 48 ++++++++++++++++++++++++------------------------ 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/control.go b/control.go index d7d60b4..0cb5043 100644 --- a/control.go +++ b/control.go @@ -72,7 +72,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) { if req.Method == "POST" { body, err := ioutil.ReadAll(req.Body) if err != nil { - log.Printf("unable to read request body:", err) + log.Printf("unable to read request body: %v", err) } req.Body.Close() cfg := struct { diff --git a/game.go b/game.go index 46aa458..58d9ab0 100644 --- a/game.go +++ b/game.go @@ -337,7 +337,6 @@ func (g *Game) run() { g.sendUpdate(payload) } } - log.Println("run done") } // sendGameOver is a special method that sends a GameOver object to the clients diff --git a/obstacle.go b/obstacle.go index d6982ac..548804e 100644 --- a/obstacle.go +++ b/obstacle.go @@ -18,8 +18,8 @@ func (o Obstacle) distance_from_point(p v.Point2d) float32 { dist = math.Min(dist, float64(p.Sub(o.Bounds.A).Mag())) dist = math.Min(dist, float64(p.Sub(o.Bounds.B).Mag())) - dist = math.Min(dist, float64(p.Sub(v.Point2d{o.Bounds.A.X, o.Bounds.B.Y}).Mag())) - dist = math.Min(dist, float64(p.Sub(v.Point2d{o.Bounds.B.X, o.Bounds.A.Y}).Mag())) + dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.A.X, Y: o.Bounds.B.Y}).Mag())) + dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.B.X, Y: o.Bounds.A.Y}).Mag())) return float32(dist) } diff --git a/protocol.go b/protocol.go index 6592dd6..3d97d13 100644 --- a/protocol.go +++ b/protocol.go @@ -306,7 +306,7 @@ encodingLoops: Id: c.Idg.Hash(), Name: name, Health: 10, - Heading: v.Vector2d{1, 0}, + Heading: v.Vector2d{X: 1, Y: 0}, Scanners: make([]Scanner, 0), Delta: c.Conf.Delta, idg: c.Idg, diff --git a/robot.go b/robot.go index 7359ddb..477c8f4 100644 --- a/robot.go +++ b/robot.go @@ -32,8 +32,8 @@ type Robot struct { Hit bool `json:"hit"` Probe *v.Point2d `json:"probe"` ProbeResult *Collision `json:"probe_result"` - gameStats *BotStats `json:-` - Delta float32 `json:-` + gameStats *BotStats `json:"-"` + Delta float32 `json:"-"` idg *IdGenerator } @@ -491,7 +491,7 @@ func (r *Robot) reset(g *Game) { // Check Obstacles retry := false for _, obj := range g.obstacles { - _, inside, _ := v.RectIntersection(obj.Bounds, r.Position, v.Vector2d{0, 0}) + _, inside, _ := v.RectIntersection(obj.Bounds, r.Position, v.Vector2d{X: 0, Y: 0}) if inside { retry = true } diff --git a/robot_test.go b/robot_test.go index 329a20c..dd17ac5 100644 --- a/robot_test.go +++ b/robot_test.go @@ -28,24 +28,24 @@ func TestCollision(t *testing.T) { obstacles: []Obstacle{ Obstacle{ Bounds: v.AABB2d{ - v.Point2d{200, 100}, - v.Point2d{300, 200}, + A: v.Point2d{X: 200, Y: 100}, + B: v.Point2d{X: 300, Y: 200}, }, }, Obstacle{ Bounds: v.AABB2d{ - v.Point2d{400, 200}, - v.Point2d{600, 300}, + A: v.Point2d{X: 400, Y: 200}, + B: v.Point2d{X: 600, Y: 300}, }, }, }, }, r: Robot{ - Position: v.Point2d{100, 100}, + Position: v.Point2d{X: 100, Y: 100}, // Heading: v.Vector2d{1, 1}, }, - target: v.Vector2d{900, 350}, - location: &v.Point2d{200, 138.88889}, + target: v.Vector2d{X: 900, Y: 350}, + location: &v.Point2d{X: 200, Y: 138.88889}, collision: true, }, // shouldn't intersect at all @@ -56,16 +56,16 @@ func TestCollision(t *testing.T) { obstacles: []Obstacle{ Obstacle{ Bounds: v.AABB2d{ - v.Point2d{200, 100}, - v.Point2d{300, 200}, + A: v.Point2d{X: 200, Y: 100}, + B: v.Point2d{X: 300, Y: 200}, }, }, }, }, r: Robot{ - Position: v.Point2d{100, 100}, + Position: v.Point2d{X: 100, Y: 100}, }, - target: v.Vector2d{0, 0}, + target: v.Vector2d{X: 0, Y: 0}, collision: false, }, } @@ -103,40 +103,40 @@ func TestProbeResultType(t *testing.T) { obstacles: []Obstacle{ Obstacle{ Bounds: v.AABB2d{ - v.Point2d{200, 100}, - v.Point2d{300, 200}, + A: v.Point2d{X: 200, Y: 100}, + B: v.Point2d{X: 300, Y: 200}, }, }, Obstacle{ Bounds: v.AABB2d{ - v.Point2d{400, 200}, - v.Point2d{600, 300}, + A: v.Point2d{X: 400, Y: 200}, + B: v.Point2d{X: 600, Y: 300}, }, }, }, - players: make(map[*player]bool), + players: make(map[*Player]bool), } r1 := Robot{ - Position: v.Point2d{100, 100}, - Probe: &v.Point2d{900, 350}, + Position: v.Point2d{X: 100, Y: 100}, + Probe: &v.Point2d{X: 900, Y: 350}, Id: "Bilbo's Bot", } - p1 := player{ + p1 := Player{ Robots: []*Robot{&r1}, - protoTalker: protoTalker{ + ProtoTalker: ProtoTalker{ Id: "bilbo", }, } r2 := Robot{ - Position: v.Point2d{100, 200}, - Probe: &v.Point2d{100, 90}, + Position: v.Point2d{X: 100, Y: 200}, + Probe: &v.Point2d{X: 100, Y: 90}, Id: "Frodo's Bot", } - p2 := player{ + p2 := Player{ Robots: []*Robot{&r2}, - protoTalker: protoTalker{ + ProtoTalker: ProtoTalker{ Id: "Frodo", }, }