refactor: extract constants into separate constants.hpp file

This commit is contained in:
2026-04-25 16:25:47 +08:00
parent 055c4d687b
commit 8b5717a655
11 changed files with 43 additions and 31 deletions

View File

@@ -20,7 +20,9 @@ public:
static void window_reshape_callback(GLFWwindow* window, int new_width, int new_height); static void window_reshape_callback(GLFWwindow* window, int new_width, int new_height);
static void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset); static void mouse_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
static void cursor_enter_callback(GLFWwindow* window, int entered); static void cursor_enter_callback(GLFWwindow* window, int entered);
static void char_callback(GLFWwindow* window, unsigned int ch);
static int start_cubed_application(int argc, char** argv); static int start_cubed_application(int argc, char** argv);
static unsigned int seed(); static unsigned int seed();
static float delte_time(); static float delte_time();
static float get_fps(); static float get_fps();

View File

@@ -1,25 +1,10 @@
#pragma once #pragma once
#include <array>
#include <toml++/toml.hpp> #include <toml++/toml.hpp>
#include <Cubed/tools/cubed_assert.hpp> #include <Cubed/tools/cubed_assert.hpp>
namespace Cubed { namespace Cubed {
constexpr int WORLD_SIZE_Y = 256;
constexpr int MAX_BLOCK_NUM = 7;
constexpr int MAX_UI_NUM = 1;
constexpr int CHUCK_SIZE = 16;
constexpr int PRE_LOAD_DISTANCE = 24;
constexpr int MAX_DISTANCE = 128;
constexpr int MAX_BLOCK_STATUS = 1;
constexpr int MAX_CHARACTER = 128;
constexpr float NORMAL_FOV = 70.0f;
constexpr int MAX_BIOME_SUM = 4;
using HeightMapArray = std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;
template <typename T> template <typename T>
concept TomlValueType = concept TomlValueType =

View File

@@ -0,0 +1,22 @@
#pragma once
#include <array>
namespace Cubed {
constexpr int WORLD_SIZE_Y = 256;
constexpr int CHUCK_SIZE = 16;
constexpr int MAX_BLOCK_NUM = 7;
constexpr int MAX_UI_NUM = 1;
constexpr int MAX_BLOCK_STATUS = 1;
constexpr int MAX_BIOME_SUM = 4;
constexpr int MAX_CHARACTER = 128;
constexpr int PRE_LOAD_DISTANCE = 24;
constexpr int MAX_DISTANCE = 128;
constexpr float DEFAULT_FOV = 70.0f;
using HeightMapArray = std::array<std::array<float, CHUCK_SIZE>, CHUCK_SIZE>;
}

View File

@@ -29,6 +29,8 @@ private:
bool m_need_save_config = false; bool m_need_save_config = false;
int m_theme = 0; int m_theme = 0;
void show_settings_tab_item(); void show_settings_tab_item();
void show_world_tab_item();
void show_player_tab_item();
}; };

View File

@@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include <Cubed/config.hpp> #include <Cubed/config.hpp>
#include <Cubed/constants.hpp>
#include <Cubed/tools/cubed_assert.hpp> #include <Cubed/tools/cubed_assert.hpp>
namespace Cubed { namespace Cubed {

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Cubed/config.hpp> #include <Cubed/config.hpp>
#include <Cubed/constants.hpp>
#include <Cubed/primitive_data.hpp> #include <Cubed/primitive_data.hpp>
#include <Cubed/shader.hpp> #include <Cubed/shader.hpp>
#include <Cubed/ui/text.hpp> #include <Cubed/ui/text.hpp>
@@ -34,7 +35,7 @@ private:
World& m_world; World& m_world;
float m_aspect = 0.0f; float m_aspect = 0.0f;
float m_fov = NORMAL_FOV; float m_fov = DEFAULT_FOV;
glm::mat4 m_p_mat, m_v_mat, m_m_mat, m_mv_mat, m_mvp_mat; glm::mat4 m_p_mat, m_v_mat, m_m_mat, m_mv_mat, m_mvp_mat;
GLuint m_mv_loc; GLuint m_mv_loc;

View File

@@ -8,7 +8,6 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <Cubed/config.hpp>
#include <Cubed/primitive_data.hpp> #include <Cubed/primitive_data.hpp>
namespace Cubed { namespace Cubed {

View File

@@ -51,8 +51,7 @@ void App::init() {
glfwSetKeyCallback(m_window.get_glfw_window(), key_callback); glfwSetKeyCallback(m_window.get_glfw_window(), key_callback);
glfwSetScrollCallback(m_window.get_glfw_window(), mouse_scroll_callback); glfwSetScrollCallback(m_window.get_glfw_window(), mouse_scroll_callback);
glfwSetCursorEnterCallback(m_window.get_glfw_window(), cursor_enter_callback); glfwSetCursorEnterCallback(m_window.get_glfw_window(), cursor_enter_callback);
glfwSetCharCallback(m_window.get_glfw_window(), char_callback);
PerlinNoise::init(); PerlinNoise::init();
m_renderer.init(); m_renderer.init();
@@ -192,6 +191,15 @@ void App::cursor_enter_callback(GLFWwindow* window, int entered) {
} }
} }
void App::char_callback(GLFWwindow* window, unsigned int c) {
ImGuiIO& io = ImGui::GetIO();
App* app = static_cast<App*>(glfwGetWindowUserPointer(window));
ASSERT_MSG(app, "nullptr");
if (io.WantCaptureKeyboard && app->m_window.is_mouse_enable()) {
ImGui_ImplGlfw_CharCallback(window, c);
}
}
void App::render() { void App::render() {
if (glfwGetWindowAttrib(m_window.get_glfw_window(), GLFW_ICONIFIED) != 0) if (glfwGetWindowAttrib(m_window.get_glfw_window(), GLFW_ICONIFIED) != 0)

View File

@@ -7,17 +7,9 @@ static InputState input_state;
namespace Input { namespace Input {
InputState& get_input_state() { InputState& get_input_state() {
return input_state; return input_state;
} }
} }

View File

@@ -1,6 +1,6 @@
#include <Cubed/config.hpp>
#include <Cubed/map_table.hpp>
#include <Cubed/texture_manager.hpp> #include <Cubed/texture_manager.hpp>
#include <Cubed/constants.hpp>
#include <Cubed/map_table.hpp>
#include <Cubed/tools/cubed_assert.hpp> #include <Cubed/tools/cubed_assert.hpp>
#include <Cubed/tools/log.hpp> #include <Cubed/tools/log.hpp>

View File

@@ -1,6 +1,6 @@
#include <Cubed/shader.hpp>
#include <Cubed/tools/font.hpp> #include <Cubed/tools/font.hpp>
#include <Cubed/constants.hpp>
#include <Cubed/shader.hpp>
#include <Cubed/tools/log.hpp> #include <Cubed/tools/log.hpp>
#include <Cubed/tools/shader_tools.hpp> #include <Cubed/tools/shader_tools.hpp>