mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
Compare commits
4 Commits
c5a78185ba
...
5b2f06b3ec
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b2f06b3ec | |||
| bd5665c935 | |||
| 59ab47d317 | |||
| e34a20599d |
@@ -8,17 +8,23 @@ class App;
|
|||||||
class Player;
|
class Player;
|
||||||
class DevPanel {
|
class DevPanel {
|
||||||
struct ConfigView {
|
struct ConfigView {
|
||||||
float fov;
|
float fov = 70.0f;
|
||||||
bool fullscreen;
|
bool fullscreen = false;
|
||||||
bool v_sync;
|
bool v_sync = true;
|
||||||
float mouse_sensitivity;
|
float mouse_sensitivity = 0.15f;
|
||||||
int width;
|
int width = 800;
|
||||||
int height;
|
int height = 600;
|
||||||
int rendering_distance;
|
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 {
|
struct PlayerProfile {
|
||||||
int game_mode = 0;
|
int game_mode = 0;
|
||||||
int gait = 0;
|
int gait = 0;
|
||||||
|
float pos[3] = {0.0f, 0.0f, 0.0f};
|
||||||
};
|
};
|
||||||
struct TextEditing {
|
struct TextEditing {
|
||||||
bool perlin_seed = false;
|
bool perlin_seed = false;
|
||||||
@@ -36,11 +42,13 @@ private:
|
|||||||
TextEditing m_text_editing;
|
TextEditing m_text_editing;
|
||||||
bool m_need_save_config = false;
|
bool m_need_save_config = false;
|
||||||
int m_theme = 0;
|
int m_theme = 0;
|
||||||
|
void show_about_table_bar();
|
||||||
void show_biome_table_bar();
|
void show_biome_table_bar();
|
||||||
void show_settings_tab_item();
|
void show_settings_tab_item();
|
||||||
void show_world_tab_item();
|
void show_world_tab_item();
|
||||||
void show_player_tab_item();
|
void show_player_tab_item();
|
||||||
|
|
||||||
|
void update_config_view();
|
||||||
void update_player_profile();
|
void update_player_profile();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ private:
|
|||||||
GLuint m_block_status_array;
|
GLuint m_block_status_array;
|
||||||
GLuint m_texture_array;
|
GLuint m_texture_array;
|
||||||
GLuint m_ui_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_status(unsigned status_id);
|
||||||
void load_block_texture(unsigned block_id);
|
void load_block_texture(unsigned block_id);
|
||||||
void load_ui_texture(unsigned id);
|
void load_ui_texture(unsigned id);
|
||||||
@@ -29,7 +31,7 @@ public:
|
|||||||
void hot_reload();
|
void hot_reload();
|
||||||
void need_reload();
|
void need_reload();
|
||||||
void update();
|
void update();
|
||||||
|
int max_aniso() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ void Config::create_config() {
|
|||||||
rendering_distance = 24
|
rendering_distance = 24
|
||||||
|
|
||||||
[devpanel]
|
[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;
|
)"sv;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -50,18 +50,7 @@ DevPanel::DevPanel(App& app) :
|
|||||||
|
|
||||||
void DevPanel::init() {
|
void DevPanel::init() {
|
||||||
m_player = &m_app.world().get_player("TestPlayer");
|
m_player = &m_app.world().get_player("TestPlayer");
|
||||||
auto config = Config::get();
|
update_config_view();
|
||||||
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_player_profile();
|
update_player_profile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +76,7 @@ void DevPanel::render() {
|
|||||||
show_settings_tab_item();
|
show_settings_tab_item();
|
||||||
show_world_tab_item();
|
show_world_tab_item();
|
||||||
show_player_tab_item();
|
show_player_tab_item();
|
||||||
|
show_about_table_bar();
|
||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
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() {
|
void DevPanel::show_biome_table_bar() {
|
||||||
ImGui::Text("Biome");
|
ImGui::Text("Biome");
|
||||||
if (ImGui::BeginTabBar("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);
|
Config::get().set("window.V-Sync", m_config.v_sync);
|
||||||
m_app.window().hot_reload();
|
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 (ImGui::Combo("Theme", &m_theme, THEMES, IM_ARRAYSIZE(THEMES))) {
|
||||||
if (m_theme == 0) {
|
if (m_theme == 0) {
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
@@ -264,14 +317,19 @@ void DevPanel::show_player_tab_item() {
|
|||||||
}
|
}
|
||||||
if (m_player->game_mode() == GameMode::CREATIVE) {
|
if (m_player->game_mode() == GameMode::CREATIVE) {
|
||||||
if (ImGui::Combo("Gait", &m_player_profile.gait, GAITS, IM_ARRAYSIZE(GAITS))) {
|
if (ImGui::Combo("Gait", &m_player_profile.gait, GAITS, IM_ARRAYSIZE(GAITS))) {
|
||||||
if (m_player_profile.gait == 0) {
|
if (m_player_profile.gait == 0) {
|
||||||
m_player->gait() = Gait::WALK;
|
m_player->gait() = Gait::WALK;
|
||||||
} else if (m_player_profile.gait == 1) {
|
} else if (m_player_profile.gait == 1) {
|
||||||
m_player->gait() = Gait::RUN;
|
m_player->gait() = Gait::RUN;
|
||||||
} else {
|
} else {
|
||||||
ASSERT_MSG(false, "Unknown Gait");
|
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("Acceleration", &m_player->acceleration(), 1.0f, 200.0f);
|
||||||
ImGui::SliderFloat("Deceleration", &m_player->deceleration(), 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();
|
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() {
|
void DevPanel::update_player_profile() {
|
||||||
if (!m_player) {
|
if (!m_player) {
|
||||||
Logger::error("Player is Nullptr");
|
Logger::error("Player is Nullptr");
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <Cubed/gameplay/tree.hpp>
|
#include <Cubed/gameplay/tree.hpp>
|
||||||
#include <Cubed/tools/cubed_hash.hpp>
|
#include <Cubed/tools/cubed_hash.hpp>
|
||||||
#include <Cubed/tools/perlin_noise.hpp>
|
#include <Cubed/tools/perlin_noise.hpp>
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
ChunkGenerator::ChunkGenerator(Chunk& chunk) :
|
ChunkGenerator::ChunkGenerator(Chunk& chunk) :
|
||||||
|
|||||||
@@ -99,7 +99,13 @@ void TextureManager::load_ui_texture(unsigned id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureManager::init_texture() {
|
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();
|
MapTable::init_map();
|
||||||
Logger::info("Map Init Success");
|
Logger::info("Map Init Success");
|
||||||
glGenTextures(1, &m_texture_array);
|
glGenTextures(1, &m_texture_array);
|
||||||
@@ -125,12 +131,8 @@ void TextureManager::init_texture() {
|
|||||||
Tools::check_opengl_error();
|
Tools::check_opengl_error();
|
||||||
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
||||||
Tools::check_opengl_error();
|
Tools::check_opengl_error();
|
||||||
|
if (m_aniso >= 1) {
|
||||||
GLfloat max_aniso = 0.0f;
|
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_block_status_array);
|
glGenTextures(1, &m_block_status_array);
|
||||||
@@ -157,9 +159,8 @@ void TextureManager::init_texture() {
|
|||||||
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
||||||
Tools::check_opengl_error();
|
Tools::check_opengl_error();
|
||||||
|
|
||||||
if (max_aniso > 0.0f) {
|
if (m_aniso >= 1) {
|
||||||
Logger::info("Support anisotropic filtering max_aniso is {}", max_aniso);
|
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
|
||||||
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_ui_array);
|
glGenTextures(1, &m_ui_array);
|
||||||
@@ -196,8 +197,13 @@ void TextureManager::need_reload() {
|
|||||||
|
|
||||||
void TextureManager::hot_reload() {
|
void TextureManager::hot_reload() {
|
||||||
delet_texture();
|
delet_texture();
|
||||||
|
|
||||||
init_texture();
|
init_texture();
|
||||||
m_need_reload = false;
|
m_need_reload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextureManager::max_aniso() const {
|
||||||
|
return static_cast<int>(m_max_aniso);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user