+#define REGISTRY_PUSH(registry, fld, it) MACRO_BEGIN { \
+ it.fld = registry##_COUNT; \
+ _R_SET(_##registry, registry##_COUNT, it); \
+ ++registry##_COUNT; \
+ if (!registry##_first) registry##_first = it; \
+ if (registry##_last) registry##_last.REGISTRY_NEXT = it; \
+ registry##_last = it; \
+} MACRO_END
+
+#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN { \
+ entity e = new_pure(registry_reserved); \
+ e.registered_id = #id "/" #suffix; \
+ REGISTRY_PUSH(registry, fld, e); \
+} MACRO_END
+
+#define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this)
+
+/** internal next pointer */
+#define REGISTRY_NEXT enemy
+.entity REGISTRY_NEXT;
+
+#define REGISTRY_SORT(...) EVAL_REGISTRY_SORT(OVERLOAD(REGISTRY_SORT, __VA_ARGS__))
+#define EVAL_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; \
+ \
+ entity a = _R_GET(_##id, i), b = _R_GET(_##id, j); \
+ _R_SET(_##id, i, b); \
+ _R_SET(_##id, j, a); \
+ \
+ entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \
+ a.REGISTRY_NEXT = b_next; \
+ b.REGISTRY_NEXT = a_next; \
+ \
+ if (i == 0) id##_first = b; \
+ else _R_GET(_##id, i - 1).REGISTRY_NEXT = b; \
+ \
+ if (j == 0) id##_first = a; \
+ else _R_GET(_##id, j - 1).REGISTRY_NEXT = a; \
+ } \
+ int _REGISTRY_CMP_##id(int i, int j, entity pass) \
+ { \
+ i += skip; j += skip; \
+ string a = _R_GET(_##id, i).registered_id; \
+ string b = _R_GET(_##id, j).registered_id; \
+ return strcmp(a, b); \
+ } \
+ STATIC_INIT(Registry_sort_##id) \
+ { \
+ heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
+ }
+
+#define REGISTRY_HASH(id) Registry_hash_##id
+
+[[accumulate]] void Registry_check(string r, string server) { }
+[[accumulate]] void Registry_send_all() { }
+
+#ifdef SVQC
+void Registry_send(string id, string hash);
+#else
+#define Registry_send(id, hash)