feat: add DevPanel

This commit is contained in:
2026-04-25 14:24:50 +08:00
parent ada0603a2f
commit 4ca2133ff3
13 changed files with 404 additions and 39 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <Cubed/camera.hpp>
#include <Cubed/dev_panel.hpp>
#include <Cubed/gameplay/world.hpp>
#include <Cubed/input.hpp>
#include <Cubed/renderer.hpp>
@@ -18,16 +19,26 @@ public:
static void window_focus_callback(GLFWwindow* window, int focused);
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 cursor_enter_callback(GLFWwindow* window, int entered);
static int start_cubed_application(int argc, char** argv);
static unsigned int seed();
static float delte_time();
static float get_fps();
Camera& camera();
DevPanel& dev_panel();
Renderer& renderer();
TextureManager& texture_manager();
Window& window();
World& world();
private:
Camera m_camera;
TextureManager m_texture_manager;
World m_world;
Renderer m_renderer{m_camera, m_world, m_texture_manager};
DevPanel m_dev_panel{*this};
Renderer m_renderer{m_camera, m_world, m_texture_manager, m_dev_panel};
Window m_window{m_renderer};

View File

@@ -114,8 +114,14 @@ public:
std::abort();
}
table->insert_or_assign(n_key, std::forward<T>(val));
}
template <typename T>
void set_and_save(std::string_view key, T&& val) {
set(key, std::forward(val));
save_to_file();
}
toml::node_view<toml::node> val_view(std::string_view key);
private:

View File

@@ -0,0 +1,35 @@
#pragma once
#include <toml++/toml.hpp>
namespace Cubed {
class App;
class Player;
class DevPanel {
struct ConfigView {
float fov;
bool fullscreen;
bool v_sync;
float mouse_sensitivity;
int width;
int height;
int rendering_distance;
};
public:
DevPanel(App& app);
void init();
void render();
private:
App& m_app;
ConfigView m_config;
Player* m_player;
bool m_need_save_config = false;
int m_theme = 0;
void show_settings_tab_item();
};
}

View File

@@ -13,11 +13,12 @@ namespace Cubed {
class Camera;
class TextureManager;
class World;
class DevPanel;
class Renderer {
public:
constexpr static int NUM_VAO = 5;
Renderer(const Camera& camera, World& world, const TextureManager& texture_manager);
Renderer(const Camera& camera, World& world, const TextureManager& texture_manager, DevPanel& dev_panel);
~Renderer();
void hot_reload();
void init();
@@ -28,6 +29,7 @@ public:
private:
const Camera& m_camera;
DevPanel& m_dev_panel;
const TextureManager& m_texture_manager;
World& m_world;
@@ -57,6 +59,7 @@ private:
void render_text();
void render_ui();
void render_world();
void render_dev_panel();
};
}

View File

@@ -5,6 +5,7 @@
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <filesystem>
#include <string>
#include <unordered_map>
@@ -31,6 +32,7 @@ public:
static std::vector<Vertex2D> vertices(const std::string& text, float x = 0.0f, float y = 0.0f, float scale = 1.0f);
static GLuint text_texture();
static const std::filesystem::path& font_path();
private:
FT_Library m_ft;
FT_Face m_face;
@@ -39,6 +41,7 @@ private:
float m_texture_height = 64;
static inline GLuint m_text_texture;
static inline std::filesystem::path m_font_path{ASSETS_PATH "fonts/IBMPlexSans-Regular.ttf"};
std::unordered_map<char8_t, Character> m_characters;
void load_character(char8_t c);

View File

@@ -12,6 +12,7 @@ public:
const GLFWwindow* get_glfw_window() const;
GLFWwindow* get_glfw_window();
void init();
void imgui_init();
void update_viewport();
// end of frame to reload!
void hot_reload();