From 93d03b404fdef3153a6d689cf8c87e2e713340db Mon Sep 17 00:00:00 2001 From: jaynus Date: Fri, 17 Apr 2015 19:26:27 -0700 Subject: [PATCH] JIP Sync events complete. --- addons/common/XEH_postInit.sqf | 49 +++++++++++-------- addons/common/XEH_preInit.sqf | 5 +- .../fnc__handleRequestAllSyncedEvents.sqf | 4 +- .../fnc__handleRequestSyncedEvent.sqf | 14 ++++-- .../functions/fnc__handleSyncedEvent.sqf | 14 +++--- .../functions/fnc_addSyncedEventHandler.sqf | 2 +- .../functions/fnc_requestSyncedEvent.sqf | 4 +- addons/common/functions/fnc_syncedEvent.sqf | 2 +- 8 files changed, 58 insertions(+), 36 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 34ada15480..2a20c0204d 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); - diag_log text format["PLAYER CHANGED!", _this]; + if (alive _newPlayer) then { [_newPlayer] call FUNC(setName) }; @@ -188,30 +210,15 @@ GVAR(OldPlayerWeapon) = currentWeapon ACE_player; {!((_this select 0) isEqualTo (_this select 1)) && {vehicle (_this select 0) == vehicle (_this select 1)}} }] call FUNC(addCanInteractWithCondition); -// 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; - - +// Lastly, do JIP events // JIP Detection and event trigger. Run this at the very end, just in case anything uses it -if(!isServer && {isNull player}) then { +if(isMultiplayer && { time > 0 || isNull player } ) then { // We are jipping! Get ready and wait, and throw the event [{ - PARAMS_2(_args,_handle); - - if(!isNull player) then { + diag_log text format["JIP Detected, waiting"]; + if(!(isNull player)) then { ["PlayerJip", [player] ] call FUNC(localEvent); - [_handle] call cba_fnc_removePerFrameHandler; + [(_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 5bacea7505..077d69578b 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -273,10 +273,13 @@ PREP(hashListPush); PREP(syncedEventPFH); PREP(addSyncedEventHandler); PREP(removeSyncedEventHandler); +PREP(requestSyncedEvent); PREP(syncedEvent); + PREP(_handleSyncedEvent); PREP(_handleRequestSyncedEvent); -PREP(requestSyncedEvent); +PREP(_handleRequestAllSyncedEvents); + GVAR(syncedEvents) = HASH_CREATE; // @TODO: Generic local-managed global-synced objects (createVehicleLocal) diff --git a/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf index 62981092fb..7c566ce4d1 100644 --- a/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf +++ b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf @@ -1,13 +1,15 @@ /* * 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 +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_1(_client); diff --git a/addons/common/functions/fnc__handleRequestSyncedEvent.sqf b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf index c9b81f8ef7..2d58aae869 100644 --- a/addons/common/functions/fnc__handleRequestSyncedEvent.sqf +++ b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf @@ -1,13 +1,20 @@ /* * Author: jaynus + * + * Receives either requests for synchronization from clients, or the synchronization data from the server. * - * - * Argument: + * 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 +//#define DEBUG_MODE_FULL #include "script_component.hpp" //SEH_s @@ -32,6 +39,7 @@ if(isServer) then { _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 index 14dfc32bae..9807896358 100644 --- a/addons/common/functions/fnc__handleSyncedEvent.sqf +++ b/addons/common/functions/fnc__handleSyncedEvent.sqf @@ -1,17 +1,17 @@ /* * Author: jaynus + * + * Handles synced events being received. Server will log them, and server/client will execute them. * - * Call and propegate a synced event - * - * Argument: - * 0: Name (String) - * 1: Arguments (Array) - * 2: TTL (Number or Code) [Optional] + * Arguments [Client] : + * 0: eventName (String) + * 1: arguments (Array) + * 2: ttl (Scalar) * * Return value: * Boolean of success */ -#define DEBUG_MODE_FULL +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_3(_name,_args,_ttl); private["_internalData", "_eventLog", "_eventCode"]; diff --git a/addons/common/functions/fnc_addSyncedEventHandler.sqf b/addons/common/functions/fnc_addSyncedEventHandler.sqf index ab9d8bb829..5d2b221178 100644 --- a/addons/common/functions/fnc_addSyncedEventHandler.sqf +++ b/addons/common/functions/fnc_addSyncedEventHandler.sqf @@ -11,7 +11,7 @@ * Return value: * Boolean of success */ -#define DEBUG_MODE_FULL +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_2(_name,_handler); diff --git a/addons/common/functions/fnc_requestSyncedEvent.sqf b/addons/common/functions/fnc_requestSyncedEvent.sqf index f18c3542b5..dea0c7adef 100644 --- a/addons/common/functions/fnc_requestSyncedEvent.sqf +++ b/addons/common/functions/fnc_requestSyncedEvent.sqf @@ -1,13 +1,15 @@ /* * 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 +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_1(_eventName); diff --git a/addons/common/functions/fnc_syncedEvent.sqf b/addons/common/functions/fnc_syncedEvent.sqf index 43f4feb5bd..70c30a19da 100644 --- a/addons/common/functions/fnc_syncedEvent.sqf +++ b/addons/common/functions/fnc_syncedEvent.sqf @@ -11,7 +11,7 @@ * Return value: * Boolean of success */ -#define DEBUG_MODE_FULL +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_2(_name,_args); private["_ttl", "_eventData", "_internalData", "_eventLog"];