mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3282 from acemod/eventLocationHash
Use location hash for ace events
This commit is contained in:
commit
77f5aebf73
@ -257,7 +257,8 @@ PREP(addCuratorUnloadEventhandler);
|
||||
PREP(fixCrateContent);
|
||||
|
||||
//ACE events global variables
|
||||
GVAR(events) = [[],[]];
|
||||
GVAR(eventsLocation) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0];
|
||||
GVAR(eventsLocation) setText QGVAR(eventsLocation);
|
||||
|
||||
PREP(globalEvent);
|
||||
PREP(_handleNetEvent);
|
||||
|
@ -16,12 +16,9 @@ params ["_eventType", "_event"];
|
||||
|
||||
if (_eventType == "ACEg") then {
|
||||
_event params ["_eventName", "_eventArgs"];
|
||||
GVAR(events) params ["_eventNames"];
|
||||
|
||||
private _eventIndex = _eventNames find _eventName;
|
||||
|
||||
if (_eventIndex != -1) then {
|
||||
private _events = (GVAR(events) select 1) select _eventIndex;
|
||||
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
|
||||
if (!isNil "_eventFunctions") then {
|
||||
|
||||
#ifdef DEBUG_EVENTS
|
||||
ACE_LOGINFO_1("* Net Event %1",_eventName);
|
||||
@ -35,7 +32,7 @@ if (_eventType == "ACEg") then {
|
||||
ACE_LOGINFO_1(" ID: %1",_forEachIndex);
|
||||
#endif
|
||||
};
|
||||
} forEach _events;
|
||||
} forEach _eventFunctions;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -15,18 +15,11 @@
|
||||
|
||||
params ["_eventName", "_eventCode"];
|
||||
|
||||
GVAR(events) params ["_eventNames"];
|
||||
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
|
||||
|
||||
private _eventFunctions = [];
|
||||
private _eventIndex = _eventNames find _eventName;
|
||||
|
||||
if (_eventIndex != -1) then {
|
||||
_eventFunctions = (GVAR(events) select 1) select _eventIndex;
|
||||
} else {
|
||||
private _eventNameCount = count _eventNames;
|
||||
|
||||
_eventNames set [_eventNameCount, _eventName];
|
||||
(GVAR(events) select 1) set [_eventNameCount, _eventFunctions];
|
||||
if (isNil "_eventFunctions") then {
|
||||
_eventFunctions = [];
|
||||
GVAR(eventsLocation) setVariable [_eventName, _eventFunctions];
|
||||
};
|
||||
|
||||
_eventFunctions pushBack _eventCode // Return event function count
|
||||
|
@ -15,12 +15,9 @@
|
||||
|
||||
params ["_eventName", "_eventArgs"];
|
||||
|
||||
GVAR(events) params ["_eventNames", "_eventArray"];
|
||||
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
|
||||
|
||||
private _eventIndex = _eventNames find _eventName;
|
||||
|
||||
if (_eventIndex != -1) then {
|
||||
private _events = _eventArray select _eventIndex;
|
||||
if (!isNil "_eventFunctions") then {
|
||||
|
||||
#ifdef DEBUG_EVENTS
|
||||
ACE_LOGINFO_1("* Local Event: %1",_eventName);
|
||||
@ -35,5 +32,5 @@ if (_eventIndex != -1) then {
|
||||
ACE_LOGINFO_1(" ID: %1",_forEachIndex);
|
||||
#endif
|
||||
};
|
||||
} forEach _events;
|
||||
} forEach _eventFunctions;
|
||||
};
|
||||
|
@ -14,11 +14,4 @@
|
||||
|
||||
params ["_eventName"];
|
||||
|
||||
GVAR(events) params ["_eventNames", "_events"];
|
||||
|
||||
private _eventFunctions = [];
|
||||
private _eventIndex = _eventNames find _eventName;
|
||||
|
||||
if (_eventIndex != -1) then {
|
||||
_events set [_eventIndex, []];
|
||||
};
|
||||
GVAR(eventsLocation) setVariable [_eventName, nil];
|
||||
|
@ -15,12 +15,9 @@
|
||||
|
||||
params ["_eventName", "_eventCodeIndex"];
|
||||
|
||||
GVAR(events) params ["_eventNames", "_events"];
|
||||
private _eventFunctions = GVAR(eventsLocation) getVariable _eventName;
|
||||
|
||||
private _eventFunctions = [];
|
||||
private _eventIndex = _eventNames find _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);};
|
||||
|
||||
if (_eventIndex != -1) then {
|
||||
_eventFunctions = _events select _eventIndex;
|
||||
_eventFunctions set [_eventCodeIndex, nil];
|
||||
};
|
||||
_eventFunctions set [_eventCodeIndex, nil];
|
||||
|
1
addons/common/tests/script_component.hpp
Normal file
1
addons/common/tests/script_component.hpp
Normal file
@ -0,0 +1 @@
|
||||
#include "\z\ace\addons\common\script_component.hpp"
|
78
addons/common/tests/test_eventHandlers.sqf
Normal file
78
addons/common/tests/test_eventHandlers.sqf
Normal file
@ -0,0 +1,78 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
#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");
|
||||
|
Loading…
Reference in New Issue
Block a user