Xonotic
intrusivelist.qh File Reference
#include "iter.qh"
+ Include dependency graph for intrusivelist.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  IntrusiveList
 limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can exist at one time freed entities must be removed from the list More...
 

Macros

#define IL_CEIL(n)   IL_FLOOR((n) + 0.5)
 
#define IL_CLEAR(this)
 Remove all elements. More...
 
#define IL_DELETE(this)
 Delete the list. More...
 
#define IL_EACH(this, cond, body)
 
#define IL_EMPTY(this)   (this.il_head == NULL)
 
#define IL_FIRST(this)   (this.il_head)
 
#define IL_FLOOR(n)   ((n) | 0)
 
#define IL_LAST(this)   (this.il_tail)
 
#define IL_LISTS_PER_BIT   IL_CEIL(IL_MAX / (3 * 24))
 
#define IL_NEW()   NEW(IntrusiveList)
 
#define IL_PEEK(this)   (this.il_tail)
 

Functions

ERASEABLE bool IL_CONTAINS (IntrusiveList this, entity it)
 
ERASEABLE void IL_DTOR (entity this)
 
ERASEABLE void IL_DTOR (IntrusiveList this)
 
ERASEABLE void IL_ENDFRAME ()
 
ERASEABLE void IL_INIT (entity this)
 
ERASEABLE void IL_INIT (IntrusiveList this)
 
ERASEABLE entity IL_POP (IntrusiveList this)
 Pop from tail. More...
 
ERASEABLE entity IL_PUSH (IntrusiveList this, entity it)
 Push to tail. More...
 
ERASEABLE void IL_REMOVE (IntrusiveList this, entity it)
 Remove any element, anywhere in the list. More...
 
ERASEABLE entity IL_SHIFT (IntrusiveList this)
 Pop from head. More...
 
ERASEABLE entity IL_UNSHIFT (IntrusiveList this, entity it)
 Push to head. More...
 
void ONREMOVE (entity this)
 

Variables

int il_id
 
IntrusiveList il_links [IL_MAX]
 
entity il_links_flds [IL_MAX *2]
 
int il_links_ptr
 
vector il_listmask
 
vector il_lists
 
const int IL_MAX = 128
 Maximum amount of creatable lists. More...
 

Macro Definition Documentation

◆ IL_CEIL

#define IL_CEIL (   n)    IL_FLOOR((n) + 0.5)

Definition at line 189 of file intrusivelist.qh.

◆ IL_CLEAR

#define IL_CLEAR (   this)
Value:
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
#define NULL
Definition: post.qh:17

Remove all elements.

Definition at line 151 of file intrusivelist.qh.

Referenced by _Movetype_PushMove(), CommonCommand_editmob(), crosshair_trace_plusvisibletriggers__is_wz(), FireRailgunBullet(), IL_DTOR(), Invasion_CheckWinner(), and pathlib_cleanup().

◆ IL_DELETE

#define IL_DELETE (   this)
Value:
delete(this); \
this = NULL; \
MACRO_END
#define delete(this)
Definition: oo.qh:72
#define NULL
Definition: post.qh:17

Delete the list.

Definition at line 163 of file intrusivelist.qh.

Referenced by Promise_reject(), Promise_resolve(), and REGISTER_MUTATOR().

◆ IL_EACH

#define IL_EACH (   this,
  cond,
  body 
)
Value:
MACRO_BEGIN \
IntrusiveList _il = this; \
assert(_il); \
.entity il_next = _il.il_nextfld; \
noref int i = 0; \
for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
{ \
const noref entity it = _it; \
_next = it.(il_next); \
if (cond) { LAMBDA(body) } \
} \
MACRO_END
entity() spawn
#define LAMBDA(...)
Definition: misc.qh:37

Definition at line 169 of file intrusivelist.qh.

