mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-02-17 20:31:57 -05:00
Merge pull request #254 from dariomanesku/master
Entry and imgui now have overridable allocators.
This commit is contained in:
commit
65bb50f84a
5 changed files with 40 additions and 8 deletions
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <string.h> // strlen
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <tinystl/allocator.h>
|
||||
#include <tinystl/vector.h>
|
||||
#include <tinystl/string.h>
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H_HEADER_GUARD
|
||||
#define COMMON_H_HEADER_GUARD
|
||||
|
||||
#include <bx/timer.h>
|
||||
#include <bx/fpumath.h>
|
||||
|
||||
#include "entry/entry.h"
|
||||
|
||||
#endif // COMMON_H_HEADER_GUARD
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "dbg.h"
|
||||
#include "cmd.h"
|
||||
#include "entry.h" //TinyStlCustomAllocator
|
||||
|
||||
#include <tinystl/allocator.h>
|
||||
#include <tinystl/string.h>
|
||||
|
|
|
@ -18,6 +18,20 @@ extern "C" int _main_(int _argc, char** _argv);
|
|||
#define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
|
||||
#define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
|
||||
|
||||
// For a custom tinystl allocator, define this and implement TinyStlCustomAllocator somewhere in the project.
|
||||
#ifndef ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
|
||||
# define ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR 0
|
||||
#endif // ENTRY_CONFIG_USE_TINYSTL
|
||||
|
||||
#if ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
|
||||
struct TinyStlCustomAllocator
|
||||
{
|
||||
static void* static_allocate(size_t _bytes);
|
||||
static void static_deallocate(void* _ptr, size_t /*_bytes*/);
|
||||
};
|
||||
# define TINYSTL_ALLOCATOR TinyStlCustomAllocator
|
||||
#endif //ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
|
||||
|
||||
namespace entry
|
||||
{
|
||||
struct WindowHandle { uint16_t idx; };
|
||||
|
|
|
@ -65,15 +65,25 @@ static const int32_t SCROLL_AREA_PADDING = 6;
|
|||
static const int32_t AREA_HEADER = 20;
|
||||
static const float s_tabStops[4] = {150, 210, 270, 330};
|
||||
|
||||
static void* imguiMalloc(size_t size, void* /*_userptr*/)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
// For a custom allocator, define this and implement imguiMalloc and imguiFree somewhere in the project.
|
||||
#ifndef IMGUI_CONFIG_CUSTOM_ALLOCATOR
|
||||
# define IMGUI_CONFIG_CUSTOM_ALLOCATOR 0
|
||||
#endif // ENTRY_CONFIG_USE_TINYSTL
|
||||
|
||||
static void imguiFree(void* _ptr, void* /*_userptr*/)
|
||||
{
|
||||
free(_ptr);
|
||||
}
|
||||
#if IMGUI_CONFIG_CUSTOM_ALLOCATOR
|
||||
void* imguiMalloc(size_t size, void* /*_userptr*/);
|
||||
void imguiFree(void* _ptr, void* /*_userptr*/);
|
||||
#else
|
||||
static void* imguiMalloc(size_t _size, void* /*_userptr*/)
|
||||
{
|
||||
return malloc(_size);
|
||||
}
|
||||
|
||||
static void imguiFree(void* _ptr, void* /*_userptr*/)
|
||||
{
|
||||
free(_ptr);
|
||||
}
|
||||
#endif //IMGUI_CONFIG_CUSTOM_ALLOCATOR
|
||||
|
||||
#define IMGUI_MIN(_a, _b) (_a)<(_b)?(_a):(_b)
|
||||
#define IMGUI_MAX(_a, _b) (_a)>(_b)?(_a):(_b)
|
||||
|
|
Loading…
Reference in a new issue