Skip to content

Commit

Permalink
Don't redo network configuration after post-match preload.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Nov 4, 2023
1 parent 9e73c8c commit 87b03f2
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package field
import (
"fmt"
"log"
"reflect"
"time"

"github.com/Team254/cheesy-arena/game"
Expand Down Expand Up @@ -82,6 +83,7 @@ type Arena struct {
matchAborted bool
soundsPlayed map[*game.MatchSound]struct{}
breakDescription string
preloadedTeams *[6]*model.Team
}

type AllianceStation struct {
Expand Down Expand Up @@ -311,9 +313,17 @@ func (arena *Arena) LoadMatch(match *model.Match) error {
return err
}

arena.setupNetwork([6]*model.Team{arena.AllianceStations["R1"].Team, arena.AllianceStations["R2"].Team,
arena.AllianceStations["R3"].Team, arena.AllianceStations["B1"].Team, arena.AllianceStations["B2"].Team,
arena.AllianceStations["B3"].Team})
arena.setupNetwork(
[6]*model.Team{
arena.AllianceStations["R1"].Team,
arena.AllianceStations["R2"].Team,
arena.AllianceStations["R3"].Team,
arena.AllianceStations["B1"].Team,
arena.AllianceStations["B2"].Team,
arena.AllianceStations["B3"].Team,
},
false,
)
}

// Reset the arena state and realtime scores.
Expand Down Expand Up @@ -404,9 +414,17 @@ func (arena *Arena) SubstituteTeams(red1, red2, red3, blue1, blue2, blue3 int) e
arena.CurrentMatch.Blue1 = blue1
arena.CurrentMatch.Blue2 = blue2
arena.CurrentMatch.Blue3 = blue3
arena.setupNetwork([6]*model.Team{arena.AllianceStations["R1"].Team, arena.AllianceStations["R2"].Team,
arena.AllianceStations["R3"].Team, arena.AllianceStations["B1"].Team, arena.AllianceStations["B2"].Team,
arena.AllianceStations["B3"].Team})
arena.setupNetwork(
[6]*model.Team{
arena.AllianceStations["R1"].Team,
arena.AllianceStations["R2"].Team,
arena.AllianceStations["R3"].Team,
arena.AllianceStations["B1"].Team,
arena.AllianceStations["B2"].Team,
arena.AllianceStations["B3"].Team,
},
false,
)
arena.MatchLoadNotifier.Notify()

if arena.CurrentMatch.Type != model.Test {
Expand Down Expand Up @@ -790,11 +808,22 @@ func (arena *Arena) preLoadNextMatch() {
log.Printf("Failed to get model for Team %d while pre-loading next match: %s", teamId, err.Error())
}
}
arena.setupNetwork(teams)
arena.setupNetwork(teams, true)
}

// Asynchronously reconfigures the networking hardware for the new set of teams.
func (arena *Arena) setupNetwork(teams [6]*model.Team) {
func (arena *Arena) setupNetwork(teams [6]*model.Team, isPreload bool) {
if isPreload {
arena.preloadedTeams = &teams
} else if arena.preloadedTeams != nil {
preloadedTeams := *arena.preloadedTeams
arena.preloadedTeams = nil
if reflect.DeepEqual(teams, preloadedTeams) {
// Skip configuring the network; this is the same set of teams that was preloaded.
return
}
}

if arena.EventSettings.NetworkSecurityEnabled {
if arena.EventSettings.Ap2TeamChannel == 0 {
// Only one AP is being used.
Expand Down

0 comments on commit 87b03f2

Please sign in to comment.