Better extend_struct
This commit is contained in:
parent
c2750bbaec
commit
332acd49fb
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ template <typename Self, typename Data>
|
||||
Data *extend_get_data(Self *self) {
|
||||
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()) {
|
||||
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<decltype(args)>(args)...); \
|
||||
self->vtable = get_vtable(); \
|
||||
} \
|
||||
name *const self; \
|
||||
_Self *const self; \
|
||||
static name##_vtable *get_vtable(); \
|
||||
private: \
|
||||
static void setup_vtable(name##_vtable *vtable); \
|
||||
|
@ -115,7 +115,7 @@ struct ChatScreen final : TextInputScreen {
|
||||
}
|
||||
};
|
||||
static Screen *create_chat_screen() {
|
||||
return extend_struct<Screen, ChatScreen>();
|
||||
return extend_struct<ChatScreen>();
|
||||
}
|
||||
|
||||
// Init
|
||||
|
@ -136,7 +136,7 @@ struct CreateWorldScreen final : TextInputScreen {
|
||||
}
|
||||
};
|
||||
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)
|
||||
|
@ -265,5 +265,5 @@ struct InfoScreen final : CustomScreen {
|
||||
|
||||
// Create Screen
|
||||
Screen *_create_options_info_screen() {
|
||||
return extend_struct<Screen, InfoScreen>();
|
||||
return extend_struct<InfoScreen>();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ struct LavaTexture final : CustomDynamicTexture {
|
||||
}
|
||||
};
|
||||
static DynamicTexture *create_lava_texture() {
|
||||
return extend_struct<DynamicTexture, LavaTexture>();
|
||||
return extend_struct<LavaTexture>();
|
||||
}
|
||||
|
||||
// LavaSideTexture
|
||||
@ -135,7 +135,7 @@ struct LavaSideTexture final : CustomDynamicTexture {
|
||||
}
|
||||
};
|
||||
static DynamicTexture *create_lava_side_texture() {
|
||||
return extend_struct<DynamicTexture, LavaSideTexture>();
|
||||
return extend_struct<LavaSideTexture>();
|
||||
}
|
||||
|
||||
// FireTexture
|
||||
@ -195,7 +195,7 @@ struct FireTexture final : CustomDynamicTexture {
|
||||
}
|
||||
};
|
||||
static DynamicTexture *create_fire_texture(const int a2) {
|
||||
return extend_struct<DynamicTexture, FireTexture>(a2);
|
||||
return extend_struct<FireTexture>(a2);
|
||||
}
|
||||
|
||||
// Add Textures
|
||||
|
@ -124,7 +124,7 @@ struct WelcomeScreen final : CustomScreen {
|
||||
}
|
||||
};
|
||||
static Screen *create_welcome_screen() {
|
||||
return extend_struct<Screen, WelcomeScreen>();
|
||||
return extend_struct<WelcomeScreen>();
|
||||
}
|
||||
|
||||
// Show Welcome Screen
|
||||
|
Loading…
Reference in New Issue
Block a user