]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/sortlist.qh
Extract more lib functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / sortlist.qh
diff --git a/qcsrc/lib/sortlist.qh b/qcsrc/lib/sortlist.qh
new file mode 100644 (file)
index 0000000..d4a1f18
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SORTLIST_H
+#define SORTLIST_H
+
+entityclass(Sort);
+//.float(entity,entity) sort_cmp;
+class(Sort) .entity chain, sort_next, sort_prev;
+
+entity Sort_Spawn();
+
+/**
+ * Swap two neighbours in a sortlist.
+ * @param a FIRST entity
+ * @param b entity after a
+ */
+#define SORT_SWAP(a,b)                                                                 \
+       b.sort_prev = a.sort_prev;                                                      \
+       a.sort_next = b.sort_next;                                                      \
+       if(b.sort_next) b.sort_next.sort_prev = a;                      \
+       if(a.sort_prev) a.sort_prev.sort_next = b;                      \
+       a.sort_prev = b;                                                                        \
+       b.sort_next = a
+
+#endif