@@ -14,12 +14,12 @@ const maxDatagramSize = 8192
14
14
type Publisher struct {
15
15
address string
16
16
conn * net.UDPConn
17
- message RefMessage
17
+ Message RefMessage
18
18
}
19
19
20
20
type RefMessage struct {
21
- referee * refproto.Referee
22
- send func ()
21
+ ProtoMsg * refproto.Referee
22
+ Send func ()
23
23
}
24
24
25
25
// NewPublisher creates a new publisher that publishes referee messages via UDP to the teams
@@ -28,8 +28,8 @@ func NewPublisher(address string) (publisher Publisher) {
28
28
publisher .address = address
29
29
30
30
// initialize default referee message
31
- publisher .message = RefMessage {send : publisher .send , referee : new (refproto.Referee )}
32
- initRefereeMessage (publisher .message . referee )
31
+ publisher .Message = RefMessage {Send : publisher .send , ProtoMsg : new (refproto.Referee )}
32
+ initRefereeMessage (publisher .Message . ProtoMsg )
33
33
34
34
publisher .connect ()
35
35
@@ -96,7 +96,7 @@ func initTeamInfo(t *refproto.Referee_TeamInfo) {
96
96
97
97
// Publish the state and command
98
98
func (p * Publisher ) Publish (state * State ) {
99
- p .message .Publish (state )
99
+ p .Message .Publish (state )
100
100
}
101
101
102
102
// Publish the state and command
@@ -111,9 +111,9 @@ func (p *Publisher) send() {
111
111
return
112
112
}
113
113
114
- bytes , err := proto .Marshal (p .message . referee )
114
+ bytes , err := proto .Marshal (p .Message . ProtoMsg )
115
115
if err != nil {
116
- log .Printf ("Could not marshal referee message: %v\n Error: %v" , p .message , err )
116
+ log .Printf ("Could not marshal referee message: %v\n Error: %v" , p .Message , err )
117
117
return
118
118
}
119
119
_ , err = p .conn .Write (bytes )
@@ -124,19 +124,19 @@ func (p *Publisher) send() {
124
124
}
125
125
126
126
func (p * RefMessage ) setState (state * State ) (republish bool ) {
127
- p .referee .GameEvents = mapGameEvents (state .GameEvents )
128
- p .referee .DesignatedPosition = mapLocation (state .PlacementPos )
129
- p .referee .ProposedGameEvents = mapProposals (state .GameEventProposals )
130
-
131
- * p .referee .PacketTimestamp = uint64 (time .Now ().UnixNano () / 1000 )
132
- * p .referee .Stage = mapStage (state .Stage )
133
- * p .referee .StageTimeLeft = int32 (state .StageTimeLeft .Nanoseconds () / 1000 )
134
- * p .referee .BlueTeamOnPositiveHalf = state .TeamState [TeamBlue ].OnPositiveHalf
135
- * p .referee .NextCommand = mapCommand (state .NextCommand , state .NextCommandFor )
136
- * p .referee .CurrentActionTimeRemaining = int32 (state .CurrentActionTimeRemaining .Nanoseconds () / 1000 )
137
-
138
- updateTeam (p .referee .Yellow , state .TeamState [TeamYellow ])
139
- updateTeam (p .referee .Blue , state .TeamState [TeamBlue ])
127
+ p .ProtoMsg .GameEvents = mapGameEvents (state .GameEvents )
128
+ p .ProtoMsg .DesignatedPosition = mapLocation (state .PlacementPos )
129
+ p .ProtoMsg .ProposedGameEvents = mapProposals (state .GameEventProposals )
130
+
131
+ * p .ProtoMsg .PacketTimestamp = uint64 (time .Now ().UnixNano () / 1000 )
132
+ * p .ProtoMsg .Stage = mapStage (state .Stage )
133
+ * p .ProtoMsg .StageTimeLeft = int32 (state .StageTimeLeft .Nanoseconds () / 1000 )
134
+ * p .ProtoMsg .BlueTeamOnPositiveHalf = state .TeamState [TeamBlue ].OnPositiveHalf
135
+ * p .ProtoMsg .NextCommand = mapCommand (state .NextCommand , state .NextCommandFor )
136
+ * p .ProtoMsg .CurrentActionTimeRemaining = int32 (state .CurrentActionTimeRemaining .Nanoseconds () / 1000 )
137
+
138
+ updateTeam (p .ProtoMsg .Yellow , state .TeamState [TeamYellow ])
139
+ updateTeam (p .ProtoMsg .Blue , state .TeamState [TeamBlue ])
140
140
return
141
141
}
142
142
@@ -156,37 +156,37 @@ func (p *RefMessage) sendCommands(state *State) {
156
156
newCommand := mapCommand (state .Command , state .CommandFor )
157
157
158
158
// send the GOAL command based on the team score for compatibility with old behavior
159
- if state .TeamState [TeamYellow ].Goals > int (* p .referee .Yellow .Score ) {
159
+ if state .TeamState [TeamYellow ].Goals > int (* p .ProtoMsg .Yellow .Score ) {
160
160
p .updateCommand (refproto .Referee_GOAL_YELLOW )
161
- p .send ()
161
+ p .Send ()
162
162
p .updateCommand (newCommand )
163
- } else if state .TeamState [TeamBlue ].Goals > int (* p .referee .Blue .Score ) {
163
+ } else if state .TeamState [TeamBlue ].Goals > int (* p .ProtoMsg .Blue .Score ) {
164
164
p .updateCommand (refproto .Referee_GOAL_BLUE )
165
- p .send ()
165
+ p .Send ()
166
166
p .updateCommand (newCommand )
167
- } else if * p .referee .Command != newCommand {
167
+ } else if * p .ProtoMsg .Command != newCommand {
168
168
switch state .Command {
169
169
case CommandBallPlacement ,
170
170
CommandDirect ,
171
171
CommandIndirect ,
172
172
CommandKickoff ,
173
173
CommandPenalty :
174
- if * p .referee .Command != refproto .Referee_STOP {
174
+ if * p .ProtoMsg .Command != refproto .Referee_STOP {
175
175
// send a STOP right before the actual command to be compatible with old behavior
176
176
p .updateCommand (refproto .Referee_STOP )
177
- p .send ()
177
+ p .Send ()
178
178
}
179
179
}
180
180
p .updateCommand (newCommand )
181
181
}
182
182
183
- p .send ()
183
+ p .Send ()
184
184
}
185
185
186
186
func (p * RefMessage ) updateCommand (newCommand refproto.Referee_Command ) {
187
- * p .referee .Command = newCommand
188
- * p .referee .CommandCounter ++
189
- * p .referee .CommandTimestamp = uint64 (time .Now ().UnixNano () / 1000 )
187
+ * p .ProtoMsg .Command = newCommand
188
+ * p .ProtoMsg .CommandCounter ++
189
+ * p .ProtoMsg .CommandTimestamp = uint64 (time .Now ().UnixNano () / 1000 )
190
190
}
191
191
192
192
func mapGameEvents (events []* GameEvent ) []* refproto.GameEvent {
0 commit comments