diff options
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 |
