Fixing bugs with pathfinding, bump version
This commit is contained in:
1 parent
8e2b019c92
commit
f1cc28ab31
22 files changed
+1119
-759
No files matched your search
@@ -16,6 +16,16 @@ void require(bool condition, const char* message)
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
FRG::Vec3fp point(float x, float y, float z)
|
||||
{
|
||||
return {FRG::fp(x), FRG::fp(y), FRG::fp(z)};
|
||||
}
|
||||
|
||||
bool samePoint(const FRG::Vec3fp& left, const FRG::Vec3fp& right)
|
||||
{
|
||||
return left.x == right.x && left.y == right.y && left.z == right.z;
|
||||
}
|
||||
|
||||
template <class Predicate>
|
||||
bool waitFor(Predicate predicate)
|
||||
{
|
||||
@@ -28,6 +38,15 @@ bool waitFor(Predicate predicate)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sameMovement(
|
||||
const FRG::CharacterState& left, const FRG::CharacterState& right)
|
||||
{
|
||||
return left.position.x.raw_value() == right.position.x.raw_value() &&
|
||||
left.position.z.raw_value() == right.position.z.raw_value() &&
|
||||
left.velocity.x.raw_value() == right.velocity.x.raw_value() &&
|
||||
left.velocity.y.raw_value() == right.velocity.y.raw_value();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -70,7 +89,22 @@ int main()
|
||||
auto hostileNpc = std::make_shared<FRG::CharacterState>();
|
||||
hostileNpc->enabled = true;
|
||||
hostileNpc->hp = 200.f;
|
||||
hostileNpc->position = point(-1.f, 0.f, 0.f);
|
||||
hostileNpc->walkTarget = point(4.f, 0.f, 0.f);
|
||||
hostileNpc->requestedWalkTarget = hostileNpc->walkTarget;
|
||||
hostileNpc->pathWaypoints = {hostileNpc->walkTarget};
|
||||
hostileNpc->velocity = {FRG::fp(1.5f), FRG::fp(0.f)};
|
||||
testLocation.npcs.emplace("hostile_npc", std::move(hostileNpc));
|
||||
auto secondHostileNpc = std::make_shared<FRG::CharacterState>();
|
||||
secondHostileNpc->enabled = true;
|
||||
secondHostileNpc->hp = 200.f;
|
||||
secondHostileNpc->position = point(1.f, 0.f, 0.f);
|
||||
secondHostileNpc->walkTarget = point(-4.f, 0.f, 0.f);
|
||||
secondHostileNpc->requestedWalkTarget = secondHostileNpc->walkTarget;
|
||||
secondHostileNpc->pathWaypoints = {secondHostileNpc->walkTarget};
|
||||
secondHostileNpc->velocity = {FRG::fp(-1.5f), FRG::fp(0.f)};
|
||||
testLocation.npcs.emplace(
|
||||
"hostile_npc_2", std::move(secondHostileNpc));
|
||||
nlohmann::json testLocationState;
|
||||
testLocation.save(testLocationState);
|
||||
initialState["currentLocationId"] = "test_location";
|
||||
@@ -93,6 +127,22 @@ int main()
|
||||
"client did not receive initial state");
|
||||
require(client->localPlayerId() == "player1", "wrong player slot assigned");
|
||||
|
||||
// Advance avoidance before the second client joins. Its initial snapshot must
|
||||
// carry previous-tick velocity or its very next ORCA result will diverge.
|
||||
server.update();
|
||||
require(
|
||||
waitFor([&]() {
|
||||
client->update(0);
|
||||
const auto first = client->snapshot();
|
||||
const auto host = authoritative.snapshot();
|
||||
return sameMovement(
|
||||
first->locations.at("test_location").npcs.at(
|
||||
"hostile_npc").state,
|
||||
host->locations.at("test_location").npcs.at(
|
||||
"hostile_npc").state);
|
||||
}),
|
||||
"first client did not apply the pre-join movement tick");
|
||||
|
||||
auto secondClient = std::make_unique<FRG::WebsocketGameClient>(
|
||||
"127.0.0.1", std::to_string(server.port()), "/");
|
||||
require(
|
||||
@@ -126,10 +176,34 @@ int main()
|
||||
authoritative.snapshot()->players.at("player2").state.enabled,
|
||||
"connection presence was not broadcast to all replicas");
|
||||
|
||||
for (int tick = 0; tick < 6; ++tick) server.update();
|
||||
require(
|
||||
waitFor([&]() {
|
||||
client->update(0);
|
||||
secondClient->update(0);
|
||||
const auto first = client->snapshot();
|
||||
const auto second = secondClient->snapshot();
|
||||
const auto host = authoritative.snapshot();
|
||||
for (const char* id : {"hostile_npc", "hostile_npc_2"}) {
|
||||
const auto& hostState =
|
||||
host->locations.at("test_location").npcs.at(id).state;
|
||||
if (!sameMovement(
|
||||
first->locations.at("test_location").npcs.at(id).state,
|
||||
hostState) ||
|
||||
!sameMovement(
|
||||
second->locations.at("test_location").npcs.at(id).state,
|
||||
hostState)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
"late-joining client diverged during character avoidance");
|
||||
|
||||
client->submit(FRG::SetCharacterDestinationCommand{
|
||||
{}, "spoofed", Eigen::Vector3f(1.234f, 0.f, 2.345f), "ignored"});
|
||||
{}, "spoofed", point(1.234f, 0.f, 2.345f), "ignored"});
|
||||
secondClient->submit(FRG::SetCharacterDestinationCommand{
|
||||
{}, "spoofed", Eigen::Vector3f(-1.234f, 0.f, 3.456f), "ignored"});
|
||||
{}, "spoofed", point(-1.234f, 0.f, 3.456f), "ignored"});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
server.update();
|
||||
server.update();
|
||||
@@ -140,17 +214,23 @@ int main()
|
||||
const auto first = client->snapshot();
|
||||
const auto second = secondClient->snapshot();
|
||||
const auto host = authoritative.snapshot();
|
||||
return first->players.at("player1").state.requestedWalkTarget.isApprox(
|
||||
Eigen::Vector3f(1.23f, 0.f, 2.35f)) &&
|
||||
second->players.at("player2").state.requestedWalkTarget.isApprox(
|
||||
Eigen::Vector3f(-1.23f, 0.f, 3.46f)) &&
|
||||
first->players.at("player2").state.requestedWalkTarget.isApprox(
|
||||
return samePoint(
|
||||
first->players.at("player1").state.requestedWalkTarget,
|
||||
point(1.234f, 0.f, 2.345f)) &&
|
||||
samePoint(
|
||||
second->players.at("player2").state.requestedWalkTarget,
|
||||
point(-1.234f, 0.f, 3.456f)) &&
|
||||
samePoint(
|
||||
first->players.at("player2").state.requestedWalkTarget,
|
||||
second->players.at("player2").state.requestedWalkTarget) &&
|
||||
second->players.at("player1").state.requestedWalkTarget.isApprox(
|
||||
samePoint(
|
||||
second->players.at("player1").state.requestedWalkTarget,
|
||||
first->players.at("player1").state.requestedWalkTarget) &&
|
||||
host->players.at("player1").state.requestedWalkTarget.isApprox(
|
||||
samePoint(
|
||||
host->players.at("player1").state.requestedWalkTarget,
|
||||
first->players.at("player1").state.requestedWalkTarget) &&
|
||||
host->players.at("player2").state.requestedWalkTarget.isApprox(
|
||||
samePoint(
|
||||
host->players.at("player2").state.requestedWalkTarget,
|
||||
second->players.at("player2").state.requestedWalkTarget);
|
||||
});
|
||||
if (!destinationsConverged) {
|
||||
@@ -160,13 +240,13 @@ int main()
|
||||
std::cerr << "destination revisions " << first->revision << ", "
|
||||
<< second->revision << ", " << host->revision << "\n"
|
||||
<< "player targets "
|
||||
<< first->players.at("player1").state.requestedWalkTarget.transpose()
|
||||
<< first->players.at("player1").state.requestedWalkTarget.toEigen().transpose()
|
||||
<< " / "
|
||||
<< host->players.at("player1").state.requestedWalkTarget.transpose()
|
||||
<< host->players.at("player1").state.requestedWalkTarget.toEigen().transpose()
|
||||
<< "\nplayer2 targets "
|
||||
<< second->players.at("player2").state.requestedWalkTarget.transpose()
|
||||
<< second->players.at("player2").state.requestedWalkTarget.toEigen().transpose()
|
||||
<< " / "
|
||||
<< host->players.at("player2").state.requestedWalkTarget.transpose()
|
||||
<< host->players.at("player2").state.requestedWalkTarget.toEigen().transpose()
|
||||
<< std::endl;
|
||||
}
|
||||
require(
|
||||
@@ -218,8 +298,17 @@ int main()
|
||||
waitFor([&]() {
|
||||
client->update(0);
|
||||
secondClient->update(0);
|
||||
return client->snapshot()->revision ==
|
||||
secondClient->snapshot()->revision;
|
||||
const auto host = authoritative.snapshot();
|
||||
return sameMovement(
|
||||
client->snapshot()->locations.at("test_location").npcs.at(
|
||||
"hostile_npc").state,
|
||||
host->locations.at("test_location").npcs.at(
|
||||
"hostile_npc").state) &&
|
||||
sameMovement(
|
||||
secondClient->snapshot()->locations.at(
|
||||
"test_location").npcs.at("hostile_npc").state,
|
||||
host->locations.at("test_location").npcs.at(
|
||||
"hostile_npc").state);
|
||||
}),
|
||||
"attack combo command was not rebroadcast in lockstep");
|
||||
|
||||
|
||||
Reference in new issue
Block a user