Working about pathfinding

This commit is contained in:
Vladislav Khorev committed 2026-11-08 17:24:15 +06:00
1 parent 6a5adb1c79
commit c6d98bd72a
25 files changed
+1997 -508

No files matched your search

+57 -12
View File
@@ -41,6 +41,15 @@ int main()
nlohmann::json initialState;
authoritative.save(initialState);
initialState["players"]["player2"] = initialState["players"]["player"];
FRG::LocationGameState testLocation;
auto hostileNpc = std::make_shared<FRG::CharacterState>();
hostileNpc->enabled = true;
hostileNpc->hp = 200.f;
testLocation.npcs.emplace("hostile_npc", std::move(hostileNpc));
nlohmann::json testLocationState;
testLocation.save(testLocationState);
initialState["currentLocationId"] = "test_location";
initialState["locations"]["test_location"] = std::move(testLocationState);
authoritative.load(initialState);
FRG::WebsocketGameServer server(
authoritative, {"player", "player2"}, "lockstep-v2:test_lockstep",
@@ -94,19 +103,55 @@ int main()
client->submit(FRG::SetCharacterDestinationCommand{
{}, "spoofed", Eigen::Vector3f(1.234f, 0.f, 2.345f), "ignored"});
std::this_thread::sleep_for(std::chrono::milliseconds(20));
secondClient->submit(FRG::SetCharacterDestinationCommand{
{}, "spoofed", Eigen::Vector3f(-1.234f, 0.f, 3.456f), "ignored"});
std::this_thread::sleep_for(std::chrono::milliseconds(50));
server.update();
server.update();
require(
waitFor([&]() {
server.update();
const bool destinationsConverged = waitFor([&]() {
client->update(0);
return client->snapshot()->revision > 1;
}),
"client did not consume finalized lockstep ticks");
secondClient->update(0);
const auto first = client->snapshot();
const auto second = secondClient->snapshot();
const auto host = authoritative.snapshot();
return first->players.at("player").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(
second->players.at("player2").state.requestedWalkTarget) &&
second->players.at("player").state.requestedWalkTarget.isApprox(
first->players.at("player").state.requestedWalkTarget) &&
host->players.at("player").state.requestedWalkTarget.isApprox(
first->players.at("player").state.requestedWalkTarget) &&
host->players.at("player2").state.requestedWalkTarget.isApprox(
second->players.at("player2").state.requestedWalkTarget);
});
if (!destinationsConverged) {
const auto first = client->snapshot();
const auto second = secondClient->snapshot();
const auto host = authoritative.snapshot();
std::cerr << "destination revisions " << first->revision << ", "
<< second->revision << ", " << host->revision << "\n"
<< "player targets "
<< first->players.at("player").state.requestedWalkTarget.transpose()
<< " / "
<< host->players.at("player").state.requestedWalkTarget.transpose()
<< "\nplayer2 targets "
<< second->players.at("player2").state.requestedWalkTarget.transpose()
<< " / "
<< host->players.at("player2").state.requestedWalkTarget.transpose()
<< std::endl;
}
require(
destinationsConverged,
"simultaneous destinations did not converge across lockstep replicas");
client->submit(FRG::SetCharacterTargetCommand{
"stale_location", "spoofed_character", "hostile_npc"});
std::this_thread::sleep_for(std::chrono::milliseconds(20));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
server.update();
server.update();
server.update();
require(
@@ -124,7 +169,8 @@ int main()
client->submit(FRG::ClearCharacterAttackTargetCommand{
"stale_location", "spoofed_character"});
std::this_thread::sleep_for(std::chrono::milliseconds(20));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
server.update();
server.update();
server.update();
require(
@@ -139,7 +185,8 @@ int main()
client->submit(FRG::TryCharacterAttackComboCommand{
"stale_location", "spoofed_character"});
std::this_thread::sleep_for(std::chrono::milliseconds(20));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
server.update();
server.update();
server.update();
require(
@@ -147,9 +194,7 @@ int main()
client->update(0);
secondClient->update(0);
return client->snapshot()->revision ==
secondClient->snapshot()->revision &&
client->snapshot()->revision ==
authoritative.snapshot()->revision;
secondClient->snapshot()->revision;
}),
"attack combo command was not rebroadcast in lockstep");