@@ -16,20 +16,20 @@ const configFileName = "config/ssl-game-controller.yaml"
16
16
17
17
// GameController controls a game
18
18
type GameController struct {
19
- Config config.Controller
20
- Publisher Publisher
21
- ApiServer ApiServer
22
- AutoRefServer * rcon.AutoRefServer
23
- TeamServer * rcon.TeamServer
24
- CiServer rcon.CiServer
25
- Engine Engine
26
- statePreserver StatePreserver
27
- numUiProtocolsLastPublish int
28
- outstandingTeamChoice * TeamChoice
29
- ConnectionMutex sync.Mutex
30
- PublishMutex sync.Mutex
31
- StateMutex sync.Mutex
32
- VisionReceiver * vision.Receiver
19
+ Config config.Controller
20
+ Publisher Publisher
21
+ ApiServer ApiServer
22
+ AutoRefServer * rcon.AutoRefServer
23
+ TeamServer * rcon.TeamServer
24
+ CiServer rcon.CiServer
25
+ Engine Engine
26
+ statePreserver StatePreserver
27
+ uiProtocolLastPublish [] * ProtocolEntry
28
+ outstandingTeamChoice * TeamChoice
29
+ ConnectionMutex sync.Mutex
30
+ PublishMutex sync.Mutex
31
+ StateMutex sync.Mutex
32
+ VisionReceiver * vision.Receiver
33
33
}
34
34
35
35
// NewGameController creates a new RefBox
@@ -40,6 +40,7 @@ func NewGameController() (c *GameController) {
40
40
c .Publisher = NewPublisher (c .Config .Network .PublishAddress )
41
41
c .ApiServer = ApiServer {}
42
42
c .ApiServer .Consumer = c
43
+ c .uiProtocolLastPublish = []* ProtocolEntry {}
43
44
44
45
c .VisionReceiver = vision .NewReceiver (c .Config .Network .VisionAddress )
45
46
c .VisionReceiver .GeometryCallback = c .ProcessGeometry
@@ -161,9 +162,13 @@ func (c *GameController) publish() {
161
162
162
163
// publishUiProtocol publishes the UI protocol, if it has changed
163
164
func (c * GameController ) publishUiProtocol () {
164
- if len (c .Engine .PersistentState .Protocol ) != c .numUiProtocolsLastPublish {
165
+ numNewEntries := len (c .Engine .PersistentState .Protocol )
166
+ numPreEntries := len (c .uiProtocolLastPublish )
167
+ if numNewEntries != numPreEntries ||
168
+ (numNewEntries > 0 && c .Engine .PersistentState .Protocol [numNewEntries - 1 ] != c .uiProtocolLastPublish [numPreEntries - 1 ]) {
165
169
c .ApiServer .PublishUiProtocol (c .Engine .PersistentState .Protocol )
166
- c .numUiProtocolsLastPublish = len (c .Engine .PersistentState .Protocol )
170
+ c .uiProtocolLastPublish = make ([]* ProtocolEntry , numNewEntries )
171
+ copy (c .uiProtocolLastPublish , c .Engine .PersistentState .Protocol )
167
172
}
168
173
}
169
174
0 commit comments