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

@@ -1,5 +1,9 @@
#pragma once
#include <glm/glm.hpp>
namespace Cubed {
struct AABB {
glm::vec3 min{0.0f, 0.0f, 0.0f};
glm::vec3 max{0.0f, 0.0f, 0.0f};
@@ -16,4 +20,6 @@ struct AABB {
(min.y <= other.max.y && max.y >= other.min.y) &&
(min.z <= other.max.z && max.z >= other.min.z);
}
};
};
}

View File

@@ -6,6 +6,8 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
namespace Cubed {
class Player;
@@ -32,4 +34,6 @@ public:
const glm::vec3& get_camera_pos() const;
};
}

View File

@@ -1,4 +1,7 @@
#pragma once
namespace Cubed {
constexpr int WORLD_SIZE_Y = 256;
constexpr int MAX_BLOCK_NUM = 7;
constexpr int MAX_UI_NUM = 1;
@@ -147,4 +150,6 @@ struct Vertex2D {
float x = 0.0f, y = 0.0f;
float s = 0.0f, t = 0.0f;
float layer = 0.0f;
};
};
}

View File

@@ -4,6 +4,9 @@
#include <unordered_map>
namespace Cubed {
class DebugCollector {
public:
static DebugCollector& get();
@@ -17,4 +20,6 @@ public:
private:
std::unordered_map<std::size_t, Text> m_texts;
};
};
}

View File

@@ -2,6 +2,8 @@
#include <array>
#include <string>
namespace Cubed {
constexpr float BIOME_NOISE_FREQUENCY = 0.003f;
constexpr float PLAIN_FREQ = 0.4f;
@@ -28,3 +30,4 @@ BiomeHeightRange get_biome_height_range(Biome biome);
Biome safe_int_to_biome(int x);
int get_interpolated_height(float world_x, float world_z, float temp, float humid);
}

View File

@@ -7,6 +7,10 @@
#include <Cubed/config.hpp>
#include <Cubed/tools/cubed_assert.hpp>
namespace Cubed {
struct BlockTexture {
std::string name;
unsigned id;
@@ -62,6 +66,9 @@ const std::array<bool, MAX_BLOCK_NUM> TRANSPARENT_MAP {
};
inline bool is_in_transparent_map(unsigned id) {
CUBED_ASSERT_MSG(id < MAX_BLOCK_NUM, "ID is invaild");
ASSERT_MSG(id < MAX_BLOCK_NUM, "ID is invaild");
return TRANSPARENT_MAP[id];
};
};
}

View File

@@ -8,6 +8,9 @@
#include <Cubed/gameplay/chunk_pos.hpp>
#include <Cubed/gameplay/block.hpp>
namespace Cubed {
class World;
// if want to use, do init_chunk(), gen_vertex_data() and
class Chunk {
@@ -71,4 +74,7 @@ public:
void set_chunk_block(int index, unsigned id);
};
};
}

View File

@@ -4,6 +4,10 @@
#include <Cubed/tools/log.hpp>
#include <Cubed/tools/cubed_assert.hpp>
namespace Cubed {
struct ChunkPos {
int x;
int z;
@@ -28,3 +32,5 @@ struct ChunkPos {
};
};
}

View File

@@ -2,6 +2,10 @@
#include <stdexcept>
#include <string>
namespace Cubed {
enum class GameMode {
CREATIVE,
SPECTATOR
@@ -16,4 +20,7 @@ inline std::string to_str(GameMode mode) {
return {"Spective"};
}
throw std::invalid_argument{"GameMode is invaild"};
}
}

View File

@@ -11,6 +11,8 @@
#include <optional>
#include <string>
namespace Cubed {
enum class Gait{
WALK,
RUN
@@ -88,4 +90,7 @@ public:
void update_player_move_state(int key, int action);
void update_scroll(double yoffset);
};
};
}

View File

@@ -2,6 +2,8 @@
#include <glm/glm.hpp>
namespace Cubed {
class Chunk;
struct TreeStructNode {
@@ -9,4 +11,6 @@ struct TreeStructNode {
unsigned id = 0;
};
bool build_tree(Chunk& chunk, const glm::ivec3& pos);
bool build_tree(Chunk& chunk, const glm::ivec3& pos);
}

View File

@@ -9,6 +9,8 @@
#include <Cubed/AABB.hpp>
#include <Cubed/gameplay/chunk.hpp>
namespace Cubed {
struct ChunkRenderSnapshot {
GLuint vbo;
size_t vertex_count;
@@ -83,4 +85,6 @@ public:
void push_delete_vbo(GLuint vbo);
};
};
}

View File

@@ -2,6 +2,9 @@
#include <GLFW/glfw3.h>
namespace Cubed {
struct MoveState {
bool forward = false;
bool back = false;
@@ -30,4 +33,7 @@ namespace Input {
InputState& get_input_state();
}
}

View File

@@ -1,6 +1,9 @@
#pragma once
#include <string>
#include <unordered_map>
namespace Cubed {
class MapTable {
private:
static std::unordered_map<unsigned, std::string> id_to_name_map;
@@ -12,3 +15,5 @@ public:
static void init_map();
};
}

View File

@@ -7,6 +7,7 @@
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <vector>
namespace Cubed {
class Camera;
class TextureManager;
@@ -54,4 +55,6 @@ private:
void render_text();
void render_ui();
void render_world();
};
};
}

