mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
improving custom malloc, removing unused code in input system
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/09 17:44:13 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/11 15:12:39 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
#include <array>
|
||||
#include <core/errors.h>
|
||||
#include <core/profile.h>
|
||||
#include <core/memory.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
Application::Application() : _in(std::make_unique<Input>())
|
||||
{
|
||||
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
||||
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/07 23:05:05 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/11 15:56:18 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <filesystem>
|
||||
#include <mlx.h>
|
||||
#include <core/memory.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -25,8 +26,9 @@ extern "C"
|
||||
if(init)
|
||||
{
|
||||
mlx::core::error::report(e_kind::error, "MLX cannot be initialized multiple times");
|
||||
return NULL;
|
||||
return NULL; // not nullptr for the C compatibility
|
||||
}
|
||||
mlx::MemManager::get(); // just to initialize the C garbage collector
|
||||
mlx::core::Application* app = new mlx::core::Application;
|
||||
mlx::Render_Core::get().init();
|
||||
if(app == nullptr)
|
||||
@@ -219,4 +221,4 @@ extern "C"
|
||||
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/07 16:32:01 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/12/08 12:56:14 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/11 15:25:02 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void* MemManager::alloc(std::size_t size)
|
||||
void* MemManager::malloc(std::size_t size)
|
||||
{
|
||||
void* ptr = std::malloc(size);
|
||||
if(ptr != nullptr)
|
||||
@@ -25,6 +25,25 @@ namespace mlx
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* MemManager::calloc(std::size_t n, std::size_t size)
|
||||
{
|
||||
void* ptr = std::calloc(n, size);
|
||||
if(ptr != nullptr)
|
||||
_blocks.push_back(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* MemManager::realloc(void* ptr, std::size_t size)
|
||||
{
|
||||
void* ptr2 = std::realloc(ptr, size);
|
||||
if(ptr2 != nullptr)
|
||||
_blocks.push_back(ptr2);
|
||||
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
|
||||
if(it != _blocks.end())
|
||||
_blocks.erase(it);
|
||||
return ptr2;
|
||||
}
|
||||
|
||||
void MemManager::free(void* ptr)
|
||||
{
|
||||
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/07 16:31:51 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/12/08 19:05:15 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/11 15:13:46 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,15 +24,17 @@ namespace mlx
|
||||
friend class Singleton<MemManager>;
|
||||
|
||||
public:
|
||||
void* alloc(std::size_t size);
|
||||
void free(void* ptr);
|
||||
static void* malloc(std::size_t size);
|
||||
static void* calloc(std::size_t n, std::size_t size);
|
||||
static void* realloc(void* ptr, std::size_t size);
|
||||
static void free(void* ptr);
|
||||
|
||||
private:
|
||||
MemManager() = default;
|
||||
~MemManager();
|
||||
|
||||
private:
|
||||
std::list<void*> _blocks;
|
||||
inline static std::list<void*> _blocks;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user