1 #include <bz/resources/resource.h>
3 #include <bz/types/identifier_internal.h>
4 #include <stb_sprintf.h>
8 struct BZResource { PHYSFS_File unused; };
10 // This is FOR DEBUG ONLY!
11 char *gBZDataDebugDirectory = NULL;
13 void bzFileSystemInit(const char *argv0, const char *dataPath) {
16 if (gBZDataDebugDirectory != NULL) {
17 bzLog("!!! A debug data directory was found !!!");
18 bzLog("!!! DO NOT SHIP IF THIS IS DISPLAYED !!!");
19 int fsr3 = PHYSFS_mount(gBZDataDebugDirectory, NULL, 0);
21 bzLog("Trying to load: %s", gBZDataDebugDirectory);
24 stbsp_snprintf(tmp, 1024, "%s%s", dataPath, "assets.pak");
25 int fsr2 = PHYSFS_mount(tmp, NULL, 0);
27 bzLog("Trying to load: %s", tmp);
31 void bzFileSystemTeardown() {
35 BZResourceID bzResourcesOpenResource(const char *type, const char *identifierFmt, ...) {
36 bzMakeIdentifier(identifier, identifierFmt);
37 bzLog("Trying to load: %s", identifier);
39 BZResourceID resource = (BZResourceID)PHYSFS_openRead(identifier);
40 bzAssertMessage(resource != NULL, "Error opening resource '%s': %s", identifier, PHYSFS_getLastError());
45 extern void bzResourcesCloseResource(BZResourceID resource) {
46 PHYSFS_File *handle = (PHYSFS_File *)resource;
50 size_t bzResourcesFileLength(BZResourceID resource) {
51 PHYSFS_File *handle = (PHYSFS_File *)resource;
52 return PHYSFS_fileLength(handle);
55 size_t bzResourcesTell(BZResourceID resource) {
56 PHYSFS_File *handle = (PHYSFS_File *)resource;
57 return PHYSFS_tell(handle);
60 size_t bzResourcesSeek(BZResourceID resource, size_t position) {
61 PHYSFS_File *handle = (PHYSFS_File *)resource;
62 return PHYSFS_seek(handle, position);
65 size_t bzResourcesReadBytes(BZResourceID resource, void *outputBuffer, size_t numBytes) {
66 PHYSFS_File *handle = (PHYSFS_File *)resource;
67 PHYSFS_sint64 r = PHYSFS_readBytes(handle, outputBuffer, numBytes);
69 // FIXME, handle error?