mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
ACE JIP synchronized event infastructure.
This commit is contained in:
parent
6c3e699fdb
commit
2be38c493c
@ -87,7 +87,7 @@ enableCamShake true;
|
||||
// Set the name for the current player
|
||||
["playerChanged", {
|
||||
EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer);
|
||||
|
||||
diag_log text format["PLAYER CHANGED!", _this];
|
||||
if (alive _newPlayer) then {
|
||||
[_newPlayer] call FUNC(setName)
|
||||
};
|
||||
@ -188,3 +188,8 @@ GVAR(OldPlayerWeapon) = currentWeapon ACE_player;
|
||||
// Players can always interact with passengers of the same vehicle
|
||||
{!((_this select 0) isEqualTo (_this select 1)) && {vehicle (_this select 0) == vehicle (_this select 1)}}
|
||||
}] call FUNC(addCanInteractWithCondition);
|
||||
|
||||
// Synced ACE events
|
||||
["SEH", FUNC(_handleSyncedEvent)] call FUNC(addEventHandler);
|
||||
["SEH_s", FUNC(_handleRequestSyncedEvent)] call FUNC(addEventHandler);
|
||||
[FUNC(syncedEventPFH), 0.5, []] call cba_fnc_addPerFrameHandler;
|
||||
|
@ -269,6 +269,18 @@ PREP(hashListSelect);
|
||||
PREP(hashListSet);
|
||||
PREP(hashListPush);
|
||||
|
||||
// Synchronized Events
|
||||
PREP(syncedEventPFH);
|
||||
PREP(addSyncedEventHandler);
|
||||
PREP(removeSyncedEventHandler);
|
||||
PREP(syncedEvent);
|
||||
PREP(_handleSyncedEvent);
|
||||
PREP(_handleRequestSyncedEvent);
|
||||
PREP(requestSyncedEvent);
|
||||
GVAR(syncedEvents) = HASH_CREATE;
|
||||
|
||||
// @TODO: Generic local-managed global-synced objects (createVehicleLocal)
|
||||
|
||||
//Debug
|
||||
ACE_COUNTERS = [];
|
||||
|
||||
|
37
addons/common/functions/fnc__handleRequestSyncedEvent.sqf
Normal file
37
addons/common/functions/fnc__handleRequestSyncedEvent.sqf
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
*
|
||||
* Argument:
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
|
||||
//SEH_s
|
||||
if(isServer) then {
|
||||
// Find the event name, and shovel out the events to the client
|
||||
PARAMS_2(_eventName,_client);
|
||||
private["_eventEntry", "_eventLog"];
|
||||
|
||||
if(!HASH_HASKEY(GVAR(syncedEvents),_eventName)) exitWith {
|
||||
diag_log text format["[ACE] Error, request for synced event - key not found."];
|
||||
false
|
||||
};
|
||||
_eventEntry = HASH_GET(GVAR(syncedEvents),_eventName);
|
||||
_eventLog = _eventEntry select 1;
|
||||
|
||||
["SEH_s", _client, [_eventName, _eventLog] ] call FUNC(targetEvent);
|
||||
} else {
|
||||
PARAMS_2(_eventName,_eventLog);
|
||||
// This is the client handling the response from the server
|
||||
// Start running the events
|
||||
{
|
||||
_eventArgs = _x select 1;
|
||||
[_eventName, _eventArgs, (_x select 2)] call FUNC(_handleSyncedEvent);
|
||||
} forEach _eventLog;
|
||||
};
|
||||
|
||||
true
|
36
addons/common/functions/fnc__handleSyncedEvent.sqf
Normal file
36
addons/common/functions/fnc__handleSyncedEvent.sqf
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
* Call and propegate a synced event
|
||||
*
|
||||
* Argument:
|
||||
* 0: Name (String)
|
||||
* 1: Arguments (Array)
|
||||
* 2: TTL (Number or Code) [Optional]
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
PARAMS_3(_name,_args,_ttl);
|
||||
private["_internalData", "_eventLog", "_eventCode"];
|
||||
|
||||
if(!HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
diag_log text format["[ACE] Error, synced event key not found."];
|
||||
false
|
||||
};
|
||||
|
||||
_internalData = HASH_GET(GVAR(syncedEvents),_name);
|
||||
|
||||
if(isServer) then {
|
||||
// Server needs to internally log it for synchronization
|
||||
if(_ttl > -1) then {
|
||||
_internalData = HASH_GET(GVAR(syncedEvents),_name);
|
||||
_eventLog = _internalData select 1;
|
||||
_eventLog pushback [diag_tickTime, _args, _ttl];
|
||||
};
|
||||
};
|
||||
|
||||
_eventCode = _internalData select 0;
|
||||
_args call _eventCode;
|
32
addons/common/functions/fnc_addSyncedEventHandler.sqf
Normal file
32
addons/common/functions/fnc_addSyncedEventHandler.sqf
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
* Register an event handler for an ACE synced event
|
||||
*
|
||||
* Argument:
|
||||
* 0: Name (String)
|
||||
* 1: Handler (Code)
|
||||
* 2: TTL (Number or Code) [Optional]
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
PARAMS_2(_name,_handler);
|
||||
|
||||
private["_ttl", "_eventId", "_data"];
|
||||
if( (count _this) > 2) then {
|
||||
_ttl = _this select 2;
|
||||
} else {
|
||||
_ttl = 0;
|
||||
};
|
||||
|
||||
if(HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
diag_log text format["[ACE] Error, duplicate synced event creation."];
|
||||
false
|
||||
};
|
||||
|
||||
_eventId = [_name, FUNC(_handleSyncedEvent)] call FUNC(addEventHandler);
|
||||
_data = [_handler,[],_ttl,_eventId];
|
||||
HASH_SET(GVAR(syncedEvents),_name,_data);
|
24
addons/common/functions/fnc_removeSyncedEventHandler.sqf
Normal file
24
addons/common/functions/fnc_removeSyncedEventHandler.sqf
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
* Remove a synced event handler
|
||||
*
|
||||
* Argument:
|
||||
* 0: Name (String)
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
PARAMS_1(_name);
|
||||
|
||||
if(!HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
diag_log text format["[ACE] Error, synced event key not found."];
|
||||
false
|
||||
};
|
||||
|
||||
_data = HASH_GET(GVAR(syncedEvents),_name);
|
||||
_eventId = _data select 3;
|
||||
|
||||
[_eventId] call ace_common_fnc_removeEventHandler;
|
||||
HASH_REM(GVAR(syncedEvents),_name);
|
17
addons/common/functions/fnc_requestSyncedEvent.sqf
Normal file
17
addons/common/functions/fnc_requestSyncedEvent.sqf
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
*
|
||||
* Argument:
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
PARAMS_1(_eventName);
|
||||
|
||||
// Only JIP machines on initialization send this off, requesting sync on events with the serverCommand
|
||||
if(isServer) exitWith { false };
|
||||
|
||||
["SEH_s", [_eventName, ACE_player] ] call ace_common_fnc_serverEvent;
|
31
addons/common/functions/fnc_syncedEvent.sqf
Normal file
31
addons/common/functions/fnc_syncedEvent.sqf
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Author: jaynus
|
||||
*
|
||||
* Call and propegate a synced event
|
||||
*
|
||||
* Argument:
|
||||
* 0: Name (String)
|
||||
* 1: Arguments (Array)
|
||||
* 2: TTL (Number or Code) [Optional] for this specific event call
|
||||
*
|
||||
* Return value:
|
||||
* Boolean of success
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
PARAMS_2(_name,_args);
|
||||
private["_ttl", "_eventData", "_internalData", "_eventLog"];
|
||||
|
||||
if( (count _this) > 2) then {
|
||||
_ttl = _this select 2;
|
||||
} else {
|
||||
_ttl = 0;
|
||||
};
|
||||
|
||||
if(!HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
|
||||
diag_log text format["[ACE] Error, synced event key not found."];
|
||||
false
|
||||
};
|
||||
|
||||
_eventData = [_name, _args,_ttl];
|
||||
["SEH", _eventData] call FUNC(globalEvent);
|
52
addons/common/functions/fnc_syncedEventPFH.sqf
Normal file
52
addons/common/functions/fnc_syncedEventPFH.sqf
Normal file
@ -0,0 +1,52 @@
|
||||
//#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
|
||||
if(!isServer) exitWith { false };
|
||||
|
||||
// Walk through the local synced events and clean up anything thats already EOL
|
||||
// @TODO: This should be iteration limited to prevent FPS lag
|
||||
private["_data"];
|
||||
{
|
||||
private["_data", "_ttl", "_eventLog", "_newEventLog", "_name"];
|
||||
_name = _x;
|
||||
|
||||
_data = HASH_GET(GVAR(syncedEvents),_name);
|
||||
_eventLog = _data select 1;
|
||||
_globalEventTTL = _data select 2;
|
||||
_newEventLog = [];
|
||||
|
||||
// @TODO: This should be iteration limited to prevent FPS lag
|
||||
{
|
||||
private["_eventEntry", "_ttlReturn"];
|
||||
_eventEntry = _x;
|
||||
|
||||
_ttlReturn = true;
|
||||
if(typeName _globalEventTTL == "CODE") then {
|
||||
_ttlReturn = [(_data select 0),_eventEntry] call _globalEventTTL;
|
||||
} else {
|
||||
_ttlReturn = call { _globalEventTTL < 1 || {diag_tickTime < (_eventEntry select 0) + _globalEventTTL} };
|
||||
};
|
||||
|
||||
if(_ttlReturn) then {
|
||||
// Do event based TTL check
|
||||
private["_eventTTL"];
|
||||
_eventTTL = _eventEntry select 2;
|
||||
|
||||
if(typeName _eventTTL == "CODE") then {
|
||||
_ttlReturn = [(_data select 0),_eventEntry] call _eventTTL;
|
||||
} else {
|
||||
_ttlReturn = call { _eventTTL < 1 || {diag_tickTime < (_eventEntry select 0) + _eventTTL} };
|
||||
};
|
||||
};
|
||||
|
||||
// Finally drop it if the TTL check fails
|
||||
if(_ttlReturn) then {
|
||||
_newEventLog pushBack _x;
|
||||
};
|
||||
} forEach _eventLog;
|
||||
|
||||
_data set[1, _newEventLog];
|
||||
} forEach (GVAR(syncedEvents) select 0);
|
||||
|
||||
|
||||
// @TODO: Next, detect if we had a new request from a JIP player, and we need to continue syncing events
|
Loading…
Reference in New Issue
Block a user