Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
intrusivelist.qh File Reference
#include "bits.qh"
#include "iter.qh"
#include "test.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)
#define IL_CLEAR(this)
 Remove all elements.
#define IL_DELETE(this)
 Delete the list.
#define IL_EACH(this, cond, body)
#define IL_EMPTY(this)
#define IL_FIRST(this)
#define IL_FLOOR(n)
#define IL_LAST(this)
#define IL_LISTS_PER_BIT   IL_CEIL(IL_MAX / (3 * 24))
#define IL_NEW()
#define IL_PEEK(this)
#define IL_TEST_BUILD()

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.
ERASEABLE entity IL_PUSH (IntrusiveList this, entity it)
 Push to tail.
ERASEABLE void IL_REMOVE (IntrusiveList this, entity it)
 Remove any element, anywhere in the list.
void IL_REMOVE_RAW (entity it)
 Clears any IL data from an entity (not an intrusive list).
ERASEABLE entity IL_SHIFT (IntrusiveList this)
 Pop from head.
string il_test_build (entity il_test, entity ent1, entity ent2, entity ent3, entity ent4, entity ent5)
ERASEABLE entity IL_UNSHIFT (IntrusiveList this, entity it)
 Push to head.
void ONREMOVE (entity this)
 Called when an entity is deleted with delete() / remove() or when a player disconnects.
 TEST (intrusivelist, ModificationsWhileLooping)

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.

Macro Definition Documentation

◆ IL_CEIL

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

Definition at line 222 of file intrusivelist.qh.

◆ IL_CLEAR

#define IL_CLEAR ( this)
Value:
MACRO_BEGIN \
IntrusiveList _il = this; \
assert(_il); \
.entity il_prev = _il.il_prevfld; \
.entity il_next = _il.il_nextfld; \
noref int i = 0; \
for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
{ \
_next = _it.(il_next); \
_it.(il_next) = _it.(il_prev) = NULL; \
} \
_il.il_head = _il.il_tail = NULL; \
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define MACRO_END
Definition macro.qh:7
#define NULL
Definition post.qh:14

Remove all elements.

Definition at line 174 of file intrusivelist.qh.

174#define IL_CLEAR(this) MACRO_BEGIN \
175 IntrusiveList _il = this; \
176 assert(_il); \
177 .entity il_prev = _il.il_prevfld; \
178 .entity il_next = _il.il_nextfld; \
179 noref int i = 0; \
180 for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
181 { \
182 _next = _it.(il_next); \
183 _it.(il_next) = _it.(il_prev) = NULL; \
184 } \
185 _il.il_head = _il.il_tail = NULL; \
186MACRO_END

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

◆ IL_DELETE

#define IL_DELETE ( this)
Value:
MACRO_BEGIN \
delete(this); \
this = NULL; \

Delete the list.

Definition at line 189 of file intrusivelist.qh.

189#define IL_DELETE(this) MACRO_BEGIN \
190 delete(this); \
191 this = NULL; \
192MACRO_END

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

◆ 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; \
entity il_loop_item_save = this.il_loop_item; \
this.il_loop_item = NULL; \
for (entity _next, _it = _il.il_head; _it; _it = _next, ++i) \
{ \
const noref entity it = _it; \
this.il_loop_item = it; \
_next = it.(il_next); \
if (cond) \
LAMBDA(body) \
if (this.il_loop_item != it) /* current item removed? */ \
_next = this.il_loop_item; \
else \
_next = it.(il_next); /* in case next item has changed */ \
} \
this.il_loop_item = il_loop_item_save; \

Definition at line 194 of file intrusivelist.qh.

