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
|
||||
* 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.
|
||||
* Author: commy2 and CAA-Picard
|
||||
* 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>
|
||||
* 1: Name of the variable <STRING>
|
||||
* 2: Value of the variable <ANY>
|
||||
* 3: Windup time <NUMBER> (default: 1)
|
||||
* 3: Embargo delay <NUMBER> (Optional. Default: 1)
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
* Return value:
|
||||
* Nothing.
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#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
|
||||
_object setVariable [_varName, _value];
|
||||
|
||||
// Exit if in SP
|
||||
// "duh"
|
||||
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 {};
|
||||
|
||||
GVAR(setVariablePublicPFH) = [{
|
||||
{
|
||||
_x params ["_object", "_varName", "_syncTime", "_idName"];
|
||||
if (ACE_diagTime > _syncTime) then {
|
||||
// set value public
|
||||
_object setVariable [_varName, _object getVariable _varName, true];
|
||||
GVAR(setVariablePublicArray) deleteAt (GVAR(setVariablePublicArray) find _x);
|
||||
GVAR(setVariableNames) deleteAt (GVAR(setVariableNames) find _x);
|
||||
};
|
||||
nil
|
||||
} count +GVAR(setVariablePublicArray);
|
||||
|
||||
if (GVAR(setVariablePublicArray) isEqualTo []) then {
|
||||
[GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler;
|
||||
GVAR(setVariablePublicPFH) = nil;
|
||||
// If the value has changed since last update
|
||||
if !(_value isEqualTo (_object getVariable _varName)) then {
|
||||
// Republish new value and reset embargo
|
||||
_object setVariable [_varName, (_object getVariable _varName), true];
|
||||
_object setVariable [_embargoTimeVarName, diag_tickTime + _delay];
|
||||
} else {
|
||||
// Remove embargo
|
||||
[_this select 1] call CBA_fnc_removePerFrameHandler;
|
||||
_object setVariable [_embargoTimeVarName, nil];
|
||||
};
|
||||
}, 0, []] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
}, 0.1, [_object, _varName, _value, _delay, _embargoTimeVarName]] call CBA_fnc_addPerFrameHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user