Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add removeGlobalEventJIP #741

Merged
merged 3 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions addons/events/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class CfgFunctions {
description = "Raises a CBA event on all machines. Event is put on a stack that is executed on every future JIP machine. Stack can be overwritten by using the same JIP-Stack-ID.";
file = "\x\cba\addons\events\fnc_globalEventJIP.sqf";
};
class removeGlobalEventJIP {
description = "Removes a globalEventJIP ID. Optionaly will wait until an object is deleted.";
file = "\x\cba\addons\events\fnc_removeGlobalEventJIP.sqf";
};
class serverEvent {
description = "Raises a CBA event on the server machine.";
file = "\x\cba\addons\events\fnc_serverEvent.sqf";
Expand Down
28 changes: 28 additions & 0 deletions addons/events/fnc_removeGlobalEventJIP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_removeGlobalEventJIP

Description:
Removes a globalEventJIP ID. Optionaly will wait until an object is deleted.

Parameters:
_jipID - A unique ID from CBA_fnc_globalEventJIP. <STRING>
_object - Object, will remove jip EH when object is deleted. Or pass nil to ignore and remove immediately [optional] <OBJECT>or<NIL>

Returns:
Nothing

Author:
PabstMirror (idea from Dystopian)
---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(removeGlobalEventJIP);

params [["_jipID", "", [""]], ["_object", nil, [nil, objNull]]];

if ((isNil "_object") || {isNull _object}) then {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params [["_jipID", "", [""]], ["_object", objNull, [objNull]]];

if (isNull _object) then {

GVAR(eventNamespaceJIP) setVariable [_jipID, nil, true];
} else {
[_object, "Deleted", {
GVAR(eventNamespaceJIP) setVariable [_thisArgs, nil, true];
}, _jipID] call CBA_fnc_addBISEventHandler;
};
20 changes: 20 additions & 0 deletions addons/events/test.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// -----------------------------------------------------------------------------
// Automatically generated by 'functions_config.rb'
// DO NOT MANUALLY EDIT THIS FILE!
// -----------------------------------------------------------------------------
#define DEBUG_MODE_FULL
#include "script_component.hpp"

#define TESTS ["globalEventJIP"]

SCRIPT(test-events);

// ----------------------------------------------------------------------------

LOG("=== Testing Events ===");

{
0 spawn compile preprocessFileLineNumbers format ["\x\cba\addons\events\test_%1.sqf", _x];
} forEach TESTS;

nil
46 changes: 46 additions & 0 deletions addons/events/test_globalEventJIP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------
#define DEBUG_SYNCHRONOUS
#include "script_component.hpp"

SCRIPT(test_globalEventJIP);

// ----------------------------------------------------------------------------
#define DEBUG_MODE_FULL

LOG("Testing globalEventJIP");

// UNIT TESTS
TEST_DEFINED("CBA_fnc_globalEventJIP","");
TEST_DEFINED("CBA_fnc_removeGlobalEventJIP","");

// Add basic testing event handler:
GVAR(test_A) = 0;
[QGVAR(test_globalEventJIP), {GVAR(test_A) = _this}] call CBA_fnc_addEventHandler;

// Test adding globalEventJIP
private _ret = [QGVAR(test_globalEventJIP), 1] call CBA_fnc_globalEventJIP;
private _expected = 1;
TEST_DEFINED_AND_OP(GVAR(test_A),==,_expected,"Verify EH ran");
TEST_FALSE(isNil {GVAR(eventNamespaceJIP) getVariable _ret},"Verify in global event namespace");

// Test removing globalEventJIP
[_ret] call CBA_fnc_removeGlobalEventJIP;
TEST_TRUE(isNil {GVAR(eventNamespaceJIP) getVariable _ret},"Verify removed from global event namespace");

// Test removing on objNull
private _ret = [QGVAR(test_globalEventJIP), 2] call CBA_fnc_globalEventJIP;
[_ret, objNull] call CBA_fnc_removeGlobalEventJIP;
TEST_TRUE(isNil {GVAR(eventNamespaceJIP) getVariable _ret},"Verify deleted on null object");

// Test removing on non-null object
private _dummyObject = "Land_bakedBeans_F" createVehicle [0,0,0];
private _ret = [QGVAR(test_globalEventJIP), 3] call CBA_fnc_globalEventJIP;
[_ret, _dummyObject] call CBA_fnc_removeGlobalEventJIP;
TEST_FALSE(isNil {GVAR(eventNamespaceJIP) getVariable _ret},"Verify not removed");
deleteVehicle _dummyObject;
sleep 0.05;
TEST_TRUE(isNull _dummyObject,"Verify Object Deleted");
TEST_TRUE(isNil {GVAR(eventNamespaceJIP) getVariable _ret},"Verify removed when deleted");


nil;
2 changes: 1 addition & 1 deletion addons/main/test.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "script_component.hpp"

#define CATEGORIES ["arrays", "common", "diagnostic", "hashes", "network", "strings", "vectors", "jr"]
#define CATEGORIES ["arrays", "common", "diagnostic", "events", "hashes", "network", "strings", "vectors", "jr"]

SCRIPT(test);

Expand Down