194#define IL_EACH(this, cond, body) MACRO_BEGIN \
195 IntrusiveList _il = this; \
196 assert(_il); \
197 .entity il_next = _il.il_nextfld; \
198 noref int i = 0; \
199 entity il_loop_item_save = this.il_loop_item; \
200 this.il_loop_item = NULL; \
201 for (entity _next, _it = _il.il_head; _it; _it = _next, ++i) \
202 { \
203 const noref entity it = _it; \
204 this.il_loop_item = it; \
205 _next = it.(il_next); \
206 if (cond) \
207 LAMBDA(body) \
208 if (this.il_loop_item != it) /* current item removed? */ \
209 _next = this.il_loop_item; \
210 else \
211 _next = it.(il_next); /* in case next item has changed */ \
212 } \
213 this.il_loop_item = il_loop_item_save; \
214MACRO_END

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(), checkpoint_passed(), client_hasweapon(), ClientConnect(), ClientDisconnect(), ClientKill_TeamChange(), CommonCommand_editmob(), conveyor_think(), counter_reset(), counter_use(), CreatureFrame_All(), crosshair_trace_plusvisibletriggers__is_wz(), crosshair_trace_waypoints(), CSQC_UpdateView(), ctf_CheckStalemate(), ctf_DelayedInit(), ctf_FlagThink(), ctf_Handle_Capture(), ctf_RemovePlayer(), cvar_settemp(), Domination_count_controlpoints(), dompoint_captured(), EndFrame(), findnearest(), Fire_ApplyDamage(), FireImoBeam(), FireRailgunBullet(), func_breakable_behave_destroyed(), func_ladder_think(), havocbot_ai(), havocbot_chooseenemy(), havocbot_ctf_calculate_middlepoint(), havocbot_ctf_find_enemy_flag(), havocbot_ctf_find_flag(), havocbot_ctf_is_basewaypoint(), havocbot_goalrating_ast_targets(), havocbot_goalrating_ball(), havocbot_goalrating_controlpoints(), havocbot_goalrating_ctf_droppedflags(), havocbot_goalrating_ctf_enemyflag(), havocbot_goalrating_ctf_ourbase(), havocbot_goalrating_items(), havocbot_goalrating_ons_controlpoints_attack(), havocbot_goalrating_ons_generator_attack(), havocbot_goalrating_tkaball(), havocbot_goalrating_waypoints(), havocbot_moveto(), havocbot_movetogoal(), havocbot_role_cts(), havocbot_role_race(), havocbot_select_an_item_of_group(), HUD_Ammo(), HUD_Radar(), Invasion_CheckWinner(), invasion_GetWaveEntity(), invasion_PickSpawn(), Item_FindTeam(), Item_ItemsTime_UpdateTime(), Item_Touch(), ka_RemoveBalls(), Kill_Notification(), LimitedChildrenRubble(), Monster_FindTarget(), MoveToRandomLocationWithinBounds(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), nade_boom(), nade_touch(), 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(), raptor_flare_think(), raptor_frame(), sandbox_Database_Save(), sandbox_ObjectAttach_Remove(), sandbox_ObjectPort_Save(), Scoreboard_ItemStats_Draw(), Scoreboard_ItemStats_WouldDraw(), SelectObservePoint(), SelectSpawnPoint(), setItemGroupCount(), spawner_use(), spiderbot_exit(), spiderbot_guide_release(), StartFrame(), swamp_think(), target_give_use(), target_items_use(), target_music_kill(), TargetMusic_RestoreGame(), Teleport_Find(), TEST(), tka_RemoveBalls(), trigger_push_velocity_think(), trigger_race_checkpoint_verify(), turret_hk_missile_think(), turret_targettrigger_touch(), turrets_manager_think(), UncustomizeEntitiesRun(), vehicles_clearreturn(), W_MineLayer_Count(), W_MineLayer_PlacedMines(), W_Seeker_Attack(), W_Seeker_Tagged_Info(), WarpZone_Find(), WarpZone_MakeAllOther(), WarpZone_MakeAllSolid(), WarpZone_StartFrame(), 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)
Value:
(this.il_head == NULL)

Definition at line 50 of file intrusivelist.qh.

Referenced by draw_ClearClip(), ka_Handler_CheckBall(), and tka_Handler_CheckBall().

◆ IL_FIRST

#define IL_FIRST ( this)
Value:
(this.il_head)

Definition at line 52 of file intrusivelist.qh.

Referenced by SelectSpawnPoint().

◆ IL_FLOOR

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

Definition at line 221 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_LAST

#define IL_LAST ( this)
Value:
(this.il_tail)

Definition at line 53 of file intrusivelist.qh.

◆ IL_LISTS_PER_BIT

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

Definition at line 224 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_NEW

◆ IL_PEEK

#define IL_PEEK ( this)
Value:
(this.il_tail)

Definition at line 54 of file intrusivelist.qh.

Referenced by _draw_SetClip(), and draw_ClearClip().

◆ IL_TEST_BUILD

