Merge remote-tracking branch 'TSnake41/master'

This commit is contained in:
TSnake41 2020-06-25 17:18:07 +02:00
commit a2a120bd63
2 changed files with 44 additions and 2 deletions

View File

@ -852,6 +852,14 @@ typedef enum {
// Callbacks to be implemented by users // Callbacks to be implemented by users
typedef void (*TraceLogCallback)(int logType, const char *text, va_list args); typedef void (*TraceLogCallback)(int logType, const char *text, va_list args);
// Filesystem override implemented by users.
typedef struct FilesystemOverride {
unsigned char *(*loadFileData)(const char *fileName, unsigned int *bytesRead);
void (*saveFileData)(const char *fileName, void *data, unsigned int bytesToWrite);
char *(*loadFileText)(const char *fileName);
void (*saveFileText)(const char *fileName, char *text);
} FilesystemOverride;
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions extern "C" { // Prevents name mangling of functions
#endif #endif
@ -945,6 +953,7 @@ RLAPI void TakeScreenshot(const char *fileName); // Takes a scr
RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included) RLAPI int GetRandomValue(int min, int max); // Returns a random value between min and max (both included)
// Files management functions // Files management functions
RLAPI void SetFilesystemOverride(FilesystemOverride override); // Set filesystem functions override.
RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read) RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)
RLAPI void SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write) RLAPI void SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write)
RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string
@ -1157,7 +1166,7 @@ RLAPI void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Col
RLAPI void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw circle within an image (Vector version) RLAPI void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw circle within an image (Vector version)
RLAPI void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color); // Draw rectangle within an image RLAPI void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color); // Draw rectangle within an image
RLAPI void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color); // Draw rectangle within an image (Vector version) RLAPI void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color); // Draw rectangle within an image (Vector version)
RLAPI void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image RLAPI void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image
RLAPI void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color); // Draw rectangle lines within an image RLAPI void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color); // Draw rectangle lines within an image
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source) RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source)
RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination) RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination)

View File

@ -69,6 +69,9 @@ static int logTypeLevel = LOG_INFO; // Minimum log type leve
static int logTypeExit = LOG_ERROR; // Log type that exits static int logTypeExit = LOG_ERROR; // Log type that exits
static TraceLogCallback logCallback = NULL; // Log callback function pointer static TraceLogCallback logCallback = NULL; // Log callback function pointer
// Filesystem function override.
static FilesystemOverride fsOverride = { NULL, NULL, NULL, NULL };
#if defined(PLATFORM_ANDROID) #if defined(PLATFORM_ANDROID)
static AAssetManager *assetManager = NULL; // Android assets manager pointer static AAssetManager *assetManager = NULL; // Android assets manager pointer
static const char *internalDataPath = NULL; // Android internal data path static const char *internalDataPath = NULL; // Android internal data path
@ -163,6 +166,12 @@ void TraceLog(int logType, const char *text, ...)
#endif // SUPPORT_TRACELOG #endif // SUPPORT_TRACELOG
} }
// Set filesystem functions override.
void SetFilesystemOverride(FilesystemOverride override)
{
fsOverride = override;
}
// Load data from file into a buffer // Load data from file into a buffer
unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
{ {
@ -171,6 +180,13 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
if (fileName != NULL) if (fileName != NULL)
{ {
if (fsOverride.loadFileData) {
data = fsOverride.loadFileData(fileName, bytesRead);
if (data)
return data;
}
FILE *file = fopen(fileName, "rb"); FILE *file = fopen(fileName, "rb");
if (file != NULL) if (file != NULL)
@ -208,6 +224,11 @@ void SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
{ {
if (fileName != NULL) if (fileName != NULL)
{ {
if (fsOverride.saveFileData) {
fsOverride.saveFileData(fileName, data, bytesToWrite);
return;
}
FILE *file = fopen(fileName, "wb"); FILE *file = fopen(fileName, "wb");
if (file != NULL) if (file != NULL)
@ -233,6 +254,13 @@ char *LoadFileText(const char *fileName)
if (fileName != NULL) if (fileName != NULL)
{ {
if (fsOverride.loadFileText) {
text = fsOverride.loadFileText(fileName);
if (text)
return text;
}
FILE *textFile = fopen(fileName, "rt"); FILE *textFile = fopen(fileName, "rt");
if (textFile != NULL) if (textFile != NULL)
@ -274,6 +302,11 @@ void SaveFileText(const char *fileName, char *text)
{ {
if (fileName != NULL) if (fileName != NULL)
{ {
if (fsOverride.saveFileText) {
fsOverride.saveFileText(fileName, text);
return;
}
FILE *file = fopen(fileName, "wt"); FILE *file = fopen(fileName, "wt");
if (file != NULL) if (file != NULL)
@ -317,7 +350,7 @@ FILE *android_fopen(const char *fileName, const char *mode)
// NOTE: AAsset provides access to read-only asset // NOTE: AAsset provides access to read-only asset
AAsset *asset = AAssetManager_open(assetManager, fileName, AASSET_MODE_UNKNOWN); AAsset *asset = AAssetManager_open(assetManager, fileName, AASSET_MODE_UNKNOWN);
if (asset != NULL) if (asset != NULL)
{ {
// Return pointer to file in the assets // Return pointer to file in the assets
return funopen(asset, android_read, android_write, android_seek, android_close); return funopen(asset, android_read, android_write, android_seek, android_close);