载入中...
搜索中...
未找到
FpsGait.cpp
浏览该文件的文档.
1#include "combat/FpsGait.h"
2
3#include "common/Diagnostic.h"
4
5#include <cmath>
6
7namespace eve::combat {
8namespace {
9
10[[nodiscard]] bool finitePositive(double v) { return std::isfinite(v) && v > 0.0; }
11
12} // namespace
13
15 if (!finitePositive(walkSpeed) || !finitePositive(sprintSpeed) || !finitePositive(crouchSpeed))
17 "fps gait speeds must be finite and positive", "speed"));
18 if (!finitePositive(standHeight) || !finitePositive(crouchHeight) || crouchHeight > standHeight)
20 "fps gait capsule heights must be positive with crouch <= stand",
21 "height"));
22 if (!finitePositive(standEyeHeight) || !finitePositive(crouchEyeHeight) || crouchEyeHeight > standEyeHeight)
24 "fps gait eye heights must be positive with crouch <= stand",
25 "eye"));
26 if (!finitePositive(capsuleRadius))
28 "fps gait capsule radius must be finite and positive", "radius"));
31 "fps gait eye height must not exceed capsule height", "eye"));
32 return Result<void>::success();
33}
34
36 auto valid = profile.validate();
37 if (!valid) return valid;
38 profile_ = profile;
39 return Result<void>::success();
40}
41
43 auto valid = profile_.validate();
44 if (!valid) return Result<FpsGaitPose>::failure(valid.status());
45
47 if (input.wantCrouch || (mode_ == FpsGaitMode::Crouch && !input.canStand))
49 else if (input.wantSprint && input.grounded)
51
52 mode_ = next;
53
55 pose.mode = mode_;
56 pose.capsuleRadius = profile_.capsuleRadius;
57 switch (mode_) {
59 pose.moveSpeed = profile_.sprintSpeed;
60 pose.capsuleHeight = profile_.standHeight;
61 pose.eyeHeight = profile_.standEyeHeight;
62 break;
64 pose.moveSpeed = profile_.crouchSpeed;
65 pose.capsuleHeight = profile_.crouchHeight;
66 pose.eyeHeight = profile_.crouchEyeHeight;
67 break;
69 default:
70 pose.moveSpeed = profile_.walkSpeed;
71 pose.capsuleHeight = profile_.standHeight;
72 pose.eyeHeight = profile_.standEyeHeight;
73 break;
74 }
76}
77
79 if (!std::isfinite(request.stridePhase) || !std::isfinite(request.moveSpeed) ||
80 !std::isfinite(request.referenceSpeed) || !std::isfinite(request.amplitude) ||
81 !std::isfinite(request.landDip))
83 DiagnosticCode::InvalidArgument, "fps head bob request must be finite", "request"));
84 if (request.referenceSpeed <= 0.0)
86 DiagnosticCode::InvalidArgument, "fps head bob reference speed must be positive", "referenceSpeed"));
87 if (request.amplitude < 0.0)
89 DiagnosticCode::InvalidArgument, "fps head bob amplitude must be non-negative", "amplitude"));
90
92 offset.eyeY = request.landDip;
93 if (!request.enabled || !request.grounded) return Result<FpsHeadBobOffset>::success(offset);
94
95 const double speed = std::max(0.0, request.moveSpeed);
96 const double frac = std::min(1.0, speed / request.referenceSpeed);
97 if (frac <= 1e-4) return Result<FpsHeadBobOffset>::success(offset);
98
99 offset.eyeY += std::sin(request.stridePhase) * request.amplitude * frac;
101}
102
103} // namespace eve::combat
eve::EntitySpatialPose pose
Stable, structured diagnostics shared by engine modules.
EvpackChunkInput input
Definition Evpack.cpp:170
First-person walk/sprint/crouch gait pose (no physics).
const GltfImportRequest & request
float v
size_t offset
bool valid
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Result< FpsGaitPose > evaluate(const FpsGaitInput &input)
Evaluate one frame and commit the mode. @cost Cheap; O(1) per call. Amortize by calling once per simu...
Definition FpsGait.cpp:42
const FpsGaitProfile & profile() const
Current profile (defaults until setProfile succeeds).
Definition FpsGait.h:61
Result< void > setProfile(const FpsGaitProfile &profile)
Replace the profile; invalid profiles leave the previous one intact.
Definition FpsGait.cpp:35
static Result< FpsHeadBobOffset > solve(const FpsHeadBobRequest &request)
Solve eye Y offset; does not mutate request.
Definition FpsGait.cpp:78
FpsGaitMode
Discrete first-person locomotion gait.
Definition FpsGait.h:13
Per-frame intent and environment facts owned by the game.
Definition FpsGait.h:31
Resolved gait pose for movers and cameras.
Definition FpsGait.h:40
Tunable speeds and capsule/eye heights for one FPS body.
Definition FpsGait.h:16
Result< void > validate() const
Reject non-finite or non-positive sizes/speeds.
Definition FpsGait.cpp:14
Eye-local vertical offset from bob + landing dip.
Definition FpsGait.h:89
Head-bob / landing dip inputs.
Definition FpsGait.h:78