|
5 | 5 | "github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon" |
6 | 6 | "github.com/RoboCup-SSL/ssl-game-controller/internal/app/vision" |
7 | 7 | "github.com/RoboCup-SSL/ssl-game-controller/pkg/timer" |
| 8 | + "github.com/RoboCup-SSL/ssl-go-tools/pkg/sslproto" |
8 | 9 | "log" |
9 | 10 | "sync" |
10 | 11 | "time" |
@@ -51,6 +52,8 @@ func NewGameController() (c *GameController) { |
51 | 52 | c.Engine = NewEngine(c.Config.Game) |
52 | 53 | c.timer = timer.NewTimer() |
53 | 54 |
|
| 55 | + c.setupTimeProvider() |
| 56 | + |
54 | 57 | return |
55 | 58 | } |
56 | 59 |
|
@@ -82,6 +85,24 @@ func (c *GameController) Run() { |
82 | 85 | go c.TeamServer.Listen(c.Config.Server.Team.Address) |
83 | 86 | } |
84 | 87 |
|
| 88 | +// setupTimeProvider changes the time provider to the vision receiver, if configured |
| 89 | +func (c *GameController) setupTimeProvider() { |
| 90 | + if c.Config.TimeFromVision { |
| 91 | + c.timer.TimeProvider = func() time.Time { |
| 92 | + return time.Unix(0, 0) |
| 93 | + } |
| 94 | + c.Engine.TimeProvider = c.timer.TimeProvider |
| 95 | + c.VisionReceiver.DetectionCallback = func(frame *sslproto.SSL_DetectionFrame) { |
| 96 | + sec := int64(*frame.TCapture) |
| 97 | + nsec := int64((*frame.TCapture - float64(sec)) * 1e9) |
| 98 | + c.timer.TimeProvider = func() time.Time { |
| 99 | + return time.Unix(sec, nsec) |
| 100 | + } |
| 101 | + c.Engine.TimeProvider = c.timer.TimeProvider |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
85 | 106 | // mainLoop updates several states every full second and publishes the new state |
86 | 107 | func (c *GameController) mainLoop() { |
87 | 108 | defer c.historyPreserver.Close() |
|
0 commit comments