Skip to content

Commit

Permalink
Check validity when caching
Browse files Browse the repository at this point in the history
Removes basically all performance penalty from the validity check
  • Loading branch information
rekterakathom committed Feb 18, 2024
1 parent e060e00 commit ff4ab4f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions addons/main/functions/fnc_doCallout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ if (isNil "_cachedSounds") then {
_cachedSounds = getArray (_protocolConfig >> _callout);
private _deleted = false;
{
private _sound = _x;
if (_sound == "") then {
private _sound = toLowerANSI _x; // playSound3D is case-insensitive

// File extension must exist for playSound3D to work
if (_sound == "" || !(".ogg" in _sound || ".wss" in _sound || ".wav" in _sound)) then {
_sound = objNull;
_deleted = true;
} else {
if (_sound select [0, 1] != "\") then {
_sound = (getArray (configFile >> "CfgVoice" >> _speaker >> "directories") select 0) + _sound;
};
};

_cachedSounds set [_forEachIndex, _sound];
} forEach _cachedSounds;

Expand All @@ -103,17 +106,7 @@ if (_cachedSounds isEqualTo []) exitWith {
};
};

// Not a valid file to play, extension must be included
private _sound = selectRandom _cachedSounds;
if !(".ogg" in _sound || ".wss" in _sound || ".wav" in _sound) exitWith {
if (GVAR(debug_functions)) then {
private _str = "WARNING: Callout file path %1 for callout %2 for speaker %3 is not valid!";
private _arr = [_str, _sound, _callout, _speaker];
_arr call FUNC(debugLog);
_arr call BIS_fnc_error;
};
};

playSound3D [_sound, _unit, isNull (objectParent _unit), eyePos _unit, 5, pitch _unit, _distance];
[_unit, true] remoteExecCall ["setRandomLip", 0];
[{
Expand Down

0 comments on commit ff4ab4f

Please sign in to comment.