Per-level custom asset loading functionality (#262)

This commit is contained in:
Matt Aaldenberg
2020-05-31 19:31:02 -04:00
committed by GitHub
parent cfcfccf58b
commit b217fec3aa
6 changed files with 127 additions and 20 deletions

View File

@@ -7,6 +7,8 @@
#include <stdlib.h>
#include <string.h>
#include "Graphics.h"
#include <iterator>
#include <algorithm>
#include <iostream>
@@ -76,7 +78,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
mkdirResult = mkdir(output, 0777);
/* Mount our base user directory */
PHYSFS_mount(output, NULL, 1);
PHYSFS_mount(output, NULL, 0);
PHYSFS_setWriteDir(output);
printf("Base directory: %s\n", output);
@@ -149,6 +151,33 @@ char *FILESYSTEM_getUserLevelDirectory()
return levelDir;
}
bool FILESYSTEM_directoryExists(const char *fname)
{
return PHYSFS_exists(fname);
}
void FILESYSTEM_mount(const char *fname)
{
std::string path(PHYSFS_getRealDir(fname));
path += PHYSFS_getDirSeparator();
path += fname;
if (!PHYSFS_mount(path.c_str(), NULL, 0)) {
printf("Error mounting: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
} else
graphics.assetdir = path.c_str();
}
void FILESYSTEM_unmountassets()
{
if (graphics.assetdir != "")
{
printf("Unmounting %s\n", graphics.assetdir.c_str());
PHYSFS_unmount(graphics.assetdir.c_str());
graphics.assetdir = "";
graphics.reloadresources();
} else printf("Cannot unmount when no asset directory is mounted\n");
}
void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem,
size_t *len, bool addnull)
{