]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/base.qh
Optimize vehicle impact code by only calling vlen() if damage would be taken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / base.qh
index 770c9f05d69c4d7b15d1d2b0a7bb4879bfae3a13..cc4cc0129593044474468adff6b9434636fcdcf9 100644 (file)
@@ -171,7 +171,8 @@ void Mutator_Remove(Mutator mut);
 bool mutator_log = false;
 .bool m_added;
 
-#define MUTATOR_IS_ENABLED(this) MUTATOR_##this.mutatorcheck()
+#define _MUTATOR_IS_ENABLED(this) this.mutatorcheck()
+#define MUTATOR_IS_ENABLED(this) _MUTATOR_IS_ENABLED(MUTATOR_##this)
 
 #ifdef GAMEQC
 /** server mutators activate corresponding client mutators for all clients */
@@ -276,14 +277,14 @@ STATIC_INIT(Mutators) {
 }
 
 STATIC_INIT_LATE(Mutators) {
-    FOREACH(Mutators, it.mutatorcheck(), Mutator_Add(it));
+    FOREACH(Mutators, _MUTATOR_IS_ENABLED(it), Mutator_Add(it));
 }
 
 #define MUTATOR_ONADD                   if (mode == MUTATOR_ADDING)
 #define MUTATOR_ONREMOVE                if (mode == MUTATOR_REMOVING)
 #define MUTATOR_ONROLLBACK_OR_REMOVE    if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
 
-#define MUTATOR_STATIC() MACRO_BEGIN \
+#define MUTATOR_STATIC() MACRO_BEGIN \
     MUTATOR_ONADD { \
         /* game loads at time 1 */ \
         if (time > 1) { \
@@ -294,7 +295,7 @@ STATIC_INIT_LATE(Mutators) {
                LOG_INFO("This is a game type and it cannot be removed at runtime."); \
                return -1; \
        } \
-MACRO_END
+MACRO_END
 
 #define MUTATOR_ADD(name)               Mutator_Add(MUTATOR_##name)
 #define MUTATOR_REMOVE(name)            Mutator_Remove(MUTATOR_##name)
@@ -318,16 +319,22 @@ STATIC_INIT_LATE(Mutators) {
     bool mut##_##cb() { return = false; } \
     ACCUMULATE bool mut##_##cb()
 
-#define MUTATOR_HOOK(cb, func, order) MACRO_BEGIN { \
+void _mutPrintFail(string cb, string func)
+{
+       // this is inside a function to avoid expanding it on compilation everytime
+       LOG_INFO("HOOK FAILED: ", cb, ":", 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); \
+            _mutPrintFail(#cb, #func); \
             return true; \
         } \
     } \
     MUTATOR_ONROLLBACK_OR_REMOVE { \
         CallbackChain_Remove(HOOK_##cb, CB_##func); \
     } \
-MACRO_END
+MACRO_END
 
 #include "events.qh"