Switch to Vec3fp and fp variables for character
This commit is contained in:
1 parent
8df016c0a4
commit
889c6d465b
23 files changed
+384
-406
No files matched your search
+16
-47
@@ -126,7 +126,7 @@ namespace FRG
|
||||
}
|
||||
|
||||
void Location::setCharacterTarget(
|
||||
Character& character, const Eigen::Vector3f& target, std::string callbackName)
|
||||
Character& character, const Vec3fp& target, std::string callbackName)
|
||||
{
|
||||
gameServer_.submit(SetCharacterDestinationCommand{
|
||||
locationId_, character.entityId(), target, std::move(callbackName)});
|
||||
@@ -1597,7 +1597,7 @@ namespace FRG
|
||||
if (playerState && !pointLights.empty()) {
|
||||
float minDist = FLT_MAX;
|
||||
for (int i = 0; i < static_cast<int>(pointLights.size()); ++i) {
|
||||
const float d = (pointLights[i].position - playerState->position).norm();
|
||||
const float d = (pointLights[i].position - playerState->position.toEigen()).norm();
|
||||
if (d < minDist) { minDist = d; nearestLightIdx = i; }
|
||||
}
|
||||
}
|
||||
@@ -1611,12 +1611,12 @@ namespace FRG
|
||||
if (!active && playerState) {
|
||||
if (pl.autoLightLimitX > 0.0f && pl.autoLightLimitY > 0.0f) {
|
||||
// Rectangular activation zone — independent of nearest-light heuristic
|
||||
const float dx = std::abs(playerState->position.x() - pl.position.x());
|
||||
const float dz = std::abs(playerState->position.z() - pl.position.z());
|
||||
const float dx = std::abs(static_cast<float>(playerState->position.x) - pl.position.x());
|
||||
const float dz = std::abs(static_cast<float>(playerState->position.z) - pl.position.z());
|
||||
active = (dx <= pl.autoLightLimitX && dz <= pl.autoLightLimitY);
|
||||
} else {
|
||||
// only the nearest autoLight activates, with optional distance cap
|
||||
const float dist = (pl.position - playerState->position).norm();
|
||||
const float dist = (pl.position - playerState->position.toEigen()).norm();
|
||||
active = (i == nearestLightIdx) &&
|
||||
(pl.autoLightDistance <= 0.0f || dist <= pl.autoLightDistance);
|
||||
}
|
||||
@@ -1632,7 +1632,7 @@ namespace FRG
|
||||
if (playerState && !activeLightIndices.empty()) {
|
||||
float minDist = FLT_MAX;
|
||||
for (int idx : activeLightIndices) {
|
||||
const float d = (pointLights[idx].position - playerState->position).norm();
|
||||
const float d = (pointLights[idx].position - playerState->position.toEigen()).norm();
|
||||
if (d < minDist) { minDist = d; shadowLight = &pointLights[idx]; }
|
||||
}
|
||||
}
|
||||
@@ -1850,37 +1850,6 @@ namespace FRG
|
||||
return true;
|
||||
}
|
||||
|
||||
void Location::nudgeCharacterAside(Character* standing, const Eigen::Vector3f& awayFrom)
|
||||
{
|
||||
auto standingState = standing ? standing->stateSnapshot() : nullptr;
|
||||
if (!standingState || standingState->isPlayer) return;
|
||||
auto locationState = stateSnapshot();
|
||||
if (!locationState || locationState->activeNavigationIndex < 0 ||
|
||||
locationState->activeNavigationIndex >=
|
||||
static_cast<int>(locationState->navigationMaps.size())) return;
|
||||
const PathFinder& navigation =
|
||||
locationState->navigationMaps[locationState->activeNavigationIndex];
|
||||
if (navigation.isReady()) return;
|
||||
|
||||
static constexpr float kNudgeDist = 1.2f;
|
||||
|
||||
Eigen::Vector3f dir = standingState->position - awayFrom;
|
||||
dir.y() = 0.f;
|
||||
if (dir.norm() < 1e-3f) dir = Eigen::Vector3f(1.f, 0.f, 0.f);
|
||||
else dir.normalize();
|
||||
|
||||
const float angles[] = { 0.f, static_cast<float>(M_PI * 0.5), static_cast<float>(-M_PI * 0.5), static_cast<float>(M_PI) };
|
||||
for (float angle : angles) {
|
||||
Eigen::Vector3f rotated = Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitY()) * dir;
|
||||
Eigen::Vector3f candidate = standingState->position + rotated * kNudgeDist;
|
||||
candidate.y() = 0.f;
|
||||
if (navigation.isWalkable(candidate)) {
|
||||
setCharacterTarget(*standing, candidate);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Location::update(int64_t delta, const LocationSimulationEvents& events)
|
||||
{
|
||||
synchronizeRemotePlayers();
|
||||
@@ -1951,7 +1920,7 @@ namespace FRG
|
||||
player->update(delta, eventFor(gameServer_.localPlayerId()));
|
||||
auto playerState = player->stateSnapshot();
|
||||
if (playerState && playerState->enabled)
|
||||
updateTriggerZones(playerState->position);
|
||||
updateTriggerZones(playerState->position.toEigen());
|
||||
}
|
||||
for (auto& [id, remote] : remotePlayers_)
|
||||
if (remote) remote->update(delta, eventFor(id));
|
||||
@@ -1988,7 +1957,7 @@ namespace FRG
|
||||
auto playerState = player ? player->stateSnapshot() : nullptr;
|
||||
if (auto* tz = getTargetTeleportZone(*locationState);
|
||||
tz && playerState && playerState->enabled) {
|
||||
float dist = (playerState->position - tz->position).norm();
|
||||
float dist = (playerState->position.toEigen() - tz->position).norm();
|
||||
if (dist <= tz->radius) {
|
||||
logger() << "[TELEPORT] Player reached teleport zone '" << tz->id << "'" << std::endl;
|
||||
gameServer_.submit(SetLocationTargetsCommand{
|
||||
@@ -2005,7 +1974,7 @@ namespace FRG
|
||||
for (auto& tz : teleportZones) {
|
||||
if (!tz.active || !tz.automatic) continue;
|
||||
const float autoR = tz.automaticRadius > 0.0f ? tz.automaticRadius : tz.radius;
|
||||
const float dist = (playerState->position - tz.position).norm();
|
||||
const float dist = (playerState->position.toEigen() - tz.position).norm();
|
||||
|
||||
if (!tz.automaticInitialized) {
|
||||
// If the player starts inside the zone (e.g. just arrived here via teleport),
|
||||
@@ -2101,7 +2070,7 @@ namespace FRG
|
||||
const Eigen::Vector3f interactionTarget = clickedObject->state.hasInteractionPosition
|
||||
? clickedObject->state.interactionPosition
|
||||
: clickedObject->state.position;
|
||||
setCharacterTarget(*player, interactionTarget);
|
||||
setCharacterTarget(*player, Vec3fp::fromEigen(interactionTarget));
|
||||
pathVisualization.start(*player, interactionTarget);
|
||||
clearCharacterAttackTarget(*player);
|
||||
//logger() << "[CLICK] Player moving to object..." << std::endl;
|
||||
@@ -2114,7 +2083,7 @@ namespace FRG
|
||||
if (clickedNpc && player) {
|
||||
auto clickedNpcState = clickedNpc->stateSnapshot();
|
||||
if (!clickedNpcState) return;
|
||||
float distance = (playerState->position - clickedNpcState->position).norm();
|
||||
float distance = (playerState->position - clickedNpcState->position).toEigen().norm();
|
||||
int npcIndex = -1;
|
||||
for (size_t i = 0; i < npcs.size(); ++i) {
|
||||
if (npcs[i].get() == clickedNpc) {
|
||||
@@ -2144,11 +2113,11 @@ namespace FRG
|
||||
setCharacterTarget(*player, clickedNpcState->position);
|
||||
pathVisualization.start(
|
||||
*player,
|
||||
clickedNpcState->position,
|
||||
clickedNpcState->position.toEigen(),
|
||||
PathVisualization::Style::Hostile);
|
||||
}
|
||||
|
||||
if (distance <= clickedNpcState->interactionRadius) {
|
||||
if (distance <= static_cast<float>(clickedNpcState->interactionRadius)) {
|
||||
//logger() << "[CLICK] Hostile NPC " << npcIndex << " in range; firing on_npc_interact" << std::endl;
|
||||
scriptEngine.callNpcInteractCallback(clickedNpc->entityId());
|
||||
}
|
||||
@@ -2172,7 +2141,7 @@ namespace FRG
|
||||
//logger() << "[CLICK] NPC " << npcIndex << " out of talk range (distance " << distance
|
||||
// << " > " << NPC_TALK_DISTANCE << "); walking to NPC..." << std::endl;
|
||||
setCharacterTarget(*player, clickedNpcState->position);
|
||||
pathVisualization.start(*player, clickedNpcState->position);
|
||||
pathVisualization.start(*player, clickedNpcState->position.toEigen());
|
||||
gameServer_.submit(SetLocationTargetsCommand{
|
||||
locationId_, std::string(), clickedNpc->entityId(),
|
||||
std::string()});
|
||||
@@ -2199,7 +2168,7 @@ namespace FRG
|
||||
gameServer_.submit(SetLocationTargetsCommand{
|
||||
locationId_, std::string(), std::string(),
|
||||
clickedTeleport->id});
|
||||
setCharacterTarget(*player, clickedTeleport->position);
|
||||
setCharacterTarget(*player, Vec3fp::fromEigen(clickedTeleport->position));
|
||||
pathVisualization.start(
|
||||
*player,
|
||||
clickedTeleport->position,
|
||||
@@ -2207,7 +2176,7 @@ namespace FRG
|
||||
clearCharacterAttackTarget(*player);
|
||||
} else {
|
||||
const Eigen::Vector3f clickedDestination(hit.x(), 0.f, hit.z());
|
||||
setCharacterTarget(*player, clickedDestination);
|
||||
setCharacterTarget(*player, Vec3fp::fromEigen(clickedDestination));
|
||||
pathVisualization.start(*player, clickedDestination);
|
||||
clearCharacterAttackTarget(*player);
|
||||
gameServer_.submit(SetLocationTargetsCommand{
|
||||
|
||||
Reference in new issue
Block a user