Skip to content

Commit

Permalink
WeatherMotionPredictor: cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolrog committed May 18, 2021
1 parent 4002c13 commit 60289ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 7 additions & 11 deletions src/d2dx/WeatherMotionPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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;
}
5 changes: 2 additions & 3 deletions src/d2dx/WeatherMotionPredictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<IGameHelper> _gameHelper;
uint32_t _frame = 0;
int32_t _frame = 0;
float _dt = 0;
Buffer<ParticleMotion> _particleMotions;
};
Expand Down

0 comments on commit 60289ec

Please sign in to comment.