From 36186ca9b575b842b4d91f1f68888f610055d96e Mon Sep 17 00:00:00 2001 From: staphen Date: Thu, 3 Aug 2023 00:17:57 -0400 Subject: [PATCH] Don't extrapolate missile position in collision interpolation logic --- Source/missiles.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index a146e3226..eb8e49fe6 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -503,14 +503,23 @@ bool MoveMissile(Missile &missile, tl::function_ref checkTile, bool if (incVelocity.deltaX != 0) traveled.deltaX = (traveled.deltaX / incVelocity.deltaX) * incVelocity.deltaX; do { + auto initialDiff = missile.position.traveled - traveled; traveled += incVelocity; + auto incDiff = missile.position.traveled - traveled; + + // we are at the original calculated position => resume with normal logic + if ((initialDiff.deltaX < 0) != (incDiff.deltaX < 0)) + break; + if ((initialDiff.deltaY < 0) != (incDiff.deltaY < 0)) + break; // calculate in-between tile Displacement pixelsTraveled = traveled >> 16; Displacement tileOffset = pixelsTraveled.screenToMissile(); Point tile = missile.position.start + tileOffset; - // we are at the original calculated position => resume with normal logic + // we haven't quite reached the missile's current position, + // but we can break early to avoid checking collisions in this tile twice if (tile == missile.position.tile) break;