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

Use CBA Versioning System properly #7173

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

#include "script_version.hpp"

#define VERSION MAJOR.MINOR.PATCHLVL.BUILD
#define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD
#define VERSION MAJOR.MINOR
#define VERSION_STR MAJOR.MINOR.PATCHLVL.BUILD
#define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD

// MINIMAL required version for the Mod. Components can specify others..
#define REQUIRED_VERSION 1.94
Expand Down
117 changes: 98 additions & 19 deletions include/x/cba/addons/main/script_macros_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,55 @@
#define MAINLOGIC main
#endif

#define ADDON DOUBLES(PREFIX,COMPONENT)
#define MAIN_ADDON DOUBLES(PREFIX,main)

/* -------------------------------------------
Macro: VERSION_CONFIG
Define CBA Versioning System config entries.

VERSION should be a floating-point number (1 separator).
VERSION_STR is a string representation of the version.
VERSION_AR is an array representation of the version.

VERSION must always be defined, otherwise it is 0.
VERSION_STR and VERSION_AR default to VERSION if undefined.

Parameters:
None

Example:
(begin example)
#define VERSION 1.0
#define VERSION_STR 1.0.1
#define VERSION_AR 1,0,1

class CfgPatches {
class MyMod_main {
VERSION_CONFIG;
};
};
(end)

Author:
?, Jonpas
------------------------------------------- */
#ifndef VERSION
#define VERSION 0
#endif

#ifndef VERSION_STR
#define VERSION_STR VERSION
#endif

#ifndef VERSION_AR
#define VERSION_AR VERSION
#endif

#ifndef VERSION_CONFIG
#define VERSION_CONFIG version = VERSION; versionStr = QUOTE(VERSION); versionAr[] = {VERSION_AR}
#define VERSION_CONFIG version = VERSION; versionStr = QUOTE(VERSION_STR); versionAr[] = {VERSION_AR}
#endif

#define ADDON DOUBLES(PREFIX,COMPONENT)
#define MAIN_ADDON DOUBLES(PREFIX,main)

/* -------------------------------------------
Group: Debugging
------------------------------------------- */
Expand Down Expand Up @@ -775,7 +809,7 @@ Macro: ISNILS()

// This only works for binarized configs after recompiling the pbos
// TODO: Reduce amount of calls / code..
#define COMPILE_FILE2_CFG_SYS(var1) compile preProcessFileLineNumbers var1
#define COMPILE_FILE2_CFG_SYS(var1) compile preprocessFileLineNumbers var1
#define COMPILE_FILE2_SYS(var1) COMPILE_FILE2_CFG_SYS(var1)

#define COMPILE_FILE_SYS(var1,var2,var3) COMPILE_FILE2_SYS('PATHTO_SYS(var1,var2,var3)')
Expand All @@ -785,13 +819,13 @@ Macro: ISNILS()
#define SETVARMAINS(var1) SETVARS(var1,MAINLOGIC)
#define GVARMAINS(var1,var2) var1##_##var2
#define CFGSETTINGSS(var1,var2) configFile >> "CfgSettings" >> #var1 >> #var2
//#define SETGVARS(var1,var2,var3) ##var1##_##var2##_##var3 =
//#define SETGVARMAINS(var1,var2) ##var1##_##var2 =
//#define SETGVARS(var1,var2,var3) var1##_##var2##_##var3 =
//#define SETGVARMAINS(var1,var2) var1##_##var2 =

// Compile-Once, JIT: On first use.
// #define PREPMAIN_SYS(var1,var2,var3) ##var1##_fnc_##var3 = { ##var1##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call ##var1##_fnc_##var3 } else { _this call ##var1##_fnc_##var3 } }
// #define PREP_SYS(var1,var2,var3) ##var1##_##var2##_fnc_##var3 = { ##var1##_##var2##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call ##var1##_##var2##_fnc_##var3 } else { _this call ##var1##_##var2##_fnc_##var3 } }
// #define PREP_SYS2(var1,var2,var3,var4) ##var1##_##var2##_fnc_##var4 = { ##var1##_##var2##_fnc_##var4 = COMPILE_FILE_SYS(var1,var3,DOUBLES(fnc,var4)); if (isNil "_this") then { call ##var1##_##var2##_fnc_##var4 } else { _this call ##var1##_##var2##_fnc_##var4 } }
// #define PREPMAIN_SYS(var1,var2,var3) var1##_fnc_##var3 = { var1##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call var1##_fnc_##var3 } else { _this call var1##_fnc_##var3 } }
// #define PREP_SYS(var1,var2,var3) var1##_##var2##_fnc_##var3 = { var1##_##var2##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3)); if (isNil "_this") then { call var1##_##var2##_fnc_##var3 } else { _this call var1##_##var2##_fnc_##var3 } }
// #define PREP_SYS2(var1,var2,var3,var4) var1##_##var2##_fnc_##var4 = { var1##_##var2##_fnc_##var4 = COMPILE_FILE_SYS(var1,var3,DOUBLES(fnc,var4)); if (isNil "_this") then { call var1##_##var2##_fnc_##var4 } else { _this call var1##_##var2##_fnc_##var4 } }