View File

@@ -2,6 +2,10 @@
#include <glad/glad.h>
#include <string>
namespace Cubed {
class Shader {
public:
Shader();
@@ -23,4 +27,6 @@ private:
std::size_t m_hash = 0;
std::string m_name = "-1";
};
};
}

View File

@@ -3,6 +3,8 @@
#include <Cubed/gameplay/block.hpp>
#include <Cubed/tools/shader_tools.hpp>
namespace Cubed {
class TextureManager {
private:
@@ -28,4 +30,7 @@ public:
void need_reload();
void update();
};
};
}

View File

@@ -1,5 +1,9 @@
#pragma once
#include <Cubed/tools/log.hpp>
namespace Cubed {
namespace Assert {
inline void msg(const char* condition, const char* file,
int line, const char* func,
@@ -17,20 +21,22 @@ namespace Assert {
}
#ifdef DEBUG_MODE
#define CUBED_ASSERT(cond) \
#define ASSERT(cond) \
do { \
if (!(cond)) { \
::Assert::msg(#cond, __FILE__, __LINE__, __func__); \
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__); \
} \
} while (0)
#define CUBED_ASSERT_MSG(cond, message) \
#define ASSERT_MSG(cond, message) \
do { \
if (!(cond)) { \
::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
::Cubed::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
} \
} while (0)
#else
#define CUBED_ASSERT(cond) ((void)0)
#define CUBED_ASSERT_MSG(cond, message) ((void)0)
#endif
#define ASSERT(cond) ((void)0)
#define ASSERT_MSG(cond, message) ((void)0)
#endif
}

View File

@@ -1,8 +1,14 @@
#pragma once
#include <string_view>
namespace Cubed {
namespace HASH {
inline std::size_t str(std::string_view value) {
return std::hash<std::string_view>{}(value);
}
}
}

View File

@@ -10,6 +10,9 @@
#include <Cubed/config.hpp>
namespace Cubed {
struct Character {
glm::vec2 uv_min;
glm::vec2 uv_max;
@@ -41,4 +44,6 @@ private:
void setup_font_character();
};
};
}

View File

@@ -6,6 +6,8 @@
#include <source_location>
#include <string>
namespace Cubed {
namespace Logger {
enum class Level {
TRACE,
@@ -94,3 +96,7 @@ namespace Logger {
}
}
}

View File

@@ -1,5 +1,11 @@
#pragma once
#include <glm/glm.hpp>
namespace Cubed {
namespace Math {
void extract_frustum_planes(const glm::mat4& mvp_matrix, std::vector<glm::vec4>& planes);
}
}

View File

@@ -2,6 +2,9 @@
#include <atomic>
#include <vector>
namespace Cubed {
class PerlinNoise {
public:
static void init();
@@ -13,4 +16,6 @@ private:
static float fade(float t);
static float lerp(float t, float a, float b);
static float grad(int hash, float x, float y, float z);
};
};
}

View File

@@ -4,6 +4,9 @@
#include <SOIL2.h>
#include <string>
namespace Cubed {
namespace Tools {
GLuint create_shader_program(const std::string& v_shader_path, const std::string& f_shader_path);
void print_shader_log(GLuint shader);
@@ -14,3 +17,5 @@ namespace Tools {
unsigned char* load_image_data(const std::string& tex_image_path);
}
}

View File

@@ -14,6 +14,9 @@ typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
#include <fstream>
#endif
namespace Cubed {
namespace Tools {
inline bool get_os_version(std::string& str) {
@@ -142,3 +145,4 @@ inline std::string get_cpu_info() {
}
}

View File

@@ -2,6 +2,9 @@
#include <Cubed/tools/cubed_assert.hpp>
#include <glm/glm.hpp>
namespace Cubed {
enum class Color {
BLACK,
WHITE,
@@ -49,7 +52,7 @@ inline constexpr glm::vec4 color_value(Color color) {
case Color::BROWN:
return vec4{0.647f, 0.165f, 0.165f, 1.0f};
default:
CUBED_ASSERT_MSG(false, "Unknown Color");
ASSERT_MSG(false, "Unknown Color");
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
}
@@ -63,3 +66,5 @@ inline glm::vec4 rgb255_to_float(int r, int g, int b, int a) {
return glm::vec4{nr, ng, nb, na};
}
}

View File

@@ -7,6 +7,8 @@
#include <Cubed/config.hpp>
#include <Cubed/ui/color.hpp>
namespace Cubed {
class Shader;
@@ -49,4 +51,6 @@ private:
void update_vertices();
void upload_to_gpu();
};
};
}

View File

@@ -1,5 +1,7 @@
#pragma once
#include <GLFW/glfw3.h>
namespace Cubed{
class Renderer;
class Window {
public:
@@ -22,4 +24,6 @@ private:
int m_height;
Renderer& m_renderer;
};
};
}