#define IL_TEST_BUILD ( )
Value:
s = il_test_build(il_test, ent1, ent2, ent3, ent4, ent5)
string il_test_build(entity il_test, entity ent1, entity ent2, entity ent3, entity ent4, entity ent5)

Definition at line 320 of file intrusivelist.qh.

Referenced by TEST().

Function Documentation

◆ IL_CONTAINS()

ERASEABLE bool IL_CONTAINS ( IntrusiveList this,
entity it )

Definition at line 57 of file intrusivelist.qh.

58{
59 assert(this, return false);
60 return (it.(this.il_nextfld) || this.il_head == it || this.il_tail == it);
61}
#define assert(expr,...)
Definition log.qh:8

References assert, and entity().

Referenced by ctf_Handle_Pickup(), ctf_RespawnFlag(), IL_PUSH(), IL_UNSHIFT(), kh_Key_Attach(), kh_Key_Detach(), ONREMOVE(), ons_GeneratorReset(), set_movetype(), spawnfunc(), and W_Electro_Orb_Stick().

◆ IL_DTOR() [1/2]

ERASEABLE void IL_DTOR ( entity this)

References entity(), and ERASEABLE.

Referenced by IntrusiveList::~IntrusiveList().

◆ IL_DTOR() [2/2]

ERASEABLE void IL_DTOR ( IntrusiveList this)

Definition at line 264 of file intrusivelist.qh.

265{
266 IL_CLEAR(this);
267 il_links[this.il_id] = NULL;
268}
#define IL_CLEAR(this)
Remove all elements.
int il_id
IntrusiveList il_links[IL_MAX]

References IL_CLEAR, il_id, il_links, and NULL.

◆ IL_ENDFRAME()

ERASEABLE void IL_ENDFRAME ( )

Definition at line 271 of file intrusivelist.qh.

272{
273#if 0
274 // incompatible with CSQC, remove() clears entities
275 for (int i = 0; i < IL_MAX; ++i)
276 {
277 IntrusiveList list = il_links[i];
278 if (list)
279 {
280 .entity nextfld = list.il_nextfld;
281 for (entity next, it = list.il_head; it; it = next)
282 {
283 next = it.(nextfld);
284 if (wasfreed(it))
285 IL_REMOVE(list, it);
286 }
287 }
288 }
289#endif
290}
next
Definition all.qh:75
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
const int IL_MAX
Maximum amount of creatable lists.

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

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

◆ IL_INIT() [1/2]

ERASEABLE void IL_INIT ( entity this)

References entity(), and ERASEABLE.

Referenced by IntrusiveList::IntrusiveList().

◆ IL_INIT() [2/2]

ERASEABLE void IL_INIT ( IntrusiveList this)

Definition at line 227 of file intrusivelist.qh.

228{
229 .entity nextfld, prevfld;
230 for (int i = il_links_ptr; i < il_links_ptr + IL_MAX; ++i)
231 {
232 int id = i;
233 if (id >= IL_MAX)
234 id -= IL_MAX;
235
236 if (!il_links[id])
237 {
238 il_links[id] = this;
239 int flds_idx = id * 2;
240 nextfld = il_links_flds[flds_idx + 0];
241 prevfld = il_links_flds[flds_idx + 1];
242 this.il_id = id;
243 int bit = IL_FLOOR(id / IL_LISTS_PER_BIT);
244 if (bit < 1 * 24)
245 this.il_listmask = '1 0 0' * BIT(bit - (0 * 24));
246 else if (bit < 2 * 24)
247 this.il_listmask = '0 1 0' * BIT(bit - (1 * 24));
248 else if (bit < 3 * 24)
249 this.il_listmask = '0 0 1' * BIT(bit - (2 * 24));
250 else
251 assert(false);
252 il_links_ptr = id + 1;
253 if (il_links_ptr >= IL_MAX)
255 this.il_nextfld = nextfld;
256 this.il_prevfld = prevfld;
257 return;
258 }
259 }
260 LOG_WARN("IntrusiveList overflow");
261}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
entity il_links_flds[IL_MAX *2]
int il_links_ptr
vector il_listmask
#define IL_LISTS_PER_BIT
#define LOG_WARN(...)
Definition log.qh:58

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

◆ IL_POP()

ERASEABLE entity IL_POP ( IntrusiveList this)

Pop from tail.

