-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.h
124 lines (107 loc) · 2.95 KB
/
block.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once
#include <array>
#include <unordered_map>
#include <string>
#include "texture.h"
extern std::array<float, 42> NZ;
extern std::array<float, 42> PZ;
extern std::array<float, 42> NX;
extern std::array<float, 42> PX;
extern std::array<float, 42> NY;
extern std::array<float, 42> PY;
enum class FaceId {
NZ = 0,
PZ,
NX,
PX,
NY,
PY
};
enum class BlockType {
BlockType_Air = 0,
BlockType_Grass,
BlockType_Sand,
BlockType_Dirt,
BlockType_Stone,
BlockType_Coal,
BlockType_Cactus,
BlockType_Shrub,
BlockType_TallGrass,
BlockType_Diamond,
BlockType_Iron,
BlockType_Leaves,
BlockType_Log,
BlockType_Water,
BlockType_Error,
BlockType_NumTypes,
};
class Block {
public:
Block()
: m_active(true)
, m_blockType(BlockType::BlockType_Air)
{}
~Block() {}
bool IsActive() { return m_active; }
void SetActive(bool active) { m_active = active; }
// This still has the problem of drawing air pockets in solid ground. i.e., one air block in a sea of dirt blocks will make the surrounding dirt blocks have a face rendered
static bool shouldDrawFace(BlockType x, BlockType y) { return (x == BlockType::BlockType_Air && y != BlockType::BlockType_Air) || (x != BlockType::BlockType_Air && y == BlockType::BlockType_Air); }
static int getVertexAO(int side1, int side2, int corner) {
if (side1 && side2) {
return 0;
}
return 3 - (side1 + side2 + corner);
}
static int getTexture(BlockType type, bool is_side) {
switch (type) {
case BlockType::BlockType_Grass:
return is_side ? Texture::str_to_texid["grass_side"] : Texture::str_to_texid["grass"];
break;
case BlockType::BlockType_Sand:
return Texture::str_to_texid["sand"];
break;
case BlockType::BlockType_Dirt:
return Texture::str_to_texid["dirt"];
break;
case BlockType::BlockType_Stone:
return Texture::str_to_texid["stone"];
break;
case BlockType::BlockType_Coal:
return Texture::str_to_texid["coal"];
break;
case BlockType::BlockType_Cactus:
return is_side ? Texture::str_to_texid["common_cactus_side"] : Texture::str_to_texid["common_cactus_top"];
break;
case BlockType::BlockType_Shrub:
return Texture::str_to_texid["common_dead_shrub"];
break;
case BlockType::BlockType_TallGrass:
return Texture::str_to_texid["common_tall_grass"];
break;
case BlockType::BlockType_Diamond:
return Texture::str_to_texid["diamond"];
break;
case BlockType::BlockType_Iron:
return Texture::str_to_texid["iron"];
break;
case BlockType::BlockType_Leaves:
return Texture::str_to_texid["leaves"];
break;
case BlockType::BlockType_Log:
return is_side ? Texture::str_to_texid["log"] : Texture::str_to_texid["logtop"];
break;
case BlockType::BlockType_Water:
return Texture::str_to_texid["water"];
break;
case BlockType::BlockType_Error:
break;
case BlockType::BlockType_Air:
[[fallthrough]]
default:
assert(0); // should never reach here
}
}
//private:
bool m_active;
BlockType m_blockType;
};