JACoders / OpenJK

Community effort to maintain and improve Jedi Academy (SP & MP) + Jedi Outcast (SP only) released by Raven Software
GNU General Public License v2.0
2.01k stars 614 forks source link

[MP] implement PC_AddGlobalDefine, PC_RemoveGlobalDefine when DEFINEHASHING is defined #1222

Open Razish opened 7 months ago

Razish commented 7 months ago

This allows you to programmatically expose values to .menu files from cgame/ui via preprocessor defines.

So we could in theory do:

diff --git a/codemp/cgame/cg_main.c b/codemp/cgame/cg_main.c
index 12bbd470e..ff1827912 100644
--- a/codemp/cgame/cg_main.c
+++ b/codemp/cgame/cg_main.c
@@ -2196,6 +2196,9 @@ void CG_LoadMenus(const char *menuFile)
    buf[len] = 0;
    trap->FS_Close( f );

+   trap->PC_AddGlobalDefine("ARCH_STRING \"" ARCH_STRING "\"");
+   trap->PC_LoadGlobalDefines("ui/jamp/menudef.h");
+
    p = buf;

    COM_BeginParseSession ("CG_LoadMenus");
diff --git a/codemp/ui/ui_main.c b/codemp/ui/ui_main.c
index 45501d947..d11a20f21 100644
--- a/codemp/ui/ui_main.c
+++ b/codemp/ui/ui_main.c
@@ -1423,6 +1423,7 @@ void UI_LoadMenus(const char *menuFile, qboolean reset) {
    int handle;
 // int start = trap->Milliseconds();

+   trap->PC_AddGlobalDefine("ARCH_STRING \"" ARCH_STRING "\"");
    trap->PC_LoadGlobalDefines ( "ui/jamp/menudef.h" );

    handle = trap->PC_LoadSource( menuFile );
ensiform commented 7 months ago

Personally I would also remove the define and always have define hashing enabled, as non-hashed behavior would be worse performance I expect.

ensiform commented 6 months ago

https://gist.github.com/ensiform/8c9a6ea23aebe7e2bdfe5929db36e637