Skip to content

Commit

Permalink
Add warning sound when there is one minute remaining in a timeout (cl…
Browse files Browse the repository at this point in the history
…oses #121).
  • Loading branch information
patfair committed Apr 30, 2022
1 parent c957ab9 commit d4d4292
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
12 changes: 9 additions & 3 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ func (arena *Arena) StartTimeout(durationSec int) error {
}

game.MatchTiming.TimeoutDurationSec = durationSec
game.UpdateMatchSounds()
arena.soundsPlayed = make(map[*game.MatchSound]struct{})
arena.MatchTimingNotifier.Notify()
arena.MatchState = TimeoutActive
arena.MatchStartTime = time.Now()
Expand Down Expand Up @@ -458,7 +460,6 @@ func (arena *Arena) Update() {
case TimeoutActive:
if matchTimeSec >= float64(game.MatchTiming.TimeoutDurationSec) {
arena.MatchState = PostTimeout
arena.playSound("end")
go func() {
// Leave the timer on the screen briefly at the end of the timeout period.
time.Sleep(time.Second * matchEndScoreDwellSec)
Expand Down Expand Up @@ -798,7 +799,7 @@ func (arena *Arena) handleEstop(station string, state bool) {
}

func (arena *Arena) handleSounds(matchTimeSec float64) {
if arena.MatchState == PreMatch || arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout {
if arena.MatchState == PreMatch {
// Only apply this logic during a match.
return
}
Expand All @@ -808,8 +809,13 @@ func (arena *Arena) handleSounds(matchTimeSec float64) {
// Skip sounds with negative timestamps; they are meant to only be triggered explicitly.
continue
}
if sound.Timeout && !(arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout) ||
!sound.Timeout && (arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout) {
// Skip timeout sounds if this is a regular match, and vice versa.
continue
}
if _, ok := arena.soundsPlayed[sound]; !ok {
if matchTimeSec > sound.MatchTimeSec {
if matchTimeSec > sound.MatchTimeSec && matchTimeSec-sound.MatchTimeSec < 1 {
arena.playSound(sound.Name)
arena.soundsPlayed[sound] = struct{}{}
}
Expand Down
60 changes: 52 additions & 8 deletions game/match_sounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type MatchSound struct {
Name string
FileExtension string
MatchTimeSec float64
Timeout bool
}

// List of sounds and how many seconds into the match they are played. A negative time indicates that the sound can only
Expand All @@ -17,13 +18,56 @@ var MatchSounds []*MatchSound

func UpdateMatchSounds() {
MatchSounds = []*MatchSound{
{"start", "wav", 0},
{"end", "wav", float64(MatchTiming.AutoDurationSec)},
{"resume", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec)},
{"warning", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec +
MatchTiming.TeleopDurationSec - MatchTiming.WarningRemainingDurationSec)},
{"end", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec +
MatchTiming.TeleopDurationSec)},
{"abort", "wav", -1},
{
"start",
"wav",
0,
false,
},
{
"end",
"wav",
float64(MatchTiming.AutoDurationSec),
false,
},
{
"resume",
"wav",
float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec),
false,
},
{
"warning",
"wav",
float64(
MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec + MatchTiming.TeleopDurationSec -
MatchTiming.WarningRemainingDurationSec,
),
false,
},
{
"end",
"wav",
float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec + MatchTiming.TeleopDurationSec),
false,
},
{
"timeout_warning",
"wav",
float64(MatchTiming.TimeoutDurationSec - MatchTiming.TimeoutWarningRemainingDurationSec),
true,
},
{
"end",
"wav",
float64(MatchTiming.TimeoutDurationSec),
true,
},
{
"abort",
"wav",
-1,
false,
},
}
}
15 changes: 8 additions & 7 deletions game/match_timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ package game
import "time"

var MatchTiming = struct {
WarmupDurationSec int
AutoDurationSec int
PauseDurationSec int
TeleopDurationSec int
WarningRemainingDurationSec int
TimeoutDurationSec int
}{0, 15, 2, 135, 30, 0}
WarmupDurationSec int
AutoDurationSec int
PauseDurationSec int
TeleopDurationSec int
WarningRemainingDurationSec int
TimeoutDurationSec int
TimeoutWarningRemainingDurationSec int
}{0, 15, 2, 135, 30, 0, 60}

func GetDurationToAutoEnd() time.Duration {
return time.Duration(MatchTiming.WarmupDurationSec+MatchTiming.AutoDurationSec) * time.Second
Expand Down
Binary file added static/audio/timeout_warning.wav
Binary file not shown.

0 comments on commit d4d4292

Please sign in to comment.