From d7e43ce28ec33ffe617798d2e9ccbecf2bed5175 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 22 Mar 2015 12:39:26 +0100 Subject: [PATCH] First draft --- addons/modules/$PBOPREFIX$ | 1 + addons/modules/CfgEventHandlers.hpp | 13 ++++++ addons/modules/XEH_postInit.sqf | 44 +++++++++++++++++++ addons/modules/XEH_preInit.sqf | 8 ++++ addons/modules/config.cpp | 28 ++++++++++++ addons/modules/functions/fnc_moduleInit.sqf | 19 ++++++++ addons/modules/functions/script_component.hpp | 1 + addons/modules/script_component.hpp | 12 +++++ 8 files changed, 126 insertions(+) create mode 100644 addons/modules/$PBOPREFIX$ create mode 100644 addons/modules/CfgEventHandlers.hpp create mode 100644 addons/modules/XEH_postInit.sqf create mode 100644 addons/modules/XEH_preInit.sqf create mode 100644 addons/modules/config.cpp create mode 100644 addons/modules/functions/fnc_moduleInit.sqf create mode 100644 addons/modules/functions/script_component.hpp create mode 100644 addons/modules/script_component.hpp diff --git a/addons/modules/$PBOPREFIX$ b/addons/modules/$PBOPREFIX$ new file mode 100644 index 0000000000..39789fcaba --- /dev/null +++ b/addons/modules/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\blank \ No newline at end of file diff --git a/addons/modules/CfgEventHandlers.hpp b/addons/modules/CfgEventHandlers.hpp new file mode 100644 index 0000000000..82d1c55d10 --- /dev/null +++ b/addons/modules/CfgEventHandlers.hpp @@ -0,0 +1,13 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + + +class Extended_PostInit_EventHandlers { + class _ACE_modules { // using a _ so it is the first postInit to be executed + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/modules/XEH_postInit.sqf b/addons/modules/XEH_postInit.sqf new file mode 100644 index 0000000000..72599b7cdc --- /dev/null +++ b/addons/modules/XEH_postInit.sqf @@ -0,0 +1,44 @@ + +#include "script_component.hpp" + +// TODO This is a basic and limited implementation that mimics some of the functionality from the A3 module framework, but not all of it. +// We have to execute this in the postInit XEH because on object init, the parameters of the modules are not yet available. They are if we execute it at the start of postInit execution. +{ + [_x] call { + private ["_logic", "_logicType", "_config", "_isGlobal", "_isDisposable", "_isPersistent","_function"]; + _logic = _this select 0; + _logicType = typeof _logic; + _logic hideobject true; + + if (_logic getvariable [QGVAR(initalized), false]) exitwith {}; + _config = (configFile >> "CfgVehicles" >> _logicType); + if !(isClass _config) exitwith {}; + + // isGlobal = 1; + _isGlobal = getNumber (_config >> "isGlobal") > 0; + _isDisposable = getNumber (_config >> "isDisposable") > 0; + _isPersistent = getNumber (_config >> "isPersistent") > 0 || getnumber (_config >> "isGlobal") > 1; + _function = getText (_config >> "function"); + if (isnil _function) then { + _function = compile _function; + } else { + _function = missionNamespace getvariable _function; + }; + + if (_isGlobal) then { + [_logic, [], true] call _function; + } else { + if (isServer) then { + [_logic, [], true] call _function; + }; + }; + + if !(_isPersistent) then { + _logic setvariable [QGVAR(initalized), true]; + }; + + if (_isDisposable) then { + deleteVehicle _logic; + }; + }; +}foreach GVAR(moduleInitCollection); diff --git a/addons/modules/XEH_preInit.sqf b/addons/modules/XEH_preInit.sqf new file mode 100644 index 0000000000..a8b9bd061e --- /dev/null +++ b/addons/modules/XEH_preInit.sqf @@ -0,0 +1,8 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(moduleInit); +GVAR(moduleInitCollection) = []; + +ADDON = true; diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp new file mode 100644 index 0000000000..7a721e681c --- /dev/null +++ b/addons/modules/config.cpp @@ -0,0 +1,28 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {"Glowbal"}; + authorUrl = ""; + VERSION_CONFIG; + }; +}; + +class CfgVehicles { + class Logic; + class Module_F: Logic { + class ArgumentsBaseUnits { + }; + }; + class ACE_Module: Module_F { + class EventHandlers { + init = QUOTE(_this call DFUNC(moduleInit)); + }; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/modules/functions/fnc_moduleInit.sqf b/addons/modules/functions/fnc_moduleInit.sqf new file mode 100644 index 0000000000..3c5f20f92c --- /dev/null +++ b/addons/modules/functions/fnc_moduleInit.sqf @@ -0,0 +1,19 @@ +/* + * Author: Glowbal + * IV Treatment local callback + * + * Arguments: + * 0: The logic object + * + * + * Return Value: + * nil + * + * Public: No + */ + +#include "script_component.hpp" + +if ((_this select 0) isKindOf "Module_F") then { + GVAR(moduleInitCollection) pushback (_this select 0); +}; diff --git a/addons/modules/functions/script_component.hpp b/addons/modules/functions/script_component.hpp new file mode 100644 index 0000000000..ffd50bc09b --- /dev/null +++ b/addons/modules/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\modules\script_component.hpp" diff --git a/addons/modules/script_component.hpp b/addons/modules/script_component.hpp new file mode 100644 index 0000000000..807540960b --- /dev/null +++ b/addons/modules/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT modules +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_MODULES + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_MODULES + #define DEBUG_SETTINGS DEBUG_SETTINGS_MODULES +#endif + +#include "\z\ace\addons\main\script_macros.hpp"