X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fintrusivelist.qh;h=be3fb00fa88ad72aad651d185bc974a4a518fd8e;hb=1b2a25e06fbc49de153addb922bae4c95f44ac1e;hp=9d3ec54c8e76c1f395ccd83b4ea2cfb585e5d7a7;hpb=268f9c69576b6bb929f66d19f0d077d19ba47edd;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/intrusivelist.qh b/qcsrc/lib/intrusivelist.qh index 9d3ec54c8..be3fb00fa 100644 --- a/qcsrc/lib/intrusivelist.qh +++ b/qcsrc/lib/intrusivelist.qh @@ -4,8 +4,11 @@ const int IL_MAX = 128; +ERASEABLE void IL_INIT(entity this); +ERASEABLE void IL_DTOR(entity this); +ERASEABLE void IL_ENDFRAME(); /** @@ -37,6 +40,7 @@ ENDCLASS(IntrusiveList) #define IL_LAST(this) (this.il_tail) #define IL_PEEK(this) (this.il_tail) +ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it) { assert(this, return false); @@ -46,6 +50,7 @@ bool IL_CONTAINS(IntrusiveList this, entity it) /** * Push to tail */ +ERASEABLE entity IL_PUSH(IntrusiveList this, entity it) { assert(this, return NULL); @@ -64,6 +69,7 @@ entity IL_PUSH(IntrusiveList this, entity it) /** * Push to head */ +ERASEABLE entity IL_UNSHIFT(IntrusiveList this, entity it) { assert(this, return NULL); @@ -82,6 +88,7 @@ entity IL_UNSHIFT(IntrusiveList this, entity it) /** * Pop from tail */ +ERASEABLE entity IL_POP(IntrusiveList this) { assert(this, return NULL); @@ -99,6 +106,7 @@ entity IL_POP(IntrusiveList this) /** * Pop from head */ +ERASEABLE entity IL_SHIFT(IntrusiveList this) { assert(this, return NULL); @@ -116,11 +124,13 @@ entity IL_SHIFT(IntrusiveList this) /** * Remove any element, anywhere in the list */ +ERASEABLE void IL_REMOVE(IntrusiveList this, entity it) { assert(this, return); .entity il_next = this.il_nextfld; .entity il_prev = this.il_prevfld; + //assert(!IL_CONTAINS(this, it), return); entity next = it.(il_next); entity prev = it.(il_prev); entity ohead = this.il_head; @@ -136,27 +146,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; \ @@ -167,7 +174,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]; @@ -179,6 +186,7 @@ int il_links_ptr; #define IL_LISTS_PER_BIT IL_CEIL(IL_MAX / (3 * 24)) +ERASEABLE void IL_INIT(IntrusiveList this) { .entity nextfld, prevfld; @@ -204,15 +212,17 @@ void IL_INIT(IntrusiveList this) return; } } - LOG_WARNF("IntrusiveList overflow"); + LOG_WARN("IntrusiveList overflow"); } +ERASEABLE void IL_DTOR(IntrusiveList this) { IL_CLEAR(this); il_links[this.il_id] = NULL; } +ERASEABLE void IL_ENDFRAME() { #if 0 @@ -232,12 +242,13 @@ void IL_ENDFRAME() #endif } +ERASEABLE void ONREMOVE(entity this) { if (this.il_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 ((this.il_lists & list.il_listmask) && IL_CONTAINS(list, this)) { IL_REMOVE(list, this); } }