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 header for PREP() macro #1022

Merged
merged 2 commits into from
Nov 9, 2018
Merged
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
47 changes: 40 additions & 7 deletions addons/main/script_macros_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,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 +933,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 Down Expand Up @@ -936,6 +962,13 @@ Macro: PATHTO_FNC()
Author:
dixon13, commy2
------------------------------------------- */
#ifdef RECOMPILE
Copy link
Contributor

Choose a reason for hiding this comment

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

Now the PATHTO_FNC header looks like it applies to recompile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alternative is having RECOMPILE to look like it belongs to PREP when it belongs to PATHTO_FNC only.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move it below PATHTO_FNC then? So that the header is still directly above what it belongs to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PATHTO_FNC uses RECOMPILE. I think it would break the way you described.

Copy link
Contributor

Choose a reason for hiding this comment

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

Macro inside a different macro is only resolved when the second macro is used.
PATHTO_FNC is resolved first. Then the RECOMPILE inside it is resolved.
So it wouldn't cause any problems if it's defined after the PATHTO_FNC macro

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess. But it still would look weird.

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

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