diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index e470e91c95..27f234970e 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -65,9 +65,31 @@ if (_currentVersion != _previousVersion) then { 0 spawn COMPILE_FILE(scripts\Version\checkVersionNumber); +// ACE events "ACEg" addPublicVariableEventHandler { _this call FUNC(_handleNetEvent); }; "ACEc" addPublicVariableEventHandler { _this call FUNC(_handleNetEvent); }; +// Synced ACE events +// Handle JIP scenario +if(!isServer) then { + ["PlayerJip", { + diag_log text format["[ACE] * JIP event synchronization initialized"]; + ["SEH_all", [player]] call FUNC(serverEvent); + }] call FUNC(addEventHandler); +} else { + ["SEH_all", FUNC(_handleRequestAllSyncedEvents)] call FUNC(addEventHandler); +}; +["SEH", FUNC(_handleSyncedEvent)] call FUNC(addEventHandler); +["SEH_s", FUNC(_handleRequestSyncedEvent)] call FUNC(addEventHandler); +[FUNC(syncedEventPFH), 0.5, []] call cba_fnc_addPerFrameHandler; + + +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ + // everything that only player controlled machines need, goes below this if (!hasInterface) exitWith {}; @@ -87,7 +109,7 @@ enableCamShake true; // Set the name for the current player ["playerChanged", { EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer); - + if (alive _newPlayer) then { [_newPlayer] call FUNC(setName) }; @@ -107,7 +129,6 @@ GVAR(OldPlayerWeapon) = currentWeapon ACE_player; // PFH to raise varios events [{ - // "playerInventoryChanged" event _newPlayerInventory = [ACE_player] call FUNC(getAllGear); if !(_newPlayerInventory isEqualTo GVAR(OldPlayerInventory)) then { @@ -188,3 +209,18 @@ 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); + +// Lastly, do JIP events +// JIP Detection and event trigger. Run this at the very end, just in case anything uses it +if(isMultiplayer && { time > 0 || isNull player } ) then { + // We are jipping! Get ready and wait, and throw the event + [{ + if(!(isNull player)) then { + ["PlayerJip", [player] ] call FUNC(localEvent); + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; + }, 0, []] call cba_fnc_addPerFrameHandler; +}; + + + diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index b5382d0b5e..077d69578b 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -269,6 +269,21 @@ PREP(hashListSelect); PREP(hashListSet); PREP(hashListPush); +// Synchronized Events +PREP(syncedEventPFH); +PREP(addSyncedEventHandler); +PREP(removeSyncedEventHandler); +PREP(requestSyncedEvent); +PREP(syncedEvent); + +PREP(_handleSyncedEvent); +PREP(_handleRequestSyncedEvent); +PREP(_handleRequestAllSyncedEvents); + +GVAR(syncedEvents) = HASH_CREATE; + +// @TODO: Generic local-managed global-synced objects (createVehicleLocal) + //Debug ACE_COUNTERS = []; diff --git a/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf new file mode 100644 index 0000000000..7c566ce4d1 --- /dev/null +++ b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf @@ -0,0 +1,25 @@ +/* + * Author: jaynus + * + * Handles a server-side request for synchronization ALL events on JIP to a client. + * + * Argument: + * 0: client (object) + * + * Return value: + * Boolean of success + */ +//#define DEBUG_MODE_FULL +#include "script_component.hpp" +PARAMS_1(_client); + +{ + private["_eventName", "_eventEntry", "_eventLog"]; + _eventName = _x; + _eventEntry = HASH_GET(GVAR(syncedEvents),_eventName); + _eventLog = _eventEntry select 1; + + ["SEH_s", _client, [_eventName, _eventLog] ] call FUNC(targetEvent); +} forEach (GVAR(syncedEvents) select 0); + +true \ No newline at end of file diff --git a/addons/common/functions/fnc__handleRequestSyncedEvent.sqf b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf new file mode 100644 index 0000000000..2d58aae869 --- /dev/null +++ b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf @@ -0,0 +1,45 @@ +/* + * Author: jaynus + * + * Receives either requests for synchronization from clients, or the synchronization data from the server. + * + * Arguments [Client] : + * 0: eventName (String) + * 1: eventLog (Array) + * + * Arguments [Server] : + * 0: eventName (String) + * 1: client (Object) + * + * 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; + diag_log text format["[ACE] + [%1] synchronized", _eventName]; +}; + +true \ No newline at end of file diff --git a/addons/common/functions/fnc__handleSyncedEvent.sqf b/addons/common/functions/fnc__handleSyncedEvent.sqf new file mode 100644 index 0000000000..9807896358 --- /dev/null +++ b/addons/common/functions/fnc__handleSyncedEvent.sqf @@ -0,0 +1,36 @@ +/* + * Author: jaynus + * + * Handles synced events being received. Server will log them, and server/client will execute them. + * + * Arguments [Client] : + * 0: eventName (String) + * 1: arguments (Array) + * 2: ttl (Scalar) + * + * 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; \ No newline at end of file diff --git a/addons/common/functions/fnc_addSyncedEventHandler.sqf b/addons/common/functions/fnc_addSyncedEventHandler.sqf new file mode 100644 index 0000000000..5d2b221178 --- /dev/null +++ b/addons/common/functions/fnc_addSyncedEventHandler.sqf @@ -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); \ No newline at end of file diff --git a/addons/common/functions/fnc_removeSyncedEventHandler.sqf b/addons/common/functions/fnc_removeSyncedEventHandler.sqf new file mode 100644 index 0000000000..6429120bbe --- /dev/null +++ b/addons/common/functions/fnc_removeSyncedEventHandler.sqf @@ -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); \ No newline at end of file diff --git a/addons/common/functions/fnc_requestSyncedEvent.sqf b/addons/common/functions/fnc_requestSyncedEvent.sqf new file mode 100644 index 0000000000..dea0c7adef --- /dev/null +++ b/addons/common/functions/fnc_requestSyncedEvent.sqf @@ -0,0 +1,19 @@ +/* + * Author: jaynus + * + * Send a request to synchronize an event name from the client->server. Execute on client only. + * + * Argument: + * 0: eventName (String) + * + * 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; \ No newline at end of file diff --git a/addons/common/functions/fnc_syncedEvent.sqf b/addons/common/functions/fnc_syncedEvent.sqf new file mode 100644 index 0000000000..70c30a19da --- /dev/null +++ b/addons/common/functions/fnc_syncedEvent.sqf @@ -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); \ No newline at end of file diff --git a/addons/common/functions/fnc_syncedEventPFH.sqf b/addons/common/functions/fnc_syncedEventPFH.sqf new file mode 100644 index 0000000000..e8a21202ab --- /dev/null +++ b/addons/common/functions/fnc_syncedEventPFH.sqf @@ -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 diff --git a/addons/medical/ACE_Settings.hpp b/addons/medical/ACE_Settings.hpp index 56e5a531ec..b42d5bc5a6 100644 --- a/addons/medical/ACE_Settings.hpp +++ b/addons/medical/ACE_Settings.hpp @@ -73,11 +73,18 @@ class ACE_Settings { }; class GVAR(allowLitterCreation) { typeName = "BOOL"; - value = true; + value = 1; + }; + class GVAR(litterSimulationDetail) { + displayName = "$STR_ACE_Medical_litterSimulationDetail"; + description = "$STR_ACE_Medical_litterSimulationDetail_Desc"; + typeName = "SCALAR"; + value = 500; + isClientSettable = 1; }; class GVAR(litterCleanUpDelay) { typeName = "SCALAR"; - value = 1800; + value = 0; }; class GVAR(medicSetting_PAK) { typeName = "SCALAR"; diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index ae6c87c1c6..9b384c67b7 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -265,3 +265,7 @@ if (USE_WOUND_EVENT_SYNC) then { ["playerInventoryChanged", { [ACE_player] call FUNC(itemCheck); }] call EFUNC(common,addEventHandler); + + +// Networked litter +[QGVAR(createLitter), FUNC(handleCreateLitter), GVAR(litterCleanUpDelay)] call EFUNC(common,addSyncedEventHandler); diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index f15b4ec109..78a2e7f71b 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -21,7 +21,6 @@ PREP(adjustPainLevel); PREP(canAccessMedicalEquipment); PREP(canTreat); PREP(canTreatCached); -PREP(createLitter); PREP(determineIfFatal); PREP(getBloodLoss); PREP(getBloodPressure); @@ -98,6 +97,10 @@ PREP(moduleTreatmentConfiguration); PREP(copyDeadBody); PREP(requestWoundSync); +// Networked litter +PREP(createLitter); +PREP(handleCreateLitter); + GVAR(injuredUnitCollection) = []; GVAR(IVBags) = []; diff --git a/addons/medical/functions/fnc_createLitter.sqf b/addons/medical/functions/fnc_createLitter.sqf index 570c6d63d3..5299fbb244 100644 --- a/addons/medical/functions/fnc_createLitter.sqf +++ b/addons/medical/functions/fnc_createLitter.sqf @@ -37,21 +37,21 @@ if !(isArray (_config >> "litter")) exitwith {}; _litter = getArray (_config >> "litter"); _createLitter = { + private["_position", "_litterClass", "_direction"]; _position = getPos (_this select 0); _litterClass = _this select 1; - _litterObject = createVehicle [_litterClass, _position, [], 0, "NONE"]; if (random(1) >= 0.5) then { - _litterObject setPos [(_position select 0) + random 2, (_position select 1) + random 2, _position select 2]; + _position = [(_position select 0) + random 2, (_position select 1) + random 2, _position select 2]; } else { - _litterObject setPos [(_position select 0) - random 2, (_position select 1) - random 2, _position select 2]; + _position = [(_position select 0) - random 2, (_position select 1) - random 2, _position select 2]; }; - _litterObject setDir (random 360); - _litterObject; -}; - -if (isnil QGVAR(allCreatedLitter)) then { - GVAR(allCreatedLitter) = []; - GVAR(litterPFHRunning) = false; + _direction = (random 360); + + // Create the litter, and timeout the event based on the cleanup delay + // The cleanup delay for events in MP is handled by the server side + [QGVAR(createLitter), [_litterClass,_position,_direction], 0] call EFUNC(common,syncedEvent); + + true }; _createdLitter = []; @@ -75,37 +75,13 @@ _createdLitter = []; // Loop through through the litter options and place the litter { if (typeName _x == "ARRAY" && {(count _x > 0)}) then { - _createdLitter pushback ([_target, _x select (floor(random(count _x)))] call _createLitter); + [_target, _x select (floor(random(count _x)))] call _createLitter; }; if (typeName _x == "STRING") then { - _createdLitter pushback ([_target, _x] call _createLitter); + [_target, _x] call _createLitter; }; }foreach _litterOptions; }; }; }; -}foreach _litter; - -if (GVAR(litterCleanUpDelay) >= 0) then { - GVAR(allCreatedLitter) pushback [time, GVAR(litterCleanUpDelay), _createdLitter]; -}; - -if !(GVAR(litterPFHRunning)) then { - GVAR(litterPFHRunning) = true; - [{ - { - if (time - (_x select 0) >= (_x select 1)) then { - { - deleteVehicle _x; - }foreach (_this select 2); - GVAR(allCreatedLitter) set[_foreachIndex, objNull]; - }; - }foreach GVAR(allCreatedLitter); - GVAR(allCreatedLitter) = GVAR(allCreatedLitter) - [objNull]; - - if (count GVAR(allCreatedLitter) == 0) exitwith { - GVAR(litterPFHRunning) = false; - [_this select 1] call CBA_fnc_removePerFrameHandler; - }; - }, 30, []] call CBA_fnc_addPerFrameHandler; -}; +}foreach _litter; \ No newline at end of file diff --git a/addons/medical/functions/fnc_handleCreateLitter.sqf b/addons/medical/functions/fnc_handleCreateLitter.sqf new file mode 100644 index 0000000000..aca47250cd --- /dev/null +++ b/addons/medical/functions/fnc_handleCreateLitter.sqf @@ -0,0 +1,47 @@ +//#define DEBUG_MODE_FULL +#include "script_component.hpp" + +if(!hasInterface) exitWith { false }; + +PARAMS_3(_litterClass,_position,_direction); +private["_litterObject"]; + +if (isNil QGVAR(allCreatedLitter)) then { + GVAR(allCreatedLitter) = []; + GVAR(litterPFHRunning) = false; +}; + +_litterObject = _litterClass createVehicleLocal _position; +_litterObject setDir _direction; + +if((count GVAR(allCreatedLitter)) > GVAR(litterSimulationDetail) ) then { + // gank the first litter object, and spawn ours. + private["_oldLitter"]; + _oldLitter = GVAR(allCreatedLitter) deleteAt 0; + { + deleteVehicle _x; + } forEach (_oldLitter select 1); +}; + +GVAR(allCreatedLitter) pushBack [time, [_litterObject]]; + +if(!GVAR(litterPFHRunning) && {GVAR(litterCleanUpDelay) > 0}) then { + [{ + { + if (time - (_x select 0) >= GVAR(litterCleanUpDelay)) then { + { + deleteVehicle _x; + } forEach (_x select 1); + GVAR(allCreatedLitter) set[_foreachIndex, objNull]; + }; + } forEach GVAR(allCreatedLitter); + GVAR(allCreatedLitter) = GVAR(allCreatedLitter) - [objNull]; + + if ( (count GVAR(allCreatedLitter)) == 0) exitwith { + [(_this select 1)] call CBA_fnc_removePerFrameHandler; + GVAR(litterPFHRunning) = false; + }; + }, 30, []] call cba_fnc_addPerFrameHandler; +}; + +true \ No newline at end of file diff --git a/addons/medical/stringtable.xml b/addons/medical/stringtable.xml index d14e532c26..6039d9e5b2 100644 --- a/addons/medical/stringtable.xml +++ b/addons/medical/stringtable.xml @@ -2,6 +2,12 @@ + + Litter Simulation Detail + + + Litter simulation detail level sets the number of litter items which will be locally spawned in the client. Excessive amounts in local areas could cause FPS lag, so this is a client only setting. + Inject Atropine Atropin injizieren @@ -1627,4 +1633,4 @@ Aberration chromatique - \ No newline at end of file +