From 31bea0f6d1bf94ad075c94418dbf9983ef6f8eef Mon Sep 17 00:00:00 2001 From: KP Date: Mon, 29 Jul 2024 02:18:17 -0500 Subject: [PATCH] Add epic anime mascot --- Data/resources/textures/.kp3d/banner.png | Bin 0 -> 5420 bytes Data/sandbox-log.txt | 577 ++++------------------- KP3Dii/KP3Dii.vcxproj | 4 + KP3Dii/KP3Dii.vcxproj.filters | 4 + KP3Dii/src/KP3D_Game.cpp | 6 +- KP3Dii/src/KP3D_Material.cpp | 0 KP3Dii/src/KP3D_Material.h | 20 + KP3Dii/src/KP3D_Resources.cpp | 41 ++ KP3Dii/src/KP3D_Resources.h | 16 + Sandbox/src/Editor.cpp | 96 +++- Sandbox/src/Editor.h | 5 +- 11 files changed, 243 insertions(+), 526 deletions(-) create mode 100644 Data/resources/textures/.kp3d/banner.png create mode 100644 KP3Dii/src/KP3D_Material.cpp create mode 100644 KP3Dii/src/KP3D_Material.h create mode 100644 KP3Dii/src/KP3D_Resources.cpp create mode 100644 KP3Dii/src/KP3D_Resources.h diff --git a/Data/resources/textures/.kp3d/banner.png b/Data/resources/textures/.kp3d/banner.png new file mode 100644 index 0000000000000000000000000000000000000000..970cf7c45da212bfcfdafa332acb8052c141a797 GIT binary patch literal 5420 zcmWkyc|4R27qv@5vSk?x(T409Gxjz6mgKc$EkYP#H1;LiC`4flLs_y*Lg;;q5n-MX z!pIVjb;4sC%zS-++;i`__jmq3=cZa)8grc%InBVpz-4M;V9UV32>qS=SeXCfx;ppN z-^LhfYplmmHzc<5m$3NiTIez`G-h!g-(&sDZ&;h#8!|F7Mk{A*3aiNQ7(41|*EcJ!;$_$67CWm#QoQH4Y0Fs4^QkxXQBxf027mpd z^OupIg>Kr<>%b0P%9jmlzT#B7dnp-qQ?UW>{tLzT*}oT)_seNDs-BP9!{q;rL0 zpKObyG{|;Ygeso%ILTp7q2C@ta(`mvNO{ui(wC=kHf+Z`qbajsGR~c55nTFmr>pw{xOf5>vDmM#rC@WHDFvELhgI%u<_Xl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/KP3Dii.vcxproj.filters b/KP3Dii/KP3Dii.vcxproj.filters index 62374ac..4e93f3c 100644 --- a/KP3Dii/KP3Dii.vcxproj.filters +++ b/KP3Dii/KP3Dii.vcxproj.filters @@ -41,6 +41,8 @@ + + @@ -95,6 +97,8 @@ + + diff --git a/KP3Dii/src/KP3D_Game.cpp b/KP3Dii/src/KP3D_Game.cpp index 2941cf3..748d746 100644 --- a/KP3Dii/src/KP3D_Game.cpp +++ b/KP3Dii/src/KP3D_Game.cpp @@ -204,10 +204,10 @@ Game::Game(std::string path, std::string cfg_path, std::string log_path): ImGui::GetIO().IniFilename = NULL; ImFontConfig font_cfg; // Uncomment for non-anti-aliased fonts: - // font_cfg.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_Bitmap; - font_cfg.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_ForceAutoHint; + font_cfg.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_Bitmap; + font_cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_ForceAutoHint; font_cfg.FontNo = 2; - ImGui::GetIO().Fonts->AddFontFromFileTTF((sys::GetFontDir() + ".kp3d/msgothic.ttc").c_str(), 16.0f, &font_cfg); + ImGui::GetIO().Fonts->AddFontFromFileTTF((sys::GetFontDir() + ".kp3d/msgothic.ttc").c_str(), 13.0f, &font_cfg); font_cfg.FontNo = 0; ImGui::GetIO().Fonts->AddFontFromFileTTF((sys::GetFontDir() + ".kp3d/msgothic.ttc").c_str(), 13.0f, &font_cfg); ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; diff --git a/KP3Dii/src/KP3D_Material.cpp b/KP3Dii/src/KP3D_Material.cpp new file mode 100644 index 0000000..e69de29 diff --git a/KP3Dii/src/KP3D_Material.h b/KP3Dii/src/KP3D_Material.h new file mode 100644 index 0000000..cddc394 --- /dev/null +++ b/KP3Dii/src/KP3D_Material.h @@ -0,0 +1,20 @@ +#pragma once + +#include "KP3D_Common.h" +#include "KP3D_Texture.h" + +namespace kp3d { + +enum MaterialTextureIndex +{ + MAT_TEX_DIFFUSE, + MAT_TEX_NORMAL, + NUM_MAT_TEX +}; + +struct Material +{ + Texture textures[NUM_MAT_TEX]; +}; + +} // namespace kp3d diff --git a/KP3Dii/src/KP3D_Resources.cpp b/KP3Dii/src/KP3D_Resources.cpp new file mode 100644 index 0000000..d70dc56 --- /dev/null +++ b/KP3Dii/src/KP3D_Resources.cpp @@ -0,0 +1,41 @@ +#include "KP3D_Resources.h" + +#include +#include + +#include "KP3D_StringUtils.h" +#include "KP3D_SystemUtils.h" + +namespace kp3d::res { + +void LoadMaterials() +{ + texture_cache.clear(); + + // Load every available texture + for (const auto& entry: std::filesystem::recursive_directory_iterator(kp3d::sys::GetTextureDir())) + { + if (entry.is_directory()) + continue; + + std::filesystem::path entry_path = entry.path(); + std::string path_str = entry_path.string(); + + if (!kp3d::str::EndsWith(path_str, ".png") && !kp3d::str::EndsWith(path_str, ".jpg")) + continue; + + std::string filename = std::filesystem::proximate(path_str, kp3d::sys::GetTextureDir()).string(); + std::replace(filename.begin(), filename.end(), '\\', '/'); + + // texture_cache.emplace(filename, ); + + // new: + // m_loaded_res_mutex.lock(); + // m_raw_texture_data.push_back(new kp3d::RawTexture(filename)); + // kp3d::EventBus::GetInstance().PublishDeferred(new kp3d::TextureLoadEvent(filename, m_raw_texture_data.size() - 1)); + // m_num_loaded++; + // m_loaded_res_mutex.unlock(); + } +} + +} // namespace kp3d::res diff --git a/KP3Dii/src/KP3D_Resources.h b/KP3Dii/src/KP3D_Resources.h new file mode 100644 index 0000000..9bfc53d --- /dev/null +++ b/KP3Dii/src/KP3D_Resources.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include "KP3D_Common.h" +#include "KP3D_Texture.h" +#include "KP3D_Material.h" + +namespace kp3d::res { + +std::unordered_map texture_cache; + +void LoadMaterials(); + +} // namespace kp3d::res diff --git a/Sandbox/src/Editor.cpp b/Sandbox/src/Editor.cpp index 6da6bb5..56da3e6 100644 --- a/Sandbox/src/Editor.cpp +++ b/Sandbox/src/Editor.cpp @@ -31,6 +31,7 @@ inline float Distance(kp3d::Vec3 a, kp3d::Vec3 b) Editor::Editor() { + m_banner.Load(".kp3d/banner.png"); m_stem.Load("editor/stem.png"); m_block.Load("block.png", true); m_mode = MODE_BUILD; @@ -260,45 +261,72 @@ void Editor::RenderUI() if (ImGui::BeginMenu("View")) { ImGui::Checkbox("Info overlay", &show_info_overlay); + ImGui::Checkbox("Selection information", &show_selection_info); ImGui::Checkbox("Console", &kp3d::console::open); ImGui::EndMenu(); } + if (ImGui::BeginMenu("Help")) + { + ImGui::Checkbox("About KP3Dii", &show_about_view); + ImGui::EndMenu(); + } ImGui::EndMainMenuBar(); // Overlay RenderUIInfo(); + RenderUIAbout(); // Sector window // ImGui::SetNextWindowSize({400, 500}, ImGuiCond_FirstUseEver); - ImGui::SetNextWindowPos({20, 200}); - if (ImGui::Begin("Selection Information", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) + ImGui::SetNextWindowPos({20, 200}, ImGuiCond_FirstUseEver); + if (show_selection_info) { - if (kp3d::editor_hovered_batch) + if (ImGui::Begin("Selection Information", &show_selection_info, ImGuiWindowFlags_AlwaysAutoResize)) { - try { - const auto& info = std::any_cast(kp3d::editor_hovered_batch->userdata); - if (info.sector) - { - ImGui::SeparatorText("Hierarchy"); - ImGui::Text("ID: %u\n", info.sector->id); - ImGui::Text("Parent ID: %u %s\n", info.sector->parent_id, info.sector->parent_id == 0 ? "(N/A)" : ""); - ImGui::Text("Children (%u):\n", info.sector->children.size()); - ImGui::Indent(); - for (const auto& sc : info.sector->children) - ImGui::Text("- ID: %u", sc->id); - ImGui::Unindent(); - ImGui::SeparatorText("Properties"); - ImGui::InputFloat("Floor height", &info.sector->floor.base_height); - ImGui::InputFloat("Ceiling height", &info.sector->ceiling.base_height); - ImGui::Checkbox("Inverted", &info.sector->inverted); - } - } catch (std::bad_any_cast& e) { - KP3D_LOG_ERROR("Bad any cast: {}", e.what()); + if (m_mode == MODE_BUILD) + { + ImGui::Text("No selection"); + } + else if (m_mode == MODE_NORMAL) + { + if (kp3d::editor_hovered_batch) + { + try + { + const auto& info = std::any_cast(kp3d::editor_hovered_batch->userdata); + if (info.sector) + { + ImGui::SeparatorText("Hierarchy"); + ImGui::Text("ID: %u\n", info.sector->id); + ImGui::Text("Parent ID: %u %s\n", info.sector->parent_id, info.sector->parent_id == 0 ? "(N/A)" : ""); + ImGui::Text("Children (%u):\n", info.sector->children.size()); + ImGui::Indent(); + for (const auto& sc : info.sector->children) + ImGui::Text("- ID: %u", sc->id); + ImGui::Unindent(); + ImGui::SeparatorText("Properties"); + ImGui::InputFloat("Floor height", &info.sector->floor.base_height); + ImGui::InputFloat("Ceiling height", &info.sector->ceiling.base_height); + ImGui::Checkbox("Inverted", &info.sector->inverted); + ImGui::SeparatorText("Materials"); + ImGui::Text("Floor:"); + ImGui::ImageButton((ImTextureID) info.sector->floor.texture->GetGLID(), {128, 128}); + ImGui::Text("Ceiling:"); + ImGui::ImageButton((ImTextureID)info.sector->ceiling.texture->GetGLID(), { 128, 128 }); + } + } + catch (std::bad_any_cast& e) + { + KP3D_LOG_ERROR("Bad any cast: {}", e.what()); + } + } } - } - ImGui::End(); + ImGui::End(); + } } + + //ImGui::ShowDemoWindow(); } void Editor::RenderUIInfo() @@ -332,6 +360,26 @@ void Editor::RenderUIInfo() } } +void Editor::RenderUIAbout() +{ + if (!show_about_view) + return; + + if (ImGui::Begin("About KP3Dii", &show_about_view, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::Image((ImTextureID)m_banner.GetGLID(), {500.0f, 200.0f}); + ImGui::Separator(); + ImGui::Text("The swaggiest game engine ever made, you dig?"); + ImGui::Text("This map editor needs work. Consider it an ad-hoc release until\nI get time to put something nicer together."); + ImGui::Text(fmt::format("\nVersion {:.{}f} {}", KP3D_VERSION, 1, KP3D_VERSION <= 2.1 ? "(in-dev dist.)" : "").c_str()); + ImGui::Text("https://www.kpworld.xyz/"); + ImGui::Separator(); + ImGui::Text("Copyright (C) kpworld.xyz 2018-2024"); + + ImGui::End(); + } +} + void Editor::OnScrollWheel(const kp3d::ScrollWheelEvent* e) { using namespace kp3d; diff --git a/Sandbox/src/Editor.h b/Sandbox/src/Editor.h index ca90602..933b096 100644 --- a/Sandbox/src/Editor.h +++ b/Sandbox/src/Editor.h @@ -29,6 +29,7 @@ public: void RenderUI(); void RenderUIInfo(); + void RenderUIAbout(); void OnScrollWheel(const kp3d::ScrollWheelEvent* e); void OnKeyPress(const kp3d::KeyPressEvent* e); @@ -37,6 +38,7 @@ private: void RenderLine(kp3d::Vec3 start, kp3d::Vec3 end, kp3d::uint color); private: + kp3d::Texture m_banner; kp3d::Texture m_stem; kp3d::Texture m_block; kp3d::Vec3 m_stem_pos; @@ -44,6 +46,7 @@ private: // TODO: Refactor me! bool show_info_overlay = true; - + bool show_selection_info = false; + bool show_about_view = false; };