Referenced by _Movetype_PushMove(), antilag_restore_all(), antilag_takeback_all(), assault_new_round(), assault_objective_use(), assault_roundstart_use(), assault_setenemytoobjective(), bot_serverframe(), botframe_autowaypoints_createwp(), botframe_autowaypoints_fix_from(), botframe_deleteuselesswaypoints(), botframe_updatedangerousobjects(), buff_Inferno_CalculateTime(), checkpoint_passed(), client_hasweapon(), ClientConnect(), ClientDisconnect(), ClientKill_TeamChange(), CommonCommand_editmob(), conveyor_think(), CreatureFrame_All(), crosshair_trace_plusvisibletriggers__is_wz(), crosshair_trace_waypoints(), CSQC_UpdateView(), cvar_settemp(), Domination_count_controlpoints(), dompoint_captured(), EndFrame(), findnearest(), Fire_ApplyDamage(), FireRailgunBullet(), func_ladder_think(), havocbot_ai(), havocbot_chooseenemy(), havocbot_gettarget(), havocbot_goalrating_ast_targets(), havocbot_goalrating_ball(), havocbot_goalrating_controlpoints(), havocbot_goalrating_items(), havocbot_goalrating_ons_controlpoints_attack(), havocbot_goalrating_ons_generator_attack(), havocbot_goalrating_waypoints(), havocbot_moveto(), havocbot_movetogoal(), havocbot_role_cts(), havocbot_role_race(), havocbot_select_an_item_of_group(), HUD_Radar(), Invasion_CheckWinner(), invasion_GetWaveEntity(), invasion_PickSpawn(), Item_FindTeam(), Item_ItemsTime_Allow(), Item_Touch(), ka_RemoveBalls(), Local_Notification_WOVA(), Monster_FindTarget(), MoveToRandomLocationWithinBounds(), MUTATOR_HOOKFUNCTION(), navigation_checkladders(), navigation_findnearestwaypoint_withdist_except(), navigation_get_really_close_waypoint(), navigation_markroutes(), navigation_markroutes_inverted(), navigation_markroutes_nearestwaypoints(), navigation_routerating(), navigation_unstuck(), NET_HANDLE(), onslaught_updatelinks(), pathlib_cleanup(), pathlib_nodeatpoint(), pathlib_waypointpath(), Physics_Frame(), Promise_reject(), Promise_resolve(), PutPlayerInServer(), race_GetFractionalLapCount(), RandomItems_GetRandomInstagibItemClassName(), RandomItems_GetRandomOverkillItemClassName(), sandbox_Database_Save(), sandbox_ObjectAttach_Remove(), sandbox_ObjectPort_Save(), Scoreboard_ItemStats_Draw(), Scoreboard_ItemStats_WouldDraw(), SelectSpawnPoint(), setItemGroupCount(), spawner_use(), StartFrame(), STATIC_INIT(), target_give_init(), target_items_use(), Teleport_Find(), trigger_race_checkpoint_verify(), vehicles_clearreturn(), WarpZone_Find(), WarpZone_MakeAllOther(), WarpZone_MakeAllSolid(), WarpZone_Projectile_Touch(), waypoint_addlink_for_custom_jumppad(), waypoint_get(), waypoint_get_type_name(), waypoint_load_links(), waypoint_remove(), waypoint_save_hardwiredlinks(), waypoint_save_links(), waypoint_saveall(), waypoint_schedulerelinkall(), waypoint_showlinks_to(), waypoint_spawn(), waypoint_spawn_fromeditor(), waypoint_spawnforitem_force(), waypoint_think(), waypoint_unreachable(), waypoint_updatecost_foralllinks(), weapon_prepareattack_checkammo(), Weapon_whereis(), WinningCondition_Invasion(), and WinningCondition_RanOutOfSpawns().

◆ IL_EMPTY

#define IL_EMPTY (   this)    (this.il_head == NULL)

Definition at line 41 of file intrusivelist.qh.

Referenced by draw_ClearClip(), and ka_Handler_CheckBall().

◆ IL_FIRST

#define IL_FIRST (   this)    (this.il_head)

Definition at line 43 of file intrusivelist.qh.

Referenced by SelectSpawnPoint().

◆ IL_FLOOR

#define IL_FLOOR (   n)    ((n) | 0)

Definition at line 188 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_LAST

#define IL_LAST (   this)    (this.il_tail)

Definition at line 44 of file intrusivelist.qh.

◆ IL_LISTS_PER_BIT

#define IL_LISTS_PER_BIT   IL_CEIL(IL_MAX / (3 * 24))

Definition at line 191 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_NEW

◆ IL_PEEK

#define IL_PEEK (   this)    (this.il_tail)

Definition at line 45 of file intrusivelist.qh.

Referenced by _draw_SetClip(), and draw_ClearClip().

Function Documentation

◆ IL_CONTAINS()

ERASEABLE bool IL_CONTAINS ( IntrusiveList  this,
entity  it 
)

