summaryrefslogtreecommitdiffhomepage
path: root/src/tile-atlas.hpp
blob: 1a06db4aeac7e42e29407e1515325c62b8b31e91 (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
#pragma once
#include "src/pass-mode.hpp"
#include "src/quads.hpp"
#include <array>
#include <memory>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/GL/Texture.h>

namespace floormat {

class tile_atlas final
{
    using quad = std::array<Vector3, 4>;
    using texcoords = std::array<Vector2, 4>;

    static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count);
    static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i);

    std::unique_ptr<const texcoords[]> texcoords_;
    GL::Texture2D tex_;
    String path_, name_;
    Vector2ui size_;
    Vector2ub dims_;
    Optional<enum pass_mode> passability;

public:
    // todo remove Optional when wall atlases are fully implemented -sh 20231122
    tile_atlas(StringView path, StringView name, const ImageView2D& img, Vector2ub tile_count, Optional<enum pass_mode> pass_mode);

    texcoords texcoords_for_id(size_t id) const;

    [[maybe_unused]] Vector2ui pixel_size() const { return size_; }
    size_t num_tiles() const;
    Vector2ub num_tiles2() const { return dims_; }
    GL::Texture2D& texture() { return tex_; }
    StringView name() const { return name_; }
    Optional<enum pass_mode> pass_mode() const; // todo remove later
    enum pass_mode pass_mode(enum pass_mode p) const;
    void set_pass_mode(enum pass_mode p); // todo remove later
};



} // namespace floormat