feat: add random seed

This commit is contained in:
2026-04-06 21:56:15 +08:00
parent f37f458b42
commit 662e3ee798
7 changed files with 48 additions and 21 deletions

View File

@@ -29,10 +29,7 @@ int Chunk::get_index(int x, int y, int z) {
void Chunk::gen_vertex_data() {
m_vertexs_data.clear();
if (m_vbo != 0) {
glDeleteBuffers(1, &m_vbo);
m_vbo = 0;
}
for (int x = 0; x < CHUCK_SIZE; x++) {
for (int y = 0; y < WORLD_SIZE_Y; y++) {
@@ -67,7 +64,11 @@ void Chunk::gen_vertex_data() {
}
}
glGenBuffers(1, &m_vbo);
if (m_vbo == 0) {
glGenBuffers(1, &m_vbo);
}
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, m_vertexs_data.size() * sizeof(Vertex), m_vertexs_data.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

View File

@@ -230,13 +230,30 @@ bool World::is_aabb_in_frustum(const glm::vec3& center, const glm::vec3& half_ex
}
return true;
}
int World::get_block(const glm::ivec3& block_pos) const {
auto [chunk_x, chunk_z] = chunk_pos(block_pos.x, block_pos.z);
auto it = m_chunks.find(ChunkPos{chunk_x, chunk_z});
if (it == m_chunks.end()) {
return 0;
}
const auto& chunk_blocks = it->second.get_chunk_blocks();
int x, y, z;
y = block_pos.y;
x = block_pos.x - chunk_x * CHUCK_SIZE;
z = block_pos.z - chunk_z * CHUCK_SIZE;
if (x < 0 || y < 0 || z < 0 || x >= CHUCK_SIZE || y >= WORLD_SIZE_Y || z >= CHUCK_SIZE) {
return 0;
}
return chunk_blocks[Chunk::get_index(x, y, z)];
}
bool World::is_block(const glm::ivec3& block_pos) const{
int world_x, world_y, world_z;
world_x = block_pos.x;
world_y = block_pos.y;
world_z = block_pos.z;
auto [chunk_x, chunk_z] = chunk_pos(world_x, world_z);
auto [chunk_x, chunk_z] = chunk_pos(block_pos.x, block_pos.z);
auto it = m_chunks.find(ChunkPos{chunk_x, chunk_z});
@@ -246,9 +263,9 @@ bool World::is_block(const glm::ivec3& block_pos) const{
const auto& chunk_blocks = it->second.get_chunk_blocks();
int x, y, z;
y = world_y;
x = world_x - chunk_x * CHUCK_SIZE;
z = world_z - chunk_z * CHUCK_SIZE;
y = block_pos.y;
x = block_pos.x - chunk_x * CHUCK_SIZE;
z = block_pos.z - chunk_z * CHUCK_SIZE;
if (x < 0 || y < 0 || z < 0 || x >= CHUCK_SIZE || y >= WORLD_SIZE_Y || z >= CHUCK_SIZE) {
return false;
}