summaryrefslogtreecommitdiffhomepage
path: root/src/chunk.hpp
blob: 13c9eeb7c2cdd352913e4634b43591d3405dca30 (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
#pragma once
#include "tile.hpp"
#include "tile-iterator.hpp"
#include <type_traits>
#include <array>

namespace floormat {

template<typename T> class basic_tile_iterator;

struct chunk final
{
    tile& operator[](local_coords xy) { return _tiles[xy.to_index()]; }
    const tile& operator[](local_coords xy) const { return _tiles[xy.to_index()]; }
    tile& operator[](std::size_t i) { return _tiles[i]; }
    const tile& operator[](std::size_t i) const { return _tiles[i]; }
    const auto& tiles() const { return _tiles; }
    auto& tiles() { return _tiles; }

    using iterator = basic_tile_iterator<tile>;
    using const_iterator = basic_tile_iterator<const tile>;

    iterator begin() { return iterator{_tiles.data(), 0}; }
    iterator end() { return iterator{_tiles.data(), _tiles.size()}; }
    const_iterator cbegin() const { return const_iterator{_tiles.data(), 0}; }
    const_iterator cend() const { return const_iterator{_tiles.data(), _tiles.size()}; }
    const_iterator begin() const { return cbegin(); }
    const_iterator end() const { return cend(); }

    bool empty() const;

    chunk() = default;
    chunk(chunk&&) = default;
    chunk& operator=(chunk&&) = default;

    fm_DECLARE_DELETED_COPY_ASSIGNMENT(chunk);
    fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(chunk);

private:
    std::array<tile, TILE_COUNT> _tiles = {};
    mutable bool _maybe_empty = true;
};

} // namespace floormat