Compare commits

..

4 Commits

Author SHA1 Message Date
5b2f06b3ec feat: add about tab item 2026-04-26 21:14:13 +08:00
bd5665c935 fix: can't find iota 2026-04-26 17:34:11 +08:00
59ab47d317 feat: add anisotropic filtering control 2026-04-26 17:29:58 +08:00
e34a20599d feat: add tp in devpanel 2026-04-26 14:26:39 +08:00
6 changed files with 142 additions and 42 deletions

View File

@@ -8,17 +8,23 @@ 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;
float fov = 70.0f;
bool fullscreen = false;
bool v_sync = true;
float mouse_sensitivity = 0.15f;
int width = 800;
int height = 600;
int rendering_distance = 24;
int aniso = 1;
int max_aniso = 1;
bool is_enable_aniso = false;
bool is_support_aniso = true;
bool is_reload = true;
};
struct PlayerProfile {
int game_mode = 0;
int gait = 0;
float pos[3] = {0.0f, 0.0f, 0.0f};
};
struct TextEditing {
bool perlin_seed = false;
@@ -36,11 +42,13 @@ private:
TextEditing m_text_editing;
bool m_need_save_config = false;
int m_theme = 0;
void show_about_table_bar();
void show_biome_table_bar();
void show_settings_tab_item();
void show_world_tab_item();
void show_player_tab_item();
void update_config_view();
void update_player_profile();
};

View File

@@ -12,6 +12,8 @@ private:
GLuint m_block_status_array;
GLuint m_texture_array;
GLuint m_ui_array;
GLfloat m_max_aniso = 0.0f;
int m_aniso = 1;
void load_block_status(unsigned status_id);
void load_block_texture(unsigned block_id);
void load_ui_texture(unsigned id);
@@ -29,7 +31,7 @@ public:
void hot_reload();
void need_reload();
void update();
int max_aniso() const;
};

View File

