feat: add dirt and stone

This commit is contained in:
2026-04-16 15:05:52 +08:00
parent 6362536daa
commit cf9aaa62a7
20 changed files with 23 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 B

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
constexpr int WORLD_SIZE_Y = 256; constexpr int WORLD_SIZE_Y = 256;
constexpr int MAX_BLOCK_NUM = 2; constexpr int MAX_BLOCK_NUM = 4;
constexpr int MAX_UI_NUM = 1; constexpr int MAX_UI_NUM = 1;
constexpr int CHUCK_SIZE = 16; constexpr int CHUCK_SIZE = 16;

View File

@@ -216,7 +216,7 @@ void Chunk::init_chunk() {
for (int x = 0; x < CHUCK_SIZE; x++) { for (int x = 0; x < CHUCK_SIZE; x++) {
for (int y = 0; y < 5; y++) { for (int y = 0; y < 5; y++) {
for (int z = 0; z < CHUCK_SIZE; z++) { for (int z = 0; z < CHUCK_SIZE; z++) {
m_blocks[get_index(x, y, z)] = 1; m_blocks[get_index(x, y, z)] = 3;
} }
} }
} }
@@ -233,10 +233,15 @@ void Chunk::init_chunk() {
0.125f * PerlinNoise::noise(world_x * 0.04f, world_z * 0.04f, 0.5f); 0.125f * PerlinNoise::noise(world_x * 0.04f, world_z * 0.04f, 0.5f);
int y_max = height * noise; int y_max = height * noise;
for (int y = 5; y < y_max; y++) { for (int y = 5; y < y_max - 5; y++) {
m_blocks[get_index(x, y, z)] = 3;
}
for (int y = y_max - 5; y < y_max - 1; y++) {
m_blocks[get_index(x, y, z)] = 2;
}
for (int y = y_max - 1; y < y_max; y++) {
m_blocks[get_index(x, y, z)] = 1; m_blocks[get_index(x, y, z)] = 1;
} }
} }
} }

View File

@@ -6,6 +6,13 @@
std::unordered_map<unsigned, std::string> MapTable::id_to_name_map; std::unordered_map<unsigned, std::string> MapTable::id_to_name_map;
std::unordered_map<size_t, unsigned> MapTable::name_to_id_map; std::unordered_map<size_t, unsigned> MapTable::name_to_id_map;
constexpr std::array<std::string, MAX_BLOCK_NUM> BLOCK_REISTER{
"air",
"grass_block",
"dirt",
"stone"
};
const std::string& MapTable::get_name_from_id(unsigned id) { const std::string& MapTable::get_name_from_id(unsigned id) {
auto it = id_to_name_map.find(id); auto it = id_to_name_map.find(id);
@@ -17,13 +24,16 @@ const unsigned MapTable::get_id_from_name(const std::string& name) {
CUBED_ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist"); CUBED_ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist");
return it->second; return it->second;
} }
void MapTable::init_map() { void MapTable::init_map() {
id_to_name_map.reserve(MAX_BLOCK_NUM); id_to_name_map.reserve(MAX_BLOCK_NUM);
name_to_id_map.reserve(MAX_BLOCK_NUM); name_to_id_map.reserve(MAX_BLOCK_NUM);
id_to_name_map[0] = "air";
name_to_id_map[HASH::str("air")] = 0; for (int i = 0; i < MAX_BLOCK_NUM; i++) {
id_to_name_map[1] = "grass_block"; id_to_name_map[i] = BLOCK_REISTER[i];
name_to_id_map[HASH::str("grass_block")] = 1; name_to_id_map[HASH::str(BLOCK_REISTER[i])] = i;
}
} }