mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
- Optimize getDetectedObject
- Cache detected mines for 0.15 s - Call detectorLoop every 0.05 s instead of 0.01s - Compile a dictionary of detectable classnames from config at start - Switch to playSound3d for global effect - Remove dummy - Change config entries to support playSound3d - Cache getDetectorConfig for better interaction menu performance - Change sound to mono wss - Close #4049
This commit is contained in:
parent
e40415b628
commit
e26eda3ac2
@ -1,10 +1,10 @@
|
||||
class ACE_detector {
|
||||
class detectableObjects {
|
||||
};
|
||||
class detectors {
|
||||
class ACE_VMM3 {
|
||||
radius = 2.5;
|
||||
sounds[] = {"ace_detector_1", "ace_detector_2", "ace_detector_3", "ace_detector_4"};
|
||||
name = "ace_detector_1";
|
||||
sound = QUOTE(PATHTO_R(sounds\metal_detector.wss));
|
||||
pitchs[] = {1, 0.9, 0.8, 0.7};
|
||||
};
|
||||
class ACE_VMH3: ACE_VMM3 {
|
||||
};
|
||||
|
@ -1,22 +0,0 @@
|
||||
class CfgSounds {
|
||||
class ace_detector_1 {
|
||||
name = "ace_detector_1";
|
||||
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 1};
|
||||
titles[] = {};
|
||||
};
|
||||
class ace_detector_2 {
|
||||
name = "ace_detector_2";
|
||||
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.9};
|
||||
titles[] = {};
|
||||
};
|
||||
class ace_detector_3 {
|
||||
name = "ace_detector_3";
|
||||
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.8};
|
||||
titles[] = {};
|
||||
};
|
||||
class ace_detector_4 {
|
||||
name = "ace_detector_4";
|
||||
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.7};
|
||||
titles[] = {};
|
||||
};
|
||||
};
|
@ -15,8 +15,6 @@ class CfgVehicles {
|
||||
displayName = CSTRING(ActivateDetector);
|
||||
condition = QUOTE(call FUNC(canActivateDetector));
|
||||
statement = QUOTE(call FUNC(activateDetector));
|
||||
showDisabled = 0;
|
||||
priority = 0.1;
|
||||
icon = QPATHTOF(ui\icon_mineDetectorOn.paa);
|
||||
exceptions[] = {};
|
||||
};
|
||||
@ -24,8 +22,6 @@ class CfgVehicles {
|
||||
displayName = CSTRING(DeactivateDetector);
|
||||
condition = QUOTE(call FUNC(canDeactivateDetector));
|
||||
statement = QUOTE(call FUNC(deactivateDetector));
|
||||
showDisabled = 0;
|
||||
priority = 0.1;
|
||||
icon = QPATHTOF(ui\icon_mineDetectorOff.paa);
|
||||
exceptions[] = {};
|
||||
};
|
||||
|
@ -1,27 +1,30 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
// Create a dictionary to store detector configs
|
||||
GVAR(detectorConfigs) = call CBA_fnc_createNamespace;
|
||||
|
||||
// Create a dictionary of detectable classnames
|
||||
GVAR(detectableClasses) = call CBA_fnc_createNamespace;
|
||||
{
|
||||
if ((getNumber (_x >> QGVAR(detectable))) == 1) then {
|
||||
GVAR(detectableClasses) setVariable [configName _x, true];
|
||||
};
|
||||
} forEach (configProperties [configFile >> "CfgVehicles", "isClass _x", true]);
|
||||
{
|
||||
if ((getNumber (_x >> QGVAR(detectable))) == 1) then {
|
||||
GVAR(detectableClasses) setVariable [configName _x, true];
|
||||
};
|
||||
} forEach (configProperties [configFile >> "CfgAmmo", "isClass _x", true]);
|
||||
|
||||
|
||||
[QGVAR(detectorEnabled), {
|
||||
params ["_unit", "_type"];
|
||||
private _config = [_type] call FUNC(getDetectorConfig);
|
||||
|
||||
private _helperObject = "ACE_LogicDummy" createVehicleLocal (getPos _unit);
|
||||
_unit setVariable [QGVAR(helperLogic), _helperObject];
|
||||
|
||||
[FUNC(detectorLoop), 0.01, [_unit, _type, _config, CBA_missionTime, _helperObject]] call CBA_fnc_addPerFrameHandler;
|
||||
[FUNC(detectorLoop), 0.05, [_unit, _type, _config, CBA_missionTime - 0.25]] call CBA_fnc_addPerFrameHandler;
|
||||
}] call CBA_fnc_addEventHandler;
|
||||
|
||||
[QGVAR(detectorDisabled), {
|
||||
params ["_unit", "_type"];
|
||||
private _helperObject = _unit getVariable [QGVAR(helperLogic), objNull];
|
||||
if !(isNull _helperObject) then {
|
||||
deleteVehicle _helperObject;
|
||||
};
|
||||
}] call CBA_fnc_addEventHandler;
|
||||
|
||||
|
||||
|
||||
//Shows detector and mine posistions in 3d when debug is on
|
||||
// Shows detector and mine posistions in 3d when debug is on
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
GVAR(debugDetector) = [];
|
||||
addMissionEventHandler ["Draw3D", {
|
||||
|
@ -4,7 +4,4 @@ ADDON = false;
|
||||
|
||||
#include "XEH_PREP.hpp"
|
||||
|
||||
// TODO load from config instead of hardcoded in sqf
|
||||
GVAR(ALL_DETECTABLE_TYPES) = ["ACE_Explosive_Object", "ACE_Explosive_Helper", "ACE_Explosives_Place", "ModuleMine_F", "TimeBombCore", "MineBase", "DirectionalBombBase", "BoundingMineBase", "PipeBombBase"];
|
||||
|
||||
ADDON = true;
|
||||
|
@ -18,5 +18,4 @@ class CfgPatches {
|
||||
#include "CfgWeapons.hpp"
|
||||
#include "CfgAmmo.hpp"
|
||||
#include "CfgVehicles.hpp"
|
||||
#include "CfgSounds.hpp"
|
||||
#include "ACE_detector.hpp"
|
||||
|
@ -32,24 +32,28 @@ if !([_unit, _type] call FUNC(isDetectorEnabled)) exitWith {
|
||||
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
if (ACE_player == _unit && {currentWeapon _unit == _type}) then {
|
||||
private _detected = [_unit, _detectorConfig] call FUNC(getDetectedObject);
|
||||
_detected params ["_hasDetected", "_object", "_distance"];
|
||||
private _distanceTiming = switch (true) do {
|
||||
case (_distance >= 2): {1};
|
||||
case (_distance >= 1.25): {0.85};
|
||||
case (_distance >= 0.75): {0.7};
|
||||
default {0.5};
|
||||
};
|
||||
if (_hasDetected && {(CBA_missionTime - _lastPlayed > _distanceTiming)}) then {
|
||||
_args set [3, CBA_missionTime];
|
||||
_detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"];
|
||||
private _sound = switch (true) do {
|
||||
case (_distance >= 2): {_sounds select 3};
|
||||
case (_distance >= 1.25): {_sounds select 2};
|
||||
case (_distance >= 0.5): {_sounds select 1};
|
||||
default {_sounds select 0};
|
||||
};
|
||||
[_unit, _sound, true] call FUNC(playDetectorSound);
|
||||
};
|
||||
if (ACE_player != _unit || {currentWeapon _unit != _type}) exitWith {};
|
||||
|
||||
private _detected = [[_unit, _detectorConfig], FUNC(getDetectedObject), _unit, QGVAR(detectedObjects), 0.15] call EFUNC(common,cachedCall);
|
||||
_detected params ["_hasDetected", "", "_distance"];
|
||||
|
||||
if (!_hasDetected) exitWith {};
|
||||
|
||||
private _distanceTiming = switch (true) do {
|
||||
case (_distance >= 2): {1};
|
||||
case (_distance >= 1.25): {0.85};
|
||||
case (_distance >= 0.75): {0.7};
|
||||
default {0.5};
|
||||
};
|
||||
|
||||
if (CBA_missionTime - _lastPlayed < _distanceTiming) exitWith {};
|
||||
|
||||
_args set [3, CBA_missionTime];
|
||||
_detectorConfig params ["", "", "_sound", "_pitchs"];
|
||||
private _pitch = switch (true) do {
|
||||
case (_distance >= 2): {_pitchs select 3};
|
||||
case (_distance >= 1.25): {_pitchs select 2};
|
||||
case (_distance >= 0.5): {_pitchs select 1};
|
||||
default {_pitchs select 0};
|
||||
};
|
||||
[_unit, _sound, _pitch] call FUNC(playDetectorSound);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Enables the mine detector
|
||||
* Get the distance to the nearest detectable object
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
@ -15,16 +15,13 @@
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#define __DR 1.3
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", "_detectorConfig"];
|
||||
_detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"];
|
||||
_detectorConfig params ["", "_radius"];
|
||||
|
||||
private _worldPosition = _unit modelToWorld (_unit selectionPosition "granat");
|
||||
private _direction = _unit weaponDirection "Put";
|
||||
|
||||
private _detectorPointAGL = _worldPosition vectorAdd (_direction vectorMultiply __DR);
|
||||
|
||||
private _nearestObjects = nearestObjects [_detectorPointAGL, [], _radius];
|
||||
@ -38,27 +35,19 @@ private _mine = objNull;
|
||||
private _distance = -1;
|
||||
|
||||
{
|
||||
private _object = _x;
|
||||
private _objectType = typeOf _x;
|
||||
|
||||
if ({_object isKindOf _x} count _detectableTypes > 0) then {
|
||||
//Try all unprepared mines in range and use first detectable one:
|
||||
if ((getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> QGVAR(detectable))) == 1) exitWith {
|
||||
_isDetectable = true;
|
||||
_mine = _x;
|
||||
_distance = _detectorPointAGL distance _x;
|
||||
};
|
||||
//Try all prepared mines in range and use first detectable one:
|
||||
if ((getNumber (configFile >> "CfgAmmo" >> (typeOf _x) >> QGVAR(detectable))) == 1) exitWith {
|
||||
_isDetectable = true;
|
||||
_mine = _x;
|
||||
_distance = _detectorPointAGL distance _x;
|
||||
};
|
||||
_isDetectable = GVAR(detectableClasses) getVariable _objectType;
|
||||
if (isNil "_isDetectable") then {
|
||||
_isDetectable = false;
|
||||
};
|
||||
|
||||
if (!isNull _mine) exitWith {};
|
||||
|
||||
// If a nun-null object was detected exit the search
|
||||
if (_isDetectable && {!isNull _x}) exitWith {
|
||||
_distance = _detectorPointAGL distance _x;
|
||||
_mine = _x;
|
||||
TRACE_3("return", _isDetectable, _mine, _distance);
|
||||
};
|
||||
} forEach _nearestObjects;
|
||||
|
||||
TRACE_3("return",_isDetectable,_mine,_distance);
|
||||
|
||||
[_isDetectable, _mine, _distance];
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Get the mine detector configuration from the config file
|
||||
* Get the mine detector configuration from the cache or config file
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Detector class name <STRING>
|
||||
@ -18,14 +18,19 @@
|
||||
|
||||
params ["_detectorType"];
|
||||
|
||||
private _config = (configFile >> "ACE_detector" >> "detectors" >> _detectorType);
|
||||
if (isClass _config) then {
|
||||
[
|
||||
_detectorType,
|
||||
getNumber (_config >> "radius"),
|
||||
GVAR(ALL_DETECTABLE_TYPES), // TODO read from config and use this as a back up value instead
|
||||
getArray (_config >> "sounds")
|
||||
];
|
||||
} else {
|
||||
[];
|
||||
private _detectorConfig = GVAR(detectorConfigs) getVariable _detectorType;
|
||||
if (isNil "_detectorConfig") then {
|
||||
private _cfgEntry = (configFile >> "ACE_detector" >> "detectors" >> _detectorType);
|
||||
if (isClass _cfgEntry) then {
|
||||
_detectorConfig = [
|
||||
_detectorType,
|
||||
getNumber (_cfgEntry >> "radius"),
|
||||
getText (_cfgEntry >> "sound"),
|
||||
getArray (_cfgEntry >> "pitchs")
|
||||
];
|
||||
} else {
|
||||
_detectorConfig = [];
|
||||
};
|
||||
GVAR(detectorConfigs) setVariable [_detectorType, _detectorConfig];
|
||||
};
|
||||
_detectorConfig
|
||||
|
@ -4,20 +4,21 @@
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Sound class name <STRING>
|
||||
* 1: Sound file name <STRING>
|
||||
* 2: Sound pitch <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [player, "ace_buzz_1"] call ace_minedetector_fnc_playDetectorSound
|
||||
* [player, "ace_buzz_1", 1] call ace_minedetector_fnc_playDetectorSound
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit", "_detectorSound"];
|
||||
params ["_unit", "_sound", "_pitch"];
|
||||
|
||||
if (isNull _unit) exitWith {
|
||||
ACE_LOGERROR_1("unit does not exist [%1]",_unit);
|
||||
@ -26,17 +27,6 @@ if (!alive _unit) exitWith {
|
||||
ACE_LOGERROR_1("unit is not alive [%1]",_unit);
|
||||
};
|
||||
|
||||
private _helperObject = _unit getVariable [QGVAR(helperLogic), objNull];
|
||||
if (!isNull _helperObject) then {
|
||||
deleteVehicle _helperObject;
|
||||
};
|
||||
_helperObject = "ACE_LogicDummy" createVehicleLocal (getPos _unit);
|
||||
private _posASL = AGLtoASL (_unit modelToWorld (_unit selectionPosition "granat"));
|
||||
|
||||
if !(isNull _helperObject) then {
|
||||
_helperObject attachTo [_unit,[0,0,-3],""];
|
||||
_unit setVariable [QGVAR(helperLogic), _helperObject];
|
||||
|
||||
[_helperObject, _unit] say3D _detectorSound;
|
||||
} else {
|
||||
ACE_LOGERROR_1("helper does not exist [%1]",_helperObject);
|
||||
};
|
||||
playSound3D [_sound, objNull, false, _posASL, 5, _pitch, 15];
|
||||
|
@ -16,3 +16,5 @@
|
||||
#endif
|
||||
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
||||
|
||||
#define __DR 1.3
|
||||
|
BIN
addons/minedetector/sounds/metal_detector.wss
Normal file
BIN
addons/minedetector/sounds/metal_detector.wss
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user