diff --git a/src/d2dx/WeatherMotionPredictor.cpp b/src/d2dx/WeatherMotionPredictor.cpp index e973f97..2859760 100644 --- a/src/d2dx/WeatherMotionPredictor.cpp +++ b/src/d2dx/WeatherMotionPredictor.cpp @@ -45,12 +45,10 @@ OffsetF WeatherMotionPredictor::GetOffset( { ParticleMotion& pm = _particleMotions.items[particleIndex & 511]; - float dx = posFromGame.x - pm.lastPos.x; - float dy = posFromGame.y - pm.lastPos.y; + const OffsetF diff = posFromGame - pm.lastPos; + const float error = max(abs(diff.x), abs(diff.y)); - float error = max(abs(dx), abs(dy)); - - if (abs((int32_t)_frame - (int32_t)pm.lastUsedFrame) > 2 || + if (abs(_frame - pm.lastUsedFrame) > 2 || error > 100.0f) { pm.velocity = { 0.0f, 0.0f }; @@ -59,17 +57,15 @@ OffsetF WeatherMotionPredictor::GetOffset( } else { - if (dx != 0 || dy != 0) + if (error > 0.0f) { - pm.velocity = { 25.0f * dx, 25.0f * dy }; + pm.velocity = diff * 25.0f; pm.lastPos = posFromGame; } } - pm.predictedPos.x += pm.velocity.x * _dt; - pm.predictedPos.y += pm.velocity.y * _dt; - + pm.predictedPos += pm.velocity * _dt; pm.lastUsedFrame = _frame; - return { pm.predictedPos.x - pm.lastPos.x, pm.predictedPos.y - pm.lastPos.y }; + return pm.predictedPos - pm.lastPos; } diff --git a/src/d2dx/WeatherMotionPredictor.h b/src/d2dx/WeatherMotionPredictor.h index 24b4189..95ee480 100644 --- a/src/d2dx/WeatherMotionPredictor.h +++ b/src/d2dx/WeatherMotionPredictor.h @@ -40,15 +40,14 @@ namespace d2dx private: struct ParticleMotion final { - uint32_t lastUsedFrame = 0; OffsetF lastPos = { 0, 0 }; OffsetF velocity = { 0, 0 }; OffsetF predictedPos = { 0, 0 }; - int64_t dtLastPosChange = 0; + int32_t lastUsedFrame = 0; }; std::shared_ptr _gameHelper; - uint32_t _frame = 0; + int32_t _frame = 0; float _dt = 0; Buffer _particleMotions; };