Skip to content

Commit

Permalink
Switch PROJECTILE to use PagedEntityContainer<PROJECTILE> as back…
Browse files Browse the repository at this point in the history
…ing storage

The game still uses `psProjectileList` to maintain stable and
predictable order of iteration for projectiles, but the
individual `PROJECTILE` instances are allocated from the
global `PagedEntityContainer<PROJECTILE>` instance.

`proj_SendProjectileAngled()` now doesn't automatically
add the spawned penetrating projectile to `psProjectileList`,
which is a little step back in terms of ease of use (need
to additional code so that spawned projectiles are added
to the `psProjectileList` manually in relevant cases).

But it allows to remove additional checks inside the
tight loop in `proj_UpdateAll()`, which enumerates all
projectiles currently in play, thus considerably speeding
up this frequent and expensive operation.

Signed-off-by: Pavel Solodovnikov <[email protected]>
  • Loading branch information
ManManson committed Mar 7, 2024
1 parent a81be6f commit fb9bc37
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 79 deletions.
3 changes: 2 additions & 1 deletion src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in
CLIP(predict.x, 0, world_coord(mapWidth - 1));
CLIP(predict.y, 0, world_coord(mapHeight - 1));

proj_SendProjectileAngled(psWeap, psAttacker, psAttacker->player, predict, psTarget, bVisibleAnyway, weapon_slot, min_angle, fireTime);
auto* psProj = proj_SendProjectileAngled(psWeap, psAttacker, psAttacker->player, predict, psTarget, bVisibleAnyway, weapon_slot, min_angle, fireTime);
proj_AddActiveProjectile(psProj);
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/multistruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ bool recvLasSat(NETQUEUE queue)
}

// Give enemy no quarter, unleash the lasat
proj_SendProjectile(&psStruct->asWeaps[0], nullptr, player, psObj->pos, psObj, true, 0);
auto* psProj = proj_SendProjectile(&psStruct->asWeaps[0], nullptr, player, psObj->pos, psObj, true, 0);
proj_AddActiveProjectile(psProj);

psStruct->asWeaps[0].lastFired = gameTime;
psStruct->asWeaps[0].ammo = 1; // abducting this field for keeping track of triggers

Expand Down
Loading

0 comments on commit fb9bc37

Please sign in to comment.