From: terencehill Date: Fri, 1 Feb 2019 15:26:21 +0000 (+0100) Subject: Reduce a bit expanded code of some often used macros X-Git-Tag: xonotic-v0.8.5~1621 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6170690fd976ff67094ac10b1123bef7f8568e26;p=xonotic%2Fxonotic-data.pk3dir.git Reduce a bit expanded code of some often used macros --- diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 163960ba5..770c9f05d 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -259,15 +259,15 @@ void Mutator_Remove(Mutator mut) } #define REGISTER_MUTATOR(id, dependence) \ - bool MUTATORFUNCTION_##id##_hooks(int mode) { return = false; } \ - bool MUTATORFUNCTION_##id(int mode) { \ + bool MUTATORFUNC_##id##_hooks(int mode) { return = false; } \ + bool MUTATORFUNC_##id(int mode) { \ return = false; \ - bool ret = MUTATORFUNCTION_##id##_hooks(mode); if (ret) return ret; \ + bool ret = MUTATORFUNC_##id##_hooks(mode); if (ret) return ret; \ } \ bool MUTATOR_##id##_check() { return dependence; } \ - REGISTER(Mutators, MUTATOR, id, m_id, NEW(Mutator, #id, MUTATORFUNCTION_##id)) \ + REGISTER(Mutators, MUTATOR, id, m_id, NEW(Mutator, #id, MUTATORFUNC_##id)) \ { this.mutatorcheck = MUTATOR_##id##_check; } \ - ACCUMULATE bool MUTATORFUNCTION_##id(int mode) + ACCUMULATE bool MUTATORFUNC_##id(int mode) STATIC_INIT(Mutators) { RegisterHooks(); @@ -301,9 +301,9 @@ STATIC_INIT_LATE(Mutators) { #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue #define _MUTATOR_CALLBACK(name, func) \ - Callback CALLBACK_##name; \ + Callback CB_##name; \ bool func(); \ - ACCUMULATE void RegisterCallbacks() { CALLBACK_##name = NEW(Callback, func); } + ACCUMULATE void RegisterCallbacks() { CB_##name = NEW(Callback, func); } #define MUTATOR_HOOKFUNCTION(...) \ EVAL_MUTATOR_HOOKFUNCTION(OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__)) @@ -314,20 +314,20 @@ STATIC_INIT_LATE(Mutators) { #define MUTATOR_HOOKFUNCTION_3(mut, cb, order) \ _MUTATOR_CALLBACK(mut##_##cb, mut##_##cb) \ - ACCUMULATE bool MUTATORFUNCTION_##mut##_hooks(int mode) { MUTATOR_HOOK(cb, mut##_##cb, order); } \ + ACCUMULATE bool MUTATORFUNC_##mut##_hooks(int mode) { MUTATOR_HOOK(cb, mut##_##cb, order); } \ bool mut##_##cb() { return = false; } \ ACCUMULATE bool mut##_##cb() -#define MUTATOR_HOOK(cb, func, order) MACRO_BEGIN { \ - MUTATOR_ONADD { \ - if (!CallbackChain_Add(HOOK_##cb, CALLBACK_##func, order)) { \ - LOG_INFO("HOOK FAILED: ", #cb, ":", #func); \ - return true; \ - } \ - } \ - MUTATOR_ONROLLBACK_OR_REMOVE { \ - CallbackChain_Remove(HOOK_##cb, CALLBACK_##func); \ - } \ +#define MUTATOR_HOOK(cb, func, order) MACRO_BEGIN { \ + MUTATOR_ONADD { \ + if (!CallbackChain_Add(HOOK_##cb, CB_##func, order)) { \ + LOG_INFO("HOOK FAILED: ", #cb, ":", #func); \ + return true; \ + } \ + } \ + MUTATOR_ONROLLBACK_OR_REMOVE { \ + CallbackChain_Remove(HOOK_##cb, CB_##func); \ + } \ } MACRO_END #include "events.qh" diff --git a/qcsrc/lib/macro.qh b/qcsrc/lib/macro.qh index f2ec6df4a..62c1e3133 100644 --- a/qcsrc/lib/macro.qh +++ b/qcsrc/lib/macro.qh @@ -1,12 +1,13 @@ #pragma once +// NOTE: spaces removed from these often used macros to reduce size when expanded #if 1 void voidfunc() { } - #define MACRO_BEGIN if (1) { - #define MACRO_END } else voidfunc() + #define MACRO_BEGIN if(1){ + #define MACRO_END }else voidfunc() #else - #define MACRO_BEGIN do { - #define MACRO_END } while (0) + #define MACRO_BEGIN do{ + #define MACRO_END }while(0) #endif /** Marker for use in (RVALUE, (expr)) */ diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index d8f18a02c..520b00c06 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -162,12 +162,10 @@ void Registry_send(string id, string hash); STATIC_INIT(Registry_check_##id) \ { \ /* Note: SHA256 isn't always available, use MD4 instead */ \ - string algo = "MD4"; \ - string join = ":"; \ - string s = ""; \ + string s = "", join = ":"; \ FOREACH(id, true, s = strcat(s, join, it.registered_id)); \ s = substring(s, strlen(join), -1); \ - string h = REGISTRY_HASH(id) = strzone(digest_hex(algo, s)); \ + string h = REGISTRY_HASH(id) = strzone(digest_hex("MD4", s)); \ LOG_DEBUGF(#id ": %s\n[%s]", h, s); \ } \ void Registry_check(string r, string sv) \ diff --git a/qcsrc/lib/spawnfunc.qh b/qcsrc/lib/spawnfunc.qh index d3198b3ce..41d8a1396 100644 --- a/qcsrc/lib/spawnfunc.qh +++ b/qcsrc/lib/spawnfunc.qh @@ -93,11 +93,11 @@ noref bool require_spawnfunc_prefix; static_init_early(); \ } \ bool dospawn = true; \ - if (__spawnfunc_expecting > 1) { __spawnfunc_expecting = false; } \ + if (__spawnfunc_expecting > 1) { __spawnfunc_expecting = 0; } \ else if (__spawnfunc_expecting) { \ /* engine call */ \ if (!g_spawn_queue) { g_spawn_queue = IL_NEW(); } \ - __spawnfunc_expecting = false; \ + __spawnfunc_expecting = 0; \ this = __spawnfunc_expect; \ __spawnfunc_expect = NULL; \ dospawn = false; \