]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reduce a bit expanded code of some often used macros
authorterencehill <piuntn@gmail.com>
Fri, 1 Feb 2019 15:26:21 +0000 (16:26 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 1 Feb 2019 15:26:21 +0000 (16:26 +0100)
qcsrc/common/mutators/base.qh
qcsrc/lib/macro.qh
qcsrc/lib/registry.qh
qcsrc/lib/spawnfunc.qh

index 163960ba5f5d9ee2d4841b277d28bbe2b316f464..770c9f05d69c4d7b15d1d2b0a7bb4879bfae3a13 100644 (file)
@@ -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"
index f2ec6df4a4206e8797f08ecb529fa0faa6adbcb3..62c1e3133c67a96f2a43bf853d97fdacca74f5b6 100644 (file)
@@ -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)) */
index d8f18a02c96e4ab98b749530dd5f1f58550609b5..520b00c06342ca095fb79560e9793cee11a3b64d 100644 (file)
@@ -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) \
index d3198b3ce4c7666bf986564916b9d9678b3dc097..41d8a1396e7caf39d7b6669e8e1d70f80bfc9cb2 100644 (file)
@@ -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; \