21Heard Hear(Vector3 source, Vector3 ears, Vector3 right) {
22 const Vector3 away = {source.x - ears.x, 0.0f, source.z - ears.z};
23 const float distance = Vector3Length(away);
24 if (distance >=
kFar) {
25 return {.volume = 0.0f, .pan = 0.0f};
29 const float volume = std::min(1.0f,
kNear / distance) *
33 distance > 0.0f ? Vector3DotProduct(away, right) / distance : 0.0f;
34 return {.volume = volume,
35 .pan = kWidestPan * side * std::min(distance, 1.0f)};
57std::array<float, 2>
Footfalls(
const ModelAnimation& clip,
int left,
59 std::array<float, 2> footfalls{0.0f, 0.5f};
61 const int frames = clip.keyframeCount - 1;
62 const int bones =
static_cast<int>(clip.boneCount);
63 if (frames < 2 || left < 0 || right < 0 || left >= bones || right >= bones) {
66 const std::array<int, 2> feet = {left, right};
67 for (std::size_t foot = 0; foot < feet.size(); ++foot) {
68 const auto height = [&](
int frame) {
69 return clip.keyframePoses[frame][feet[foot]].translation.y;
71 float low = height(0);
72 float high = height(0);
73 for (
int frame = 1; frame < frames; ++frame) {
74 low = std::min(low, height(frame));
75 high = std::max(high, height(frame));
79 const float down = low + (high - low) / 6.0f;
80 for (
int frame = 0; frame < frames; ++frame) {
81 const int before = (frame + frames - 1) % frames;
82 if (height(frame) <= down && height(before) > down) {
84 static_cast<float>(frame) /
static_cast<float>(frames);
93 std::vector<uint64_t> stepped;
94 std::map<uint64_t, float> loops;
95 for (
const auto& [who, gait] : gaits) {
96 loops[who] = gait.loops;
97 const auto last = loops_.find(who);
99 if (last == loops_.end() || gait.loops < last->second) {
102 for (
const float footfall : gait.footfalls) {
104 if (std::floor(gait.loops - footfall) >
105 std::floor(last->second - footfall)) {
106 stepped.push_back(who);
110 loops_ = std::move(loops);
115 std::vector<Figure> started;
116 std::map<uint32_t, std::pair<uint32_t, float>> skills;
117 for (
const Figure& figure : figures) {
118 if (figure.monster || figure.npc || figure.to != protocol::MOTION_SKILL) {
121 skills[figure.id] = {figure.to_skill, figure.to_time};
122 const auto last = skills_.find(figure.id);
123 const bool fresh = last == skills_.end() ||
124 last->second.first != figure.to_skill ||
125 figure.to_time < last->second.second;
127 started.push_back(figure);
130 skills_ = std::move(skills);