Port a bunch of Godot container templates to GDExtension.
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
void *operator new(size_t p_size, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool
|
||||
void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool
|
||||
void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory
|
||||
|
||||
_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
|
||||
@@ -76,10 +77,27 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
|
||||
return p_obj;
|
||||
}
|
||||
|
||||
#define memalloc(m_size) Memory::alloc_static(m_size)
|
||||
#define memrealloc(m_mem, m_size) Memory::realloc_static(m_mem, m_size)
|
||||
#define memfree(m_mem) Memory::free_static(m_mem)
|
||||
|
||||
#define memnew(m_class) _post_initialize(new ("") m_class)
|
||||
|
||||
#define memnew_allocator(m_class, m_allocator) _post_initialize(new (m_allocator::alloc) m_class)
|
||||
#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement, sizeof(m_class), "") m_class)
|
||||
|
||||
// Generic comparator used in Map, List, etc.
|
||||
template <class T>
|
||||
struct Comparator {
|
||||
_ALWAYS_INLINE_ bool operator()(const T &p_a, const T &p_b) const { return (p_a < p_b); }
|
||||
};
|
||||
|
||||
class DefaultAllocator {
|
||||
public:
|
||||
_ALWAYS_INLINE_ static void *alloc(size_t p_memory) { return Memory::alloc_static(p_memory); }
|
||||
_ALWAYS_INLINE_ static void free(void *p_ptr) { Memory::free_static(p_ptr); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void memdelete(T *p_class, typename std::enable_if<!std::is_base_of_v<godot::Wrapped, T>>::type * = 0) {
|
||||
if (!__has_trivial_destructor(T)) {
|
||||
@@ -94,6 +112,15 @@ void memdelete(T *p_class) {
|
||||
godot::internal::gdn_interface->object_destroy(p_class->_owner);
|
||||
}
|
||||
|
||||
template <class T, class A>
|
||||
void memdelete_allocator(T *p_class) {
|
||||
if (!__has_trivial_destructor(T)) {
|
||||
p_class->~T();
|
||||
}
|
||||
|
||||
A::free(p_class);
|
||||
}
|
||||
|
||||
#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count)
|
||||
|
||||
template <typename T>
|
||||
@@ -137,6 +164,19 @@ void memdelete_arr(T *p_class) {
|
||||
Memory::free_static(ptr);
|
||||
}
|
||||
|
||||
struct _GlobalNil {
|
||||
int color = 1;
|
||||
_GlobalNil *right;
|
||||
_GlobalNil *left;
|
||||
_GlobalNil *parent;
|
||||
|
||||
_GlobalNil();
|
||||
};
|
||||
|
||||
struct _GlobalNilClass {
|
||||
static _GlobalNil _nil;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // ! GODOT_CPP_MEMORY_HPP
|
||||
|
||||
Reference in New Issue
Block a user