summaryrefslogtreecommitdiffhomepage
path: root/src/hole.hpp
blob: 64e531498ed00880994a76f40a0e1cdd96d4285e (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
#pragma once
#include "object.hpp"
#include <array>

namespace floormat {

struct hole_proto final : object_proto
{
    ~hole_proto() noexcept override;
    hole_proto();
    hole_proto(const hole_proto&);
    hole_proto& operator=(const hole_proto&);
    hole_proto(hole_proto&&) noexcept;
    hole_proto& operator=(hole_proto&&) noexcept;
    bool operator==(const hole_proto&) const;

    uint8_t height = 0;
    bool on_render  : 1 = true;
    bool on_physics : 1 = true;
    bool is_wall    : 1 = false;
};

struct hole final : object
{
    uint8_t _height = 0;
    const bool on_render  : 1 = true;
    const bool on_physics : 1 = true;
    const bool is_wall    : 1 = false;

    hole(object_id id, class chunk& c, const hole_proto& proto);
    ~hole() noexcept override;

    Vector2 ordinal_offset(Vector2b offset) const override;
    float depth_offset() const override;
    object_type type() const noexcept override;
    void update(const std::shared_ptr<object>& ptr, size_t& i, const Ns& dt) override;
    bool is_dynamic() const override;
    bool is_virtual() const override;

    explicit operator hole_proto() const;

    friend class world;
};

struct cut_rectangle_result
{
    struct bbox { Vector2i position; Vector2ub bbox_size; };
    struct rect { Vector2i min, max; };

    uint8_t size = 0;
    std::array<rect, 8> array;

    operator ArrayView<const bbox>() const;
};

cut_rectangle_result cut_rectangle(cut_rectangle_result::bbox input, cut_rectangle_result::bbox hole);

} // namespace floormat