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)
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)
 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 214 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 162 of file intrusivelist.qh.

162#define IL_CLEAR(this) \
163 MACRO_BEGIN \
164 IntrusiveList _il = this; \
165 assert(_il); \
166 .entity il_prev = _il.il_prevfld; \
167 .entity il_next = _il.il_nextfld; \
168 noref int i = 0; \
169 for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
170 { \
171 _next = _it.(il_next); \
172 _it.(il_next) = _it.(il_prev) = NULL; \
173 } \
174 _il.il_head = _il.il_tail = NULL; \
175 MACRO_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 180 of file intrusivelist.qh.

180#define IL_DELETE(this) \
181 MACRO_BEGIN \
182 delete(this); \
183 this = NULL; \
184 MACRO_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; \
#define LAMBDA(...)
Definition misc.qh:34

Definition at line 186 of file intrusivelist.qh.

186#define IL_EACH(this, cond, body) \
187 MACRO_BEGIN \
188 IntrusiveList _il = this; \
189 assert(_il); \
190 .entity il_next = _il.il_nextfld; \
191 noref int i = 0; \
192 entity il_loop_item_save = this.il_loop_item; \
193 this.il_loop_item = NULL; \
194 for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
195 { \
196 const noref entity it = _it; \
197 this.il_loop_item = it; \
198 _next = it.(il_next); \
199 if (cond) { LAMBDA(body) } \
200 if (this.il_loop_item != it) /* current item removed? */ \
201 _next = this.il_loop_item; \
202 else \
203 _next = it.(il_next); /* in case next item has changed */ \
204 } \
205 this.il_loop_item = il_loop_item_save; \
206 MACRO_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_init(), 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 44 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 46 of file intrusivelist.qh.

Referenced by SelectSpawnPoint().

◆ IL_FLOOR

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

Definition at line 213 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_LAST

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

Definition at line 47 of file intrusivelist.qh.

◆ IL_LISTS_PER_BIT

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

Definition at line 216 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ IL_NEW

◆ IL_PEEK

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

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

Referenced by TEST().

Function Documentation

◆ IL_CONTAINS()

ERASEABLE bool IL_CONTAINS ( IntrusiveList this,
entity it )

Definition at line 51 of file intrusivelist.qh.

52{
53 assert(this, return false);
54 return it.(this.il_nextfld) || this.il_head == it || this.il_tail == it;
55}
#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(), 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 248 of file intrusivelist.qh.

249{
250 IL_CLEAR(this);
251 il_links[this.il_id] = NULL;
252}
#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 255 of file intrusivelist.qh.

256{
257#if 0
258 // incompatible with CSQC, remove() clears entities
259 for (int i = 0; i < IL_MAX; ++i) {
260 IntrusiveList list = il_links[i];
261 if (list) {
262 .entity nextfld = list.il_nextfld;
263 for (entity next, it = list.il_head; it; it = next) {
264 next = it.(nextfld);
265 if (wasfreed(it)) {
266 IL_REMOVE(list, it);
267 }
268 }
269 }
270 }
271#endif
272}
next
Definition all.qh:93
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 219 of file intrusivelist.qh.

220{
221 .entity nextfld, prevfld;
222 for (int i = il_links_ptr; i < il_links_ptr + IL_MAX; ++i) {
223 int id = i;
224 if (id >= IL_MAX) id -= IL_MAX;
225
226 if (!il_links[id]) {
227 il_links[id] = this;
228 int flds_idx = id * 2;
229 nextfld = il_links_flds[flds_idx + 0];
230 prevfld = il_links_flds[flds_idx + 1];
231 this.il_id = id;
232 int bit = IL_FLOOR(id / IL_LISTS_PER_BIT);
233 if (bit < (1 * 24)) this.il_listmask = '1 0 0' * BIT(bit - (0 * 24));
234 else if (bit < (2 * 24)) this.il_listmask = '0 1 0' * BIT(bit - (1 * 24));
235 else if (bit < (3 * 24)) this.il_listmask = '0 0 1' * BIT(bit - (2 * 24));
236 else assert(false);
237 il_links_ptr = id + 1;
239 this.il_nextfld = nextfld;
240 this.il_prevfld = prevfld;
241 return;
242 }
243 }
244 LOG_WARN("IntrusiveList overflow");
245}
#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:61

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 99 of file intrusivelist.qh.

100{
101 assert(this, return NULL);
102 .entity il_next = this.il_nextfld;
103 .entity il_prev = this.il_prevfld;
104
105 if (!this.il_tail) return NULL;
106 entity it = this.il_tail;
107 entity prev = it.(il_prev);
108 if (prev) (this.il_tail = prev).(il_next) = NULL;
109 else this.il_head = this.il_tail = NULL;
110 if (this.il_loop_item == it)
111 this.il_loop_item = NULL;
112 it.(il_prev) = NULL;
113 return it;
114}
prev
Definition all.qh:71

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 61 of file intrusivelist.qh.

62{
63 assert(this, return NULL);
64 assert(it, return NULL);
65 .entity il_next = this.il_nextfld;
66 .entity il_prev = this.il_prevfld;
67 assert(!IL_CONTAINS(this, it), return NULL);
68
69 entity tail = it.(il_prev) = this.il_tail;
70 tail ? (tail.(il_next) = it) : this.il_head = it;
71 this.il_tail = it;
72 it.il_lists |= this.il_listmask;
73 return it;
74}
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
entity this
Definition self.qh:72

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_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(), 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 141 of file intrusivelist.qh.

