1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Use SDL allocators for PhysFS

PhysFS by default just uses system malloc(), realloc(), and free(); it
provides a way to change them, with a struct named PHYSFS_Allocator and
a function named PHYSFS_setAllocator().

According to PhysFS docs, this function should be called before
PHYSFS_init(), which is why this allocator stuff is handled in
FileSystemUtils.cpp.

Also, I've had to make two "bridge" functions, because PHYSFS_Allocator
wants pointers to functions taking in `PHYSFS_uint64`s, not `size_t`s.
This commit is contained in:
Misa 2021-02-22 18:31:19 -08:00 committed by Ethan Lee
parent 38d5664601
commit 4a8c0a38ee

View file

@ -30,12 +30,31 @@ static void PLATFORM_getOSDirectory(char* output);
static void PLATFORM_migrateSaveData(char* output); static void PLATFORM_migrateSaveData(char* output);
static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation); static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation);
static void* bridged_malloc(PHYSFS_uint64 size)
{
return SDL_malloc(size);
}
static void* bridged_realloc(void* ptr, PHYSFS_uint64 size)
{
return SDL_realloc(ptr, size);
}
static const PHYSFS_Allocator allocator = {
NULL,
NULL,
bridged_malloc,
bridged_realloc,
SDL_free
};
int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath) int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
{ {
char output[MAX_PATH]; char output[MAX_PATH];
int mkdirResult; int mkdirResult;
const char* pathSep = PHYSFS_getDirSeparator(); const char* pathSep = PHYSFS_getDirSeparator();
PHYSFS_setAllocator(&allocator);
PHYSFS_init(argvZero); PHYSFS_init(argvZero);
PHYSFS_permitSymbolicLinks(1); PHYSFS_permitSymbolicLinks(1);