From 496b82be71ff8a02f9d0afb922e1b203735c2225 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 5 Apr 2023 20:34:08 +0200 Subject: [PATCH] [MIRROR] Adds VERB_REF and derivative [MDB IGNORE] (#20346) * Adds VERB_REF and derivative (#74500) ## About The Pull Request Apparently in (one) place in the codebase, we were still using stuff like `.verb/example_verb` for stuff like `INVOKE_ASYNC()` and `CALLBACK()`s, and I'm pretty sure this is one of those things that are being phased out in 515 (like we had to deal with in 4d6a8bc5371eb61f9adb7c4dd1b8c441d3ae9251), so let's give it the same treatment as we did `PROC_REF` in November 2022. In order to make this work, I created a generic backend of define macros, and then moved two things: `PROC_REF` and `VERB_REF` to just leverage that backend as needed. This was done just so we didn't have to copy-paste code in case we needed to update these macros in the future, let me know if I should approach this a different way. ## Why It's Good For The Game code don't break (or at least the compile-time assertions won't break) when we inevitably fully shift to 515. whoopie! ## Changelog Nothing players should be concerned about. * Adds VERB_REF and derivative --------- Co-authored-by: san7890 --- .github/guides/STANDARDS.md | 3 ++- code/__byond_version_compat.dm | 32 +++++++++++++++++++++++++------- code/modules/client/verbs/ooc.dm | 4 ++-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/guides/STANDARDS.md b/.github/guides/STANDARDS.md index fd3679cb41f..1350be3735a 100644 --- a/.github/guides/STANDARDS.md +++ b/.github/guides/STANDARDS.md @@ -100,7 +100,7 @@ While we normally encourage (and in some cases, even require) bringing out of da ### RegisterSignal() #### PROC_REF Macros -When referencing procs in RegisterSignal, Callback and other procs you should use PROC_REF,TYPE_PROC_REF and GLOBAL_PROC_REF macros. +When referencing procs in RegisterSignal, Callback and other procs you should use PROC_REF, TYPE_PROC_REF and GLOBAL_PROC_REF macros. They ensure compilation fails if the reffered to procs change names or get removed. The macro to be used depends on how the proc you're in relates to the proc you want to use: @@ -142,6 +142,7 @@ Example: addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(funny)), 100)) ``` +Note that the same rules go for verbs too! We have VERB_REF() and TYPE_VERB_REF() as you need it in these same cases. GLOBAL_VERB_REF() isn't a thing however, as verbs are not global. #### Signal Handlers diff --git a/code/__byond_version_compat.dm b/code/__byond_version_compat.dm index feece392c90..cf84b77b747 100644 --- a/code/__byond_version_compat.dm +++ b/code/__byond_version_compat.dm @@ -27,19 +27,37 @@ #define LIBCALL call_ext #endif -// So we want to have compile time guarantees these procs exist on local type, unfortunately 515 killed the .proc/procname syntax so we have to use nameof() +// So we want to have compile time guarantees these methods exist on local type, unfortunately 515 killed the .proc/procname and .verb/verbname syntax so we have to use nameof() +// For the record: GLOBAL_VERB_REF would be useless as verbs can't be global. + #if DM_VERSION < 515 -/// Call by name proc reference, checks if the proc exists on this type or as a global proc + +/// Call by name proc references, checks if the proc exists on either this type or as a global proc. #define PROC_REF(X) (.proc/##X) -/// Call by name proc reference, checks if the proc exists on given type or as a global proc +/// Call by name verb references, checks if the verb exists on either this type or as a global verb. +#define VERB_REF(X) (.verb/##X) + +/// Call by name proc reference, checks if the proc exists on either the given type or as a global proc #define TYPE_PROC_REF(TYPE, X) (##TYPE.proc/##X) -/// Call by name proc reference, checks if the proc is existing global proc +/// Call by name verb reference, checks if the verb exists on either the given type or as a global verb +#define TYPE_VERB_REF(TYPE, X) (##TYPE.verb/##X) + +/// Call by name proc reference, checks if the proc is an existing global proc #define GLOBAL_PROC_REF(X) (/proc/##X) + #else -/// Call by name proc reference, checks if the proc exists on this type or as a global proc + +/// Call by name proc references, checks if the proc exists on either this type or as a global proc. #define PROC_REF(X) (nameof(.proc/##X)) -/// Call by name proc reference, checks if the proc exists on given type or as a global proc +/// Call by name verb references, checks if the verb exists on either this type or as a global verb. +#define VERB_REF(X) (nameof(.verb/##X)) + +/// Call by name proc reference, checks if the proc exists on either the given type or as a global proc #define TYPE_PROC_REF(TYPE, X) (nameof(##TYPE.proc/##X)) -/// Call by name proc reference, checks if the proc is existing global proc +/// Call by name verb reference, checks if the verb exists on either the given type or as a global verb +#define TYPE_VERB_REF(TYPE, X) (nameof(##TYPE.verb/##X)) + +/// Call by name proc reference, checks if the proc is an existing global proc #define GLOBAL_PROC_REF(X) (/proc/##X) + #endif diff --git a/code/modules/client/verbs/ooc.dm b/code/modules/client/verbs/ooc.dm index 8ad008990a4..8902cf3a00c 100644 --- a/code/modules/client/verbs/ooc.dm +++ b/code/modules/client/verbs/ooc.dm @@ -424,9 +424,9 @@ GLOBAL_VAR_INIT(normal_ooc_colour, "#002eb8") if (!prefs.read_preference(/datum/preference/toggle/auto_fit_viewport)) return if(fully_created) - INVOKE_ASYNC(src, .verb/fit_viewport) + INVOKE_ASYNC(src, VERB_REF(fit_viewport)) else //Delayed to avoid wingets from Login calls. - addtimer(CALLBACK(src, .verb/fit_viewport, 1 SECONDS)) + addtimer(CALLBACK(src, VERB_REF(fit_viewport), 1 SECONDS)) /client/verb/policy() set name = "Show Policy"