// Compile-Once, at Macro. As opposed to Compile-Once, on first use.
#define PREPMAIN_SYS(var1,var2,var3) var1##_fnc_##var3 = COMPILE_FILE_SYS(var1,var2,DOUBLES(fnc,var3))
Expand Down Expand Up @@ -890,6 +924,39 @@ Macro: GVARMAIN()
#define SETVARMAIN SETVARMAINS(PREFIX)
#define IFCOUNT(var1,var2,var3) if (count var1 > var2) then { var3 = var1 select var2 };

/* -------------------------------------------
Macro: PREP()

Description:
Defines a function.

Full file path:
'\MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT\fnc_<FNC>.sqf'

Resulting function name:
'PREFIX_COMPONENT_<FNC>'

The PREP macro should be placed in a script run by a XEH preStart and XEH preInit event.

The PREP macro allows for CBA function caching, which drastically speeds up load times.
Beware though that function caching is enabled by default and as such to disable it, you need to
#define DISABLE_COMPILE_CACHE above your #include "script_components.hpp" include!

The function will be defined in ui and mission namespace. It can not be overwritten without
a mission restart.

Parameters:
FUNCTION NAME - Name of the function, unquoted <STRING>

Examples:
(begin example)
PREP(banana);
call FUNC(banana);
(end)

Author:
dixon13
------------------------------------------- */
//#define PREP(var1) PREP_SYS(PREFIX,COMPONENT_F,var1)

#ifdef DISABLE_COMPILE_CACHE
Expand All @@ -900,13 +967,6 @@ Macro: GVARMAIN()
#define PREPMAIN(var1) ['PATHTO_SYS(PREFIX,COMPONENT_F,DOUBLES(fnc,var1))', 'TRIPLES(PREFIX,fnc,var1)'] call SLX_XEH_COMPILE_NEW
#endif

#ifdef RECOMPILE
#undef RECOMPILE
#define RECOMPILE recompile = 1
#else
#define RECOMPILE recompile = 0
#endif

/* -------------------------------------------
Macro: PATHTO_FNC()

Expand All @@ -916,6 +976,7 @@ Macro: PATHTO_FNC()
Full file path in addons:
'\MAINPREFIX\PREFIX\SUBPREFIX\COMPONENT\fnc_<FNC>.sqf'
Define 'RECOMPILE' to enable recompiling.
Define 'SKIP_FUNCTION_HEADER' to skip adding function header.

Parameters:
FUNCTION NAME - Name of the function, unquoted <STRING>
Expand All @@ -936,8 +997,22 @@ Macro: PATHTO_FNC()
Author:
dixon13, commy2
------------------------------------------- */
#ifdef RECOMPILE
#undef RECOMPILE
#define RECOMPILE recompile = 1
#else
#define RECOMPILE recompile = 0
#endif
// Set function header type: -1 - no header; 0 - default header; 1 - system header.
#ifdef SKIP_FUNCTION_HEADER
#define CFGFUNCTION_HEADER headerType = -1
#else
#define CFGFUNCTION_HEADER headerType = 0
#endif

#define PATHTO_FNC(func) class func {\
file = QPATHTOF(DOUBLES(fnc,func).sqf);\
CFGFUNCTION_HEADER;\
RECOMPILE;\
}

Expand Down Expand Up @@ -1086,6 +1161,7 @@ Macros: IS_x()
/* -------------------------------------------
Macro: SCRIPT()
Sets name of script (relies on PREFIX and COMPONENT values being #defined).
Define 'SKIP_SCRIPT_NAME' to skip adding scriptName.

Parameters:
NAME - Name of script [Indentifier]
Expand All @@ -1098,8 +1174,11 @@ Macro: SCRIPT()
Author:
Spooner
------------------------------------------- */
#define SCRIPT(NAME) \
scriptName 'PREFIX\COMPONENT\NAME'
#ifndef SKIP_SCRIPT_NAME
#define SCRIPT(NAME) scriptName 'PREFIX\COMPONENT\NAME'
#else
#define SCRIPT(NAME) /* nope */
#endif

/* -------------------------------------------
Macros: EXPLODE_n()
Expand Down