Definition at line 48 of file intrusivelist.qh.

References assert, and ERASEABLE.

Referenced by IL_PUSH(), IL_UNSHIFT(), kh_Key_Attach(), kh_Key_Detach(), ONREMOVE(), and ons_GeneratorReset().

49 {
50  assert(this, return false);
51  return it.(this.il_nextfld) || this.il_head == it || this.il_tail == it;
52 }
#define assert(expr,...)
Definition: log.qh:8
+ Here is the caller graph for this function:

◆ IL_DTOR() [1/2]

ERASEABLE void IL_DTOR ( entity  this)

Referenced by IntrusiveList::IntrusiveList ::~ IntrusiveList().

+ Here is the caller graph for this function:

◆ IL_DTOR() [2/2]

ERASEABLE void IL_DTOR ( IntrusiveList  this)

Definition at line 223 of file intrusivelist.qh.

References ERASEABLE, IL_CLEAR, il_id, and NULL.

224 {
225  IL_CLEAR(this);
226  il_links[this.il_id] = NULL;
227 }
#define IL_CLEAR(this)
Remove all elements.
int il_id
#define NULL
Definition: post.qh:17
IntrusiveList il_links[IL_MAX]

◆ IL_ENDFRAME()

ERASEABLE void IL_ENDFRAME ( )

Definition at line 230 of file intrusivelist.qh.

References entity(), IL_MAX, IntrusiveList::il_nextfld, IL_REMOVE(), and next.

Referenced by CSQC_UpdateView(), EndFrame(), and m_draw().

231 {
232 #if 0
233  // incompatible with CSQC, remove() clears entities
234  for (int i = 0; i < IL_MAX; ++i) {
235  IntrusiveList list = il_links[i];
236  if (list) {
237  .entity nextfld = list.il_nextfld;
238  for (entity next, it = list.il_head; it; it = next) {
239  next = it.(nextfld);
240  if (wasfreed(it)) {
241  IL_REMOVE(list, it);
242  }
243  }
244  }
245  }
246 #endif
247 }
const int IL_MAX
Maximum amount of creatable lists.
Definition: intrusivelist.qh:9
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
entity() spawn
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
next
Definition: all.qh:88
IntrusiveList il_links[IL_MAX]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IL_INIT() [1/2]

ERASEABLE void IL_INIT ( entity  this)

Referenced by IntrusiveList::IntrusiveList ::IntrusiveList().

+ Here is the caller graph for this function:

◆ IL_INIT() [2/2]

ERASEABLE void IL_INIT ( IntrusiveList  this)

Definition at line 194 of file intrusivelist.qh.

References assert, ERASEABLE, IL_FLOOR, il_id, il_links_flds, il_links_ptr, il_listmask, IL_LISTS_PER_BIT, IL_MAX, and LOG_WARN.

195 {
196  .entity nextfld, prevfld;
197  for (int i = il_links_ptr; i < il_links_ptr + IL_MAX; ++i) {
198  int idx = i;
199  if (idx >= IL_MAX) idx -= IL_MAX;
200  int id = idx;
201  idx *= 2;
202  if (!il_links[idx]) {
203  il_links[idx] = this;
204  nextfld = il_links_flds[idx + 0];
205  prevfld = il_links_flds[idx + 1];
206  this.il_id = id;
207  int bit = IL_FLOOR(id / IL_LISTS_PER_BIT);
208  if (bit < (1 * 24)) this.il_listmask = '1 0 0' * (1 << (bit - (0 * 24)));
209  else if (bit < (2 * 24)) this.il_listmask = '0 1 0' * (1 << (bit - (1 * 24)));
210  else if (bit < (3 * 24)) this.il_listmask = '0 0 1' * (1 << (bit - (2 * 24)));
211  else assert(false);
212  il_links_ptr = id + 1;
213  if (il_links_ptr >= IL_MAX) il_links_ptr -= IL_MAX;
214  this.il_nextfld = nextfld;
215  this.il_prevfld = prevfld;
216  return;
217  }
218  }
219  LOG_WARN("IntrusiveList overflow");
220 }
const int IL_MAX
Maximum amount of creatable lists.
Definition: intrusivelist.qh:9
#define assert(expr,...)
Definition: log.qh:8
#define LOG_WARN(...)
Definition: log.qh:66
int il_links_ptr
#define IL_LISTS_PER_BIT
int il_id
#define IL_FLOOR(n)
vector il_listmask
entity il_links_flds[IL_MAX *2]
IntrusiveList il_links[IL_MAX]

