Skip to content

Commit

Permalink
Fix sound regression (FAForever#6208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hdt80bro authored May 22, 2024
1 parent 810e8c5 commit 2f02490
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions lua/SimSyncUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ function SyncCameraRequest(data)
table.insert(Sync.CameraRequests, data)
end

---comment
---@param data any
---@param data SoundBlueprint
function SyncVoice(data)
local Sync = Sync
Sync.Voice = Sync.Voice or { }
Expand Down
4 changes: 2 additions & 2 deletions lua/UserSync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function OnSync()
--Play Sounds
if Sync.Sounds then
for k, v in Sync.Sounds do
PlaySound(Sound{ Bank=v.Bank, Cue=v.Cue })
PlaySound(Sound(v))
end
end

Expand Down Expand Up @@ -302,7 +302,7 @@ function OnSync()
if Sync.Voice then
if not import("/lua/ui/game/missiontext.lua").IsHeadPlaying() then
for k, v in Sync.Voice do
PlayVoice(Sound{ Bank=v.Bank, Cue=v.Cue }, true)
PlayVoice(Sound(v), true)
end
end
end
Expand Down
49 changes: 28 additions & 21 deletions lua/aibrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -739,47 +739,54 @@ AIBrain = Class(AIBrainHQComponent, AIBrainStatisticsComponent, AIBrainJammerCom
},

---@param self AIBrain
---@param string string
---@param key string
---@param sound SoundHandle
PlayVOSound = function(self, string, sound)
if not self.VOTable then
self.VOTable = {}
end

local VO = self.VOSounds[string]
if not VO then
WARN('PlayVOSound: ' .. string .. " not found")
return
end

if not self.VOTable[string] and VO['obs'] and GetFocusArmy() == -1 and self:GetArmyIndex() == 1 then
-- Don't stop sound IF not repeated AND sound is flagged as 'obs' AND i'm observer AND only from PlayerIndex = 1
elseif self.VOTable[string] or GetFocusArmy() ~= self:GetArmyIndex() then
PlayVOSound = function(self, key, sound)
if not self.VOSounds[key] then
WARN("PlayVOSound: " .. key .. " not found")
return
end

local cue, bank
if sound then
cue, bank = GetCueBank(sound)
else
cue, bank = VO['bank'], 'XGG'
-- note: what the VO sound table calls a "bank" is actually a "cue"
cue, bank = self.VOSounds[key]["bank"], "XGG"
end

if not (bank and cue) then
WARN('PlayVOSound: No valid bank/cue for ' .. string)
WARN("PlayVOSound: No valid bank/cue for " .. key)
return
end

self.VOTable[string] = true
ForkThread(self.PlayVOSoundThread, self, string, {
ForkThread(self.PlayVOSoundThread, self, key, {
Cue = cue,
Bank = bank
Bank = bank,
})
end,

---@param self AIBrain
---@param key string
---@param data SoundBlueprint
PlayVOSoundThread = function(self, key, data)
if not self.VOTable then
self.VOTable = {}
end
if self.VOTable[key] then
return
end
local sound = self.VOSounds[key]
local focusArmy = GetFocusArmy()
local armyIndex = self:GetArmyIndex()
if focusArmy ~= armyIndex and not (focusArmy == -1 and armyIndex == 1 and sound.obs) then
return
end

self.VOTable[key] = true

import("/lua/SimSyncUtils.lua").SyncVoice(data)
WaitSeconds(self.VOSounds["timeout"])
WaitSeconds(sound.timeout)

self.VOTable[key] = nil
end,
Expand Down

0 comments on commit 2f02490

Please sign in to comment.