refactor: warp everything in Cubed namespace

This commit is contained in:
2026-04-20 22:18:02 +08:00
parent 6c74f4582c
commit c2321a0a6e
49 changed files with 288 additions and 66 deletions

View File

@@ -6,6 +6,8 @@
#include <cmath>
#include <unordered_map>
namespace Cubed {
std::string get_biome_str(Biome biome) {
std::string str;
using enum Biome;
@@ -86,7 +88,7 @@ Biome safe_int_to_biome(int x) {
};
auto it = INT_TO_BIOME_MAP.find(x);
CUBED_ASSERT_MSG(it != INT_TO_BIOME_MAP.end(), ":Can't Find");
ASSERT_MSG(it != INT_TO_BIOME_MAP.end(), ":Can't Find");
return it->second;
}
@@ -131,4 +133,5 @@ int get_interpolated_height(float world_x, float world_z, float temp, float humi
return static_cast<int>(h);
}
}

View File

@@ -9,6 +9,9 @@
#include <numeric>
#include <utility>
namespace Cubed {
Chunk::Chunk(World& world, ChunkPos chunk_pos) :
m_world(world),
m_chunk_pos(chunk_pos)
@@ -61,10 +64,10 @@ const std::vector<uint8_t>& Chunk::get_chunk_blocks() const{
}
int Chunk::get_index(int x, int y, int z) {
CUBED_ASSERT(!(x < 0 || y < 0 || z < 0 || x >= CHUCK_SIZE || y >= WORLD_SIZE_Y || z >= CHUCK_SIZE));
ASSERT(!(x < 0 || y < 0 || z < 0 || x >= CHUCK_SIZE || y >= WORLD_SIZE_Y || z >= CHUCK_SIZE));
if ((x * WORLD_SIZE_Y + y) * CHUCK_SIZE + z < 0 || (x * WORLD_SIZE_Y + y) * CHUCK_SIZE + z >= CHUCK_SIZE * CHUCK_SIZE * WORLD_SIZE_Y) {
Logger::error("block pos x {} y {} z {} range error", x, y, z);
CUBED_ASSERT(0);
ASSERT(0);
}
return (x * WORLD_SIZE_Y + y) * CHUCK_SIZE + z;
}
@@ -208,7 +211,7 @@ void Chunk::init_chunk() {
void Chunk::upload_to_gpu() {
CUBED_ASSERT(is_need_upload());
ASSERT(is_need_upload());
if (m_vbo == 0) {
glGenBuffers(1, &m_vbo);
}
@@ -333,3 +336,4 @@ void Chunk::resolve_blocks() {
mark_dirty();
}
}

View File

@@ -7,6 +7,8 @@
#include <Cubed/tools/log.hpp>
#include <GLFW/glfw3.h>
namespace Cubed {
Player::Player(World& world, const std::string& name) :
m_world(world),
m_name(name)
@@ -529,4 +531,7 @@ void Player::update_scroll(double yoffset) {
}
}
}
}
}
}

View File

@@ -4,6 +4,9 @@
#include <array>
namespace Cubed {
using glm::ivec3;
static constexpr std::array<TreeStructNode, 62> TREE {{
@@ -95,4 +98,6 @@ bool build_tree(Chunk& chunk, const glm::ivec3& pos) {
chunk.set_chunk_block(Chunk::get_index(tree_node), d.id);
}
return true;
}
}

View File

@@ -9,6 +9,9 @@
#include <execution>
namespace Cubed {
static constexpr ChunkPos CHUNK_DIR[] {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}
};
@@ -44,7 +47,7 @@ const std::optional<LookBlock>& World::get_look_block_pos(const std::string& nam
auto it = m_players.find(HASH::str(name));
if (it == m_players.end()) {
Logger::error("Can't find player {}", name);
CUBED_ASSERT(0);
ASSERT(0);
return null_look_block;
}
@@ -65,7 +68,7 @@ Player& World::get_player(const std::string& name){
auto it = m_players.find(HASH::str(name));
if (it == m_players.end()) {
Logger::error("Can't find player {}", name);
CUBED_ASSERT(0);
ASSERT(0);
}
return it->second;
@@ -205,7 +208,7 @@ void World::gen_chunks_internal() {
ChunkPosSet required_chunks;
compute_required_chunks(required_chunks);
CUBED_ASSERT_MSG(!required_chunks.empty(), "required chunks is empty!!");
ASSERT_MSG(!required_chunks.empty(), "required chunks is empty!!");
std::vector<ChunkPos> need_gen_chunks_pos;
sync_and_collect_missing_chunks(need_gen_chunks_pos, required_chunks);
@@ -545,4 +548,6 @@ void World::update(float delta_time) {
void World::push_delete_vbo(GLuint vbo) {
std::lock_guard lk(m_delete_vbo_mutex);
m_pending_delete_vbo.push_back(vbo);
}
}