test(platforms): Fire Temple millstones turn as the client turns them

MillstoneC keeps turning one way through full laps; MillstoneB takes the short way back (178 degrees), as the
client's shortest-arc angular velocity does. Real waypoints from firetemple.luz.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-28 11:12:24 -06:00
parent 73f18fc5bf
commit 5a0b88a0a2

View File

@@ -1381,3 +1381,84 @@ TEST_F(MovingPlatformComponentTest, FallingTileSoundsLikeLive) {
ASSERT_EQ(got.size(), 1u);
EXPECT_EQ(got[0], bytes(GameMessages::StopNDAudioEmitter(id, rise)));
}
namespace {
// A millstone path of the Fire Temple (firetemple.luz): one place, the rotations about y, 5 s a stretch (time based)
void AddMillstonePath(const std::string& name, const NiPoint3& position, const std::vector<NiQuaternion>& rotations) {
Path path;
path.pathType = PathType::MovingPlatform;
path.pathName = name;
path.pathBehavior = PathBehavior::Loop;
path.movingPlatform.timeBasedMovement = 1;
for (const auto& rotation : rotations) {
PathWaypoint waypoint;
waypoint.position = position;
waypoint.rotation = rotation;
waypoint.speed = 5.0f;
path.pathWaypoints.push_back(waypoint);
}
const_cast<Zone*>(Game::zoneManager->GetZone())->AddPath(path);
}
// The turn about y in degrees, carried on from the last one (no jump of a full turn)
float Unwrap(const NiQuaternion& rotation, const float last) {
float yaw = 2.0f * std::atan2(rotation.y, rotation.w) * 180.0f / 3.14159265f;
while (yaw - last > 180.0f) yaw -= 360.0f;
while (yaw - last < -180.0f) yaw += 360.0f;
return yaw;
}
}
// MillstoneC: four waypoints a quarter turn apart. Each stretch turns the short way, as the client's angular velocity,
// so the millstone keeps turning the same way, a full turn a lap, without a jump at any waypoint
TEST_F(MovingPlatformComponentTest, FireTempleMillstoneTurnsAFullCircle) {
const NiPoint3 position(-1048.3772f, 329.40533f, -538.69922f);
AddMillstonePath("TestMillstoneC", position, {
NiQuaternion(1.0f, 0.0f, -0.0f, 0.0f), NiQuaternion(0.707107f, 0.0f, -0.707107f, 0.0f),
NiQuaternion(0.0f, 0.0f, 1.0f, 0.0f), NiQuaternion(0.707107f, 0.0f, 0.707107f, 0.0f) });
info.pos = position;
info.rot = QuatUtils::IDENTITY;
Entity entity(288300744895900140, info);
entity.AddComponent<SimplePhysicsComponent>(-1);
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestMillstoneC");
float yaw = 0.0f;
float largestStep = 0.0f;
for (int32_t frame = 0; frame < 15 * 42; frame++) {
platform->Run(1.0f / 15.0f);
const float next = Unwrap(entity.GetRotation(), yaw);
EXPECT_LE(next, yaw + 0.001f) << "frame " << frame;
largestStep = std::max(largestStep, yaw - next);
yaw = next;
}
// Two laps of 4 x (5 s + the wait, 0.1 s in whole physics steps) in 42 s, and some of the next stretch
EXPECT_LT(yaw, -720.0f);
EXPECT_GT(yaw, -760.0f);
EXPECT_LT(largestStep, 90.0f / 75.0f + 0.01f);
}
// MillstoneB: a quarter turn one way (to 181 degrees), the short way back to -1 (178 degrees the other way) and a
// quarter turn on to the start; the client's shortest turns, never the long way round
TEST_F(MovingPlatformComponentTest, FireTempleMillstoneTurnsTheShortWay) {
const NiPoint3 position(-1135.88037f, 329.42001f, -538.77277f);
AddMillstonePath("TestMillstoneB", position, {
NiQuaternion(0.707107f, 0.0f, -0.707107f, 0.0f), NiQuaternion(-0.008727f, 0.0f, 0.999962f, 0.0f),
NiQuaternion(0.999962f, 0.0f, -0.008727f, 0.0f) });
info.pos = position;
info.rot = NiQuaternion(0.707107f, 0.0f, -0.707107f, 0.0f);
Entity entity(288300744895900141, info);
entity.AddComponent<SimplePhysicsComponent>(-1);
auto* const platform = entity.AddComponent<MovingPlatformComponent>(-1, "TestMillstoneB");
float yaw = -90.0f;
float lowest = yaw;
float highest = yaw;
for (int32_t frame = 0; frame < 15 * 31; frame++) {
platform->Run(1.0f / 15.0f);
const float next = Unwrap(entity.GetRotation(), yaw);
EXPECT_LT(std::abs(next - yaw), 180.0f / 75.0f + 0.01f) << "frame " << frame;
yaw = next;
lowest = std::min(lowest, yaw);
highest = std::max(highest, yaw);
}
EXPECT_NEAR(lowest, -179.0f, 0.1f);
EXPECT_NEAR(highest, -1.0f, 0.1f);
}