]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Slightly refactor mutators code
authorotta8634 <k9wolf@pm.me>
Wed, 8 Jan 2025 10:13:39 +0000 (18:13 +0800)
committerotta8634 <k9wolf@pm.me>
Wed, 8 Jan 2025 10:13:39 +0000 (18:13 +0800)
These changes allow mutators to be properly shown in the guide.
Renamed .m_name to .mutatorname, and added (new) .m_name which would be displayed in the guide.
Allowed use of classes other than Mutator in the Mutators registry, so that m_name, m_icon, and m_color can be stored in such class and then displayed in the guide.
Also removed itemstime and waypointsprites mutators from the guide.

qcsrc/common/mutators/base.qh
qcsrc/common/mutators/mutator/itemstime/itemstime.qc
qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc

index 2b4d3e34cbe23f61c1bd84ed587dbe705b07edfe..def5e367ee2be9bc7ef92c029ada94927d7f309a 100644 (file)
@@ -155,11 +155,21 @@ USING(mutatorfunc_t, bool(int));
 CLASS(Mutator, Object)
     ATTRIB(Mutator, m_id, int, 0);
     ATTRIB(Mutator, m_name, string);
+    ATTRIB(Mutator, m_color, vector, '1 1 1');
+    ATTRIB(Mutator, m_icon, string);
+    ATTRIB(Mutator, mutatorname, string);
     ATTRIB(Mutator, mutatorfunc, mutatorfunc_t);
     ATTRIB(Mutator, mutatorcheck, bool());
+    METHOD(Mutator, describe, string(entity this)) {
+        TC(Mutator, this);
+        return SUPER(Mutator).describe(this);
+    }
+    METHOD(Mutator, display, void(entity this, void(string name, string icon) returns)) {
+        returns(this.m_name, this.m_icon);
+    }
     CONSTRUCTOR(Mutator, string _name, mutatorfunc_t func) {
         CONSTRUCT(Mutator);
-        this.m_name = _name;
+        this.mutatorname = _name;
         this.mutatorfunc = func;
     }
 ENDCLASS(Mutator)
@@ -226,7 +236,7 @@ bool Mutator_Add(Mutator mut)
     mutatorfunc_t func = mut.mutatorfunc;
     if (!func(MUTATOR_ADDING)) {
         // good
-        if (mutator_log) LOG_TRACEF("Mutator: added %s", mut.m_name);
+        if (mutator_log) LOG_TRACEF("Mutator: added %s", mut.mutatorname);
 #ifdef SVQC
         Net_LinkEntity(mut, false, 0, Mutator_SendEntity);
 #endif
@@ -254,23 +264,27 @@ void Mutator_Remove(Mutator mut)
         // baaaaad
         error("Mutator_Remove: removing mutator failed");
     }
-    if (mutator_log) LOG_TRACEF("Mutator: removed %s", mut.m_name);
+    if (mutator_log) LOG_TRACEF("Mutator: removed %s", mut.mutatorname);
 #ifdef SVQC
     Net_UnlinkEntity(mut);
 #endif
 }
 
-#define REGISTER_MUTATOR(id, dependence) \
+#define _REGISTER_MUTATOR(id, dependence, cname) \
     bool MUTATORFUNC_##id##_hooks(int mode) { return = false; } \
     bool MUTATORFUNC_##id(int mode) { \
         return = false; \
         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, MUTATORFUNC_##id)) \
+    REGISTER(Mutators, MUTATOR, id, m_id, NEW(cname, #id, MUTATORFUNC_##id)) \
     { this.mutatorcheck = MUTATOR_##id##_check; } \
     ACCUMULATE bool MUTATORFUNC_##id(int mode)
 
+#define REGISTER_MUTATOR(...) EVAL(OVERLOAD(REGISTER_MUTATOR, __VA_ARGS__))
+#define REGISTER_MUTATOR_2(id, dependence)        _REGISTER_MUTATOR(id, dependence, Mutator)
+#define REGISTER_MUTATOR_3(id, dependence, cname) _REGISTER_MUTATOR(id, dependence, cname)
+
 STATIC_INIT(Mutators) {
     RegisterHooks();
     RegisterCallbacks();
index 5aa59bffc38eb6f29f2da638dfb25a9527d54e44..1c96e1b6e300bd737c9af5c4cbb871eb7dfabac9 100644 (file)
@@ -1,8 +1,7 @@
 #include "itemstime.qh"
 
-REGISTER_MUTATOR(itemstime, true);
-
 #ifdef GAMEQC
+REGISTER_MUTATOR(itemstime, true);
 REGISTER_NET_TEMP(itemstime)
 #endif
 
index f3172c7110ece1c162dccf95bbc112884f5f7ce9..f79dad44b6d661cbd1ad62b4d2f5349e7c45560e 100644 (file)
@@ -1,8 +1,7 @@
 #include "waypointsprites.qh"
 
-REGISTER_MUTATOR(waypointsprites, true);
-
 #ifdef GAMEQC
+REGISTER_MUTATOR(waypointsprites, true);
 REGISTER_NET_LINKED(waypointsprites)
 #endif