mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
finxing memory usages
This commit is contained in:
@@ -109,12 +109,7 @@ namespace mlx
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
for(auto& window : m_graphics)
|
||||
{
|
||||
if(window && window->GetWindow()->GetName() == "让我们在月光下做爱吧")
|
||||
window.reset();
|
||||
}
|
||||
|
||||
m_mesh_registry.Reset();
|
||||
m_font_registry.Reset();
|
||||
p_render_core.reset();
|
||||
p_sdl_manager.reset();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "mlx_extended.h"
|
||||
#include <PreCompiled.h>
|
||||
|
||||
#include <Core/Application.h>
|
||||
@@ -274,7 +275,7 @@ extern "C"
|
||||
mlx::NonOwningPtr<mlx::Texture> texture = mlx->app->GetTexture(image);
|
||||
if(!texture)
|
||||
return;
|
||||
gs->TexturePut(texture, x, y, 1.0f, 0.0f);
|
||||
gs->TexturePut(texture, x, y, 1.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void mlx_string_put(mlx_context mlx, mlx_window win, int x, int y, int color, char* str)
|
||||
@@ -299,7 +300,7 @@ extern "C"
|
||||
void mlx_set_font(mlx_context mlx, char* filepath)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filepath == nullptr)
|
||||
if(filepath == nullptr)
|
||||
{
|
||||
mlx::Error("Font loader: filepath is NULL");
|
||||
return;
|
||||
@@ -319,7 +320,7 @@ extern "C"
|
||||
void mlx_set_font_scale(mlx_context mlx, char* filepath, float scale)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filepath == nullptr)
|
||||
if(filepath == nullptr)
|
||||
{
|
||||
mlx::Error("Font loader: filepath is NULL");
|
||||
return;
|
||||
@@ -332,4 +333,87 @@ extern "C"
|
||||
}
|
||||
mlx->app->LoadFont(file, scale);
|
||||
}
|
||||
|
||||
// Extended
|
||||
|
||||
void mlx_set_window_max_size(mlx_context mlx, mlx_window win, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
gs->GetWindow()->SetMaxSize(x, y);
|
||||
}
|
||||
|
||||
void mlx_set_window_min_size(mlx_context mlx, mlx_window win, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
gs->GetWindow()->SetMinSize(x, y);
|
||||
}
|
||||
|
||||
void mlx_maximise_window(mlx_context mlx, mlx_window win)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
gs->GetWindow()->Maximize();
|
||||
}
|
||||
|
||||
void mlx_minimize_window(mlx_context mlx, mlx_window win)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
gs->GetWindow()->Minimize();
|
||||
}
|
||||
|
||||
void mlx_restore_window(mlx_context mlx, mlx_window win)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
gs->GetWindow()->Restore();
|
||||
}
|
||||
|
||||
void mlx_pixel_put_array(mlx_context mlx, mlx_window win, int x, int y, int* pixels)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
}
|
||||
|
||||
void mlx_get_image_region(mlx_context mlx, mlx_image image, int x, int y, int w, int h, int* dst)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::Texture> texture = mlx->app->GetTexture(image);
|
||||
if(!texture)
|
||||
return;
|
||||
}
|
||||
|
||||
void mlx_set_image_region(mlx_context mlx, mlx_image image, int x, int y, int w, int h, int* pixels)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::Texture> texture = mlx->app->GetTexture(image);
|
||||
if(!texture)
|
||||
return;
|
||||
}
|
||||
|
||||
void mlx_put_transformed_image_to_window(mlx_context mlx, mlx_window win, mlx_image image, int x, int y, float scale_x, float scale_y, float angle)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||
if(!gs)
|
||||
return;
|
||||
mlx::NonOwningPtr<mlx::Texture> texture = mlx->app->GetTexture(image);
|
||||
if(!texture)
|
||||
return;
|
||||
gs->TexturePut(texture, x, y, scale_x, scale_y, angle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,15 +68,16 @@ namespace mlx
|
||||
|
||||
#ifdef MLX_COMPILER_MSVC
|
||||
void* ptr2 = _aligned_realloc(ptr, alignment, size);
|
||||
if(it != s_blocks.end())
|
||||
s_blocks.erase(it);
|
||||
#else
|
||||
void* ptr2 = AlignedMalloc(alignment, size);
|
||||
if(it != s_blocks.end())
|
||||
{
|
||||
std::memcpy(ptr2, ptr, it->size);
|
||||
Free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(it != s_blocks.end())
|
||||
s_blocks.erase(it);
|
||||
|
||||
if(ptr2 != nullptr)
|
||||
s_blocks.emplace_back(ptr, size, true);
|
||||
return ptr2;
|
||||
|
||||
@@ -59,6 +59,8 @@ namespace mlx
|
||||
flags |= SDL_WINDOW_SHOWN;
|
||||
if(info->is_resizable)
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
if(info->is_fullscreen)
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
|
||||
infos->window = SDL_CreateWindow(info->title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, info->width, info->height, flags);
|
||||
if(!infos->window)
|
||||
@@ -148,6 +150,31 @@ namespace mlx
|
||||
SDL_SetWindowFullscreen(static_cast<Internal::WindowInfos*>(window)->window, (enable ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
||||
}
|
||||
|
||||
void SDLManager::SetWindowMaxSize(Handle window, int x, int y) const noexcept
|
||||
{
|
||||
SDL_SetWindowMaximumSize(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||
}
|
||||
|
||||
void SDLManager::SetWindowMinSize(Handle window, int x, int y) const noexcept
|
||||
{
|
||||
SDL_SetWindowMinimumSize(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||
}
|
||||
|
||||
void SDLManager::MaximizeWindow(Handle window) const noexcept
|
||||
{
|
||||
SDL_MaximizeWindow(static_cast<Internal::WindowInfos*>(window)->window);
|
||||
}
|
||||
|
||||
void SDLManager::MinimizeWindow(Handle window) const noexcept
|
||||
{
|
||||
SDL_MinimizeWindow(static_cast<Internal::WindowInfos*>(window)->window);
|
||||
}
|
||||
|
||||
void SDLManager::RestoreWindow(Handle window) const noexcept
|
||||
{
|
||||
SDL_RestoreWindow(static_cast<Internal::WindowInfos*>(window)->window);
|
||||
}
|
||||
|
||||
void SDLManager::GetWindowPosition(Handle window, int* x, int* y) const noexcept
|
||||
{
|
||||
SDL_GetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||
|
||||
Reference in New Issue
Block a user