@@ -45,7 +45,11 @@ void Config::create_config() {
rendering_distance = 24
[devpanel]
theme = 0 # 0 is Dark Theme, 1 is Light Theme
theme = 0 # 0 is Dark Theme, 1 is Light Theme
[texture]
aniso = 1 # i is the minimun value, indicating off
)"sv;
try {

View File

@@ -50,18 +50,7 @@ DevPanel::DevPanel(App& app) :
void DevPanel::init() {
m_player = &m_app.world().get_player("TestPlayer");
auto config = Config::get();
m_config.fov = static_cast<float>(config.val_view("player.fov").value_or(70.0));
m_config.fullscreen = config.val_view("window.fullscreen").value_or(false);
m_config.v_sync = config.val_view("window.V-Sync").value_or(true);
m_config.mouse_sensitivity = static_cast<float>(config.val_view("player.mouse_sensitivity").value_or(0.15));
m_config.width = config.val_view("window.width").value_or(800);
m_config.height = config.val_view("window.height").value_or(600);
m_config.rendering_distance = config.val_view("world.rendering_distance").value_or(24);
m_theme = config.val_view("devpanel.theme").value_or(0);
if (m_theme != 1 && m_theme != 0) {
m_theme = 0;
}
update_config_view();
update_player_profile();
}
@@ -87,6 +76,7 @@ void DevPanel::render() {
show_settings_tab_item();
show_world_tab_item();
show_player_tab_item();
show_about_table_bar();
ImGui::EndTabBar();
}
ImGui::End();
@@ -95,6 +85,29 @@ void DevPanel::render() {
}
void DevPanel::show_about_table_bar() {
if (ImGui::BeginTabItem("about")) {
ImGui::Text("Cubed - A cube game like Minecraft, using C++ and OpenGL.");
ImGui::Text("Author: zhenyan121");
ImGui::Separator();
ImGui::Text("Libraries Used");
ImGui::Text("glad");
ImGui::Text("GLFW");
ImGui::Text("SOIL2");
ImGui::Text("GLM");
ImGui::Text("FreeType");
ImGui::Text("toml++");
ImGui::Text("Dear ImGui");
ImGui::Separator();
ImGui::Text("Special Thanks");
ImGui::Text("TANGERIME");
ImGui::Text("SkyOnPole");
ImGui::Text("free_w_cloud");
ImGui::Text("Last but not least, thanks to you");
ImGui::EndTabItem();
}
}
void DevPanel::show_biome_table_bar() {
ImGui::Text("Biome");
if (ImGui::BeginTabBar("Biome")) {
@@ -186,7 +199,47 @@ void DevPanel::show_settings_tab_item() {
Config::get().set("window.V-Sync", m_config.v_sync);
m_app.window().hot_reload();
}
if (ImGui::Checkbox("Aniso", &m_config.is_enable_aniso)) {
m_config.is_reload = false;
if (m_config.is_enable_aniso) {
m_config.max_aniso = m_app.texture_manager().max_aniso();
if (m_config.max_aniso < 2) {
m_config.is_support_aniso = false;
} else {
m_config.aniso = 2;
}
} else {
m_config.aniso = 1;
}
}
if (m_config.is_enable_aniso) {
ImGui::SameLine();
if (!m_config.is_support_aniso) {
ImGui::Text("Not Support\n");
} else {
if (ImGui::SliderInt("##aniso", &m_config.aniso, 2, m_config.max_aniso)) {
m_config.is_reload = false;
int log = static_cast<int>(std::log2(m_config.aniso) + 0.5f);
m_config.aniso = static_cast<int>(std::pow(2, log));
if (m_config.aniso < 2) {
m_config.aniso = 2;
}
if (m_config.aniso > m_config.max_aniso) {
m_config.aniso = m_config.max_aniso;
}
}
}
}
if (ImGui::Button("ReloadTexture")) {
Config::get().set("texture.aniso", m_config.aniso);
m_app.texture_manager().hot_reload();
m_config.is_reload = true;
}
if (!m_config.is_reload) {
ImGui::SameLine();
ImGui::Text("Your need to click this button to apply config\n");
}
if (ImGui::Combo("Theme", &m_theme, THEMES, IM_ARRAYSIZE(THEMES))) {
if (m_theme == 0) {
ImGui::StyleColorsDark();
@@ -264,14 +317,19 @@ void DevPanel::show_player_tab_item() {
}
if (m_player->game_mode() == GameMode::CREATIVE) {
if (ImGui::Combo("Gait", &m_player_profile.gait, GAITS, IM_ARRAYSIZE(GAITS))) {
if (m_player_profile.gait == 0) {
m_player->gait() = Gait::WALK;
} else if (m_player_profile.gait == 1) {
m_player->gait() = Gait::RUN;
} else {
ASSERT_MSG(false, "Unknown Gait");
if (m_player_profile.gait == 0) {
m_player->gait() = Gait::WALK;
} else if (m_player_profile.gait == 1) {
m_player->gait() = Gait::RUN;
} else {
ASSERT_MSG(false, "Unknown Gait");
}
}
}
ImGui::DragFloat3("##player_pos", m_player_profile.pos);
ImGui::SameLine();
if (ImGui::Button("TP")) {
m_player->set_player_pos({m_player_profile.pos[0], m_player_profile.pos[1], m_player_profile.pos[2]});
}
ImGui::SliderFloat("Acceleration", &m_player->acceleration(), 1.0f, 200.0f);
ImGui::SliderFloat("Deceleration", &m_player->deceleration(), 1.0f, 200.0f);
@@ -306,7 +364,27 @@ void DevPanel::show_player_tab_item() {
ImGui::EndTabItem();
}
}
void DevPanel::update_config_view() {
auto config = Config::get();
m_config.fov = static_cast<float>(config.val_view("player.fov").value_or(70.0));
m_config.fullscreen = config.val_view("window.fullscreen").value_or(false);
m_config.v_sync = config.val_view("window.V-Sync").value_or(true);
m_config.mouse_sensitivity = static_cast<float>(config.val_view("player.mouse_sensitivity").value_or(0.15));
m_config.width = config.val_view("window.width").value_or(800);
m_config.height = config.val_view("window.height").value_or(600);
m_config.rendering_distance = config.val_view("world.rendering_distance").value_or(24);
m_theme = config.val_view("devpanel.theme").value_or(0);
if (m_theme != 1 && m_theme != 0) {
m_theme = 0;
}
m_config.aniso = config.val_view("texture.aniso").value_or(1);
m_config.max_aniso = m_app.texture_manager().max_aniso();
if (m_config.aniso <= 1) {
m_config.is_enable_aniso = false;
} else {
m_config.is_enable_aniso = true;
}
}
void DevPanel::update_player_profile() {
if (!m_player) {
Logger::error("Player is Nullptr");

View File

@@ -4,6 +4,8 @@
#include <Cubed/gameplay/tree.hpp>
#include <Cubed/tools/cubed_hash.hpp>
#include <Cubed/tools/perlin_noise.hpp>
#include <numeric>
namespace Cubed {
ChunkGenerator::ChunkGenerator(Chunk& chunk) :

View File

@@ -99,7 +99,13 @@ void TextureManager::load_ui_texture(unsigned id) {
}
void TextureManager::init_texture() {
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &m_max_aniso);
if (m_max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", m_max_aniso);
}
m_aniso = Config::get().get<int>("texture.aniso");
m_aniso = std::min(static_cast<int>(m_max_aniso), m_aniso);
Logger::info("Setting Texture Aniso is {}", m_aniso);
MapTable::init_map();
Logger::info("Map Init Success");
glGenTextures(1, &m_texture_array);
@@ -125,12 +131,8 @@ void TextureManager::init_texture() {
Tools::check_opengl_error();
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
Tools::check_opengl_error();
GLfloat max_aniso = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &max_aniso);
if (max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", max_aniso);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
if (m_aniso >= 1) {
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
}
glGenTextures(1, &m_block_status_array);
@@ -157,9 +159,8 @@ void TextureManager::init_texture() {
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
Tools::check_opengl_error();
if (max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", max_aniso);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
if (m_aniso >= 1) {
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
}
glGenTextures(1, &m_ui_array);
@@ -196,8 +197,13 @@ void TextureManager::need_reload() {
void TextureManager::hot_reload() {
delet_texture();
init_texture();
m_need_reload = false;
}
int TextureManager::max_aniso() const {
return static_cast<int>(m_max_aniso);
}
}