aboutsummaryrefslogtreecommitdiff
path: root/src/shared/entity/animate.hh
blob: 9a5c910eb14ff3e263275a0d6d691f496761defe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef SHARED_ENTITY_ANIMATE_HH_
#define SHARED_ENTITY_ANIMATE_HH_

#include "shared/entity/entity.hh"

namespace shared {

// An animate is a thing with viewangles, commands and velocity, ie mobs,
// players etc.
class animate : virtual public entity {
public:
    using commands_t = std::uint32_t;
    enum mask : commands_t {
        forward = 1 << 0,
        left = 1 << 1,
        backward = 1 << 2,
        right = 1 << 3,
        jump = 1 << 4,
        crouch = 1 << 5,
        sprint = 1 << 6,
        attack = 1 << 7,

        flying = 1 << 30
    };

protected:
    commands_t commands;
    shared::math::angles viewangles;
    glm::vec3 velocity;
    std::uint32_t active_item;

public:
    template <typename... Args>
    animate(const commands_t& commands, const shared::math::angles& viewangles,
            const glm::vec3& velocity, const std::uint32_t& active_item,
            Args&&... args) noexcept
        : entity(std::forward<Args>(args)...), commands(commands),
          viewangles(viewangles), velocity(velocity), active_item(active_item) {
    }

    animate(const proto::animate& proto) noexcept
        : entity(proto.entity()), commands(proto.commands()),
          viewangles(shared::net::get_angles(proto.viewangles())),
          velocity(shared::net::get_vec3(proto.velocity())),
          active_item(proto.active_item()) {}

public:
    void pack(proto::animate* const proto) const noexcept {
        this->entity::pack(proto->mutable_entity());

        proto->set_active_item(this->active_item);
        proto->set_commands(this->commands);
        shared::net::set_angles(proto->mutable_viewangles(), this->viewangles);
        shared::net::set_vec3(proto->mutable_velocity(), this->velocity);
    }

public:
    const decltype(commands)& get_commands() const noexcept {
        return this->commands;
    }
    decltype(commands)& get_mutable_commands() noexcept {
        return this->commands;
    }
    const decltype(viewangles)& get_angles() const noexcept {
        return this->viewangles;
    }
    decltype(viewangles)& get_mutable_angles() noexcept {
        return this->viewangles;
    }
    const decltype(velocity)& get_velocity() const noexcept {
        return this->velocity;
    }
    decltype(velocity)& get_mutable_velocity() noexcept {
        return this->velocity;
    }
    const decltype(active_item)& get_active_item() const noexcept {
        return this->active_item;
    }
    decltype(active_item)& get_mutable_active_item() noexcept {
        return this->active_item;
    }

public:
    bool operator==(const animate&) const noexcept = default;
};

} // namespace shared

#endif