Definition at line 105 of file intrusivelist.qh.

106{
107 assert(this, return NULL);
108 .entity il_next = this.il_nextfld;
109 .entity il_prev = this.il_prevfld;
110
111 if (!this.il_tail)
112 return NULL;
113 entity it = this.il_tail;
114 entity prev = it.(il_prev);
115 if (prev)
116 (this.il_tail = prev).(il_next) = NULL;
117 else
118 this.il_head = this.il_tail = NULL;
119 if (this.il_loop_item == it)
120 this.il_loop_item = NULL;
121 it.(il_prev) = NULL;
122 return it;
123}
prev
Definition all.qh:53

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

Referenced by TEST().

◆ IL_PUSH()

ERASEABLE entity IL_PUSH ( IntrusiveList this,
entity it )

Push to tail.

Definition at line 65 of file intrusivelist.qh.

66{
67 assert(this, return NULL);
68 assert(it, return NULL);
69 .entity il_next = this.il_nextfld;
70 .entity il_prev = this.il_prevfld;
71 assert(!IL_CONTAINS(this, it), return NULL);
72
73 entity tail = it.(il_prev) = this.il_tail;
74 if (tail)
75 tail.(il_next) = it;
76 else
77 this.il_head = it;
78 this.il_tail = it;
79 it.il_lists |= this.il_listmask;
80 return it;
81}
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)

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

Referenced by DamageText::DamageText(), DebugText3d::DebugText3d(), __spawnfunc_defer(), __spawnfunc_spawn(), _draw_SetClip(), _Movetype_PushMove(), _Promise_handle(), buff_Init(), conveyor_think(), CopyBody(), counter_use(), cpicon_construct(), crosshair_trace_plusvisibletriggers__is_wz(), ctf_FlagSetup(), ctf_Handle_Drop(), ctf_Handle_Pickup(), cvar_settemp(), dom_controlpoint_setup(), electro_orb_setup(), Ent_WaypointSprite(), fd_secret_use(), FireGrapplingHook(), FireImoBeam(), FireRailgunBullet(), freezetag_Unfreeze(), func_breakable_behave_restore(), func_breakable_setup(), func_ladder_think(), generator_construct(), il_test_build(), ka_DropEvent(), ka_SpawnBalls(), kh_Key_Detach(), ListNewChildRubble(), LocalCommand_debugmodel(), M_Golem_Attack_Lightning(), M_Mage_Attack_Spike(), M_Spider_Attack_Web(), monster_changeteam(), Monster_Spawn(), Monster_Spawn_Setup(), nade_darkness_boom(), nade_ice_boom(), nade_napalm_ball(), nade_napalm_boom(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), ons_CaptureShield_Spawn(), ons_ControlPoint_Icon_Spawn(), ons_generator_ray_spawn(), ons_GeneratorReset(), ons_GeneratorSetup(), onslaught_updatelinks(), orb_setup(), pathlib_mknode(), PutPlayerInServer(), RaptorCBShellfragToss(), REGISTER_MUTATOR(), REGISTER_MUTATOR(), relocate_spawnpoint(), ReplaceOldListedChildRubble(), sandbox_ObjectSpawn(), Send_Notification(), set_movetype(), SetCustomizer(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), spawnfunc(), StartItem(), STATIC_INIT(), STATIC_INIT(), STATIC_INIT(), SV_OnEntityPreSpawnFunction(), swamp_think(), target_checkpoint_setup(), TEST(), tka_SpawnBalls(), toss_nade(), TossGib(), turret_construct(), turret_initialize(), turret_projectile(), vehicle_initialize(), vehicles_projectile(), vehicles_setreturn(), vehicles_spawn(), W_Arc_Attack_Bolt(), W_Arc_Beam(), W_Blaster_Attack(), W_Crylink_Attack(), W_Crylink_Attack2(), W_Devastator_Attack(), W_Electro_Attack_Bolt(), W_Electro_Attack_Orb(), W_Electro_Orb_Stick(), W_Fireball_Attack1(), W_Fireball_Attack2(), W_Hagar_Attack(), W_Hagar_Attack2(), W_Hagar_Attack2_Load_Release(), W_HLAC_Attack(), W_HLAC_Attack2(), W_Hook_Attack2(), W_MineLayer_Attack(), W_MineLayer_Stick(), W_Mortar_Attack(), W_Mortar_Attack2(), W_Nexball_Attack2(), W_OverkillRocketPropelledChainsaw_Attack(), W_Porto_Attack(), W_Porto_Fail(), W_RocketMinsta_Attack(), W_Seeker_Fire_Flac(), W_Seeker_Fire_Missile(), W_Seeker_Fire_Tag(), W_Seeker_Tag_Touch(), walker_fire_rocket(), and waypoint_spawn().

