summaryrefslogtreecommitdiffhomepage
path: root/loader/loader.hpp
blob: faa0269a228f19e5768dfa9605ac2a8faef4f447 (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
78
79
80
81
82
83
84
85
86
87
#pragma once
#include "compat/defs.hpp"
#include "src/pass-mode.hpp"
#include "loader/policy.hpp"
#include <memory>
#include <Corrade/Containers/String.h>

//namespace Magnum { using Vector2ub = Math::Vector2<unsigned char>; }
namespace Magnum::Trade { template<uint32_t> class ImageData; using ImageData2D = ImageData<2>; }

namespace floormat {

struct serialized_scenery;
namespace loader_detail {}
namespace Serialize {}

struct anim_def;
class anim_atlas;
struct anim_cell;
struct scenery_proto;
struct vobj_info;
class ground_atlas;
struct ground_cell;
struct wall_cell;
class wall_atlas;
struct scenery_proto;

struct vobj_info final
{
    String name, descr;
    std::shared_ptr<anim_atlas> atlas;
};

struct loader_
{
    virtual StringView shader(StringView filename) noexcept = 0;
    virtual Trade::ImageData2D make_error_texture(Vector2ui size) = 0;
    virtual Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false) = 0;
    virtual const std::shared_ptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0;
    virtual ArrayView<const String> anim_atlas_list() = 0;
    virtual std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir = ANIM_PATH, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0;
    virtual std::shared_ptr<class wall_atlas> wall_atlas(StringView name, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0;
    virtual ArrayView<const wall_cell> wall_atlas_list() = 0;
    virtual void destroy() = 0;
    static loader_& default_loader() noexcept;
    virtual ArrayView<const ground_cell> ground_atlas_list() noexcept(false) = 0; // todo maybe try returning
    virtual ArrayView<const serialized_scenery> sceneries() = 0;
    virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0;
    virtual StringView startup_directory() noexcept = 0;
    static StringView strip_prefix(StringView name);
    virtual const vobj_info& vobj(StringView name) = 0;
    virtual ArrayView<const struct vobj_info> vobj_list() = 0;
    static StringView make_atlas_path(char(&buf)[fm_FILENAME_MAX], StringView dir, StringView name);
    [[nodiscard]] static bool check_atlas_name(StringView name) noexcept;

    virtual const wall_cell& make_invalid_wall_atlas() = 0;
    virtual const ground_cell& make_invalid_ground_atlas() = 0;
    virtual const anim_cell& make_invalid_anim_atlas() = 0;

    /** \deprecated{internal use only}*/ [[nodiscard]]
    std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false);
    /** \deprecated{internal use only}*/ [[nodiscard]]
    std::shared_ptr<class wall_atlas> get_wall_atlas(StringView name) noexcept(false);
    /** \deprecated{internal use only}*/ [[nodiscard]]
    std::shared_ptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false);

    virtual ~loader_() noexcept;
    fm_DECLARE_DELETED_COPY_ASSIGNMENT(loader_);
    fm_DECLARE_DELETED_MOVE_ASSIGNMENT(loader_);

    static constexpr StringView INVALID = "<invalid>"_s;
    static const StringView ANIM_PATH;
    static const StringView SCENERY_PATH;
    static const StringView TEMP_PATH;
    static const StringView VOBJ_PATH;
    static const StringView GROUND_TILESET_PATH;
    static const StringView WALL_TILESET_PATH;

protected:
    static anim_def deserialize_anim_def(StringView filename) noexcept(false);

    loader_();
};

extern loader_& loader; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

} // namespace floormat