]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Registry: simplify API
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 15 Nov 2015 03:01:09 +0000 (14:01 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 15 Nov 2015 03:01:09 +0000 (14:01 +1100)
qcsrc/common/command/all.qh
qcsrc/common/items/all.qh
qcsrc/common/minigames/cl_minigames.qh
qcsrc/common/minigames/sv_minigames.qh
qcsrc/common/mutators/mutator/buffs/all.qh
qcsrc/lib/net.qh
qcsrc/lib/registry.qh
qcsrc/lib/stats.qh
qcsrc/server/cl_player.qh

index d1eb3cf76e284bf3b1ddc547366bef69218ac1ef..9e16238d17af8dea6150ee44c210229052ae5227 100644 (file)
@@ -5,7 +5,7 @@
 REGISTRY(GENERIC_COMMANDS, BITS(7))
 #define GENERIC_COMMANDS_from(i) _GENERIC_COMMANDS_from(i, NULL)
 REGISTER_REGISTRY(GENERIC_COMMANDS)
-REGISTRY_SORT(GENERIC_COMMANDS, 0)
+REGISTRY_SORT(GENERIC_COMMANDS)
 
 #define GENERIC_COMMAND(id, description) \
        CLASS(genericcommand_##id, Command) \
index ab86ea6736eaca2b592cb6e212bdc1aa6b42392b..1bd22f660e52264f488a53390d015045dff5d7cd 100644 (file)
@@ -11,7 +11,7 @@ REGISTER_REGISTRY(Items)
 /** If you register a new item, make sure to add it to all.inc */
 #define REGISTER_ITEM(id, class) REGISTER(Items, ITEM, id, m_id, NEW(class))
 
-REGISTRY_SORT(Items, 0)
+REGISTRY_SORT(Items)
 REGISTRY_CHECK(Items)
 STATIC_INIT(Items) { FOREACH(Items, true, LAMBDA(it.m_id = i)); }
 
index f21c6e482d10c5b3310557ee6eba9178d6c28c0e..fe75e038b6e2d054be9b9d8720f20ff948ba2568 100644 (file)
@@ -116,11 +116,11 @@ REGISTRY(Minigames, BITS(3))
 REGISTER_REGISTRY(Minigames)
 REGISTRY_CHECK(Minigames)
 #define REGISTER_MINIGAME(name,nicename) \
-    REGISTER(Minigames, MINIGAMEname, m_id, new(minigame_descriptor)); \
+    REGISTER(Minigames, MINIGAME_##name, m_id, new(minigame_descriptor)); \
     void name##_hud_board(vector, vector); \
     void name##_hud_status(vector, vector); \
     int name##_client_event(entity, string, ...); \
-    REGISTER_INIT_POST(MINIGAMEname) { \
+    REGISTER_INIT_POST(MINIGAME_##name) { \
         make_pure(this); \
         this.netname = strzone(strtolower(#name)); \
         this.message = nicename; \
@@ -128,6 +128,6 @@ REGISTRY_CHECK(Minigames)
                this.minigame_hud_status = name##_hud_status; \
                this.minigame_event = name##_client_event; \
     } \
-    REGISTER_INIT(MINIGAMEname)
+    REGISTER_INIT(MINIGAME_##name)
 
 #endif
index eb6825ed600e52ad46df1c47af15717d3a10229d..0fb3d572cc6996d2849bb9ccc17f69c94c58d4ba 100644 (file)
@@ -51,14 +51,14 @@ REGISTRY(Minigames, BITS(3))
 REGISTER_REGISTRY(Minigames)
 REGISTRY_CHECK(Minigames)
 #define REGISTER_MINIGAME(name,nicename) \
-    REGISTER(Minigames, MINIGAMEname, m_id, new(minigame_descriptor)); \
+    REGISTER(Minigames, MINIGAME_##name, m_id, new(minigame_descriptor)); \
     int name##_server_event(entity, string, ...); \
-    REGISTER_INIT_POST(MINIGAMEname) { \
+    REGISTER_INIT_POST(MINIGAME_##name) { \
         make_pure(this); \
         this.netname = strzone(strtolower(#name)); \
         this.message = nicename; \
                this.minigame_event = name##_server_event; \
     } \
-    REGISTER_INIT(MINIGAMEname)
+    REGISTER_INIT(MINIGAME_##name)
 
 #endif
index 94a00b9de76bd8ea19a02fe009ad493f1e153066..db22d314115f510c7a58369af9c2c8b1d9678754 100644 (file)
@@ -17,13 +17,13 @@ REGISTER_REGISTRY(Buffs)
 REGISTRY_CHECK(Buffs)
 
 #define REGISTER_BUFF(id) \
-    REGISTER(Buffs, BUFFid, m_id, NEW(Buff)); \
-    REGISTER_INIT_POST(BUFFid) { \
+    REGISTER(Buffs, BUFF_##id, m_id, NEW(Buff)); \
+    REGISTER_INIT_POST(BUFF_##id) { \
         this.netname = this.m_name; \
         this.m_itemid = BIT(this.m_id - 1); \
         this.m_sprite = strzone(strcat("buff-", this.m_name)); \
     } \
-    REGISTER_INIT(BUFFid)
+    REGISTER_INIT(BUFF_##id)
 
 #include "../../../items/item/pickup.qh"
 CLASS(Buff, Pickup)
index 45b377a00edc29e84dd9ffbe74bd81253b7af8c9..5a683f54c2562b3d3f6091cd6724e6529d700ec8 100644 (file)
 REGISTRY(LinkedEntities, BITS(8) - 1)
 #define LinkedEntities_from(i) _LinkedEntities_from(i, NULL)
 REGISTER_REGISTRY(LinkedEntities)
-REGISTRY_SORT(LinkedEntities, 0)
+REGISTRY_SORT(LinkedEntities)
 REGISTRY_CHECK(LinkedEntities)
 STATIC_INIT(RegisterLinkedEntities_renumber)
 {
@@ -141,7 +141,7 @@ STATIC_INIT(RegisterLinkedEntities_renumber)
 REGISTRY(TempEntities, BITS(8) - 80)
 #define TempEntities_from(i) _TempEntities_from(i, NULL)
 REGISTER_REGISTRY(TempEntities)
-REGISTRY_SORT(TempEntities, 0)
+REGISTRY_SORT(TempEntities)
 REGISTRY_CHECK(TempEntities)
 STATIC_INIT(RegisterTempEntities_renumber)
 {
index 52ab23377454bb92dfe75708ace67d428eac92e5..16d35b0dd3e2b8bec4e1cce0a3feb70d565e71d0 100644 (file)
@@ -39,14 +39,16 @@ REGISTRY(Registries, BITS(8))
  * @param fld       The field to store the locally unique unique entity id
  * @param inst      An expression to create a new instance, invoked for every registration
  */
-#define REGISTER(registry, ns, id, fld, inst) \
-       entity ns##_##id; \
-       REGISTER_INIT(ns, id) {} \
-       REGISTER_INIT_POST(ns, id) {} \
-       void Register_##ns##_##id() \
+#define REGISTER(...) EVAL(OVERLOAD(REGISTER, __VA_ARGS__))
+#define REGISTER_5(registry, ns, id, fld, inst) REGISTER_4(registry, ns##_##id, fld, inst)
+#define REGISTER_4(registry, id, fld, inst) \
+       entity id; \
+       REGISTER_INIT(id) {} \
+       REGISTER_INIT_POST(id) {} \
+       void Register_##id() \
        { \
                if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%s)", ftos(registry##_MAX)); \
-               entity this = ns##_##id = inst; \
+               entity this = id = inst; \
                this.registered_id = #id; \
                this.fld = registry##_COUNT; \
                _##registry[registry##_COUNT] = this; \
@@ -54,20 +56,22 @@ REGISTRY(Registries, BITS(8))
                if (!registry##_first) registry##_first = this; \
                if (registry##_last)   registry##_last.REGISTRY_NEXT = this; \
                registry##_last = this; \
-               Register_##ns##_##id##_init(this); \
-               Register_##ns##_##id##_init_post(this); \
+               Register_##id##_init(this); \
+               Register_##id##_init_post(this); \
        } \
-       ACCUMULATE_FUNCTION(Register##registry, Register_##ns##_##id) \
-       REGISTER_INIT(ns, id)
+       ACCUMULATE_FUNCTION(Register##registry, Register_##id) \
+       REGISTER_INIT(id)
 
-#define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
-#define REGISTER_INIT_POST(ns, id) [[accumulate]] void Register_##ns##_##id##_init_post(entity this)
+#define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this)
+#define REGISTER_INIT_POST(id) [[accumulate]] void Register_##id##_init_post(entity this)
 
 /** internal next pointer */
 #define REGISTRY_NEXT enemy
 .entity REGISTRY_NEXT;
 
-#define REGISTRY_SORT(id, skip) \
+#define REGISTRY_SORT(...) EVAL(OVERLOAD(REGISTRY_SORT, __VA_ARGS__))
+#define REGISTRY_SORT_1(id) REGISTRY_SORT_2(id, 0)
+#define REGISTRY_SORT_2(id, skip) \
        void _REGISTRY_SWAP_##id(int i, int j, entity pass) \
        { \
                i += skip; j += skip; \
index 7dd2706fd240c798e8dff885bd916f122222335f..12dc425cd356e876a78e3406d4cb58126a6ea4d8 100644 (file)
@@ -59,7 +59,7 @@ const int STATS_ENGINE_RESERVE = 32 + (8 * 3); // Not sure how to handle vector
 
 REGISTRY(Stats, 220 - STATS_ENGINE_RESERVE)
 REGISTER_REGISTRY(Stats)
-REGISTRY_SORT(Stats, 0)
+REGISTRY_SORT(Stats)
 REGISTRY_CHECK(Stats)
 STATIC_INIT(RegisterStats_renumber)
 {
index 76c49d852f572c2f1138c00eb538b25f5db56204..37bc06310b0d2af80a1d7295f1b2072b41bda189 100644 (file)
@@ -109,7 +109,7 @@ REGISTRY(GlobalSounds, BITS(8) - 1)
                this.m_globalsoundstr = str; \
        }
 REGISTER_REGISTRY(GlobalSounds)
-REGISTRY_SORT(GlobalSounds, 0)
+REGISTRY_SORT(GlobalSounds)
 REGISTRY_CHECK(GlobalSounds)
 PRECACHE(GlobalSounds)
 {