Deprecate ACE events framework

CBA 2.4.0 entirely replaces the ACE events framework.

Adds wrappers with deprecated warnings to all of the public event framework functions and removes all of the underlying GVARs and code.
This commit is contained in:
SilentSpike 2016-05-22 16:02:40 +01:00
parent 391191241b
commit f0b8da33c4
14 changed files with 18 additions and 358 deletions

View File

@ -235,7 +235,6 @@ PREP(dumpPerformanceCounters);
PREP(dumpArray);
PREP(globalEvent);
PREP(_handleNetEvent);
PREP(addEventHandler);
PREP(objectEvent);
PREP(targetEvent);

View File

@ -173,10 +173,6 @@ if (isServer) then {
// Set up remote execution
//////////////////////////////////////////////////
// ACE events
"ACEg" addPublicVariableEventHandler {_this call FUNC(_handleNetEvent)};
"ACEc" addPublicVariableEventHandler {_this call FUNC(_handleNetEvent)};
// Synced ACE events
// Handle JIP scenario
if (!isServer) then {

View File

@ -5,10 +5,6 @@ ADDON = false;
#include "XEH_PREP.hpp"
//ACE events global variables
GVAR(eventsLocation) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0];
GVAR(eventsLocation) setText QGVAR(eventsLocation);
// backwards comp
DFUNC(canUseWeapon) = {
ACE_DEPRECATED("ace_common_fnc_canUseWeapon","3.7.0","CBA_fnc_canUseWeapon");

View File

@ -1,81 +0,0 @@
/*
* Author: jaynus
* Internal net event handler.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_eventType", "_event"];
if (_eventType == "ACEg") then {
_event params ["_eventName", "_eventArgs"];
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
if (!isNil "_eventFunctions") then {
#ifdef DEBUG_EVENTS
ACE_LOGINFO_1("* Net Event %1",_eventName);
ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif
{
if (!isNil "_x") then {
_eventArgs call CALLSTACK_NAMED(_x, FORMAT_2("Net Event %1 ID: %2",_eventName,_forEachIndex));
#ifdef DEBUG_EVENTS_CALLSTACK
ACE_LOGINFO_1(" ID: %1",_forEachIndex);
#endif
};
} forEach _eventFunctions;
};
};
if (_eventType == "ACEc") then {
if (isServer) then {
_event params ["_eventName", "_eventTargets", "_eventArgs"];
private _sentEvents = [];
if (!IS_ARRAY(_eventTargets)) then {
_eventTargets = [_eventTargets];
};
//If not multiplayer, and there are targets, then just run localy
if (!isMultiplayer && {count _eventTargets > 0}) exitWith {
ACEg = [_eventName, _eventArgs];
["ACEg", ACEg] call FUNC(_handleNetEvent);
};
private _serverFlagged = false;
{
private _owner = _x;
if (IS_OBJECT(_x)) then {
_owner = owner _x;
};
if !(_owner in _sentEvents) then {
_sentEvents pushBack _owner;
ACEg = [_eventName, _eventArgs];
if (isDedicated || {_x != ACE_player}) then {
if (isDedicated && {local _x} && {!_serverFlagged}) then {
_serverFlagged = true;
["ACEg", ACEg] call FUNC(_handleNetEvent);
} else {
_owner publicVariableClient "ACEg";
};
} else {
["ACEg", ACEg] call FUNC(_handleNetEvent);
};
};
false
} count _eventTargets;
};
};

View File

@ -1,25 +1,5 @@
/*
* Author: Nou
* Add an event handler.
*
* Arguments:
* 0: Event name <STRING>
* 1: Event code <CODE>
*
* Return Value:
* Event handler ID number (for use with fnc_removeEventHandler) <NUMBER>
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventCode"];
_this call CBA_fnc_addEventHandler;
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
if (isNil "_eventFunctions") then {
_eventFunctions = [];
GVAR(eventsLocation) setVariable [_eventName, _eventFunctions];
};
_eventFunctions pushBack _eventCode // Return event function count
ACE_DEPRECATED("ace_common_fnc_addEventHandler","3.8.0","CBA_fnc_addEventHandler");

View File

@ -1,21 +1,5 @@
/*
* Author: Nou
* Execute a global event on all clients, including self.
*
* Arguments:
* 0: Event name <STRING>
* 1: Event args <ANY>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventArgs"];
_this call CBA_fnc_globalEvent;
ACEg = [_eventName, _eventArgs];
publicVariable "ACEg";
["ACEg", ACEg] call FUNC(_handleNetEvent);
ACE_DEPRECATED("ace_common_fnc_globalEvent","3.8.0","CBA_fnc_globalEvent");

View File

@ -1,36 +1,5 @@
/*
* Author: Nou
* Execute a local event on this client only.
*
* Arguments:
* 0: Event name (string)
* 1: Event args (any)
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_eventName", "_eventArgs"];
_this call CBA_fnc_localEvent;
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
if (!isNil "_eventFunctions") then {
#ifdef DEBUG_EVENTS
ACE_LOGINFO_1("* Local Event: %1",_eventName);
ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif
{
if (!isNil "_x") then {
_eventArgs call CALLSTACK_NAMED(_x,FORMAT_2("Local Event %1 ID: %2",_eventName,_forEachIndex));
#ifdef DEBUG_EVENTS_CALLSTACK
ACE_LOGINFO_1(" ID: %1",_forEachIndex);
#endif
};
} forEach _eventFunctions;
};
ACE_DEPRECATED("ace_common_fnc_localEvent","3.8.0","CBA_fnc_localEvent");

View File

@ -1,34 +1,7 @@
/*
* Author: PabstMirror
* Execute an event where object is local.
* If local there is no network traffic/delay (Unlike targetEvent)
*
* Arguments:
* 0: Event name (STRING)
* 1: Event target <OBJECT>
* 2: Event args <ANY>
*
* Return Value:
* None
*
* Example:
* ["doThing", vehicle player, []] call ace_common_fnc_objectEvent
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventTarget", "_eventArgs"];
#ifdef DEBUG_EVENTS
ACE_LOGINFO_2("* Object Event: %1 - %2",_eventName,_eventTarget);
ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif
[_eventName, _eventArgs, _eventTargets] call CBA_fnc_targetEvent;
if (local _eventTarget) then {
[_eventName, _eventArgs] call FUNC(localEvent);
} else {
_this call FUNC(targetEvent);
};
nil
ACE_DEPRECATED("ace_common_fnc_objectEvent","3.8.0","CBA_fnc_targetEvent");

View File

@ -1,17 +1,8 @@
/*
* Author: Nou
* Remove all events of a certain event type.
*
* Argument:
* 0: Event name <STRING>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName"];
GVAR(eventsLocation) setVariable [_eventName, nil];
CBA_events_eventNamespace setVariable [_eventName,nil];
CBA_events_eventHashes setVariable [_eventName,nil];
ACE_DEPRECATED("ace_common_fnc_removeAllEventHandlers","3.8.0","N/A (remove events individually w/ CBA_fnc_removeEventHandler)");

View File

@ -1,23 +1,5 @@
/*
* Author: Nou
* Remove an event handler.
*
* Argument:
* 0: Event name <STRING>
* 1: Event code <NUMBER>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventCodeIndex"];
_this call CBA_fnc_removeEventHandler;
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
if (isNil "_eventFunctions") exitWith {TRACE_1("eventName not found",_eventName);};
if ((_eventCodeIndex < 0) || {(count _eventFunctions) <= _eventCodeIndex}) exitWith {TRACE_2("index out of bounds",_eventName,_eventCodeIndex);};
_eventFunctions set [_eventCodeIndex, nil];
ACE_DEPRECATED("ace_common_fnc_removeEventHandler","3.8.0","CBA_fnc_removeEventHandler");

View File

@ -1,29 +1,5 @@
/*
* Author: Nou
* Execute a event only on the server.
*
* Argument:
* 0: Event name <STRING>
* 1: Event args <ANY>
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventArgs"];
_this call CBA_fnc_serverEvent;
#ifdef DEBUG_EVENTS
ACE_LOGINFO_1("* Server Event: %1",_eventName);
ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif
ACEg = [_eventName, _eventArgs];
if (!isServer) then {
publicVariableServer "ACEg";
} else {
["ACEg", ACEg] call FUNC(_handleNetEvent);
};
ACE_DEPRECATED("ace_common_fnc_serverEvent","3.8.0","CBA_fnc_serverEvent");

View File

@ -1,33 +1,7 @@
/*
* Author: Nou
* Execute a event only on specific clients.
*
* Arguments:
* 0: Event name (STRING)
* 1: Event targets <OBJECT, ARRAY>
* 2: Event args <ANY>
*
* Note: If local executor is in list of targets, event will execute with
* network delay, and not immediatly.
*
* Return Value:
* None
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_eventName", "_eventTargets", "_eventArgs"];
#ifdef DEBUG_EVENTS
ACE_LOGINFO_2("* Target Event: %1 - %2",_eventName,_eventTargets);
ACE_LOGINFO_1(" args=%1",_eventArgs);
#endif
[_eventName,_eventArgs,_eventTargets] call CBA_fnc_targetEvent;
ACEc = [_eventName, _eventTargets, _eventArgs];
if (!isServer) then {
publicVariableServer "ACEc";
} else {
["ACEc", ACEc] call FUNC(_handleNetEvent);
};
ACE_DEPRECATED("ace_common_fnc_targetEvent","3.8.0","CBA_fnc_targetEvent");

View File

@ -1 +0,0 @@
#include "\z\ace\addons\common\script_component.hpp"

View File

@ -1,78 +0,0 @@
// ----------------------------------------------------------------------------
#define DEBUG_MODE_FULL
#include "script_component.hpp"
#ifndef TEST_DEFINED_AND_OP
if (true) exitWith {};
#endif
// ----------------------------------------------------------------------------
LOG('Testing EventHandlers');
TEST_DEFINED(QFUNC(_handleNetEvent),"");
TEST_DEFINED(QFUNC(addEventHandler),"");
TEST_DEFINED(QFUNC(localEvent),"");
TEST_DEFINED(QFUNC(targetEvent),"");
TEST_DEFINED(QFUNC(globalEvent),"");
TEST_DEFINED(QFUNC(serverEvent),"");
TEST_DEFINED(QFUNC(removeAllEventHandlers),"");
TEST_DEFINED(QFUNC(removeEventHandler),"");
private _result = ["A", {}] call ace_common_fnc_addEventHandler;
private _expected = 0;
TEST_DEFINED_AND_OP(_result,==,_expected,"Adding first A EH");
_result = ["A", {GVAR(test_A2) = _this}] call ace_common_fnc_addEventHandler;
_expected = 1;
TEST_DEFINED_AND_OP(_result,==,_expected,"Adding second A EH");
_result = ["A", {GVAR(test_A3) = _this}] call ace_common_fnc_addEventHandler;
_expected = 2;
TEST_DEFINED_AND_OP(_result,==,_expected,"Adding third A EH");
GVAR(test_A2) = -1;
["A", 11] call FUNC(localEvent);
_expected = 11;
_result = GVAR(test_A2);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test Local Event");
//Remove 2nd EH
["A", 1] call FUNC(removeEventHandler);
GVAR(test_A2) = -1;
GVAR(test_A3) = -1;
["A", 22] call FUNC(localEvent);
_expected = -1;
_result = GVAR(test_A2);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test 2nd (removed) EH");
_expected = 22;
_result = GVAR(test_A3);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test 3rd Event");
//Remove All EH:
["A"] call FUNC(removeAllEventHandlers);
GVAR(test_A3) = -1;
["A", 77] call FUNC(localEvent);
_expected = -1;
_result = GVAR(test_A3);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test 3rd is removed after removeAll");
//Much harder to test network events
TRACE_2("testing network events",isServer,isDedicated);
["B", {GVAR(test_B) = _this}] call ace_common_fnc_addEventHandler;
GVAR(test_B) = -1;
["B", 33] call FUNC(globalEvent);
_expected = 33;
_result = GVAR(test_B);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test globalEvent");
GVAR(test_B) = -1;
["B", 44] call FUNC(serverEvent);
_expected = if (isServer) then {44} else {-1};
_result = GVAR(test_B);
TEST_DEFINED_AND_OP(_result,==,_expected,"Test serverEvent");