1947: Optimize CCollision::MoveBox to stop looping once velocity is 0 r=heinrich5991 a=def-



Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2019-10-22 20:42:21 +00:00 committed by GitHub
commit 3b5a085de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -491,13 +491,16 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas
if(Distance > 0.00001f)
{
//vec2 old_pos = pos;
float Fraction = 1.0f/(float)(Max+1);
for(int i = 0; i <= Max; i++)
{
//float amount = i/(float)max;
//if(max == 0)
//amount = 0;
// Early break as optimization to stop checking for collisions for
// large distances after the obstacles we have already hit reduced
// our speed to exactly 0.
if(Vel == vec2(0, 0))
{
break;
}
vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice