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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Razish
Copy link
Member

@Razish Razish commented Mar 2, 2024

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 );

…G is defined

added some const qualifiers so it's actually useful in practice
@ensiform
Copy link
Member

ensiform commented Mar 2, 2024

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

@@ -910,5 +910,7 @@ botlib_export_t *GetBotLibAPI(int apiVersion, botlib_import_t *import) {
be_botlib_export.BotLibUpdateEntity = Export_BotLibUpdateEntity;
be_botlib_export.Test = BotExportTest;

PC_Init();
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a little bit ugly to call it here, but necessary. Otherwise we'd have to drill it out further through other exported APIs and just call it from there 🤷
Let's just assume if you're getting any botlib exports, you want it to be ready for use.

@ensiform
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants