mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Configurable memory allocation functions.
This commit is contained in:
parent
8c2f817da9
commit
d66f211456
@ -54,8 +54,8 @@
|
||||
#define SPINE_EXTENSION_H_
|
||||
|
||||
/* All allocation uses these. */
|
||||
#define MALLOC(TYPE,COUNT) ((TYPE*)malloc(sizeof(TYPE) * COUNT))
|
||||
#define CALLOC(TYPE,COUNT) ((TYPE*)calloc(1, sizeof(TYPE) * COUNT))
|
||||
#define MALLOC(TYPE,COUNT) ((TYPE*)_malloc(sizeof(TYPE) * COUNT))
|
||||
#define CALLOC(TYPE,COUNT) ((TYPE*)_calloc(1, sizeof(TYPE) * COUNT))
|
||||
#define NEW(TYPE) CALLOC(TYPE,1)
|
||||
|
||||
/* Gets the direct super class. Type safe. */
|
||||
@ -74,7 +74,7 @@
|
||||
#define VTABLE(TYPE,VALUE) ((_##TYPE##Vtable*)((TYPE*)VALUE)->vtable)
|
||||
|
||||
/* Frees memory. Can be used on const. */
|
||||
#define FREE(VALUE) free((void*)VALUE)
|
||||
#define FREE(VALUE) _free((void*)VALUE)
|
||||
|
||||
/* Allocates a new char[], assigns it to TO, and copies FROM to it. Can be used on const. */
|
||||
#define MALLOC_STR(TO,FROM) strcpy(CONST_CAST(char*, TO) = (char*)malloc(strlen(FROM) + 1), FROM)
|
||||
@ -106,50 +106,59 @@ char* _Util_readFile (const char* path, int* length);
|
||||
* Internal API available for extension:
|
||||
*/
|
||||
|
||||
void* _malloc (size_t size);
|
||||
void* _calloc (size_t num, size_t size);
|
||||
void _free (void* ptr);
|
||||
|
||||
void _setMalloc (void* (*_malloc) (size_t size));
|
||||
void _setFree (void (*_free) (void* ptr));
|
||||
|
||||
char* _readFile (const char* path, int* length);
|
||||
|
||||
void _Skeleton_init (Skeleton* self, SkeletonData* data, /**/
|
||||
/**/
|
||||
|
||||
void _Skeleton_init (Skeleton* self, SkeletonData* data, //
|
||||
void (*dispose) (Skeleton* skeleton));
|
||||
void _Skeleton_deinit (Skeleton* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _Attachment_init (Attachment* self, const char* name, AttachmentType type, /**/
|
||||
void (*dispose) (Attachment* self), /**/
|
||||
void _Attachment_init (Attachment* self, const char* name, AttachmentType type, //
|
||||
void (*dispose) (Attachment* self), //
|
||||
void (*draw) (Attachment* self, struct Slot* slot));
|
||||
void _Attachment_deinit (Attachment* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _RegionAttachment_init (RegionAttachment* self, const char* name, /**/
|
||||
void (*dispose) (Attachment* self), /**/
|
||||
void _RegionAttachment_init (RegionAttachment* self, const char* name, //
|
||||
void (*dispose) (Attachment* self), //
|
||||
void (*draw) (Attachment* self, struct Slot* slot));
|
||||
void _RegionAttachment_deinit (RegionAttachment* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _Timeline_init (Timeline* self, /**/
|
||||
void (*dispose) (Timeline* self), /**/
|
||||
void _Timeline_init (Timeline* self, //
|
||||
void (*dispose) (Timeline* self), //
|
||||
void (*apply) (const Timeline* self, Skeleton* skeleton, float time, float alpha));
|
||||
void _Timeline_deinit (Timeline* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _CurveTimeline_init (CurveTimeline* self, int frameCount, /**/
|
||||
void (*dispose) (Timeline* self), /**/
|
||||
void _CurveTimeline_init (CurveTimeline* self, int frameCount, //
|
||||
void (*dispose) (Timeline* self), //
|
||||
void (*apply) (const Timeline* self, Skeleton* skeleton, float time, float alpha));
|
||||
void _CurveTimeline_deinit (CurveTimeline* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _AtlasPage_init (AtlasPage* self, const char* name, /**/
|
||||
void _AtlasPage_init (AtlasPage* self, const char* name, //
|
||||
void (*dispose) (AtlasPage* self));
|
||||
void _AtlasPage_deinit (AtlasPage* self);
|
||||
|
||||
/**/
|
||||
|
||||
void _AttachmentLoader_init (AttachmentLoader* self, /**/
|
||||
void (*dispose) (AttachmentLoader* self), /**/
|
||||
void _AttachmentLoader_init (AttachmentLoader* self, //
|
||||
void (*dispose) (AttachmentLoader* self), //
|
||||
Attachment* (*newAttachment) (AttachmentLoader* self, Skin* skin, AttachmentType type, const char* name));
|
||||
void _AttachmentLoader_deinit (AttachmentLoader* self);
|
||||
void _AttachmentLoader_setError (AttachmentLoader* self, const char* error1, const char* error2);
|
||||
|
||||
@ -30,6 +30,28 @@
|
||||
namespace spine {
|
||||
#endif
|
||||
|
||||
static void* (*mallocFunc) (size_t size) = malloc;
|
||||
static void (*freeFunc) (void* ptr) = free;
|
||||
|
||||
void* _malloc (size_t size) {
|
||||
return mallocFunc(size);
|
||||
}
|
||||
void* _calloc (size_t num, size_t size) {
|
||||
void* ptr = mallocFunc(size);
|
||||
if (ptr) memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
void _free (void* ptr) {
|
||||
freeFunc(ptr);
|
||||
}
|
||||
|
||||
void _setMalloc (void* (*malloc) (size_t size)) {
|
||||
mallocFunc = malloc;
|
||||
}
|
||||
void _setFree (void (*free) (void* ptr)) {
|
||||
freeFunc = free;
|
||||
}
|
||||
|
||||
char* _readFile (const char* path, int* length) {
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!file) return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user