Skip to content

Version 1.0.1

Compare
Choose a tag to compare
@Cleptomania Cleptomania released this 03 Mar 06:47
· 4 commits to development since this release
64d824e

This release contains a number of performance improvements to collision detection.

Namely a new version of are_polygons_intersecting called are_polygons_intersecting_native. This new function accepts &Vec<(f32, f32)> instead of Vec<(f32, f32)>. The normal function cannot accept references due to it being a [#pyfunction]. This means that whenever it is used natively from Rust, we have to copy the vectors into it. The native function allows us to just pass references to the vectors and avoid the copy.

There are also a handful of other places where copying the points vector from a HitBox has been eliminated in favor of passing by reference, another major area this has been done in is with get_adjusted_points, which now has a similar get_adjusted_points_native function. In addition to this new native function on HitBox and RotatableHitBox, they now have an internal cache of the adjusted points, such that the adjusted points are only re-calculated when the cache is marked as dirty.

The final major improvement is using the intern macro on strings sent to getattr within the collision detection functions. This avoids allocating a new string within Python every time the function is called, and passes a reference to the same string on subsequent calls to it, this greatly improves performance because this process is very expensive and happening in a very hot loop.