summaryrefslogtreecommitdiffhomepage
path: root/src/scenery.hpp
blob: aabf7315b89ab6c4452284baede6a50055ae8d7f (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
#pragma once
#include <cstdint>
#include <memory>

namespace floormat {

struct anim_atlas;

enum class rotation : std::uint8_t {
    N, NE, E, SE, S, SW, W, NW,
};

constexpr inline rotation rotation_COUNT = rotation{8};

enum class scenery_type : std::uint8_t {
    none, generic, door, object,
};

struct scenery final
{
    struct none_tag_t final {};
    struct generic_tag_t final {};
    struct door_tag_t final {};

    static constexpr auto NO_FRAME = (std::uint16_t)-1;
    static constexpr inline auto none    = none_tag_t{};
    static constexpr inline auto generic = generic_tag_t{};
    static constexpr inline auto door    = door_tag_t{};

    using frame_t = std::uint16_t;

    float delta = 0;
    frame_t frame = NO_FRAME;
    rotation     r        : 3 = rotation::N;
    std::uint8_t passable : 1 = false;
    std::uint8_t active   : 1 = false;
    std::uint8_t closing  : 1 = true;
    scenery_type type     : 2 = scenery_type::none;

    scenery() noexcept;
    scenery(none_tag_t) noexcept;
    scenery(generic_tag_t, rotation r, const anim_atlas& atlas, bool passable = false, frame_t frame = 0);
    scenery(door_tag_t, rotation r, const anim_atlas& atlas, bool is_open = false);
    scenery(float dt, frame_t frame, rotation r, bool passable, scenery_type type);

    bool can_activate() const noexcept;
    bool activate(const anim_atlas& atlas);
    void update(float dt, const anim_atlas& anim);
};

struct scenery_proto final {
    std::shared_ptr<anim_atlas> atlas;
    scenery frame;

    scenery_proto() noexcept;
    explicit scenery_proto(scenery::none_tag_t) noexcept;
    scenery_proto(const std::shared_ptr<anim_atlas>& atlas, const scenery& frame);
    scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool passable = false, scenery::frame_t frame = 0);
    scenery_proto(scenery::door_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool is_open = false);
    scenery_proto& operator=(const scenery_proto&) noexcept;

    operator bool() const noexcept;
};

struct scenery_ref final {
    std::shared_ptr<anim_atlas>& atlas;
    scenery& frame;

    scenery_ref(std::shared_ptr<anim_atlas>& atlas, scenery& frame) noexcept;
    scenery_ref(const scenery_ref&) noexcept;
    scenery_ref(scenery_ref&&) noexcept;
    scenery_ref& operator=(const scenery_proto& proto) noexcept;
    operator scenery_proto() const noexcept;
    operator bool() const noexcept;
};

} // namespace floormat