]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/intrusivelist.qh
Include LegendGuard in the credits for their code, art and translation contributions...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / intrusivelist.qh
index fc0e080eae32fa103333559653d439a403895cb2..63a21565601085c4e34ce72c8aff021ae5fa70e6 100644 (file)
@@ -2,6 +2,10 @@
 
 #include "iter.qh"
 
+/**
+ * Maximum amount of creatable lists.
+ * Lists can be given endless amount of entities, only restricted by engine limitations.
+ */
 const int IL_MAX = 128;
 
 ERASEABLE
@@ -146,27 +150,24 @@ void IL_REMOVE(IntrusiveList this, entity it)
  */
 #define IL_CLEAR(this) \
        MACRO_BEGIN \
-       { \
                IntrusiveList __il = this; \
                assert(__il); \
                .entity il_prev = __il.il_prevfld; \
                IL_EACH(__il, true, it.(il_next) = it.(il_prev) = NULL); \
                __il.il_head = __il.il_tail = NULL; \
-       MACRO_END
+       MACRO_END
 
 /**
  * Delete the list
  */
 #define IL_DELETE(this) \
        MACRO_BEGIN \
-       { \
                delete(this); \
                this = NULL; \
-       MACRO_END
+       MACRO_END
 
 #define IL_EACH(this, cond, body) \
        MACRO_BEGIN \
-       { \
                IntrusiveList _il = this; \
                assert(_il); \
                .entity il_next = _il.il_nextfld; \
@@ -177,7 +178,7 @@ void IL_REMOVE(IntrusiveList this, entity it)
                        _next = it.(il_next); \
                        if (cond) { LAMBDA(body) } \
                } \
-       MACRO_END
+       MACRO_END
 
 .int il_id;
 IntrusiveList il_links[IL_MAX];
@@ -215,7 +216,7 @@ void IL_INIT(IntrusiveList this)
                        return;
                }
        }
-       LOG_WARNF("IntrusiveList overflow");
+       LOG_WARN("IntrusiveList overflow");
 }
 
 ERASEABLE
@@ -245,13 +246,16 @@ void IL_ENDFRAME()
 #endif
 }
 
-ERASEABLE
+// called when an entity is deleted with delete() / remove()
+// or when a player disconnects
 void ONREMOVE(entity this)
 {
-       if (this.il_lists) {
+       // remove 'this' from any intrusive lists it is on
+       vector lists = this.il_lists;
+       if (lists) {
                for (int i = 0; i < IL_MAX; ++i) {
                        IntrusiveList list = il_links[i];
-                       if (this.il_lists & list.il_listmask && IL_CONTAINS(list, this)) {
+                       if ((lists & list.il_listmask) && IL_CONTAINS(list, this)) {
                                IL_REMOVE(list, this);
                        }
                }