From 332acd49fb6944bb7fc96f786eb7d2c465bd5e08 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 21 Nov 2024 14:03:59 -0500 Subject: [PATCH] Better extend_struct --- launcher/src/ui/color.cpp | 2 +- launcher/src/ui/frame.cpp | 3 --- mods/include/mods/extend/extend.h | 5 +++-- mods/src/chat/ui.cpp | 2 +- mods/src/game-mode/ui.cpp | 2 +- mods/src/options/info.cpp | 2 +- mods/src/textures/lava.cpp | 6 +++--- mods/src/title-screen/welcome.cpp | 2 +- 8 files changed, 11 insertions(+), 13 deletions(-) diff --git a/launcher/src/ui/color.cpp b/launcher/src/ui/color.cpp index ba71d2fdb9..af9ef7ad4d 100644 --- a/launcher/src/ui/color.cpp +++ b/launcher/src/ui/color.cpp @@ -78,6 +78,6 @@ void Frame::patch_colors(ImGuiStyle &style) { }; for (const int target_color : target_colors_modify) { ImVec4 &color = style.Colors[target_color]; - color.z = color.x; + color.y = color.z = color.x; } } \ No newline at end of file diff --git a/launcher/src/ui/frame.cpp b/launcher/src/ui/frame.cpp index 551aa54b21..72d43f28b5 100644 --- a/launcher/src/ui/frame.cpp +++ b/launcher/src/ui/frame.cpp @@ -35,7 +35,6 @@ Frame::~Frame() { // Run Loop int Frame::run() { int ret = 0; - constexpr ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); while (!glfwWindowShouldClose(window) && ret == 0) { glfwPollEvents(); // Update Style @@ -61,8 +60,6 @@ int Frame::run() { ImGui::End(); // Render To OpenGL ImGui::Render(); - glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); - glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); } diff --git a/mods/include/mods/extend/extend.h b/mods/include/mods/extend/extend.h index c6b3e02137..7e270150d1 100644 --- a/mods/include/mods/extend/extend.h +++ b/mods/include/mods/extend/extend.h @@ -41,7 +41,7 @@ template Data *extend_get_data(Self *self) { return (Data *) (self + 1); } -template +template auto extend_struct(auto&&... args) -> decltype(Self::allocate()) { constexpr size_t size = sizeof(Self) + sizeof(Data); Self *out = (Self *) ::operator new(size); @@ -53,11 +53,12 @@ auto extend_struct(auto&&... args) -> decltype(Self::allocate()) { // Helpers #define CREATE_HELPER(name) \ struct Custom##name { \ + using _Self = name; \ explicit Custom##name(auto&&... args): self(((name *) this) - 1) { \ self->constructor(std::forward(args)...); \ self->vtable = get_vtable(); \ } \ - name *const self; \ + _Self *const self; \ static name##_vtable *get_vtable(); \ private: \ static void setup_vtable(name##_vtable *vtable); \ diff --git a/mods/src/chat/ui.cpp b/mods/src/chat/ui.cpp index bf313c0b10..dbeef2847c 100644 --- a/mods/src/chat/ui.cpp +++ b/mods/src/chat/ui.cpp @@ -115,7 +115,7 @@ struct ChatScreen final : TextInputScreen { } }; static Screen *create_chat_screen() { - return extend_struct(); + return extend_struct(); } // Init diff --git a/mods/src/game-mode/ui.cpp b/mods/src/game-mode/ui.cpp index 915a013911..dbc1877a57 100644 --- a/mods/src/game-mode/ui.cpp +++ b/mods/src/game-mode/ui.cpp @@ -136,7 +136,7 @@ struct CreateWorldScreen final : TextInputScreen { } }; static Screen *create_create_world_screen() { - return extend_struct(); + return extend_struct(); } // Unique Level Name (https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/client/gui/screens/CreateWorldScreen.cpp#L65-L83) diff --git a/mods/src/options/info.cpp b/mods/src/options/info.cpp index 4f33219d74..04be1e8efb 100644 --- a/mods/src/options/info.cpp +++ b/mods/src/options/info.cpp @@ -265,5 +265,5 @@ struct InfoScreen final : CustomScreen { // Create Screen Screen *_create_options_info_screen() { - return extend_struct(); + return extend_struct(); } diff --git a/mods/src/textures/lava.cpp b/mods/src/textures/lava.cpp index a7292a44ca..d7e86a9642 100644 --- a/mods/src/textures/lava.cpp +++ b/mods/src/textures/lava.cpp @@ -69,7 +69,7 @@ struct LavaTexture final : CustomDynamicTexture { } }; static DynamicTexture *create_lava_texture() { - return extend_struct(); + return extend_struct(); } // LavaSideTexture @@ -135,7 +135,7 @@ struct LavaSideTexture final : CustomDynamicTexture { } }; static DynamicTexture *create_lava_side_texture() { - return extend_struct(); + return extend_struct(); } // FireTexture @@ -195,7 +195,7 @@ struct FireTexture final : CustomDynamicTexture { } }; static DynamicTexture *create_fire_texture(const int a2) { - return extend_struct(a2); + return extend_struct(a2); } // Add Textures diff --git a/mods/src/title-screen/welcome.cpp b/mods/src/title-screen/welcome.cpp index 73fa7d1959..27e88ceba1 100644 --- a/mods/src/title-screen/welcome.cpp +++ b/mods/src/title-screen/welcome.cpp @@ -124,7 +124,7 @@ struct WelcomeScreen final : CustomScreen { } }; static Screen *create_welcome_screen() { - return extend_struct(); + return extend_struct(); } // Show Welcome Screen