◆ IL_POP()

ERASEABLE entity IL_POP ( IntrusiveList  this)

Pop from tail.

Definition at line 96 of file intrusivelist.qh.

References assert, entity(), ERASEABLE, NULL, and prev.

97 {
98  assert(this, return NULL);
99  .entity il_next = this.il_nextfld;
100  .entity il_prev = this.il_prevfld;
101 
102  if (!this.il_tail) return NULL;
103  entity it = this.il_tail;
104  entity prev = it.(il_prev);
105  if (prev) (this.il_tail = prev).(il_next) = NULL;
106  else this.il_head = this.il_tail = NULL;
107  return it;
108 }
#define assert(expr,...)
Definition: log.qh:8
entity() spawn
prev
Definition: all.qh:66
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:

◆ IL_PUSH()

ERASEABLE entity IL_PUSH ( IntrusiveList  this,
entity  it 
)

Push to tail.

Definition at line 58 of file intrusivelist.qh.

References assert, entity(), ERASEABLE, IL_CONTAINS(), il_listmask, and NULL.

Referenced by _draw_SetClip(), _Movetype_PushMove(), _Promise_handle(), _StartItem(), buff_Init(), conveyor_think(), CopyBody(), cpicon_construct(), ctf_FlagSetup(), cvar_settemp(), DamageText::DamageText ::DamageText(), dom_controlpoint_setup(), FireGrapplingHook(), FireRailgunBullet(), func_ladder_think(), generator_construct(), GENERIC_COMMAND(), ka_DropEvent(), ka_SpawnBall(), kh_Key_Detach(), Local_Notification_WOVA(), LocalCommand_debugmodel(), monster_changeteam(), Monster_Spawn(), Monster_Spawn_Setup(), NET_HANDLE(), ons_CaptureShield_Spawn(), ons_ControlPoint_Icon_Spawn(), ons_generator_ray_spawn(), ons_GeneratorReset(), ons_GeneratorSetup(), onslaught_updatelinks(), pathlib_mknode(), Player::Player ::Player(), PutPlayerInServer(), REGISTER_MUTATOR(), relocate_spawnpoint(), sandbox_ObjectSpawn(), spawnfunc(), STATIC_INIT(), SV_OnEntityPreSpawnFunction(), target_checkpoint_setup(), Teleport_Touch(), train_next(), trigger_push_findtarget(), turret_construct(), Unfreeze(), vehicle_initialize(), vehicles_projectile(), vehicles_setreturn(), vehicles_spawn(), W_Nexball_Attack2(), WarpZone_Projectile_Touch(), and waypoint_spawn().

59 {
60  assert(this, return NULL);
61  assert(it, return NULL);
62  .entity il_next = this.il_nextfld;
63  .entity il_prev = this.il_prevfld;
64  assert(!IL_CONTAINS(this, it), return NULL);
65 
66  entity tail = it.(il_prev) = this.il_tail;
67  tail ? (tail.(il_next) = it) : this.il_head = it;
68  this.il_tail = it;
69  it.il_lists |= this.il_listmask;
70  return it;
71 }
#define assert(expr,...)
Definition: log.qh:8
entity() spawn
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
#define NULL
Definition: post.qh:17
vector il_listmask
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IL_REMOVE()

ERASEABLE void IL_REMOVE ( IntrusiveList  this,
entity  it 
)

Remove any element, anywhere in the list.

Definition at line 132 of file intrusivelist.qh.

References assert, entity(), LOG_DEBUGF, next, NULL, and prev.

Referenced by draw_ClearClip(), dumpnode(), Freeze(), IL_ENDFRAME(), invasion_SpawnChosenMonster(), ka_TouchEvent(), kh_Key_Attach(), MUTATOR_HOOKFUNCTION(), ONREMOVE(), ons_generator_ray_draw(), onslaught_updatelinks(), Player::Player ::~ Player(), PlayerCorpseDamage(), PutObserverInServer(), and PutPlayerInServer().

