-
Notifications
You must be signed in to change notification settings - Fork 159
add functions to play and stop sounds with speed of sound delay #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
commy2
wants to merge
8
commits into
master
Choose a base branch
from
speed-of-sound-events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f0e7ce
add functions to play and stop sounds with speed of sound delay
commy2 086fb00
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into speed…
commy2 a5d0ae6
fix typos
commy2 50f3661
fix missing arguments
commy2 e625a40
fix a bug
commy2 eac2a56
Merge branch 'master' of https://github.com/CBATeam/CBA_A3 into speed…
commy2 a2e9066
refactor
commy2 52e1b28
refactor
commy2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_executeWhenSoundWaveArrived | ||
|
|
||
| Description: | ||
| Executes code snippet if sound from an origin has arrived at the camera. | ||
|
|
||
| Parameters: | ||
| _origin - Object or position from where sound emits <OBJECT, PosASL> | ||
| _code - Code to execute <CODE> | ||
| _arguments - Additional arguments to pass to code, default [] <ANY> | ||
|
|
||
| Returns: | ||
| Nothing. | ||
|
|
||
| Passed Arguments: | ||
| _origin - Same as above OR null object <OBJECT> | ||
| _position - Current position of origin OR initial position <PosASL> | ||
| _arguments - Same as above <NUMBER> | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| [cursorTarget, {playSound (_this select 2)}, "Alarm"] call CBA_fnc_executeWhenSoundWaveArrived; | ||
| (end) | ||
|
|
||
| Author: | ||
| commy2 | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| if (!hasInterface) exitWith {}; | ||
|
|
||
| params [ | ||
| ["_origin", cameraOn, [objNull, []], [3]], | ||
| ["_code", {}, [{}]], | ||
| ["_arguments", []] | ||
| ]; | ||
|
|
||
| [{ | ||
| params ["_code", "_origin", "_arguments", "_startTime"]; | ||
|
|
||
| // Abort if origin of sound was deleted. | ||
| if (_origin isEqualTo objNull) exitWith { | ||
| true // quit | ||
| }; | ||
|
|
||
| private _position = _origin; | ||
| if (_position isEqualType objNull) then { | ||
| _position = getPosASL _position; | ||
| } else { | ||
| _origin = objNull; | ||
| }; | ||
|
|
||
| private _distanceToCamera = _position vectorDistance AGLToASL positionCameraToWorld [0,0,0]; | ||
| private _travelledDistance = (CBA_missionTime - _startTime) * SPEED_OF_SOUND; | ||
|
|
||
| if (_distanceToCamera < _travelledDistance) exitWith { | ||
| [_origin, _position, _arguments] call _code; | ||
|
|
||
| true // quit | ||
| }; | ||
|
|
||
| false // continue | ||
| }, {}, [_code, _origin, _arguments, CBA_missionTime]] call CBA_fnc_waitUntilAndExecute; | ||
|
|
||
| nil | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_playSoundSOS | ||
|
|
||
| Description: | ||
| Plays sound from object or position with speed of sound delay. | ||
|
|
||
| Parameters: | ||
| _origin - Object that emitted sound <OBJECT, PosASL> | ||
| _sound - CfgSounds class to play, rhs argument of say3D <STRING, ARRAY> | ||
|
|
||
| Returns: | ||
| Sound handler, used to stop the sound. <STRING> | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| _handler = [cursorTarget, "Alarm"] call CBA_fnc_playSoundSOS; | ||
|
|
||
| private _dummy = "#particlesource" createVehicleLocal [0,0,0]; | ||
| _dummy attachTo [tank1, [0,0,0], "memory_point"]; | ||
| [_dummy, "Alarm"] call CBA_fnc_playSoundSOS; | ||
| (end) | ||
|
|
||
| Author: | ||
| commy2 | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| params [["_origin", objNull], ["_sound", "", ["", []]]]; | ||
|
|
||
| if (!isNil QGVAR(publicSounds)) then { | ||
| GVAR(publicSounds) = [] call CBA_fnc_createNamespace; | ||
| }; | ||
|
|
||
| private _id = (GVAR(publicSounds) getVariable ["#id", -1]) + 1; | ||
|
|
||
| if (_id > 1E7) exitWith { | ||
| ERROR_1("Maximum amount of sound ids reached. Sound was %1.", _sound); | ||
| nil | ||
| }; | ||
|
|
||
| GVAR(publicSounds) setVariable ["#id", _id]; | ||
|
|
||
| private _handler = format ["%1:%2", CBA_clientID, _id]; | ||
|
|
||
| if (_origin isEqualType objNull && {typeOf _origin isEqualTo ""}) then { | ||
| // Origin is dummy. | ||
| ["CBA_playSoundSOS", [_origin, _sound, _handler]] call CBA_fnc_globalEvent; | ||
| } else { | ||
| // Origin is position or proper object, @todo CfgAmmo? | ||
| ["CBA_playSoundSOS_createDummy", [_origin, _sound, _handler]] call CBA_fnc_globalEvent; | ||
| }; | ||
|
|
||
| _handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_stopSoundSOS | ||
|
|
||
| Description: | ||
| Stops sound from object or position with speed of sound delay. | ||
|
|
||
| Parameters: | ||
| _handler - Sound handler reported by CBA_fnc_playSoundSOS <ARRAY> | ||
|
|
||
| Returns: | ||
| Nothing. | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| _handler call CBA_fnc_stopSoundSOS; | ||
| (end) | ||
|
|
||
| Author: | ||
| commy2 | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| params [["_handler", "empty", [""]]]; | ||
|
|
||
| ["CBA_stopSoundSOS", _handler] call CBA_fnc_globalEvent; | ||
|
|
||
| nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| if (hasInterface) then { | ||
| ["CBA_playSoundSOS", { | ||
| params ["_origin", "_sound", "_handler"]; | ||
|
|
||
| GVAR(publicSounds) setVariable [_handler, [objNull, _origin]]; | ||
|
|
||
| [_origin, { | ||
| params ["_origin", "", "_args"]; | ||
| _args params ["_sound", "_handler"]; | ||
|
|
||
| private _source = allMissionObjects "#soundonvehicle"; | ||
| _origin say3D _sound; | ||
| _source = (allMissionObjects "#soundonvehicle" - _source) param [0, objNull]; | ||
|
|
||
| GVAR(publicSounds) setVariable [_handler, [_source, _origin]]; | ||
| }, [_sound, _handler]] call CBA_fnc_executeWhenSoundWaveArrived; | ||
| }] call CBA_fnc_addEventHandler; | ||
|
|
||
| ["CBA_stopSoundSOS", { | ||
| params ["_handler"]; | ||
|
|
||
| (GVAR(publicSounds) getVariable [_handler, [nil, objNull]]) params ["", "_origin"]; | ||
|
|
||
| [_origin, { | ||
| params ["", "", "_handler"]; | ||
| (GVAR(publicSounds) getVariable _handler) params ["_source"]; | ||
|
|
||
| deleteVehicle _source; | ||
| }, _handler] call CBA_fnc_executeWhenSoundWaveArrived; | ||
| }] call CBA_fnc_addEventHandler; | ||
|
|
||
| ["CBA_playSoundSOS_createDummy", { | ||
| params ["_origin", "_sound", "_handler"]; | ||
|
|
||
| GVAR(publicSounds) setVariable [_handler, [objNull, _origin]]; | ||
|
|
||
| [_origin, { | ||
| params ["_origin", "_position", "_args"]; | ||
| _args params ["_sound", "_handler"]; | ||
|
|
||
| private _dummy = "#particlesource" createVehicleLocal ASLToAGL _position; | ||
|
|
||
| if (!isNull _origin) then { | ||
| _dummy attachTo [_origin, [0,0,0]]; | ||
| }; | ||
|
|
||
| private _source = allMissionObjects "#soundonvehicle"; | ||
| _dummy say3D _sound; | ||
| _source = (allMissionObjects "#soundonvehicle" - _source) param [0, objNull]; | ||
|
|
||
| GVAR(publicSounds) setVariable [_handler, [_source, _origin]]; | ||
|
|
||
| // Source is deleted by game if sound finished, manually delete dummy. | ||
| [{ | ||
| params ["_source"]; | ||
| isNull _source // return | ||
| }, { | ||
| params ["", "_dummy"]; | ||
| detach _dummy; | ||
| deleteVehicle _dummy; | ||
| }, [_source, _dummy]] call CBA_fnc_waitUntilAndExecute; | ||
| }, [_sound, _handler]] call CBA_fnc_executeWhenSoundWaveArrived; | ||
| }] call CBA_fnc_addEventHandler; | ||
|
|
||
| ["CBA_playSoundSOSLooped", { | ||
| }] call CBA_fnc_addEventHandler; | ||
|
|
||
| ["CBA_stopSoundSOSLooped", { | ||
| params ["_handler"]; | ||
|
|
||
| (GVAR(publicSounds) getVariable [_handler, [nil, objNull]]) params ["", "_origin"]; | ||
|
|
||
| [_origin, { | ||
| params ["", "", "_handler"]; | ||
| (GVAR(publicSounds) getVariable _handler) params ["_source", "_dummy"]; | ||
|
|
||
| deleteVehicle _source; | ||
| deleteVehicle _dummy; | ||
| }, _handler] call CBA_fnc_executeWhenSoundWaveArrived; | ||
| }] call CBA_fnc_addEventHandler; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.