44 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
55 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
66 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/vision"
7+ "github.com/RoboCup-SSL/ssl-game-controller/pkg/refproto"
78 "github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
89 "github.com/RoboCup-SSL/ssl-go-tools/pkg/sslproto"
910 "log"
@@ -20,6 +21,7 @@ type GameController struct {
2021 ApiServer ApiServer
2122 AutoRefServer * rcon.AutoRefServer
2223 TeamServer * rcon.TeamServer
24+ CiServer rcon.CiServer
2325 Engine Engine
2426 historyPreserver HistoryPreserver
2527 numUiProtocolsLastPublish int
@@ -49,6 +51,8 @@ func NewGameController() (c *GameController) {
4951 c .TeamServer .LoadTrustedKeys (c .Config .Server .Team .TrustedKeysDir )
5052 c .TeamServer .ProcessTeamRequest = c .ProcessTeamRequests
5153
54+ c .CiServer = rcon .NewCiServer ()
55+
5256 c .Engine = NewEngine (c .Config .Game , time .Now ().Unix ())
5357
5458 c .setupTimeProvider ()
@@ -78,17 +82,29 @@ func (c *GameController) Run() {
7882 c .TeamServer .AllowedTeamNames = []string {c .Engine .State .TeamState [TeamYellow ].Name ,
7983 c .Engine .State .TeamState [TeamBlue ].Name }
8084
81- go c .mainLoop ()
82- go c .publishToNetwork ()
8385 go c .AutoRefServer .Listen (c .Config .Server .AutoRef .Address )
8486 go c .AutoRefServer .ListenTls (c .Config .Server .AutoRef .AddressTls )
8587 go c .TeamServer .Listen (c .Config .Server .Team .Address )
8688 go c .TeamServer .ListenTls (c .Config .Server .Team .AddressTls )
89+
90+ if c .Config .TimeAcquisitionMode == config .TimeAcquisitionModeSystem ||
91+ c .Config .TimeAcquisitionMode == config .TimeAcquisitionModeVision {
92+ go c .updateLoop ()
93+ go c .publishToNetwork ()
94+ } else if c .Config .TimeAcquisitionMode == config .TimeAcquisitionModeCi {
95+ // do not send multicast packages - mainly for network performance issues, because publish will be called
96+ // more frequently in the CI mode
97+ c .Publisher .Message .Send = func () {}
98+ c .CiServer .TimeConsumer = c .updateCi
99+ go c .CiServer .Listen (c .Config .Server .Ci .Address )
100+ } else {
101+ log .Println ("Unknown time acquisition mode: " , c .Config .TimeAcquisitionMode )
102+ }
87103}
88104
89105// setupTimeProvider changes the time provider to the vision receiver, if configured
90106func (c * GameController ) setupTimeProvider () {
91- if c .Config .TimeFromVision {
107+ if c .Config .TimeAcquisitionMode == config . TimeAcquisitionModeVision {
92108 c .Engine .TimeProvider = func () time.Time {
93109 return time .Unix (0 , 0 )
94110 }
@@ -98,15 +114,27 @@ func (c *GameController) setupTimeProvider() {
98114 }
99115}
100116
101- // mainLoop updates several states every full second and publishes the new state
102- func (c * GameController ) mainLoop () {
117+ // updateLoop calls update() regularly
118+ func (c * GameController ) updateLoop () {
103119 for {
104120 time .Sleep (time .Millisecond * 10 )
121+ c .update ()
122+ }
123+ }
105124
106- newFullSecond , eventTriggered := c .Engine .Update ()
107- if eventTriggered || newFullSecond {
108- c .publish ()
109- }
125+ // updateCi updates the current time to the given time and returns the updated referee message
126+ func (c * GameController ) updateCi (t time.Time ) * refproto.Referee {
127+ c .Engine .TimeProvider = func () time.Time { return t }
128+ c .update ()
129+ c .Publisher .Publish (c .Engine .State )
130+ return c .Publisher .Message .ProtoMsg
131+ }
132+
133+ // update updates several states and publishes the new state to the UI every full second or on events
134+ func (c * GameController ) update () {
135+ newFullSecond , eventTriggered := c .Engine .Update ()
136+ if eventTriggered || newFullSecond {
137+ c .publish ()
110138 }
111139}
112140
0 commit comments