File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ type GameController struct {
2828 outstandingTeamChoice * TeamChoice
2929 ConnectionMutex sync.Mutex
3030 PublishMutex sync.Mutex
31+ StateMutex sync.Mutex
3132 VisionReceiver * vision.Receiver
3233}
3334
@@ -118,12 +119,16 @@ func (c *GameController) setupTimeProvider() {
118119func (c * GameController ) updateLoop () {
119120 for {
120121 time .Sleep (time .Millisecond * 10 )
122+ c .StateMutex .Lock ()
121123 c .update ()
124+ c .StateMutex .Unlock ()
122125 }
123126}
124127
125128// updateCi updates the current time to the given time and returns the updated referee message
126129func (c * GameController ) updateCi (t time.Time ) * refproto.Referee {
130+ c .StateMutex .Lock ()
131+ defer c .StateMutex .Unlock ()
127132 c .Engine .TimeProvider = func () time.Time { return t }
128133 c .update ()
129134 c .Publisher .Publish (c .Engine .State )
@@ -178,13 +183,16 @@ func (c *GameController) updateOnlineStates() {
178183func (c * GameController ) publishToNetwork () {
179184 for {
180185 time .Sleep (25 * time .Millisecond )
186+ c .StateMutex .Lock ()
181187 c .Publisher .Publish (c .Engine .State )
188+ c .StateMutex .Unlock ()
182189 }
183190}
184191
185192// OnNewEvent processes the given event
186193func (c * GameController ) OnNewEvent (event Event ) {
187-
194+ c .StateMutex .Lock ()
195+ defer c .StateMutex .Unlock ()
188196 if event .GameEvent != nil && ! c .Engine .disabledGameEvent (event .GameEvent .Type ) && c .askForTeamDecisionIfRequired (event ) {
189197 return
190198 }
You can’t perform that action at this time.
0 commit comments