aboutsummaryrefslogtreecommitdiff
path: root/src/client/entity/player.hh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/client/entity/player.hh
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/client/entity/player.hh')
-rw-r--r--src/client/entity/player.hh73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/client/entity/player.hh b/src/client/entity/player.hh
new file mode 100644
index 0000000..d9bdc18
--- /dev/null
+++ b/src/client/entity/player.hh
@@ -0,0 +1,73 @@
+#ifndef CLIENT_ENTITY_PLAYER_HH_
+#define CLIENT_ENTITY_PLAYER_HH_
+
+#include <chrono>
+#include <optional>
+#include <string>
+#include <utility>
+
+#include "client/entity/moveable.hh"
+#include "client/entity/entity.hh"
+#include "client/item/block.hh"
+#include "client/item/items.hh"
+#include "client/math.hh"
+#include "client/render/camera.hh"
+#include "client/render/model.hh"
+#include "client/render/program.hh"
+
+namespace client {
+
+// Renderable player, similar to client::chunk. We also store the message the
+// player wants to say.
+class player : virtual public shared::player, public client::moveable {
+public:
+ static constexpr auto MSG_SHOW_TIME = std::chrono::seconds{15};
+ struct message {
+ std::string text;
+ std::chrono::time_point<std::chrono::steady_clock> receive_time;
+ message(const std::string& message) noexcept {
+ this->text = message;
+ this->receive_time = std::chrono::steady_clock::now();
+ }
+ };
+ std::optional<message> message;
+
+private:
+ glm::vec3 get_world_pos(const client::player& lp) noexcept;
+
+public:
+ player(shared::player&& p) noexcept
+ : shared::entity(p), shared::animate(p), shared::player(p),
+ client::entity(p), client::animate(std::move(p)) {
+
+ // upgrade our inventory contents to client::item::item
+ for (auto& item : this->inventory.contents) {
+ if (item == nullptr) {
+ continue;
+ }
+
+ item = client::item::make_item(item->get_type(), item->quantity);
+ }
+ }
+ player(const proto::animate& proto) noexcept
+ : shared::entity(proto.entity()), shared::animate(proto),
+ shared::player(proto), client::entity(proto.entity()),
+ client::animate(proto) {}
+
+ virtual void draw(const client::player& localplayer) noexcept override;
+ virtual void draw_wts(const client::player& localplayer) noexcept override;
+
+ const std::optional<struct message>& get_message() noexcept {
+ if (this->message.has_value()) {
+ const auto now = std::chrono::steady_clock::now();
+ if (now > this->message->receive_time + player::MSG_SHOW_TIME) {
+ this->message.reset();
+ }
+ }
+ return this->message;
+ }
+};
+
+} // namespace client
+
+#endif