◆ IL_REMOVE()

ERASEABLE void IL_REMOVE ( IntrusiveList this,
entity it )

Remove any element, anywhere in the list.

Definition at line 149 of file intrusivelist.qh.

150{
151 assert(this, return);
152 .entity il_next = this.il_nextfld;
153 .entity il_prev = this.il_prevfld;
154 //assert(!IL_CONTAINS(this, it), return);
155 entity next = it.(il_next);
156 entity prev = it.(il_prev);
157 entity ohead = this.il_head;
158 entity otail = this.il_tail;
159 if (next)
160 next.(il_prev) = prev;
161 else
162 this.il_tail = prev;
163 if (prev)
164 prev.(il_next) = next;
165 else
166 this.il_head = next;
167 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);
168 if (this.il_loop_item == it)
169 this.il_loop_item = it.(il_next);
170 it.(il_next) = it.(il_prev) = NULL;
171}
#define LOG_DEBUGF(...)
Definition log.qh:79

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

Referenced by ctf_Handle_Pickup(), ctf_RespawnFlag(), DamageText::DamageText_draw2d(), draw_ClearClip(), dumpnode(), freezetag_Freeze(), func_breakable_behave_destroyed(), IL_ENDFRAME(), invasion_SpawnChosenMonster(), ka_TouchEvent(), kh_Key_Attach(), MUTATOR_HOOKFUNCTION(), NET_HANDLE(), ONREMOVE(), ons_generator_ray_draw(), onslaught_updatelinks(), PlayerCorpseDamage(), PutObserverInServer(), PutPlayerInServer(), race_SendTime(), ReplaceOldListedChildRubble(), and TEST().

◆ IL_REMOVE_RAW()

void IL_REMOVE_RAW ( entity it)

Clears any IL data from an entity (not an intrusive list).

it should be used only in very particular cases such as after a copyentity call

Definition at line 294 of file intrusivelist.qh.

295{
296 if (it.il_lists)
297 {
298 it.il_lists = '0 0 0';
299 for (int i = 0; i < IL_MAX * 2; ++i)
300 it.il_links_flds[i] = nil;
301 }
302}

References entity(), and IL_MAX.

Referenced by copyentity_qc().

◆ IL_SHIFT()

ERASEABLE entity IL_SHIFT ( IntrusiveList this)

Pop from head.

Definition at line 127 of file intrusivelist.qh.

128{
129 assert(this, return NULL);
130 .entity il_next = this.il_nextfld;
131 .entity il_prev = this.il_prevfld;
132
133 if (!this.il_head)
134 return NULL;
135 entity it = this.il_head;
136 entity next = it.(il_next);
137 if (next)
138 (this.il_head = next).(il_prev) = NULL;
139 else
140 this.il_head = this.il_tail = NULL;
141 if (this.il_loop_item == it)
142 this.il_loop_item = it.(il_next);
143 it.(il_next) = NULL;
144 return it;
145}

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

Referenced by TEST().

◆ il_test_build()

string il_test_build ( entity il_test,
entity ent1,
entity ent2,
entity ent3,
entity ent4,
entity ent5 )

Definition at line 322 of file intrusivelist.qh.

323{
324 IL_CLEAR(il_test);
325 IL_PUSH(il_test, ent1);
326 IL_PUSH(il_test, ent2);
327 IL_PUSH(il_test, ent3);
328 IL_PUSH(il_test, ent4);
329 IL_PUSH(il_test, ent5);
330 return "";
331}
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.

References entity(), IL_CLEAR, and IL_PUSH().

◆ IL_UNSHIFT()

ERASEABLE entity IL_UNSHIFT ( IntrusiveList this,
entity it )

Push to head.

Definition at line 85 of file intrusivelist.qh.

