From 2f78dbc34a00fc1b3f5fb6c5b33a3e232adcd07f Mon Sep 17 00:00:00 2001 From: Drulikar Date: Wed, 28 Jun 2023 03:05:32 -0700 Subject: [PATCH] Port TG#74500 --- .github/guides/STANDARDS.md | 4 +++- code/_byond_version_compat.dm | 32 +++++++++++++++++++++++++------- code/_onclick/click.dm | 4 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/guides/STANDARDS.md b/.github/guides/STANDARDS.md index fc764d09c816..c9b988bd07ff 100644 --- a/.github/guides/STANDARDS.md +++ b/.github/guides/STANDARDS.md @@ -126,7 +126,7 @@ While we normally encourage (and in some cases, even require) bringing out of da This is a simple one - as we will eventually move to 515, we will need to ditch this kind of callback. So please don't add any new ones. Make our lives easier. ### 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: @@ -168,6 +168,8 @@ This is a simple one - as we will eventually move to 515, we will need to ditch 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 All procs that are registered to listen for signals using `RegisterSignal()` must contain at the start of the proc `SIGNAL_HANDLER` eg; diff --git a/code/_byond_version_compat.dm b/code/_byond_version_compat.dm index b5379a3b6d5c..df2f02d383b1 100644 --- a/code/_byond_version_compat.dm +++ b/code/_byond_version_compat.dm @@ -31,19 +31,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/_onclick/click.dm b/code/_onclick/click.dm index affbc28cdd45..df7dd48a1dd1 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -82,7 +82,7 @@ return face_atom(A) - if(mods["middle"]) + if(mods["middle"]) return // Special type of click. if (is_mob_restrained()) @@ -334,7 +334,7 @@ if(prefs.adaptive_zoom) INVOKE_ASYNC(src, PROC_REF(adaptive_zoom)) else if(prefs.auto_fit_viewport) - INVOKE_ASYNC(src, .verb/fit_viewport) + INVOKE_ASYNC(src, VERB_REF(fit_viewport)) /client/proc/get_adaptive_zoom_factor() if(!prefs.adaptive_zoom)