142{
143 assert(this, return);
144 .entity il_next = this.il_nextfld;
145 .entity il_prev = this.il_prevfld;
146 //assert(!IL_CONTAINS(this, it), return);
147 entity next = it.(il_next);
148 entity prev = it.(il_prev);
149 entity ohead = this.il_head;
150 entity otail = this.il_tail;
151 next ? next.(il_prev) = prev : this.il_tail = prev;
152 prev ? prev.(il_next) = next : this.il_head = next;
153 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);
154 if (this.il_loop_item == it)
155 this.il_loop_item = it.(il_next);
156 it.(il_next) = it.(il_prev) = NULL;
157}
#define LOG_DEBUGF(...)
Definition log.qh:81

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)

Definition at line 276 of file intrusivelist.qh.

277{
278 if (it.il_lists)
279 {
280 it.il_lists = '0 0 0';
281 for (int i = 0; i < IL_MAX * 2; ++i)
282 it.il_links_flds[i] = nil;
283 }
284}

References entity(), and IL_MAX.

Referenced by copyentity_qc().

◆ IL_SHIFT()

ERASEABLE entity IL_SHIFT ( IntrusiveList this)

Pop from head.

Definition at line 120 of file intrusivelist.qh.

121{
122 assert(this, return NULL);
123 .entity il_next = this.il_nextfld;
124 .entity il_prev = this.il_prevfld;
125
126 if (!this.il_head) return NULL;
127 entity it = this.il_head;
128 entity next = it.(il_next);
129 if (next) (this.il_head = next).(il_prev) = NULL;
130 else this.il_head = this.il_tail = NULL;
131 if (this.il_loop_item == it)
132 this.il_loop_item = it.(il_next);
133 it.(il_next) = NULL;
134 return it;
135}

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 305 of file intrusivelist.qh.

306{
307 IL_CLEAR(il_test);
308 IL_PUSH(il_test, ent1);
309 IL_PUSH(il_test, ent2);
310 IL_PUSH(il_test, ent3);
311 IL_PUSH(il_test, ent4);
312 IL_PUSH(il_test, ent5);
313 return "";
314}
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 80 of file intrusivelist.qh.

81{
82 assert(this, return NULL);
83 assert(it, return NULL);
84 .entity il_next = this.il_nextfld;
85 .entity il_prev = this.il_prevfld;
86 assert(!IL_CONTAINS(this, it), return NULL);
87
88 entity head = it.(il_next) = this.il_head;
89 head ? (head.(il_prev) = it) : this.il_tail = it;
90 this.il_head = it;
91 it.il_lists |= this.il_listmask;
92 return it;
93}

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

◆ ONREMOVE()

void ONREMOVE ( entity this)

Definition at line 288 of file intrusivelist.qh.

289{
290 // remove 'this' from any intrusive lists it is on
291 vector lists = this.il_lists;
292 if (lists) {
293 for (int i = 0; i < IL_MAX; ++i) {
294 IntrusiveList list = il_links[i];
295 if ((lists & list.il_listmask) && IL_CONTAINS(list, this)) {
296 IL_REMOVE(list, this);
297 }
298 }
299 }
300}
vector il_lists
vector
Definition self.qh:92

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

◆ TEST()

TEST ( intrusivelist ,
ModificationsWhileLooping  )

Definition at line 316 of file intrusivelist.qh.

317{
318 IntrusiveList il_test = IL_NEW();
319 entity ent1 = new(1), ent2 = new(2), ent3 = new(3), ent4 = new(4), ent5 = new(5);
320 string s;
321
323 IL_EACH(il_test, true,
324 {
325 s = strcat(s, it.classname);
326 if (it == ent2) IL_REMOVE(il_test, ent3);
327 if (it == ent4) IL_PUSH(il_test, ent3);
328 });
329 EXPECT_TRUE(s == "12453");
330
332 IL_EACH(il_test, true,
333 {
334 s = strcat(s, it.classname);
335 if (it == ent2) IL_REMOVE(il_test, ent2);
336 if (it == ent3) IL_REMOVE(il_test, ent3);
337 if (it == ent3) IL_REMOVE(il_test, ent4);
338 if (it == ent5) IL_POP(il_test);
339 });
340 EXPECT_TRUE(s == "1235");
341
343 IL_REMOVE(il_test, ent5);
344 IL_EACH(il_test, true,
345 {
346 s = strcat(s, it.classname);
347 if (it == ent1) IL_SHIFT(il_test);
348 if (it == ent4) IL_POP(il_test);
349 });
350 EXPECT_TRUE(s == "1234");
351
353 IL_EACH(il_test, true,
354 {
355 s = strcat(s, it.classname);
356 if (it == ent2)
357 IL_EACH(il_test, true,
358 {
359 s = strcat(s, it.classname);
360 if (it == ent3)
361 IL_EACH(il_test, true,
362 {
363 s = strcat(s, it.classname);
364 });
365 if (it == ent4)
366 break;
367 });
368 });
369 EXPECT_TRUE(s == "12123123454345");
370
371 IL_DELETE(il_test);
372 delete(ent1); delete(ent2); delete(ent3); delete(ent4); delete(ent5);
373
374 SUCCEED();
375}
#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:15
#define EXPECT_TRUE(condition)
Definition test.qh:46

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 208 of file intrusivelist.qh.

Referenced by IL_DTOR(), and IL_INIT().

◆ il_links

IntrusiveList il_links[IL_MAX]

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

Referenced by IL_INIT().

◆ il_links_ptr

int il_links_ptr

Definition at line 211 of file intrusivelist.qh.

Referenced by IL_INIT().

◆ il_listmask

vector il_listmask

Definition at line 40 of file intrusivelist.qh.

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

◆ il_lists

vector il_lists

Definition at line 38 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().