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 {
28
28
outstandingTeamChoice * TeamChoice
29
29
ConnectionMutex sync.Mutex
30
30
PublishMutex sync.Mutex
31
+ StateMutex sync.Mutex
31
32
VisionReceiver * vision.Receiver
32
33
}
33
34
@@ -118,12 +119,16 @@ func (c *GameController) setupTimeProvider() {
118
119
func (c * GameController ) updateLoop () {
119
120
for {
120
121
time .Sleep (time .Millisecond * 10 )
122
+ c .StateMutex .Lock ()
121
123
c .update ()
124
+ c .StateMutex .Unlock ()
122
125
}
123
126
}
124
127
125
128
// updateCi updates the current time to the given time and returns the updated referee message
126
129
func (c * GameController ) updateCi (t time.Time ) * refproto.Referee {
130
+ c .StateMutex .Lock ()
131
+ defer c .StateMutex .Unlock ()
127
132
c .Engine .TimeProvider = func () time.Time { return t }
128
133
c .update ()
129
134
c .Publisher .Publish (c .Engine .State )
@@ -178,13 +183,16 @@ func (c *GameController) updateOnlineStates() {
178
183
func (c * GameController ) publishToNetwork () {
179
184
for {
180
185
time .Sleep (25 * time .Millisecond )
186
+ c .StateMutex .Lock ()
181
187
c .Publisher .Publish (c .Engine .State )
188
+ c .StateMutex .Unlock ()
182
189
}
183
190
}
184
191
185
192
// OnNewEvent processes the given event
186
193
func (c * GameController ) OnNewEvent (event Event ) {
187
-
194
+ c .StateMutex .Lock ()
195
+ defer c .StateMutex .Unlock ()
188
196
if event .GameEvent != nil && ! c .Engine .disabledGameEvent (event .GameEvent .Type ) && c .askForTeamDecisionIfRequired (event ) {
189
197
return
190
198
}
You can’t perform that action at this time.
0 commit comments