Batch #16446 by Yommy: 0 byte-identical, 1 confirmed by peer review. - fn_17876 MovementRouteInterpolation::Sample: logic confirmed by peer review Peer-reviewed-by: eAthena, youko, kyoshi Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
58 lines
2.3 KiB
C++
58 lines
2.3 KiB
C++
#include "Contents/MovementRouteInterpolation.h"
|
|
|
|
// OFFSET: 0x00AD92C0
|
|
// FUNCTION: fn_17876
|
|
int MovementRouteInterpolation::Sample(std::uint32_t tick, float* x, float* y, int* metadata) {
|
|
if (this->points.empty()) {
|
|
return -1;
|
|
}
|
|
|
|
if (this->points.front().tick > tick) {
|
|
*x = static_cast<float>(this->points.front().x);
|
|
*y = static_cast<float>(this->points.front().y);
|
|
*metadata = this->points[1].metadata;
|
|
return 0;
|
|
}
|
|
|
|
std::uint32_t index = this->segment;
|
|
for (; index < this->points.size() - 1; ++index) {
|
|
if (this->points[index].tick <= tick && tick < this->points[index + 1].tick) {
|
|
const float elapsed = static_cast<float>(static_cast<std::int32_t>(tick - this->points[index].tick));
|
|
float originX;
|
|
float deltaX;
|
|
float deltaY;
|
|
if (index == 0) {
|
|
originX = this->startX;
|
|
deltaX = static_cast<float>(this->points[index + 1].x) - originX;
|
|
deltaY = static_cast<float>(this->points[index + 1].y) - this->startY;
|
|
} else {
|
|
originX = static_cast<float>(this->points[index].x);
|
|
deltaX = static_cast<float>(this->points[index + 1].x - this->points[index].x);
|
|
deltaY = static_cast<float>(this->points[index + 1].y - this->points[index].y);
|
|
}
|
|
|
|
const float duration = static_cast<float>(this->points[index + 1].tick - this->points[index].tick);
|
|
const float offsetY = elapsed * deltaY;
|
|
*x = originX + (deltaX * elapsed) / duration;
|
|
const float yDuration = static_cast<float>(this->points[index + 1].tick - this->points[index].tick);
|
|
const float originY = index == 0 ? this->startY : static_cast<float>(this->points[index].y);
|
|
*y = originY + offsetY / yDuration;
|
|
|
|
const std::uint32_t midpoint = this->points[index].tick + ((this->points[index + 1].tick - this->points[index].tick) >> 1);
|
|
*metadata = tick < midpoint ? this->points[index].metadata : this->points[index + 1].metadata;
|
|
this->segment = index;
|
|
return static_cast<int>(index);
|
|
}
|
|
}
|
|
|
|
*metadata = this->points[index].metadata;
|
|
*x = static_cast<float>(this->points[index].x);
|
|
*y = static_cast<float>(this->points[index].y);
|
|
return -1;
|
|
}
|
|
|
|
// OFFSET: 0x00AD9500
|
|
// FUNCTION: fn_17877
|
|
std::uint32_t MovementRouteInterpolation::Segment() const {
|
|
return this->segment;
|
|
}
|