diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 21:57:46 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 21:57:46 +1100 |
| commit | e4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch) | |
| tree | ed58c3c246e3af1af337697695d780aa31f6ad9a /src/shared/entity/player.hh | |
| parent | 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff) | |
Update to most recent version (old initial commit)
Diffstat (limited to 'src/shared/entity/player.hh')
| -rw-r--r-- | src/shared/entity/player.hh | 63 |
1 files changed, 63 insertions, 0 deletions
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 <algorithm> + +#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 <typename... Args> + 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<shared::item::items>(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 |
