ang_z = ReadByte() * 360 / 256;
return = true;
- Casing casing = RubbleNew(new(casing));
+ Casing casing = ListNewChildRubble(CasingsNGibs, new(casing));
casing.silent = (_state & 0x80);
casing.state = (_state & 0x7F);
casing.origin = org;
setsize(casing, '0 0 -1', '0 0 -1');
- RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
+ LimitedChildrenRubble(CasingsNGibs, "casing", autocvar_cl_casings_maxcount, Casing_Delete, NULL);
}
#endif
entity gib;
// TODO remove some gibs according to cl_nogibs
- gib = RubbleNew(new(gib));
+ gib = ListNewChildRubble(CasingsNGibs, new(gib));
set_movetype(gib, MOVETYPE_BOUNCE);
gib.gravity = 1;
gib.solid = SOLID_CORPSE;
gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
gib.drawmask = MASK_NORMAL;
- RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
+ LimitedChildrenRubble(CasingsNGibs, "gib", autocvar_cl_gibs_maxcount, Gib_Delete, NULL);
}
NET_HANDLE(net_gibsplash, bool isNew)
#include "rubble.qh"
#ifdef GAMEQC
-void RubbleLimit(string cname, int limit, void(entity) deleteproc)
-{
+
+void LimitedChildrenRubble(IntrusiveList list, string cname, int limit, void(entity) deleteproc, entity parent){
// remove rubble of the same type if it's at the limit
// remove multiple rubble if the limit has been decreased
while (1)
entity oldest = NULL;
float oldesttime = 0;
// compare to all other matching entities
- IL_EACH(g_rubble, it.classname == cname,
+ IL_EACH(list, it.classname == cname,
{
- ++c;
- if(!oldest || oldesttime > it.creationtime)
- {
- oldest = it;
- oldesttime = it.creationtime;
+ if(!parent ||parent == it.owner){
+ ++c;
+ if(!oldest || oldesttime > it.creationtime)
+ {
+ oldest = it;
+ oldesttime = it.creationtime;
+ }
}
});
}
}
-entity RubbleNew(entity e)
-{
- e.creationtime = time;
- IL_PUSH(g_rubble, e);
- return e;
+
+// This function doesn't preserve linked list order but it is not needed as creationtime is used instead of list position for comparing ages.
+// IL_Replace or similiar order preserving function did not exist at the time of creating this.
+entity ReplaceOldListedChildRubble(IntrusiveList list, entity child, entity oldChild){
+ child.creationtime = oldChild.creationtime;
+ IL_REMOVE(list, oldChild);
+ IL_PUSH(list, child);
+ return child;
}
+
+entity ListNewChildRubble(IntrusiveList list, entity child){
+ child.creationtime = time;
+ IL_PUSH(list, child);
+ return child;
+}
+
#endif
entityclass(Rubble);
classfield(Rubble).float creationtime;
-IntrusiveList g_rubble;
-STATIC_INIT(g_rubble) { g_rubble = IL_NEW(); }
+IntrusiveList CasingsNGibs;
+STATIC_INIT(CasingsNGibs) { CasingsNGibs = IL_NEW(); }
-void RubbleLimit(string cname, int limit, void(entity) deleteproc);
+IntrusiveList LimitedElectroBallRubbleList;
+STATIC_INIT(LimitedElectroBallRubbleList) { LimitedElectroBallRubbleList = IL_NEW(); }
+
+
+void LimitedChildrenRubble(IntrusiveList list, string cname, int limit, void(entity) deleteproc, entity parent);
+
+entity ReplaceOldListedChildRubble(IntrusiveList list, entity child, entity oldChild);
+
+entity ListNewChildRubble(IntrusiveList list, entity child);
-entity RubbleNew(entity e);
#endif
IL_PUSH(g_bot_dodge, newproj);
// check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
- if(IL_CONTAINS(g_rubble, this))
+ if(IL_CONTAINS(LimitedElectroBallRubbleList, this))
{
- newproj.creationtime = this.creationtime;
- IL_PUSH(g_rubble, newproj);
+ ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
}
delete(this);
if(WEP_CVAR_SEC(electro, limit) > 0)
{
- RubbleNew(proj);
- RubbleLimit("electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash);
+ ListNewChildRubble(LimitedElectroBallRubbleList, proj);
+ LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
}
CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
#include "iter.qh"
+/**
+ * This limitation is only towards maximum amount of creatable lists.
+ * Lists can be given endless amount of entities, only restricted by engine limitations.
+ */
const int IL_MAX = 128;
ERASEABLE