Better extend_struct

This commit is contained in:
TheBrokenRail 2024-11-21 14:03:59 -05:00
parent c2750bbaec
commit 332acd49fb
8 changed files with 11 additions and 13 deletions

View File

@ -78,6 +78,6 @@ void Frame::patch_colors(ImGuiStyle &style) {
}; };
for (const int target_color : target_colors_modify) { for (const int target_color : target_colors_modify) {
ImVec4 &color = style.Colors[target_color]; ImVec4 &color = style.Colors[target_color];
color.z = color.x; color.y = color.z = color.x;
} }
} }

View File

@ -35,7 +35,6 @@ Frame::~Frame() {
// Run Loop // Run Loop
int Frame::run() { int Frame::run() {
int ret = 0; int ret = 0;
constexpr ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
while (!glfwWindowShouldClose(window) && ret == 0) { while (!glfwWindowShouldClose(window) && ret == 0) {
glfwPollEvents(); glfwPollEvents();
// Update Style // Update Style
@ -61,8 +60,6 @@ int Frame::run() {
ImGui::End(); ImGui::End();
// Render To OpenGL // Render To OpenGL
ImGui::Render(); 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()); ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }

View File

@ -41,7 +41,7 @@ template <typename Self, typename Data>
Data *extend_get_data(Self *self) { Data *extend_get_data(Self *self) {
return (Data *) (self + 1); return (Data *) (self + 1);
} }
template <typename Self, typename Data> template <typename Data, typename Self = typename Data::_Self>
auto extend_struct(auto&&... args) -> decltype(Self::allocate()) { auto extend_struct(auto&&... args) -> decltype(Self::allocate()) {
constexpr size_t size = sizeof(Self) + sizeof(Data); constexpr size_t size = sizeof(Self) + sizeof(Data);
Self *out = (Self *) ::operator new(size); Self *out = (Self *) ::operator new(size);
@ -53,11 +53,12 @@ auto extend_struct(auto&&... args) -> decltype(Self::allocate()) {
// Helpers // Helpers
#define CREATE_HELPER(name) \ #define CREATE_HELPER(name) \
struct Custom##name { \ struct Custom##name { \
using _Self = name; \
explicit Custom##name(auto&&... args): self(((name *) this) - 1) { \ explicit Custom##name(auto&&... args): self(((name *) this) - 1) { \
self->constructor(std::forward<decltype(args)>(args)...); \ self->constructor(std::forward<decltype(args)>(args)...); \
self->vtable = get_vtable(); \ self->vtable = get_vtable(); \
} \ } \
name *const self; \ _Self *const self; \
static name##_vtable *get_vtable(); \ static name##_vtable *get_vtable(); \
private: \ private: \
static void setup_vtable(name##_vtable *vtable); \ static void setup_vtable(name##_vtable *vtable); \

View File

@ -115,7 +115,7 @@ struct ChatScreen final : TextInputScreen {
} }
}; };
static Screen *create_chat_screen() { static Screen *create_chat_screen() {
return extend_struct<Screen, ChatScreen>(); return extend_struct<ChatScreen>();
} }
// Init // Init

View File

@ -136,7 +136,7 @@ struct CreateWorldScreen final : TextInputScreen {
} }
}; };
static Screen *create_create_world_screen() { static Screen *create_create_world_screen() {
return extend_struct<Screen, CreateWorldScreen>(); return extend_struct<CreateWorldScreen>();
} }
// Unique Level Name (https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/client/gui/screens/CreateWorldScreen.cpp#L65-L83) // Unique Level Name (https://github.com/ReMinecraftPE/mcpe/blob/d7a8b6baecf8b3b050538abdbc976f690312aa2d/source/client/gui/screens/CreateWorldScreen.cpp#L65-L83)

View File

@ -265,5 +265,5 @@ struct InfoScreen final : CustomScreen {
// Create Screen // Create Screen
Screen *_create_options_info_screen() { Screen *_create_options_info_screen() {
return extend_struct<Screen, InfoScreen>(); return extend_struct<InfoScreen>();
} }

View File

@ -69,7 +69,7 @@ struct LavaTexture final : CustomDynamicTexture {
} }
}; };
static DynamicTexture *create_lava_texture() { static DynamicTexture *create_lava_texture() {
return extend_struct<DynamicTexture, LavaTexture>(); return extend_struct<LavaTexture>();
} }
// LavaSideTexture // LavaSideTexture
@ -135,7 +135,7 @@ struct LavaSideTexture final : CustomDynamicTexture {
} }
}; };
static DynamicTexture *create_lava_side_texture() { static DynamicTexture *create_lava_side_texture() {
return extend_struct<DynamicTexture, LavaSideTexture>(); return extend_struct<LavaSideTexture>();
} }
// FireTexture // FireTexture
@ -195,7 +195,7 @@ struct FireTexture final : CustomDynamicTexture {
} }
}; };
static DynamicTexture *create_fire_texture(const int a2) { static DynamicTexture *create_fire_texture(const int a2) {
return extend_struct<DynamicTexture, FireTexture>(a2); return extend_struct<FireTexture>(a2);
} }
// Add Textures // Add Textures

View File

@ -124,7 +124,7 @@ struct WelcomeScreen final : CustomScreen {
} }
}; };
static Screen *create_welcome_screen() { static Screen *create_welcome_screen() {
return extend_struct<Screen, WelcomeScreen>(); return extend_struct<WelcomeScreen>();
} }
// Show Welcome Screen // Show Welcome Screen