From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/shared/entity/player.hh | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/shared/entity/player.hh (limited to 'src/shared/entity/player.hh') diff --git a/src/shared/entity/player.hh b/src/shared/entity/player.hh new file mode 100644 index 0000000..a2fcd81 --- /dev/null +++ b/src/shared/entity/player.hh @@ -0,0 +1,63 @@ +#ifndef SHARED_ENTITY_PLAYER_HH_ +#define SHARED_ENTITY_PLAYER_HH_ + +#include + +#include "shared/entity/moveable.hh" +#include "shared/entity/animate.hh" +#include "shared/item/items.hh" +#include "shared/movement/struct.hh" + +namespace shared { + +class player : virtual public shared::moveable { +public: + static constexpr float HEIGHT = 1.9f; + static constexpr float EYE_HEIGHT = HEIGHT * 0.8f; + static constexpr float HALFWIDTH = 0.25f; + + static constexpr int INVENTORY_COLS = 10; + static constexpr int INVENTORY_ROWS = 5; + +public: + shared::item::items inventory; + +public: + template + player(shared::item::items&& inventory, const commands_t& commands, + const shared::math::angles& viewangles, const glm::vec3& velocity, + const std::uint32_t& active_item, Args&&... args) noexcept + : shared::entity(args...), shared::animate(commands, viewangles, + velocity, active_item, + args...), + inventory(std::forward(inventory)) {} + + player(const proto::player& proto) noexcept + : entity(proto.animate().entity()), animate(proto.animate()), + inventory(proto.inventory()) {} + + // constructor for no inventory + player(const proto::animate& proto) noexcept + : entity(proto.entity()), animate(proto), inventory() {} + + virtual ~player() noexcept {} + +public: + void pack(proto::player* const proto) const noexcept { + this->animate::pack(proto->mutable_animate()); + this->inventory.pack(proto->mutable_inventory()); + } + + virtual const movement::aabb& get_aabb() const noexcept override { + static constexpr movement::aabb aabb = { + .min = {-HALFWIDTH + movement::EPSILON, 0.0f + movement::EPSILON, + -HALFWIDTH + movement::EPSILON}, + .max = {HALFWIDTH - movement::EPSILON, HEIGHT - movement::EPSILON, + HALFWIDTH - movement::EPSILON}}; + return aabb; + } +}; + +} // namespace shared + +#endif -- cgit v1.2.3