From af5b472679e0c2ccbb07af1a3ec2d29f86988d31 Mon Sep 17 00:00:00 2001 From: Marco Silipo Date: Wed, 27 Jun 2018 12:03:33 +0200 Subject: [PATCH 01/13] Added promise system --- addons/promise/$PBOPREFIX$ | 1 + addons/promise/CfgFunctions.hpp | 11 +++++++ addons/promise/config.cpp | 17 ++++++++++ addons/promise/fnc_callback.sqf | 29 ++++++++++++++++ addons/promise/fnc_create.sqf | 51 +++++++++++++++++++++++++++++ addons/promise/fnc_done.sqf | 24 ++++++++++++++ addons/promise/fnc_init.sqf | 28 ++++++++++++++++ addons/promise/fnc_receiver.sqf | 32 ++++++++++++++++++ addons/promise/license.txt | 21 ++++++++++++ addons/promise/script_component.hpp | 4 +++ 10 files changed, 218 insertions(+) create mode 100644 addons/promise/$PBOPREFIX$ create mode 100644 addons/promise/CfgFunctions.hpp create mode 100644 addons/promise/config.cpp create mode 100644 addons/promise/fnc_callback.sqf create mode 100644 addons/promise/fnc_create.sqf create mode 100644 addons/promise/fnc_done.sqf create mode 100644 addons/promise/fnc_init.sqf create mode 100644 addons/promise/fnc_receiver.sqf create mode 100644 addons/promise/license.txt create mode 100644 addons/promise/script_component.hpp diff --git a/addons/promise/$PBOPREFIX$ b/addons/promise/$PBOPREFIX$ new file mode 100644 index 000000000..5477a44d8 --- /dev/null +++ b/addons/promise/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\promise diff --git a/addons/promise/CfgFunctions.hpp b/addons/promise/CfgFunctions.hpp new file mode 100644 index 000000000..6bebb6192 --- /dev/null +++ b/addons/promise/CfgFunctions.hpp @@ -0,0 +1,11 @@ +class CfgFunctions { + class CBA { + class Network { + PATHTO_FNC(promise_create); + PATHTO_FNC(promise_callback); + PATHTO_FNC(promise_done); + PATHTO_FNC(promise_receiver); + PATHTO_FNC(promise_init); + }; + }; +}; diff --git a/addons/promise/config.cpp b/addons/promise/config.cpp new file mode 100644 index 000000000..82ee0436e --- /dev/null +++ b/addons/promise/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + author = "$STR_CBA_Author"; + name = CSTRING(component); + url = "$STR_CBA_URL"; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {}; + version = VERSION; + authors[] = {"X39"}; + }; +}; + +#include "CfgFunctions.hpp" diff --git a/addons/promise/fnc_callback.sqf b/addons/promise/fnc_callback.sqf new file mode 100644 index 000000000..b9d529d47 --- /dev/null +++ b/addons/promise/fnc_callback.sqf @@ -0,0 +1,29 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_callback + +Description: + Method that gets called when the receiver is done. + Will in the end execute the promise-code locally. + + WARNING! Not intended to be called by client-code! + +Parameters: + _id - The Promise-ID of the now finished promise. + _data - The result data of the now finished promise. + +Returns: + Nothing + +Example: + Nothing + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_id", "_data"]; +private _request = GVAR(requests) select _id; +GVAR(requests) set [_id, 0]; +[_request select 0, _data] call (_request select 1); +nil \ No newline at end of file diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf new file mode 100644 index 000000000..60b9102f5 --- /dev/null +++ b/addons/promise/fnc_create.sqf @@ -0,0 +1,51 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_create + +Description: + Creates and executes a new Promise. + +Parameters: + _objects - Object or array of objects that perform Say + _params - [sound, maxTitlesDistance,speed] or "sound" + + _rcv - remoteExecCall target. + _mthd - either string (methodname) or code to execute on target. + _mthdArgs - custom arguments to pass to the target. + _args - args to pass to the callback (see next param) + _cb - callback for the promise (executed on current machine). + Will receive an array, with index 0 being what is passed include + _args and index 1 being whatever is returned by the target invokation + [_args, _mthdResult] + +Returns: + Identifier that allows to check if a promise is yet done. + See CBA_fnc_promise_done. + +Example: + (begin example) + [ + random_player, "random_method", [], + [_someLocalVariable], { + params ["_args", "_result"]; + _args params ["_someLocalVariable"]; + diag_log _result; + diag_log _someLocalVariable; + } + ] call CBA_fnc_promise_create; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +params ["_rcv", "_mthd", "_mthdArgs", "_args", "_cb"]; +private _stamp = diag_tickTime; +private _index = 0; +isNil { + _index = GVAR(requests) find 0; + if (_index == -1) then + { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } + else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } +}; +[_index, _mthd, _mthdArgs] remoteExec ["Promise_Receiver", _rcv, false]; +[_index, _stamp] \ No newline at end of file diff --git a/addons/promise/fnc_done.sqf b/addons/promise/fnc_done.sqf new file mode 100644 index 000000000..dd9d2c800 --- /dev/null +++ b/addons/promise/fnc_done.sqf @@ -0,0 +1,24 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_done + +Description: + Checks if a given promise was processed yet. + +Parameters: + _promiseHandle - Handle returned by CBA_fnc_promise_create + +Returns: + Boolean, true if it is done yet, false if it is not. + +Example: + (begin example) + _promiseHandle call CBA_fnc_promise_done; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +params ["_index", "_stamp"]; +private _promise = Promise_Requests select 0; +if (_promise isEqualTo 0) { true } else { _promise select 2 != _stamp } \ No newline at end of file diff --git a/addons/promise/fnc_init.sqf b/addons/promise/fnc_init.sqf new file mode 100644 index 000000000..eeedca85c --- /dev/null +++ b/addons/promise/fnc_init.sqf @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_init + +Description: + Initializes the required variabels for the promise system. + +Parameters: + Nothing + +Returns: + Nothing + +Example: + (begin example) + [] call CBA_fnc_promise_init; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +isNil { + if isNil QGVAR(requests) then { + GVAR(requests) = []; + }; +}; + +nil diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf new file mode 100644 index 000000000..fbab3218b --- /dev/null +++ b/addons/promise/fnc_receiver.sqf @@ -0,0 +1,32 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_receiver + +Description: + Method that gets called when a sender has a request. + + WARNING! Not intended to be called by client-code! + +Parameters: + _id - the promise ID, local to the sender. + _mthd - The method to execute, either string (var name) or code. + _args - Arguments to pass to the method. + +Returns: + Nothing + +Example: + Nothing + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_id", "_mthd", "_args"]; +private _res = if (_mthd isEqualType "") then { + _args call (missionNamespace getVariable _mthd); +} else { + _args call _mthd; +}; +[_id, _res] remoteExec ["Promise_Callback", remoteExecutedOwner, false]; +nil \ No newline at end of file diff --git a/addons/promise/license.txt b/addons/promise/license.txt new file mode 100644 index 000000000..740a12b7c --- /dev/null +++ b/addons/promise/license.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Marco Silipo (X39) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/addons/promise/script_component.hpp b/addons/promise/script_component.hpp new file mode 100644 index 000000000..9ad9b2f60 --- /dev/null +++ b/addons/promise/script_component.hpp @@ -0,0 +1,4 @@ +#define COMPONENT promise +#include "\x\cba\addons\main\script_mod.hpp" + +#include "\x\cba\addons\main\script_macros.hpp" \ No newline at end of file From fbd6d48a65fa7ed95b1bdbd2855ddf345526996e Mon Sep 17 00:00:00 2001 From: Marco Silipo Date: Wed, 27 Jun 2018 12:03:33 +0200 Subject: [PATCH 02/13] Added promise system --- addons/promise/$PBOPREFIX$ | 1 + addons/promise/CfgFunctions.hpp | 11 +++++++ addons/promise/config.cpp | 17 ++++++++++ addons/promise/fnc_callback.sqf | 29 ++++++++++++++++ addons/promise/fnc_create.sqf | 51 +++++++++++++++++++++++++++++ addons/promise/fnc_done.sqf | 24 ++++++++++++++ addons/promise/fnc_init.sqf | 28 ++++++++++++++++ addons/promise/fnc_receiver.sqf | 32 ++++++++++++++++++ addons/promise/license.txt | 21 ++++++++++++ addons/promise/script_component.hpp | 4 +++ 10 files changed, 218 insertions(+) create mode 100644 addons/promise/$PBOPREFIX$ create mode 100644 addons/promise/CfgFunctions.hpp create mode 100644 addons/promise/config.cpp create mode 100644 addons/promise/fnc_callback.sqf create mode 100644 addons/promise/fnc_create.sqf create mode 100644 addons/promise/fnc_done.sqf create mode 100644 addons/promise/fnc_init.sqf create mode 100644 addons/promise/fnc_receiver.sqf create mode 100644 addons/promise/license.txt create mode 100644 addons/promise/script_component.hpp diff --git a/addons/promise/$PBOPREFIX$ b/addons/promise/$PBOPREFIX$ new file mode 100644 index 000000000..5477a44d8 --- /dev/null +++ b/addons/promise/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\promise diff --git a/addons/promise/CfgFunctions.hpp b/addons/promise/CfgFunctions.hpp new file mode 100644 index 000000000..6bebb6192 --- /dev/null +++ b/addons/promise/CfgFunctions.hpp @@ -0,0 +1,11 @@ +class CfgFunctions { + class CBA { + class Network { + PATHTO_FNC(promise_create); + PATHTO_FNC(promise_callback); + PATHTO_FNC(promise_done); + PATHTO_FNC(promise_receiver); + PATHTO_FNC(promise_init); + }; + }; +}; diff --git a/addons/promise/config.cpp b/addons/promise/config.cpp new file mode 100644 index 000000000..82ee0436e --- /dev/null +++ b/addons/promise/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + author = "$STR_CBA_Author"; + name = CSTRING(component); + url = "$STR_CBA_URL"; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {}; + version = VERSION; + authors[] = {"X39"}; + }; +}; + +#include "CfgFunctions.hpp" diff --git a/addons/promise/fnc_callback.sqf b/addons/promise/fnc_callback.sqf new file mode 100644 index 000000000..b9d529d47 --- /dev/null +++ b/addons/promise/fnc_callback.sqf @@ -0,0 +1,29 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_callback + +Description: + Method that gets called when the receiver is done. + Will in the end execute the promise-code locally. + + WARNING! Not intended to be called by client-code! + +Parameters: + _id - The Promise-ID of the now finished promise. + _data - The result data of the now finished promise. + +Returns: + Nothing + +Example: + Nothing + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_id", "_data"]; +private _request = GVAR(requests) select _id; +GVAR(requests) set [_id, 0]; +[_request select 0, _data] call (_request select 1); +nil \ No newline at end of file diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf new file mode 100644 index 000000000..60b9102f5 --- /dev/null +++ b/addons/promise/fnc_create.sqf @@ -0,0 +1,51 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_create + +Description: + Creates and executes a new Promise. + +Parameters: + _objects - Object or array of objects that perform Say + _params - [sound, maxTitlesDistance,speed] or "sound" + + _rcv - remoteExecCall target. + _mthd - either string (methodname) or code to execute on target. + _mthdArgs - custom arguments to pass to the target. + _args - args to pass to the callback (see next param) + _cb - callback for the promise (executed on current machine). + Will receive an array, with index 0 being what is passed include + _args and index 1 being whatever is returned by the target invokation + [_args, _mthdResult] + +Returns: + Identifier that allows to check if a promise is yet done. + See CBA_fnc_promise_done. + +Example: + (begin example) + [ + random_player, "random_method", [], + [_someLocalVariable], { + params ["_args", "_result"]; + _args params ["_someLocalVariable"]; + diag_log _result; + diag_log _someLocalVariable; + } + ] call CBA_fnc_promise_create; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +params ["_rcv", "_mthd", "_mthdArgs", "_args", "_cb"]; +private _stamp = diag_tickTime; +private _index = 0; +isNil { + _index = GVAR(requests) find 0; + if (_index == -1) then + { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } + else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } +}; +[_index, _mthd, _mthdArgs] remoteExec ["Promise_Receiver", _rcv, false]; +[_index, _stamp] \ No newline at end of file diff --git a/addons/promise/fnc_done.sqf b/addons/promise/fnc_done.sqf new file mode 100644 index 000000000..dd9d2c800 --- /dev/null +++ b/addons/promise/fnc_done.sqf @@ -0,0 +1,24 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_done + +Description: + Checks if a given promise was processed yet. + +Parameters: + _promiseHandle - Handle returned by CBA_fnc_promise_create + +Returns: + Boolean, true if it is done yet, false if it is not. + +Example: + (begin example) + _promiseHandle call CBA_fnc_promise_done; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +params ["_index", "_stamp"]; +private _promise = Promise_Requests select 0; +if (_promise isEqualTo 0) { true } else { _promise select 2 != _stamp } \ No newline at end of file diff --git a/addons/promise/fnc_init.sqf b/addons/promise/fnc_init.sqf new file mode 100644 index 000000000..eeedca85c --- /dev/null +++ b/addons/promise/fnc_init.sqf @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_init + +Description: + Initializes the required variabels for the promise system. + +Parameters: + Nothing + +Returns: + Nothing + +Example: + (begin example) + [] call CBA_fnc_promise_init; + (end) + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +isNil { + if isNil QGVAR(requests) then { + GVAR(requests) = []; + }; +}; + +nil diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf new file mode 100644 index 000000000..fbab3218b --- /dev/null +++ b/addons/promise/fnc_receiver.sqf @@ -0,0 +1,32 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_promise_receiver + +Description: + Method that gets called when a sender has a request. + + WARNING! Not intended to be called by client-code! + +Parameters: + _id - the promise ID, local to the sender. + _mthd - The method to execute, either string (var name) or code. + _args - Arguments to pass to the method. + +Returns: + Nothing + +Example: + Nothing + +Author: + X39 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_id", "_mthd", "_args"]; +private _res = if (_mthd isEqualType "") then { + _args call (missionNamespace getVariable _mthd); +} else { + _args call _mthd; +}; +[_id, _res] remoteExec ["Promise_Callback", remoteExecutedOwner, false]; +nil \ No newline at end of file diff --git a/addons/promise/license.txt b/addons/promise/license.txt new file mode 100644 index 000000000..740a12b7c --- /dev/null +++ b/addons/promise/license.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Marco Silipo (X39) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/addons/promise/script_component.hpp b/addons/promise/script_component.hpp new file mode 100644 index 000000000..9ad9b2f60 --- /dev/null +++ b/addons/promise/script_component.hpp @@ -0,0 +1,4 @@ +#define COMPONENT promise +#include "\x\cba\addons\main\script_mod.hpp" + +#include "\x\cba\addons\main\script_macros.hpp" \ No newline at end of file From fed80b4f4a9c1f780949875bd35c5a3579e5e298 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 02:37:18 +0100 Subject: [PATCH 03/13] tab --> spaces --- addons/promise/fnc_callback.sqf | 8 +++--- addons/promise/fnc_create.sqf | 44 ++++++++++++++++----------------- addons/promise/fnc_init.sqf | 6 ++--- addons/promise/fnc_receiver.sqf | 10 ++++---- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/addons/promise/fnc_callback.sqf b/addons/promise/fnc_callback.sqf index b9d529d47..65bdcbff5 100644 --- a/addons/promise/fnc_callback.sqf +++ b/addons/promise/fnc_callback.sqf @@ -3,9 +3,9 @@ Function: CBA_fnc_promise_callback Description: Method that gets called when the receiver is done. - Will in the end execute the promise-code locally. - - WARNING! Not intended to be called by client-code! + Will in the end execute the promise-code locally. + + WARNING! Not intended to be called by client-code! Parameters: _id - The Promise-ID of the now finished promise. @@ -26,4 +26,4 @@ params ["_id", "_data"]; private _request = GVAR(requests) select _id; GVAR(requests) set [_id, 0]; [_request select 0, _data] call (_request select 1); -nil \ No newline at end of file +nil diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index 60b9102f5..d74414b06 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -2,36 +2,36 @@ Function: CBA_fnc_promise_create Description: - Creates and executes a new Promise. + Creates and executes a new Promise. Parameters: _objects - Object or array of objects that perform Say _params - [sound, maxTitlesDistance,speed] or "sound" - _rcv - remoteExecCall target. - _mthd - either string (methodname) or code to execute on target. - _mthdArgs - custom arguments to pass to the target. - _args - args to pass to the callback (see next param) - _cb - callback for the promise (executed on current machine). + _rcv - remoteExecCall target. + _mthd - either string (methodname) or code to execute on target. + _mthdArgs - custom arguments to pass to the target. + _args - args to pass to the callback (see next param) + _cb - callback for the promise (executed on current machine). Will receive an array, with index 0 being what is passed include - _args and index 1 being whatever is returned by the target invokation - [_args, _mthdResult] + _args and index 1 being whatever is returned by the target invokation + [_args, _mthdResult] Returns: Identifier that allows to check if a promise is yet done. - See CBA_fnc_promise_done. + See CBA_fnc_promise_done. Example: (begin example) [ - random_player, "random_method", [], - [_someLocalVariable], { - params ["_args", "_result"]; - _args params ["_someLocalVariable"]; - diag_log _result; - diag_log _someLocalVariable; - } - ] call CBA_fnc_promise_create; + random_player, "random_method", [], + [_someLocalVariable], { + params ["_args", "_result"]; + _args params ["_someLocalVariable"]; + diag_log _result; + diag_log _someLocalVariable; + } + ] call CBA_fnc_promise_create; (end) Author: @@ -42,10 +42,10 @@ params ["_rcv", "_mthd", "_mthdArgs", "_args", "_cb"]; private _stamp = diag_tickTime; private _index = 0; isNil { - _index = GVAR(requests) find 0; - if (_index == -1) then - { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } - else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } + _index = GVAR(requests) find 0; + if (_index == -1) then + { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } + else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } }; [_index, _mthd, _mthdArgs] remoteExec ["Promise_Receiver", _rcv, false]; -[_index, _stamp] \ No newline at end of file +[_index, _stamp] diff --git a/addons/promise/fnc_init.sqf b/addons/promise/fnc_init.sqf index eeedca85c..1e9bd064a 100644 --- a/addons/promise/fnc_init.sqf +++ b/addons/promise/fnc_init.sqf @@ -20,9 +20,9 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" isNil { - if isNil QGVAR(requests) then { - GVAR(requests) = []; - }; + if isNil QGVAR(requests) then { + GVAR(requests) = []; + }; }; nil diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf index fbab3218b..acdd9760c 100644 --- a/addons/promise/fnc_receiver.sqf +++ b/addons/promise/fnc_receiver.sqf @@ -3,8 +3,8 @@ Function: CBA_fnc_promise_receiver Description: Method that gets called when a sender has a request. - - WARNING! Not intended to be called by client-code! + + WARNING! Not intended to be called by client-code! Parameters: _id - the promise ID, local to the sender. @@ -24,9 +24,9 @@ Author: params ["_id", "_mthd", "_args"]; private _res = if (_mthd isEqualType "") then { - _args call (missionNamespace getVariable _mthd); + _args call (missionNamespace getVariable _mthd); } else { - _args call _mthd; + _args call _mthd; }; [_id, _res] remoteExec ["Promise_Callback", remoteExecutedOwner, false]; -nil \ No newline at end of file +nil From 4a2d77f76f1f720be90c8be494e22155144deb19 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 02:39:16 +0100 Subject: [PATCH 04/13] Altered variable to GVAR macro --- addons/promise/fnc_done.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/promise/fnc_done.sqf b/addons/promise/fnc_done.sqf index dd9d2c800..fcacb7622 100644 --- a/addons/promise/fnc_done.sqf +++ b/addons/promise/fnc_done.sqf @@ -20,5 +20,5 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" params ["_index", "_stamp"]; -private _promise = Promise_Requests select 0; +private _promise = GVAR(requests) select 0; if (_promise isEqualTo 0) { true } else { _promise select 2 != _stamp } \ No newline at end of file From 49f3c9ec687b1e08018fe30628b0810351cd9031 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 02:47:47 +0100 Subject: [PATCH 05/13] Changed two more non-macro usages --- addons/promise/fnc_create.sqf | 2 +- addons/promise/fnc_receiver.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index d74414b06..eee185bc1 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -47,5 +47,5 @@ isNil { { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } }; -[_index, _mthd, _mthdArgs] remoteExec ["Promise_Receiver", _rcv, false]; +[_index, _mthd, _mthdArgs] remoteExec [QGVAR(requests), _rcv, false]; [_index, _stamp] diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf index acdd9760c..f73709be8 100644 --- a/addons/promise/fnc_receiver.sqf +++ b/addons/promise/fnc_receiver.sqf @@ -28,5 +28,5 @@ private _res = if (_mthd isEqualType "") then { } else { _args call _mthd; }; -[_id, _res] remoteExec ["Promise_Callback", remoteExecutedOwner, false]; +[_id, _res] remoteExec [QGVAR(requests), remoteExecutedOwner, false]; nil From 3a950e7f317d66fe9ca47d020c6aebb4322f49ff Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:45:19 +0100 Subject: [PATCH 06/13] renamed _mthd to _method --- addons/promise/fnc_receiver.sqf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf index f73709be8..06bdaa201 100644 --- a/addons/promise/fnc_receiver.sqf +++ b/addons/promise/fnc_receiver.sqf @@ -8,7 +8,7 @@ Description: Parameters: _id - the promise ID, local to the sender. - _mthd - The method to execute, either string (var name) or code. + _method - The method to execute, either string (var name) or code. _args - Arguments to pass to the method. Returns: @@ -22,11 +22,11 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params ["_id", "_mthd", "_args"]; -private _res = if (_mthd isEqualType "") then { - _args call (missionNamespace getVariable _mthd); +params ["_id", "_method", "_args"]; +private _res = if (_method isEqualType "") then { + _args call (missionNamespace getVariable _method); } else { - _args call _mthd; + _args call _method; }; [_id, _res] remoteExec [QGVAR(requests), remoteExecutedOwner, false]; nil From 7024e758407a24c6a7aff4f6de77c09ba179ae6b Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:46:09 +0100 Subject: [PATCH 07/13] replaced if with BOOL || CODE --- addons/promise/fnc_done.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/promise/fnc_done.sqf b/addons/promise/fnc_done.sqf index fcacb7622..3aed54a32 100644 --- a/addons/promise/fnc_done.sqf +++ b/addons/promise/fnc_done.sqf @@ -21,4 +21,4 @@ Author: #include "script_component.hpp" params ["_index", "_stamp"]; private _promise = GVAR(requests) select 0; -if (_promise isEqualTo 0) { true } else { _promise select 2 != _stamp } \ No newline at end of file +_promise isEqualTo 0 || {_promise select 2 != _stamp} From a2cea8aa4a005d8494fe475acdd2211dd99f9ed9 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:49:33 +0100 Subject: [PATCH 08/13] Removed copy-paste leftover in documentation --- addons/promise/fnc_create.sqf | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index eee185bc1..e00a070db 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -5,9 +5,6 @@ Description: Creates and executes a new Promise. Parameters: - _objects - Object or array of objects that perform Say - _params - [sound, maxTitlesDistance,speed] or "sound" - _rcv - remoteExecCall target. _mthd - either string (methodname) or code to execute on target. _mthdArgs - custom arguments to pass to the target. From ac912c96efc0ac361708ab9ee918426b86a20822 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:50:46 +0100 Subject: [PATCH 09/13] Fixed formatting --- addons/arrays/fnc_findMax.sqf | 2 +- addons/promise/fnc_create.sqf | 9 ++++++--- addons/promise/script_component.hpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/arrays/fnc_findMax.sqf b/addons/arrays/fnc_findMax.sqf index 5d7838d2c..c00d1b981 100644 --- a/addons/arrays/fnc_findMax.sqf +++ b/addons/arrays/fnc_findMax.sqf @@ -26,7 +26,7 @@ SCRIPT(findMax); [_this] params [["_array", [], [[]]]]; -if !(_array isEqualTypeAll 0) exitWith {nil}; +if !(_array isEqualTypeAll 0) exitWith { nil }; private _reverse = + _array; reverse _reverse; diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index e00a070db..234a27036 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -40,9 +40,12 @@ private _stamp = diag_tickTime; private _index = 0; isNil { _index = GVAR(requests) find 0; - if (_index == -1) then - { _index = GVAR(requests) pushBack [_args, _cb, _stamp]; } - else { GVAR(requests) set [_index, [_args, _cb, _stamp]]; } + if (_index == -1) then { + _index = GVAR(requests) pushBack [_args, _cb, _stamp]; + } + else { + GVAR(requests) set [_index, [_args, _cb, _stamp]]; + } }; [_index, _mthd, _mthdArgs] remoteExec [QGVAR(requests), _rcv, false]; [_index, _stamp] diff --git a/addons/promise/script_component.hpp b/addons/promise/script_component.hpp index 9ad9b2f60..6ef3b1538 100644 --- a/addons/promise/script_component.hpp +++ b/addons/promise/script_component.hpp @@ -1,4 +1,4 @@ #define COMPONENT promise #include "\x\cba\addons\main\script_mod.hpp" -#include "\x\cba\addons\main\script_macros.hpp" \ No newline at end of file +#include "\x\cba\addons\main\script_macros.hpp" From a673d2b1c314a0742228fb3d9d2a3fba9b56d625 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:55:12 +0100 Subject: [PATCH 10/13] Added datatypes to documentation --- addons/promise/fnc_callback.sqf | 4 ++-- addons/promise/fnc_create.sqf | 13 ++++++------- addons/promise/fnc_done.sqf | 4 ++-- addons/promise/fnc_receiver.sqf | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/promise/fnc_callback.sqf b/addons/promise/fnc_callback.sqf index 65bdcbff5..28fa8c6cc 100644 --- a/addons/promise/fnc_callback.sqf +++ b/addons/promise/fnc_callback.sqf @@ -8,8 +8,8 @@ Description: WARNING! Not intended to be called by client-code! Parameters: - _id - The Promise-ID of the now finished promise. - _data - The result data of the now finished promise. + _id - The Promise-ID of the now finished promise. + _data - The result data of the now finished promise. Returns: Nothing diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index 234a27036..071fc623b 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -5,18 +5,17 @@ Description: Creates and executes a new Promise. Parameters: - _rcv - remoteExecCall target. - _mthd - either string (methodname) or code to execute on target. - _mthdArgs - custom arguments to pass to the target. - _args - args to pass to the callback (see next param) - _cb - callback for the promise (executed on current machine). + _rcv - remoteExecCall target. + _mthd - either string (methodname) or code to execute on target. + _mthdArgs - custom arguments to pass to the target. + _args - args to pass to the callback (see next param) + _cb - callback for the promise (executed on current machine). Will receive an array, with index 0 being what is passed include _args and index 1 being whatever is returned by the target invokation [_args, _mthdResult] Returns: - Identifier that allows to check if a promise is yet done. - See CBA_fnc_promise_done. + Identifier that allows to check if a promise is yet done. See CBA_fnc_promise_done. Example: (begin example) diff --git a/addons/promise/fnc_done.sqf b/addons/promise/fnc_done.sqf index 3aed54a32..c4550a62f 100644 --- a/addons/promise/fnc_done.sqf +++ b/addons/promise/fnc_done.sqf @@ -5,10 +5,10 @@ Description: Checks if a given promise was processed yet. Parameters: - _promiseHandle - Handle returned by CBA_fnc_promise_create + _promiseHandle - Handle returned by CBA_fnc_promise_create Returns: - Boolean, true if it is done yet, false if it is not. + Boolean, true if it is done yet, false if it is not. Example: (begin example) diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf index 06bdaa201..a32406cea 100644 --- a/addons/promise/fnc_receiver.sqf +++ b/addons/promise/fnc_receiver.sqf @@ -7,9 +7,9 @@ Description: WARNING! Not intended to be called by client-code! Parameters: - _id - the promise ID, local to the sender. - _method - The method to execute, either string (var name) or code. - _args - Arguments to pass to the method. + _id - the promise ID, local to the sender. + _method - The method to execute, either string (var name) or code. + _args - Arguments to pass to the method. Returns: Nothing From 6164de7a57ee98c7395c743c240f872cd0031ca1 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:58:34 +0100 Subject: [PATCH 11/13] Adjusted variable names --- addons/promise/fnc_create.sqf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index 071fc623b..eb657fba2 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -5,11 +5,11 @@ Description: Creates and executes a new Promise. Parameters: - _rcv - remoteExecCall target. - _mthd - either string (methodname) or code to execute on target. - _mthdArgs - custom arguments to pass to the target. + _receiver - remoteExecCall target. + _method - either string (methodname) or code to execute on target. + _methodArgs - custom arguments to pass to the target. _args - args to pass to the callback (see next param) - _cb - callback for the promise (executed on current machine). + _callback - callback for the promise (executed on current machine). Will receive an array, with index 0 being what is passed include _args and index 1 being whatever is returned by the target invokation [_args, _mthdResult] @@ -34,17 +34,17 @@ Author: X39 ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params ["_rcv", "_mthd", "_mthdArgs", "_args", "_cb"]; +params ["_receiver", "_method", "_methodArgs", "_args", "_callback"]; private _stamp = diag_tickTime; private _index = 0; isNil { _index = GVAR(requests) find 0; if (_index == -1) then { - _index = GVAR(requests) pushBack [_args, _cb, _stamp]; + _index = GVAR(requests) pushBack [_args, _callback, _stamp]; } else { - GVAR(requests) set [_index, [_args, _cb, _stamp]]; + GVAR(requests) set [_index, [_args, _callback, _stamp]]; } }; -[_index, _mthd, _mthdArgs] remoteExec [QGVAR(requests), _rcv, false]; +[_index, _method, _methodArgs] remoteExec [QGVAR(requests), _receiver, false]; [_index, _stamp] From e2068d15f8098f1a01ab59a6b305a250b04e3ba6 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 15:59:12 +0100 Subject: [PATCH 12/13] Fixed typo --- addons/promise/fnc_init.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/promise/fnc_init.sqf b/addons/promise/fnc_init.sqf index 1e9bd064a..855dd5ef0 100644 --- a/addons/promise/fnc_init.sqf +++ b/addons/promise/fnc_init.sqf @@ -2,7 +2,7 @@ Function: CBA_fnc_promise_init Description: - Initializes the required variabels for the promise system. + Initializes the required variables for the promise system. Parameters: Nothing From 5129a5da51d2ce34fd59af78266c4de554bef202 Mon Sep 17 00:00:00 2001 From: X39 Date: Fri, 5 Feb 2021 16:02:56 +0100 Subject: [PATCH 13/13] changed all occurances of method to function --- addons/promise/fnc_callback.sqf | 2 +- addons/promise/fnc_create.sqf | 10 +++++----- addons/promise/fnc_receiver.sqf | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/promise/fnc_callback.sqf b/addons/promise/fnc_callback.sqf index 28fa8c6cc..75aebb644 100644 --- a/addons/promise/fnc_callback.sqf +++ b/addons/promise/fnc_callback.sqf @@ -2,7 +2,7 @@ Function: CBA_fnc_promise_callback Description: - Method that gets called when the receiver is done. + Function that gets called when the receiver is done. Will in the end execute the promise-code locally. WARNING! Not intended to be called by client-code! diff --git a/addons/promise/fnc_create.sqf b/addons/promise/fnc_create.sqf index eb657fba2..97eb20bcf 100644 --- a/addons/promise/fnc_create.sqf +++ b/addons/promise/fnc_create.sqf @@ -6,8 +6,8 @@ Description: Parameters: _receiver - remoteExecCall target. - _method - either string (methodname) or code to execute on target. - _methodArgs - custom arguments to pass to the target. + _function - either string (functionname) or code to execute on target. + _functionArgs - custom arguments to pass to the target. _args - args to pass to the callback (see next param) _callback - callback for the promise (executed on current machine). Will receive an array, with index 0 being what is passed include @@ -20,7 +20,7 @@ Returns: Example: (begin example) [ - random_player, "random_method", [], + random_player, "random_function", [], [_someLocalVariable], { params ["_args", "_result"]; _args params ["_someLocalVariable"]; @@ -34,7 +34,7 @@ Author: X39 ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params ["_receiver", "_method", "_methodArgs", "_args", "_callback"]; +params ["_receiver", "_function", "_functionArgs", "_args", "_callback"]; private _stamp = diag_tickTime; private _index = 0; isNil { @@ -46,5 +46,5 @@ isNil { GVAR(requests) set [_index, [_args, _callback, _stamp]]; } }; -[_index, _method, _methodArgs] remoteExec [QGVAR(requests), _receiver, false]; +[_index, _function, _functionArgs] remoteExec [QGVAR(requests), _receiver, false]; [_index, _stamp] diff --git a/addons/promise/fnc_receiver.sqf b/addons/promise/fnc_receiver.sqf index a32406cea..0228cf41e 100644 --- a/addons/promise/fnc_receiver.sqf +++ b/addons/promise/fnc_receiver.sqf @@ -2,14 +2,14 @@ Function: CBA_fnc_promise_receiver Description: - Method that gets called when a sender has a request. + Function that gets called when a sender has a request. WARNING! Not intended to be called by client-code! Parameters: _id - the promise ID, local to the sender. - _method - The method to execute, either string (var name) or code. - _args - Arguments to pass to the method. + _function - The function to execute, either string (var name) or code. + _args - Arguments to pass to the function. Returns: Nothing @@ -22,11 +22,11 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params ["_id", "_method", "_args"]; -private _res = if (_method isEqualType "") then { - _args call (missionNamespace getVariable _method); +params ["_id", "_function", "_args"]; +private _res = if (_function isEqualType "") then { + _args call (missionNamespace getVariable _function); } else { - _args call _method; + _args call _function; }; [_id, _res] remoteExec [QGVAR(requests), remoteExecutedOwner, false]; nil