nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
telegraphs.cc
Go to the documentation of this file.
1#include "client/telegraphs.h"
2
3#include <algorithm>
4#include <cstdint>
5#include <map>
6#include <utility>
7
8namespace nanommo {
9
10float Telegraph::Filled() const {
11 const float shows = static_cast<float>(skill.telegraph_ms()) / 1000.0f;
12 return shows > 0.0f ? std::clamp(1.0f - left / shows, 0.0f, 1.0f) : 1.0f;
13}
14
15void Telegraphs::Update(const protocol::World& world, float seconds) {
16 std::map<uint32_t, Telegraph> shown;
17 for (const protocol::Monster& monster : world.monsters()) {
18 const auto kind = kinds_.find(monster.kind());
19 if (monster.motion() != protocol::MOTION_SKILL || kind == kinds_.end()) {
20 continue;
21 }
22 const auto skill = std::ranges::find(kind->second.skills(), monster.skill(),
23 &monsters::Skill::id);
24 if (skill == kind->second.skills().end()) {
25 continue;
26 }
27 const float left = static_cast<float>(monster.lands_in()) / 1000.0f;
28 const auto before = shown_.find(monster.id());
29 if (before == shown_.end() || before->second.skill.id() != skill->id() ||
30 left > before->second.left + kLate) {
31 shown[monster.id()] = {.skill = *skill,
32 .at = {.x = monster.x(), .z = monster.z()},
33 .yaw = monster.yaw(),
34 .left = left};
35 continue;
36 }
37 // A world comes twenty times a second, and we draw more often, so it
38 // counts down by itself in between. A world that came late doesn't wind
39 // it back.
40 Telegraph telegraph = before->second;
41 telegraph.left = std::max(std::min(telegraph.left - seconds, left), 0.0f);
42 shown[monster.id()] = std::move(telegraph);
43 }
44 shown_ = std::move(shown);
45}
46
47} // namespace nanommo
static constexpr float kLate
Definition telegraphs.h:31
void Update(const protocol::World &world, float seconds)
Definition telegraphs.cc:15
const std::map< uint32_t, Telegraph > & shown() const
By the monster's id.
Definition telegraphs.h:42
Definition chat.cc:9
monsters::Skill skill
Definition telegraphs.h:16
float Filled() const
How far its shape has filled, from 0 as it shows to 1 as it lands.
Definition telegraphs.cc:10