VOX
A little voxel engine
Loading...
Searching...
No Matches
Block.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "define.hpp"
4#include "HitBox.hpp"
5
6#include <string>
7#include <vector>
8
9typedef uint64_t BlockProperties;
10typedef uint32_t TextureID;
11
12// Block properties
13#define BLOCK_PROPERTY_NONE 0U // default
14#define BLOCK_PROPERTY_SOLID 1U // solid block (can be walked on)
15#define BLOCK_PROPERTY_OPAQUE 1U << 1 // opaque block (cannot be seen through)
16#define BLOCK_PROPERTY_CUBE 1U << 2 // cube block (is a standard cube shape)
17#define BLOCK_PROPERTY_LIGHT 1U << 3 // light block (emits light)
18#define BLOCK_PROPERTY_FLUID 1U << 4 // fluid block (flows)
19
20// Block faces coresponding to the texture array
21#define BLOCK_FACE_TOP 0
22#define BLOCK_FACE_BOTTOM 1
23#define BLOCK_FACE_RIGHT 2
24#define BLOCK_FACE_LEFT 3
25#define BLOCK_FACE_FRONT 4
26#define BLOCK_FACE_BACK 5
28{
29
30public:
31
32 enum class Type : uint16_t
33 {
34 Air,
35 Grass,
36 Dirt,
37 Stone,
38 Sand,
39 Water,
40 Glass,
41 Light,
42 Wood,
43 Leaves,
44 None
45
46 } const id = Type::None;
47
51 const uint8_t emit_light; // light level emitted by the block
52 const uint8_t absorb_light; // light level absorbed by the block
53
54
55 static inline const std::vector<std::string> texture_names = {
56 "assets/textures/block/grass_top.png", // 0
57 "assets/textures/block/grass_top.png", // 1
58 "assets/textures/block/grass_side.png", // 2
59 "assets/textures/block/dirt.png", // 3
60 "assets/textures/block/stone.png", // 4
61 "assets/textures/block/water.png", // 5
62 "assets/textures/block/glass_clear.png", // 6
63 "assets/textures/block/light.png", // 7
64 "assets/textures/block/wood_top.png", // 8
65 "assets/textures/block/wood.png", // 9
66 "assets/textures/block/oak_leaves.png", // 10
67 "assets/textures/block/sand.png" //11
68 // "assets/textures/block/debug/white.png",
69 // "assets/textures/block/debug/right.png",
70 // "assets/textures/block/debug/left.png",
71 // "assets/textures/block/debug/front.png",
72 // "assets/textures/block/debug/top.png",
73 // "assets/textures/block/debug/back_bottom.png",
74 };
75
76};
77
80{
81
82public:
83
85 {
86 static BlocksInfo instance;
87 return instance;
88 }
89
90 const BlockInfo & get(const BlockInfo::Type id)
91 {
92 return m_infos[static_cast<size_t>(id)];
93 }
94
95 bool hasProperty(const BlockInfo::Type id, const BlockProperties properties)
96 {
97 return (get(id).properties & properties) == properties;
98 }
99
100 bool hasProperty(const BlockInfo::Type id, const BlockProperties properties, const BlockProperties not_properties)
101 {
102 return (get(id).properties & (properties | not_properties)) == properties;
103 }
104
105private:
106
107 std::vector<BlockInfo> m_infos;
108
109 BlocksInfo();
110
111};
112
BlockInfo::Type BlockType
Definition: Block.hpp:78
uint64_t BlockProperties
Definition: Block.hpp:9
BlocksInfo & g_blocks_info
Definition: Block.cpp:3
uint32_t TextureID
Definition: Block.hpp:10
Definition: Block.hpp:28
const HitBox hitbox
Definition: Block.hpp:50
static const std::vector< std::string > texture_names
Definition: Block.hpp:55
Type
Definition: Block.hpp:33
const uint8_t emit_light
Definition: Block.hpp:51
const BlockProperties properties
Definition: Block.hpp:49
const TextureID texture[6]
Definition: Block.hpp:48
const uint8_t absorb_light
Definition: Block.hpp:52
Definition: Block.hpp:80
static BlocksInfo & getInstance()
Definition: Block.hpp:84
bool hasProperty(const BlockInfo::Type id, const BlockProperties properties, const BlockProperties not_properties)
Definition: Block.hpp:100
const BlockInfo & get(const BlockInfo::Type id)
Definition: Block.hpp:90
bool hasProperty(const BlockInfo::Type id, const BlockProperties properties)
Definition: Block.hpp:95
Definition: HitBox.hpp:11