Switch to Vec3fp and fp variables for character

This commit is contained in:
Vladislav Khorev committed 2026-11-13 18:56:44 +06:00
1 parent 8df016c0a4
commit 889c6d465b
23 files changed
+384 -406

No files matched your search

+4 -4
View File
@@ -137,19 +137,19 @@ struct SetGlobalFloatCommand { std::string key; float value; };
struct SetCharacterPositionCommand {
std::string locationId;
std::string characterId;
Eigen::Vector3f position;
Vec3fp position;
bool updateHomePosition = false;
};
struct SetCharacterFacingAngleCommand {
std::string locationId;
std::string characterId;
float angle;
fp angle;
bool setCurrentAngle = false;
};
struct SetCharacterHomePositionCommand {
std::string locationId;
std::string characterId;
Eigen::Vector3f position;
Vec3fp position;
};
struct SetCharacterTargetCommand {
std::string locationId;
@@ -173,7 +173,7 @@ struct ClearCharacterAttackTargetCommand {
struct SetCharacterDestinationCommand {
std::string locationId;
std::string characterId;
Eigen::Vector3f target;
Vec3fp target;
std::string callbackName;
};
struct StopCharacterCommand {
+2 -2
View File
@@ -70,11 +70,11 @@ void InternalGameServer::updateBattleZoneTestBot(std::int64_t deltaMs)
battleZoneTestBotElapsedMs_ %= kBattleZoneTestBotIntervalMs;
static std::mt19937 randomEngine(std::random_device{}());
static std::uniform_real_distribution<float> coordinate(-10.0f, 10.0f);
static std::uniform_int_distribution<int> coordinate(-100, 100); //Divide by 10 then.
submit(SetCharacterDestinationCommand{
state_.currentLocationName,
kBattleZonePlayer2Id,
Eigen::Vector3f(coordinate(randomEngine), 0.f, coordinate(randomEngine)),
Vec3fp(static_cast<fp>(coordinate(randomEngine)) / static_cast<fp>(10), static_cast<fp>(0.f), coordinate(randomEngine) / static_cast<fp>(10)),
std::string()});
}
+43 -5
View File
@@ -91,6 +91,44 @@ bool readTarget(
return true;
}
bool readTargetFp(
const nlohmann::json& value, FRG::Vec3fp& target, std::string& error)
{
if (!value.is_array() || value.size() != 3) {
error = "target must contain three coordinates";
return false;
}
FRG::fp coords[3];
for (std::size_t index = 0; index < 3; ++index) {
if (!value[index].is_number()) {
error = "target coordinates must be numbers";
return false;
}
const double coordinate = value[index].get<double>();
if (!std::isfinite(coordinate) || std::abs(coordinate) > 100000.0) {
error = "target coordinate is not finite or is out of range";
return false;
}
// Округляем до сотых в double и конвертируем в Q20.12 (fp)
coords[index] = FRG::fp(coordinate);
}
target.x = coords[0];
target.y = coords[1];
target.z = coords[2];
return true;
}
nlohmann::json targetJsonFp(const FRG::Vec3fp& target)
{
return nlohmann::json::array({
static_cast<double>(target.x),
static_cast<double>(target.y),
static_cast<double>(target.z)
});
}
nlohmann::json targetJson(const Eigen::Vector3f& target)
{
return nlohmann::json::array({target.x(), target.y(), target.z()});
@@ -161,7 +199,7 @@ bool parseInitialStateMessage(
}
std::uint64_t LockstepTimeline::schedule(
const std::string& playerId, const Eigen::Vector3f& target)
const std::string& playerId, const Vec3fp& target)
{
const std::uint64_t sequence = nextCommandSequence_++;
pending_[currentTick_ + inputDelayTicks_].push_back(
@@ -206,7 +244,7 @@ std::string makeDestinationInputMessage(const DestinationInputMessage& message)
{
return envelope("destination_input", {
{"clientSequence", message.clientSequence},
{"target", targetJson(message.target)}
{"target", targetJsonFp(message.target)}
});
}
@@ -219,7 +257,7 @@ bool parseDestinationInputMessage(
return false;
if (!payload.contains("target"))
return error = "target is required", false;
return readTarget(payload["target"], message.target, error);
return readTargetFp(payload["target"], message.target, error);
}
std::string makeCharacterActionInputMessage(
@@ -265,7 +303,7 @@ std::string makeTickMessage(const TickMessage& message)
{"type", "destination"},
{"commandSequence", command.commandSequence},
{"playerId", command.playerId},
{"target", targetJson(command.target)}
{"target", targetJsonFp(command.target)}
});
} else {
if constexpr (std::is_same_v<T, ScheduledCharacterEnabledCommand>) {
@@ -320,7 +358,7 @@ bool parseTickMessage(
destination.commandSequence = previousSequence;
if (!value.contains("playerId") || !value["playerId"].is_string() ||
!value.contains("target") ||
!readTarget(value["target"], destination.target, error)) {
!readTargetFp(value["target"], destination.target, error)) {
if (error.empty()) error = "invalid destination command";
return false;
}
+4 -3
View File
@@ -7,6 +7,7 @@
#include <string>
#include <variant>
#include <vector>
#include "../navigation/PathFinder.h"
namespace FRG {
@@ -25,7 +26,7 @@ struct InitialStateMessage {
struct DestinationInputMessage {
std::uint64_t clientSequence = 0;
Eigen::Vector3f target = Eigen::Vector3f::Zero();
Vec3fp target;
};
struct CharacterActionInputMessage {
@@ -37,7 +38,7 @@ struct CharacterActionInputMessage {
struct ScheduledDestinationCommand {
std::uint64_t commandSequence = 0;
std::string playerId;
Eigen::Vector3f target = Eigen::Vector3f::Zero();
Vec3fp target;
};
struct ScheduledCharacterEnabledCommand {
@@ -73,7 +74,7 @@ public:
std::uint64_t currentTick() const { return currentTick_; }
std::uint64_t schedule(
const std::string& playerId, const Eigen::Vector3f& target);
const std::string& playerId, const Vec3fp& target);
std::uint64_t scheduleCharacterEnabled(
const std::string& locationId, const std::string& characterId,
bool enabled);