diff --git a/addons/common/functions/fnc_addLineToDebugDraw.sqf b/addons/common/functions/fnc_addLineToDebugDraw.sqf index 5fca9d68c1..46f015c5e0 100644 --- a/addons/common/functions/fnc_addLineToDebugDraw.sqf +++ b/addons/common/functions/fnc_addLineToDebugDraw.sqf @@ -11,7 +11,7 @@ * None * * Example: - * [[0,0,0], [1,1,0], [1,0,0,1]]] call ace_common_fnc_addLineToDebugDraw; + * [[0,0,0], [1,1,0], [1,0,0,1]] call ace_common_fnc_addLineToDebugDraw; * * Public: No */ diff --git a/addons/refuel/functions/fnc_checkFuel.sqf b/addons/refuel/functions/fnc_checkFuel.sqf index 8acecccfd6..081f344732 100644 --- a/addons/refuel/functions/fnc_checkFuel.sqf +++ b/addons/refuel/functions/fnc_checkFuel.sqf @@ -21,7 +21,7 @@ params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]]]; private _fuel = [_target] call FUNC(getFuel); [ - REFUEL_PROGRESS_DURATION * 2.5, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION * 2), [_unit, _target, _fuel], { params ["_args"]; diff --git a/addons/refuel/functions/fnc_connectNozzle.sqf b/addons/refuel/functions/fnc_connectNozzle.sqf index a124a331d5..807960977e 100644 --- a/addons/refuel/functions/fnc_connectNozzle.sqf +++ b/addons/refuel/functions/fnc_connectNozzle.sqf @@ -41,7 +41,6 @@ private _actionID = _unit addAction [format ["%1", locali if (cameraView == "EXTERNAL") then { _virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0])); }; - private _virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition); private _lineInterection = lineIntersects [eyePos ace_player, _virtualPosASL, ace_player]; //Don't allow placing in a bad position: @@ -57,7 +56,7 @@ private _actionID = _unit addAction [format ["%1", locali _unit removeAction _actionID; if (GVAR(placeAction) == PLACE_APPROVE) then { - [_unit, _target, _virtualPos, _nozzle] call FUNC(ConnectNozzleAction); + [_unit, _target, _virtualPosASL, _nozzle] call FUNC(ConnectNozzleAction); }; }; // TODO add model like in attach/functions/fnc_attach }, 0, [_unit, _target, _nozzle, _actionID] ] call cba_fnc_addPerFrameHandler; diff --git a/addons/refuel/functions/fnc_connectNozzleAction.sqf b/addons/refuel/functions/fnc_connectNozzleAction.sqf index b132863672..31ebe1bfdc 100644 --- a/addons/refuel/functions/fnc_connectNozzleAction.sqf +++ b/addons/refuel/functions/fnc_connectNozzleAction.sqf @@ -6,7 +6,7 @@ * Arguments: * 0: Unit * 1: Target - * 2: Visual Position + * 2: Visual Position ASL * 3: Nozzle * * Return Value: @@ -20,60 +20,55 @@ #include "script_component.hpp" private ["_closeInDistance", "_endPosTestOffset"]; -params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_startingPosition", [0,0,0], [[]], 3], ["_nozzle", objNull, [objNull]]]; -private _startingOffset = _target worldToModel _startingPosition; +params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_startingPosASL", [0,0,0], [[]], 3], ["_nozzle", objNull, [objNull]]]; -private _startDistanceFromCenter = vectorMagnitude _startingOffset; -private _closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]); -private _closeInMax = _startDistanceFromCenter; -private _closeInMin = 0; +private _bestPosASL = []; +private _bestPosDistance = 1e99; +private _viewPos = _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1])) vectorMultiply 3); +private _modelVector = _startingPosASL vectorFromTo (AGLtoASL (_target modelToWorld [0,0,0])); +private _modelVectorLow = _startingPosASL vectorFromTo (AGLtoASL (_target modelToWorld [0,0,-1])); -while {(_closeInMax - _closeInMin) > 0.01} do { - _closeInDistance = (_closeInMax + _closeInMin) / 2; - _endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance); - _endPosTestOffset set [2, (_startingOffset select 2)]; - private _endPosTest = _target modelToWorldVisual _endPosTestOffset; - - private _doesIntersect = false; +{ + private _endPosASL = _x; + // [_startingPosASL, _endPosASL, [1,0,0,1]] call EFUNC(common,addLineToDebugDraw); // Debug scan lines + private _intersections = lineIntersectsSurfaces [_startingPosASL, _endPosASL, _unit]; { - if (_doesIntersect) exitWith {}; - private _startingPosShifted = _startingPosition vectorAdd _x; - _startASL = if (surfaceIsWater _startingPosShifted) then {_startingPosShifted} else {ATLtoASL _startingPosShifted}; - { - _endPosShifted = _endPosTest vectorAdd _x; - private _endASL = if (surfaceIsWater _startingPosShifted) then {_endPosShifted} else {ATLtoASL _endPosShifted}; - - //Uncomment to see the lazor show, and see how the scanning works: - // drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]]; - if (_target in lineIntersectsWith [_startASL, _endASL, _unit]) exitWith {_doesIntersect = true}; - } forEach [[0,0,0.045], [0,0,-0.045], [0,0.045,0], [0,-0.045,0], [0.045,0,0], [-0.045,0,0]]; - } forEach [[0,0,0], [0,0,0.05], [0,0,-0.05]]; - - if (_doesIntersect) then { - _closeInMax = _closeInDistance; - } else { - _closeInMin = _closeInDistance; - }; -}; - -_closeInDistance = (_closeInMax + _closeInMin) / 2; + _x params ["_intersectPosASL", "", "_intersectObject"]; + if (_intersectObject == _target) then { + private _distance = _startingPosASL distance _intersectPosASL; + if (_distance < _bestPosDistance) then { + _bestPosDistance = _distance; + _bestPosASL = _intersectPosASL; + }; + }; + } forEach _intersections; +} forEach [ + // Shoot rays towards player's view angle and see which spot is closest + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1])) vectorMultiply 3), + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [-0.25,0,1])) vectorMultiply 3), + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0.25,0,1])) vectorMultiply 3), + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,-0.25,1])) vectorMultiply 3), + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [-0.25,-0.25,1])) vectorMultiply 3), + _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0.25,-0.25,1])) vectorMultiply 3), + AGLtoASL (_target modelToWorld [0,0,0]), // Try old method of just using model center + AGLtoASL (_target modelToWorld [0,0,-0.5]) +]; //Checks (too close to center or can't attach) -if ((_startDistanceFromCenter - _closeInDistance) < 0.1) exitWith { +if (_bestPosASL isEqualTo []) exitWith { TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter); [localize LSTRING(Failed)] call EFUNC(common,displayTextStructured); }; //Move it out slightly, for visibility sake (better to look a little funny than be embedded//sunk in the hull and be useless) -_closeInDistance = (_closeInDistance - 0.05); +_bestPosASL = _bestPosASL vectorAdd ((_bestPosASL vectorFromTo _startingPosASL) vectorMultiply 0.05); -_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance); -_endPosTestOffset set [2, (_startingOffset select 2)]; +private _attachPosModel = _target worldToModel (ASLtoAGL _bestPosASL); [ - REFUEL_PROGRESS_DURATION, - [_unit, _nozzle, _target, _endPosTestOffset], + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), + [_unit, _nozzle, _target, _attachPosModel], { params ["_args"]; _args params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_target", objNull, [objNull]], ["_endPosTestOffset", [0,0,0], [[]], 3]]; diff --git a/addons/refuel/functions/fnc_readFuelCounter.sqf b/addons/refuel/functions/fnc_readFuelCounter.sqf index 1b1fb78e81..98393e69ea 100644 --- a/addons/refuel/functions/fnc_readFuelCounter.sqf +++ b/addons/refuel/functions/fnc_readFuelCounter.sqf @@ -19,7 +19,7 @@ params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]]]; [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _target], { params ["_args"]; diff --git a/addons/refuel/functions/fnc_returnNozzle.sqf b/addons/refuel/functions/fnc_returnNozzle.sqf index 752be90d23..2b1ac64f8b 100644 --- a/addons/refuel/functions/fnc_returnNozzle.sqf +++ b/addons/refuel/functions/fnc_returnNozzle.sqf @@ -24,7 +24,7 @@ private _source = _nozzle getVariable QGVAR(source); if (isNull _nozzle || {_source != _target}) exitWith {false}; [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _nozzle, _target], { params ["_args"]; diff --git a/addons/refuel/functions/fnc_takeNozzle.sqf b/addons/refuel/functions/fnc_takeNozzle.sqf index 285dd37ced..1b0baac80c 100644 --- a/addons/refuel/functions/fnc_takeNozzle.sqf +++ b/addons/refuel/functions/fnc_takeNozzle.sqf @@ -39,7 +39,7 @@ if (isNull _nozzle) then { // func is called on fuel truck _endPosOffset = _endPosOffset select 0; }; [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _target, _endPosOffset], { params ["_args"]; @@ -105,7 +105,7 @@ if (isNull _nozzle) then { // func is called on fuel truck ] call EFUNC(common,progressBar); } else { // func is called on muzzle either connected or on ground [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _nozzle], { params ["_args"]; diff --git a/addons/refuel/functions/fnc_turnOff.sqf b/addons/refuel/functions/fnc_turnOff.sqf index 31308607bb..2c2b8de158 100644 --- a/addons/refuel/functions/fnc_turnOff.sqf +++ b/addons/refuel/functions/fnc_turnOff.sqf @@ -19,7 +19,7 @@ params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]]]; [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _nozzle], { params ["_args"]; diff --git a/addons/refuel/functions/fnc_turnOn.sqf b/addons/refuel/functions/fnc_turnOn.sqf index b7a4cf1bc9..cf8656f558 100644 --- a/addons/refuel/functions/fnc_turnOn.sqf +++ b/addons/refuel/functions/fnc_turnOn.sqf @@ -19,7 +19,7 @@ params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]]]; [ - REFUEL_PROGRESS_DURATION, + TIME_PROGRESSBAR(REFUEL_PROGRESS_DURATION), [_unit, _nozzle], { params ["_args"]; diff --git a/addons/refuel/script_component.hpp b/addons/refuel/script_component.hpp index 19f12ed366..3f85277a99 100644 --- a/addons/refuel/script_component.hpp +++ b/addons/refuel/script_component.hpp @@ -5,6 +5,7 @@ // #define DEBUG_MODE_FULL // #define DISABLE_COMPILE_CACHE // #define ENABLE_PERFORMANCE_COUNTERS +// #define FAST_PROGRESSBARS #ifdef DEBUG_ENABLED_REFUEL #define DEBUG_MODE_FULL @@ -29,3 +30,9 @@ _weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel); \ _unit selectWeapon _weaponSelect; \ _unit setVariable [QGVAR(selectedWeaponOnRefuel), nil]; + +#ifdef FAST_PROGRESSBARS + #define TIME_PROGRESSBAR(X) ((X) * 0.075) +#else + #define TIME_PROGRESSBAR(X) (X) +#endif