86{
87 assert(this, return NULL);
88 assert(it, return NULL);
89 .entity il_next = this.il_nextfld;
90 .entity il_prev = this.il_prevfld;
91 assert(!IL_CONTAINS(this, it), return NULL);
92
93 entity head = it.(il_next) = this.il_head;
94 if (head)
95 head.(il_prev) = it;
96 else
97 this.il_tail = it;
98 this.il_head = it;
99 it.il_lists |= this.il_listmask;
100 return it;
101}

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

◆ ONREMOVE()

void ONREMOVE ( entity this)

Called when an entity is deleted with delete() / remove() or when a player disconnects.

Definition at line 306 of file intrusivelist.qh.

307{
308 // remove 'this' from any intrusive lists it is on
309 vector lists = this.il_lists;
310 if (lists)
311 for (int i = 0; i < IL_MAX; ++i)
312 {
313 IntrusiveList list = il_links[i];
314 if ((lists & list.il_listmask) && IL_CONTAINS(list, this))
315 IL_REMOVE(list, this);
316 }
317}
vector il_lists
vector
Definition self.qh:96

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

◆ TEST()

TEST ( intrusivelist ,
ModificationsWhileLooping  )

Definition at line 333 of file intrusivelist.qh.

334{
335 IntrusiveList il_test = IL_NEW();
336 entity ent1 = new(1), ent2 = new(2), ent3 = new(3), ent4 = new(4), ent5 = new(5);
337 string s;
338
340 IL_EACH(il_test, true,
341 {
342 s = strcat(s, it.classname);
343 if (it == ent2) IL_REMOVE(il_test, ent3);
344 if (it == ent4) IL_PUSH(il_test, ent3);
345 });
346 EXPECT_TRUE(s == "12453");
347
349 IL_EACH(il_test, true,
350 {
351 s = strcat(s, it.classname);
352 if (it == ent2) IL_REMOVE(il_test, ent2);
353 if (it == ent3) IL_REMOVE(il_test, ent3);
354 if (it == ent3) IL_REMOVE(il_test, ent4);
355 if (it == ent5) IL_POP(il_test);
356 });
357 EXPECT_TRUE(s == "1235");
358
360 IL_REMOVE(il_test, ent5);
361 IL_EACH(il_test, true,
362 {
363 s = strcat(s, it.classname);
364 if (it == ent1) IL_SHIFT(il_test);
365 if (it == ent4) IL_POP(il_test);
366 });
367 EXPECT_TRUE(s == "1234");
368
370 IL_EACH(il_test, true,
371 {
372 s = strcat(s, it.classname);
373 if (it == ent2)
374 IL_EACH(il_test, true,
375 {
376 s = strcat(s, it.classname);
377 if (it == ent3)
378 IL_EACH(il_test, true, s = strcat(s, it.classname));
379 if (it == ent4)
380 break;
381 });
382 });
383 EXPECT_TRUE(s == "12123123454345");
384
385 IL_DELETE(il_test);
386 delete(ent1); delete(ent2); delete(ent3); delete(ent4); delete(ent5);
387
388 SUCCEED();
389}
#define IL_NEW()
ERASEABLE entity IL_POP(IntrusiveList this)
Pop from tail.
#define IL_EACH(this, cond, body)
ERASEABLE entity IL_SHIFT(IntrusiveList this)
Pop from head.
#define IL_TEST_BUILD()
#define IL_DELETE(this)
Delete the list.
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SUCCEED()
Must be present at the end of a test.
Definition test.qh:17
#define EXPECT_TRUE(condition)
Definition test.qh:47

References entity(), EXPECT_TRUE, IL_DELETE, IL_EACH, IL_NEW, IL_POP(), IL_PUSH(), IL_REMOVE(), IL_SHIFT(), IL_TEST_BUILD, strcat(), and SUCCEED.

Variable Documentation

◆ il_id

int il_id

Definition at line 216 of file intrusivelist.qh.

Referenced by IL_DTOR(), and IL_INIT().

◆ il_links

IntrusiveList il_links[IL_MAX]

Definition at line 217 of file intrusivelist.qh.

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

◆ il_links_flds

entity il_links_flds[IL_MAX *2]

Definition at line 218 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ il_links_ptr

int il_links_ptr

Definition at line 219 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ il_listmask

vector il_listmask

Definition at line 46 of file intrusivelist.qh.

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

◆ il_lists

vector il_lists

Definition at line 44 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 11 of file intrusivelist.qh.

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