@@ -16,20 +16,20 @@ const configFileName = "config/ssl-game-controller.yaml"
1616
1717// GameController controls a game
1818type 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
3333}
3434
3535// NewGameController creates a new RefBox
@@ -40,6 +40,7 @@ func NewGameController() (c *GameController) {
4040 c .Publisher = NewPublisher (c .Config .Network .PublishAddress )
4141 c .ApiServer = ApiServer {}
4242 c .ApiServer .Consumer = c
43+ c .uiProtocolLastPublish = []* ProtocolEntry {}
4344
4445 c .VisionReceiver = vision .NewReceiver (c .Config .Network .VisionAddress )
4546 c .VisionReceiver .GeometryCallback = c .ProcessGeometry
@@ -161,9 +162,13 @@ func (c *GameController) publish() {
161162
162163// publishUiProtocol publishes the UI protocol, if it has changed
163164func (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 ]) {
165169 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 )
167172 }
168173}
169174
0 commit comments