mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Modify setVariablePublic so it published inmediately if the variable hasn't being publishes recently. Then establish an embargo time before it can be published again.
This commit is contained in:
parent
d36543d3a9
commit
de902ca4fd
@ -1,56 +1,59 @@
|
|||||||
/*
|
/*
|
||||||
* Author: commy2 and joko // Jonas
|
* Author: commy2 and CAA-Picard
|
||||||
* Sets a public variable, but wait a certain amount of time to transfer the value over the network. Changing the value by calling this function again resets the windup timer.
|
* Publish a variable, but wait a certain amount of time before allowing it to be published it again.
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Argument:
|
||||||
* 0: Object the variable should be assigned to <OBJECT>
|
* 0: Object the variable should be assigned to <OBJECT>
|
||||||
* 1: Name of the variable <STRING>
|
* 1: Name of the variable <STRING>
|
||||||
* 2: Value of the variable <ANY>
|
* 2: Value of the variable <ANY>
|
||||||
* 3: Windup time <NUMBER> (default: 1)
|
* 3: Embargo delay <NUMBER> (Optional. Default: 1)
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return value:
|
||||||
* None
|
* Nothing.
|
||||||
*
|
*
|
||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
params ["_object", "_varName", "_value", ["_sync", 1]];
|
EXPLODE_4_PVT(_this,_object,_varName,_value,_delay);
|
||||||
|
|
||||||
|
if (isNil "_delay") then {
|
||||||
|
_delay = 1;
|
||||||
|
};
|
||||||
|
|
||||||
// set value locally
|
// set value locally
|
||||||
_object setVariable [_varName, _value];
|
_object setVariable [_varName, _value];
|
||||||
|
|
||||||
// Exit if in SP
|
// "duh"
|
||||||
if (!isMultiplayer) exitWith {};
|
if (!isMultiplayer) exitWith {};
|
||||||
|
|
||||||
private ["_idName", "_syncTime"];
|
// Fenerate stacked eventhandler id
|
||||||
|
private "_embargoTimeVarName";
|
||||||
|
_embargoTimeVarName = format ["ACE_PE_%1", _varName];
|
||||||
|
|
||||||
_idName = format ["ACE_setVariablePublic_%1", _varName];
|
// If we are on embargo, exit
|
||||||
|
if !(isNil (_object getVariable _embargoTimeVarName)) exitWith {}
|
||||||
|
|
||||||
if (_idName in GVAR(setVariableNames)) exitWith {};
|
// Publish
|
||||||
|
_object setVariable [_varName, _value, true];
|
||||||
|
|
||||||
_syncTime = ACE_diagTime + _sync;
|
// Generate embargo PFH
|
||||||
|
_object setVariable [_embargoTimeVarName, diag_tickTime + _delay];
|
||||||
|
|
||||||
GVAR(setVariableNames) pushBack _idName;
|
[{
|
||||||
|
EXPLODE_5_PVT(_this select 0,_object,_varName,_value,_delay, _embargoTimeVarName);
|
||||||
|
|
||||||
GVAR(setVariablePublicArray) pushBack [_object, _varName, _syncTime, _idName];
|
if (diag_tickTime < (_object getVariable _embargoTimeVarName)) exitWith {}
|
||||||
|
|
||||||
if (isNil QGVAR(setVariablePublicPFH)) exitWith {};
|
// If the value has changed since last update
|
||||||
|
if !(_value isEqualTo (_object getVariable _varName)) then {
|
||||||
GVAR(setVariablePublicPFH) = [{
|
// Republish new value and reset embargo
|
||||||
{
|
_object setVariable [_varName, (_object getVariable _varName), true];
|
||||||
_x params ["_object", "_varName", "_syncTime", "_idName"];
|
_object setVariable [_embargoTimeVarName, diag_tickTime + _delay];
|
||||||
if (ACE_diagTime > _syncTime) then {
|
} else {
|
||||||
// set value public
|
// Remove embargo
|
||||||
_object setVariable [_varName, _object getVariable _varName, true];
|
[_this select 1] call CBA_fnc_removePerFrameHandler;
|
||||||
GVAR(setVariablePublicArray) deleteAt (GVAR(setVariablePublicArray) find _x);
|
_object setVariable [_embargoTimeVarName, nil];
|
||||||
GVAR(setVariableNames) deleteAt (GVAR(setVariableNames) find _x);
|
|
||||||
};
|
};
|
||||||
nil
|
|
||||||
} count +GVAR(setVariablePublicArray);
|
|
||||||
|
|
||||||
if (GVAR(setVariablePublicArray) isEqualTo []) then {
|
}, 0.1, [_object, _varName, _value, _delay, _embargoTimeVarName]] call CBA_fnc_addPerFrameHandler;
|
||||||
[GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler;
|
|
||||||
GVAR(setVariablePublicPFH) = nil;
|
|
||||||
};
|
|
||||||
}, 0, []] call CBA_fnc_addPerFrameHandler;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user