]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
overkill: optimise loot item mutator hooks
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 18 Jun 2023 22:13:58 +0000 (08:13 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 21 Jun 2023 10:59:03 +0000 (20:59 +1000)
No need to delete an item then spawn it again, and we can use the
itemdef to skip the classname search.

qcsrc/common/mutators/mutator/overkill/sv_overkill.qc

index 5dd0fdbb255c45031d31bf237a85e9dc24d8c95b..d4a1f4aeb1ebf17b01cc59877efe92336f9355e5 100644 (file)
@@ -78,12 +78,13 @@ MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
        }
 }
 
-void ok_DropItem(entity this, entity targ)
+void ok_DropItem(entity this, entity attacker, entity e)
 {
-       entity e = spawn();
        e.ok_item = true;
-       Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
-               '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
+       e.itemdef = ITEM_ArmorSmall;
+       e.origin = this.origin + '0 0 32';
+       e.velocity = '0 0 200' + normalize(attacker.origin - this.origin) * 500;
+       e.lifetime = 5;
 }
 
 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
@@ -91,9 +92,10 @@ MUTATOR_HOOKFUNCTION(ok, PlayerDies)
        entity frag_attacker = M_ARGV(1, entity);
        entity frag_target = M_ARGV(2, entity);
 
-       entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
-
-       ok_DropItem(frag_target, targ);
+       entity attacker = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
+       entity item = spawn();
+       ok_DropItem(frag_target, attacker, item);
+       Item_Initialise(item);
 
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
@@ -106,14 +108,10 @@ MUTATOR_HOOKFUNCTION(ok, PlayerDies)
 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
 {
        entity mon = M_ARGV(0, entity);
-       entity olditem = M_ARGV(1, entity);
+       entity item = M_ARGV(1, entity);
        entity frag_attacker = M_ARGV(2, entity);
 
-       delete(olditem);
-
-       M_ARGV(1, entity) = NULL;
-
-       ok_DropItem(mon, frag_attacker);
+       ok_DropItem(mon, frag_attacker, item);
 }
 
 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)