Working on cutscenes and pathfinding
This commit is contained in:
1 parent
80825e3220
commit
020f31e1e4
17 files changed
+192
-73
No files matched your search
+27
-1
@@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
#include <cfloat>
|
||||
#include <limits>
|
||||
#include <random>
|
||||
#include "GameConstants.h"
|
||||
#include "Character.h"
|
||||
#include "external/nlohmann/json.hpp"
|
||||
@@ -1325,6 +1326,23 @@ namespace ZL
|
||||
static constexpr int64_t kReplanCooldownMs = 500;
|
||||
static constexpr float kStuckMovementThreshold = 0.02f;
|
||||
static constexpr int kStuckFrameThreshold = 4;
|
||||
static constexpr float kStuckPauseMin = 0.5f;
|
||||
static constexpr float kStuckPauseMax = 1.0f;
|
||||
|
||||
const float deltaS = static_cast<float>(deltaMs) / 1000.f;
|
||||
|
||||
// Tick down pause timers; replan NPCs when their pause expires.
|
||||
for (auto it = stuckPauseRemainingS.begin(); it != stuckPauseRemainingS.end();) {
|
||||
it->second -= deltaS;
|
||||
if (it->second <= 0.f) {
|
||||
if (!it->first->isPlayer) {
|
||||
it->first->forceReplan();
|
||||
}
|
||||
it = stuckPauseRemainingS.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = replanCooldownRemainingMs.begin(); it != replanCooldownRemainingMs.end();) {
|
||||
it->second -= deltaMs;
|
||||
@@ -1362,8 +1380,16 @@ namespace ZL
|
||||
if (c->isMoving()) {
|
||||
if (moved < kStuckMovementThreshold) {
|
||||
if (++stuckFrameCounts[c] >= kStuckFrameThreshold) {
|
||||
c->forceReplan();
|
||||
c->stopInPlace();
|
||||
stuckFrameCounts[c] = 0;
|
||||
if (stuckPauseRemainingS.find(c) == stuckPauseRemainingS.end()) {
|
||||
if (!c->isPlayer) {
|
||||
static std::mt19937 rng(std::random_device{}());
|
||||
std::uniform_real_distribution<float> pauseDist(kStuckPauseMin, kStuckPauseMax);
|
||||
stuckPauseRemainingS[c] = pauseDist(rng);
|
||||
}
|
||||
// Player just stops; replan is not scheduled.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stuckFrameCounts[c] = 0;
|
||||
|
||||
Reference in new issue
Block a user