133 {
134  assert(this, return);
135  .entity il_next = this.il_nextfld;
136  .entity il_prev = this.il_prevfld;
137  //assert(!IL_CONTAINS(this, it), return);
138  entity next = it.(il_next);
139  entity prev = it.(il_prev);
140  entity ohead = this.il_head;
141  entity otail = this.il_tail;
142  next ? next.(il_prev) = prev : this.il_tail = prev;
143  prev ? prev.(il_next) = next : this.il_head = next;
144  LOG_DEBUGF("remove %i (%i :: %i), head: %i -> %i, tail: %i -> %i", it, it.(il_prev), it.(il_next), ohead, this.il_head, otail, this.il_tail);
145  it.(il_next) = it.(il_prev) = NULL;
146 }
#define assert(expr,...)
Definition: log.qh:8
entity() spawn
prev
Definition: all.qh:66
#define NULL
Definition: post.qh:17
next
Definition: all.qh:88
#define LOG_DEBUGF(...)
Definition: log.qh:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IL_SHIFT()

ERASEABLE entity IL_SHIFT ( IntrusiveList  this)

Pop from head.

Definition at line 114 of file intrusivelist.qh.

References assert, entity(), ERASEABLE, next, and NULL.

115 {
116  assert(this, return NULL);
117  .entity il_next = this.il_nextfld;
118  .entity il_prev = this.il_prevfld;
119 
120  if (!this.il_head) return NULL;
121  entity it = this.il_head;
122  entity next = it.(il_next);
123  if (next) (this.il_head = next).(il_prev) = NULL;
124  else this.il_head = this.il_tail = NULL;
125  return it;
126 }
#define assert(expr,...)
Definition: log.qh:8
entity() spawn
#define NULL
Definition: post.qh:17
next
Definition: all.qh:88
+ Here is the call graph for this function:

◆ IL_UNSHIFT()

ERASEABLE entity IL_UNSHIFT ( IntrusiveList  this,
entity  it 
)

Push to head.

Definition at line 77 of file intrusivelist.qh.

References assert, entity(), ERASEABLE, IL_CONTAINS(), il_listmask, and NULL.

78 {
79  assert(this, return NULL);
80  assert(it, return NULL);
81  .entity il_next = this.il_nextfld;
82  .entity il_prev = this.il_prevfld;
83  assert(!IL_CONTAINS(this, it), return NULL);
84 
85  entity head = it.(il_next) = this.il_head;
86  head ? (head.(il_prev) = it) : this.il_tail = it;
87  this.il_head = it;
88  it.il_lists |= this.il_listmask;
89  return it;
90 }
#define assert(expr,...)
Definition: log.qh:8
entity() spawn
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
#define NULL
Definition: post.qh:17
vector il_listmask
+ Here is the call graph for this function:

◆ ONREMOVE()

void ONREMOVE ( entity  this)

Definition at line 251 of file intrusivelist.qh.

References IL_CONTAINS(), il_lists, IL_MAX, IL_REMOVE(), and vector().

Referenced by ClientDisconnect(), and CSQC_Ent_Update().

252 {
253  // remove 'this' from any intrusive lists it is on
254  vector lists = this.il_lists;
255  if (lists) {
256  for (int i = 0; i < IL_MAX; ++i) {
257  IntrusiveList list = il_links[i];
258  if ((lists & list.il_listmask) && IL_CONTAINS(list, this)) {
259  IL_REMOVE(list, this);
260  }
261  }
262  }
263 }
const int IL_MAX
Maximum amount of creatable lists.
Definition: intrusivelist.qh:9
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector il_lists
IntrusiveList il_links[IL_MAX]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ il_id

int il_id

Definition at line 183 of file intrusivelist.qh.

Referenced by IL_DTOR(), and IL_INIT().

◆ il_links

IntrusiveList il_links[IL_MAX]

Definition at line 184 of file intrusivelist.qh.

◆ il_links_flds

entity il_links_flds[IL_MAX *2]

Definition at line 185 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ il_links_ptr

int il_links_ptr

Definition at line 186 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ il_listmask

vector il_listmask

Definition at line 37 of file intrusivelist.qh.

Referenced by IL_INIT(), IL_PUSH(), and IL_UNSHIFT().

◆ il_lists

vector il_lists

Definition at line 35 of file intrusivelist.qh.

Referenced by ONREMOVE().

◆ IL_MAX

const int IL_MAX = 128

Maximum amount of creatable lists.

Lists can be given endless amount of entities, only restricted by engine limitations.

Definition at line 9 of file intrusivelist.qh.

Referenced by IL_ENDFRAME(), IL_INIT(), and ONREMOVE().