dreamstalker / rehlds

Reverse-engineered HLDS
GNU General Public License v3.0
625 stars 165 forks source link

Improve pfnShouldCollide condition on SV_ClipToLinks #985

Closed dystopm closed 9 months ago

dystopm commented 9 months ago

Considered a heavy function, SV_ClipToLinks is called almost every frame where things "move". Since a fix done in the pfnShouldCollide function (#46) this function can be used safely, but in the context given, it wastes a lot of checks.

pfnShouldCollide is used by mods to filter entity collision from one to another, by allowing to NOT collide (but not to force collision), but just after this is called, some basic physics stuff is called to detect collision each other, having by result an useless call of pfnShouldCollide before.

https://github.com/dreamstalker/rehlds/blob/de3679f0391f1452532c820f07a8c4042b1c4281/rehlds/engine/world.cpp#L1193-L1223

(like, checking they are far each other, why I'm checking collision on two distant entities?)

This PR moves pfnShouldCollide check after all the basic physics stuff, just to reduce function call inside plugins or submodules. There is no benefit in handling collisions in pfnShouldColide since subsequently there are conditions that will prevent their collision anyway.