summaryrefslogtreecommitdiffhomepage
path: root/src/tile.hpp
blob: c679b5c08ba10cf5cdd49afaa9e6169e865ba2f9 (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
#pragma once
#include "tile-image.hpp"
#include "compat/borrowed-ptr.hpp"

namespace floormat {

class chunk;
class anim_atlas;

struct tile_proto final
{
    bptr<class ground_atlas> ground_atlas;
    bptr<class wall_atlas> wall_north_atlas, wall_west_atlas;
    variant_t ground_variant = 0, wall_north_variant = 0, wall_west_variant = 0;

    tile_image_proto ground() const noexcept;
    wall_image_proto wall_north() const noexcept;
    wall_image_proto wall_west() const noexcept;

    friend bool operator==(const tile_proto& a, const tile_proto& b) noexcept;
};

struct tile_ref final
{
    tile_ref(class chunk& c, uint8_t i) noexcept;

    tile_image_ref ground() noexcept;
    wall_image_ref wall_north() noexcept;
    wall_image_ref wall_west() noexcept;

    tile_image_proto ground() const noexcept;
    wall_image_proto wall_north() const noexcept;
    wall_image_proto wall_west() const noexcept;

    bptr<class ground_atlas> ground_atlas() noexcept;
    bptr<class wall_atlas> wall_north_atlas() noexcept;
    bptr<class wall_atlas> wall_west_atlas() noexcept;

    bptr<const class ground_atlas> ground_atlas() const noexcept;
    bptr<const class wall_atlas> wall_north_atlas() const noexcept;
    bptr<const class wall_atlas> wall_west_atlas() const noexcept;

    explicit operator tile_proto() const noexcept;

    class chunk& chunk() noexcept { return *_chunk; }
    const class chunk& chunk() const noexcept { return *_chunk; }
    size_t index() const noexcept { return i; }

    friend bool operator==(const tile_ref& a, const tile_ref& b) noexcept;

private:
    class chunk* _chunk;
    uint8_t i;
};

} //namespace floormat