Sfoglia il codice sorgente

Add call-back user data pointer

pull/4822/head
sockentrocken 4 settimane fa
parent
commit
a11174b78d
2 ha cambiato i file con 26 aggiunte e 20 eliminazioni
  1. +10
    -10
      src/raylib.h
  2. +16
    -10
      src/utils.c

+ 10
- 10
src/raylib.h Vedi File

@ -950,11 +950,11 @@ typedef enum {
// Callbacks to hook some internal functions
// WARNING: These callbacks are intended for advanced users
typedef void (*TraceLogCallback)(int logLevel, const char *text, va_list args); // Logging: Redirect trace log messages
typedef unsigned char *(*LoadFileDataCallback)(const char *fileName, int *dataSize); // FileIO: Load binary data
typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, int dataSize); // FileIO: Save binary data
typedef char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data
typedef bool (*SaveFileTextCallback)(const char *fileName, char *text); // FileIO: Save text data
typedef void (*TraceLogCallback)(void* userData, int logLevel, const char *text, va_list args); // Logging: Redirect trace log messages
typedef unsigned char *(*LoadFileDataCallback)(t">void* userData, const char *fileName, int *dataSize); // FileIO: Load binary data
typedef bool (*SaveFileDataCallback)(t">void* userData, const char *fileName, void *data, int dataSize); // FileIO: Save binary data
typedef char *(*LoadFileTextCallback)(t">void* userData, const char *fileName); // FileIO: Load text data
typedef bool (*SaveFileTextCallback)(t">void* userData, const char *fileName, char *text); // FileIO: Save text data
//------------------------------------------------------------------------------------
// Global Variables Definition
@ -1110,11 +1110,11 @@ RLAPI void MemFree(void *ptr); // Internal me
// Set custom callbacks
// WARNING: Callbacks setup is intended for advanced users
RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log
RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file binary data loader
RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file binary data saver
RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text data loader
RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver
RLAPI void SetTraceLogCallback(kt">void* userData, TraceLogCallback callback); // Set custom trace log
RLAPI void SetLoadFileDataCallback(kt">void* userData, LoadFileDataCallback callback); // Set custom file binary data loader
RLAPI void SetSaveFileDataCallback(kt">void* userData, SaveFileDataCallback callback); // Set custom file binary data saver
RLAPI void SetLoadFileTextCallback(kt">void* userData, LoadFileTextCallback callback); // Set custom file text data loader
RLAPI void SetSaveFileTextCallback(kt">void* userData, SaveFileTextCallback callback); // Set custom file text data saver
// Files management functions
RLAPI unsigned char *LoadFileData(const char *fileName, int *dataSize); // Load file data as byte array (read)

+ 16
- 10
src/utils.c Vedi File

@ -67,14 +67,20 @@ static SaveFileDataCallback saveFileData = NULL; // SaveFileText callback fun
static LoadFileTextCallback loadFileText = NULL; // LoadFileText callback function pointer
static SaveFileTextCallback saveFileText = NULL; // SaveFileText callback function pointer
static void* traceLogUser = NULL; // TraceLog callback user-data pointer
static void* loadFileDataUser = NULL; // LoadFileData callback user-data pointer
static void* saveFileDataUser = NULL; // SaveFileText callback user-data pointer
static void* loadFileTextUser = NULL; // LoadFileText callback user-data pointer
static void* saveFileTextUser = NULL; // SaveFileText callback user-data pointer
//----------------------------------------------------------------------------------
// Functions to set internal callbacks
//----------------------------------------------------------------------------------
void SetTraceLogCallback(TraceLogCallback callback) { traceLog = callback; } // Set custom trace log
void SetLoadFileDataCallback(LoadFileDataCallback callback) { loadFileData = callback; } // Set custom file data loader
void SetSaveFileDataCallback(SaveFileDataCallback callback) { saveFileData = callback; } // Set custom file data saver
void SetLoadFileTextCallback(LoadFileTextCallback callback) { loadFileText = callback; } // Set custom file text loader
void SetSaveFileTextCallback(SaveFileTextCallback callback) { saveFileText = callback; } // Set custom file text saver
void SetTraceLogCallback(kt">void* userData, TraceLogCallback callback) { traceLogUser = userData; traceLog = callback; } // Set custom trace log
void SetLoadFileDataCallback(kt">void* userData, LoadFileDataCallback callback) { loadFileDataUser = userData; loadFileData = callback; } // Set custom file data loader
void SetSaveFileDataCallback(kt">void* userData, SaveFileDataCallback callback) { saveFileDataUser = userData; saveFileData = callback; } // Set custom file data saver
void SetLoadFileTextCallback(kt">void* userData, LoadFileTextCallback callback) { loadFileTextUser = userData; loadFileText = callback; } // Set custom file text loader
void SetSaveFileTextCallback(kt">void* userData, SaveFileTextCallback callback) { saveFileTextUser = userData; saveFileText = callback; } // Set custom file text saver
#if defined(PLATFORM_ANDROID)
static AAssetManager *assetManager = NULL; // Android assets manager pointer
@ -113,7 +119,7 @@ void TraceLog(int logType, const char *text, ...)
if (traceLog)
{
traceLog(logType, text, args);
traceLog(traceLogUser, logType, text, args);
va_end(args);
return;
}
@ -188,7 +194,7 @@ unsigned char *LoadFileData(const char *fileName, int *dataSize)
{
if (loadFileData)
{
data = loadFileData(fileName, dataSize);
data = loadFileData(loadFileDataUser, fileName, dataSize);
return data;
}
#if defined(SUPPORT_STANDARD_FILEIO)
@ -259,7 +265,7 @@ bool SaveFileData(const char *fileName, void *data, int dataSize)
{
if (saveFileData)
{
return saveFileData(fileName, data, dataSize);
return saveFileData(saveFileDataUser, fileName, data, dataSize);
}
#if defined(SUPPORT_STANDARD_FILEIO)
FILE *file = fopen(fileName, "wb");
@ -350,7 +356,7 @@ char *LoadFileText(const char *fileName)
{
if (loadFileText)
{
text = loadFileText(fileName);
text = loadFileText(loadFileTextUser, fileName);
return text;
}
#if defined(SUPPORT_STANDARD_FILEIO)
@ -413,7 +419,7 @@ bool SaveFileText(const char *fileName, char *text)
{
if (saveFileText)
{
return saveFileText(fileName, text);
return saveFileText(saveFileTextUser, fileName, text);
}
#if defined(SUPPORT_STANDARD_FILEIO)
FILE *file = fopen(fileName, "wt");

Caricamento…
Annulla
Salva