]> git.lizzy.rs Git - dragonfireclient.git/blob - src/texture_override.h
Force-update shadows when the world is changed (#12364)
[dragonfireclient.git] / src / texture_override.h
1 /*
2 Minetest
3 Copyright (C) 2020 Hugues Ross <hugues.ross@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes.h"
23 #include <string>
24 #include <vector>
25
26 typedef u16 override_t;
27
28 //! Bitmask enum specifying what a texture override should apply to
29 enum class OverrideTarget : override_t
30 {
31         INVALID = 0,
32         TOP = 1 << 0,
33         BOTTOM = 1 << 1,
34         LEFT = 1 << 2,
35         RIGHT = 1 << 3,
36         FRONT = 1 << 4,
37         BACK = 1 << 5,
38         INVENTORY = 1 << 6,
39         WIELD = 1 << 7,
40         SPECIAL_1 = 1 << 8,
41         SPECIAL_2 = 1 << 9,
42         SPECIAL_3 = 1 << 10,
43         SPECIAL_4 = 1 << 11,
44         SPECIAL_5 = 1 << 12,
45         SPECIAL_6 = 1 << 13,
46
47         // clang-format off
48         SIDES = LEFT | RIGHT | FRONT | BACK,
49         ALL_FACES = TOP | BOTTOM | SIDES,
50         ALL_SPECIAL = SPECIAL_1 | SPECIAL_2 | SPECIAL_3 | SPECIAL_4 | SPECIAL_5 | SPECIAL_6,
51         NODE_TARGETS = ALL_FACES | ALL_SPECIAL,
52         ITEM_TARGETS = INVENTORY | WIELD,
53         // clang-format on
54 };
55
56 struct TextureOverride
57 {
58         std::string id;
59         std::string texture;
60         override_t target;
61
62         // Helper function for checking if an OverrideTarget is found in
63         // a TextureOverride without casting
64         inline bool hasTarget(OverrideTarget overrideTarget) const
65         {
66                 return (target & static_cast<override_t>(overrideTarget)) != 0;
67         }
68 };
69
70 //! Class that provides texture override information from a texture pack
71 class TextureOverrideSource
72 {
73 public:
74         TextureOverrideSource(std::string filepath);
75
76         //! Get all overrides that apply to item definitions
77         std::vector<TextureOverride> getItemTextureOverrides();
78
79         //! Get all overrides that apply to node definitions
80         std::vector<TextureOverride> getNodeTileOverrides();
81
82 private:
83         std::vector<TextureOverride> m_overrides;
84 };