Skip to content

Commit dd7a194

Browse files
committed
WARNING: REDESIGN: REMOVED: utils module, functionality moved to rcore module: logging and file-system #4551
[utils] was created long time ago, when [rcore] contained all the platforms code, the purpose of the file was exposing basic filesystem functionality across modules and also logging mechanism but many things have changed since then and there is no need to keep using this module. - Logging system has been move to [rcore] module and macros are exposed through `config.h` to other modules - File system functionality has also been centralized in [rcore] module that along the years it was already adding more and more file-system functions, now they are all in the same module - Android specific code has been moved to `rcore_android.c`, it had no sense to have specific platform code in `utils`, [rcore] is responsible of all platform code.
1 parent 2f6feb7 commit dd7a194

22 files changed

Lines changed: 527 additions & 691 deletions

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
197197
}
198198

199199
var c_source_files: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 2);
200-
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c", "src/utils.c" });
200+
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c" });
201201

202202
if (options.rshapes) {
203203
try c_source_files.append(b.allocator, "src/rshapes.c");

projects/VS2022/raylib/raylib.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@
582582
<ClCompile Include="..\..\..\src\rshapes.c" />
583583
<ClCompile Include="..\..\..\src\rtext.c" />
584584
<ClCompile Include="..\..\..\src\rtextures.c" />
585-
<ClCompile Include="..\..\..\src\utils.c" />
586585
</ItemGroup>
587586
<ItemGroup>
588587
<ClInclude Include="..\..\..\src\external\cgltf.h" />

projects/VS2022/raylib/raylib.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
<ClCompile Include="..\..\..\src\rtextures.c">
2323
<Filter>Source Files</Filter>
2424
</ClCompile>
25-
<ClCompile Include="..\..\..\src\utils.c">
26-
<Filter>Source Files</Filter>
27-
</ClCompile>
2825
<ClCompile Include="..\..\..\src\platforms\rcore_android.c">
2926
<Filter>Source Files\Platform Files</Filter>
3027
</ClCompile>

src/Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ endif
658658
OBJS = rcore.o \
659659
rshapes.o \
660660
rtextures.o \
661-
rtext.o \
662-
utils.o
661+
rtext.o
663662

664663
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
665664
ifeq ($(USE_EXTERNAL_GLFW),FALSE)
@@ -758,7 +757,7 @@ endif
758757
rcore.o : platforms/*.c
759758

760759
# Compile core module
761-
rcore.o : rcore.c raylib.h rlgl.h utils.h raymath.h rcamera.h rgestures.h
760+
rcore.o : rcore.c raylib.h rlgl.h raymath.h rcamera.h rgestures.h
762761
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
763762

764763
# Compile rglfw module
@@ -770,15 +769,11 @@ rshapes.o : rshapes.c raylib.h rlgl.h
770769
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
771770

772771
# Compile textures module
773-
rtextures.o : rtextures.c raylib.h rlgl.h utils.h
772+
rtextures.o : rtextures.c raylib.h rlgl.h
774773
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
775774

776775
# Compile text module
777-
rtext.o : rtext.c raylib.h utils.h
778-
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
779-
780-
# Compile utils module
781-
utils.o : utils.c utils.h
776+
rtext.o : rtext.c raylib.h
782777
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
783778

784779
# Compile models module

src/config.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
//------------------------------------------------------------------------------------
3232
// Module selection - Some modules could be avoided
33-
// Mandatory modules: rcore, rlgl, utils
33+
// Mandatory modules: rcore, rlgl
3434
//------------------------------------------------------------------------------------
3535
#define SUPPORT_MODULE_RSHAPES 1
3636
#define SUPPORT_MODULE_RTEXTURES 1
@@ -41,6 +41,16 @@
4141
//------------------------------------------------------------------------------------
4242
// Module: rcore - Configuration Flags
4343
//------------------------------------------------------------------------------------
44+
// Standard file io library (stdio.h) included
45+
#define SUPPORT_STANDARD_FILEIO 1
46+
// Show TRACELOG() output messages
47+
#define SUPPORT_TRACELOG 1
48+
#if defined(SUPPORT_TRACELOG)
49+
#define TRACELOG(level, ...) TraceLog(level, __VA_ARGS__)
50+
#else
51+
#define TRACELOG(level, ...) (void)0
52+
#endif
53+
4454
// Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
4555
#define SUPPORT_CAMERA_SYSTEM 1
4656
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
@@ -72,7 +82,7 @@
7282

7383
// Support for clipboard image loading
7484
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
75-
#define SUPPORT_CLIPBOARD_IMAGE 1
85+
#define SUPPORT_CLIPBOARD_IMAGE 1
7686

7787
// NOTE: Clipboard image loading requires support for some image file formats
7888
// TODO: Those defines should probably be removed from here, letting the user manage them
@@ -96,6 +106,7 @@
96106

97107
// rcore: Configuration values
98108
//------------------------------------------------------------------------------------
109+
#define MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
99110
#define MAX_FILEPATH_CAPACITY 8192 // Maximum file paths capacity
100111
#define MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value)
101112

@@ -281,16 +292,4 @@
281292

282293
#define MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Maximum number of audio pool channels
283294

284-
//------------------------------------------------------------------------------------
285-
// Module: utils - Configuration Flags
286-
//------------------------------------------------------------------------------------
287-
// Standard file io library (stdio.h) included
288-
#define SUPPORT_STANDARD_FILEIO 1
289-
// Show TRACELOG() output messages
290-
#define SUPPORT_TRACELOG 1
291-
292-
// utils: Configuration values
293-
//------------------------------------------------------------------------------------
294-
#define MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
295-
296295
#endif // CONFIG_H

src/platforms/rcore_android.c

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* - Improvement 01
1414
* - Improvement 02
1515
*
16-
* ADDITIONAL NOTES:
17-
* - TRACELOG() function is located in raylib [utils] module
18-
*
1916
* CONFIGURATION:
2017
* #define RCORE_PLATFORM_CUSTOM_FLAG
2118
* Custom flag for rcore on target platform -not used-
@@ -48,7 +45,11 @@
4845

4946
#include <android_native_app_glue.h> // Required for: android_app struct and activity management
5047
#include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
48+
#include <android/log.h> // Required for: Android log system: __android_log_vprint()
49+
#include <android/asset_manager.h> // Required for: AAssetManager
5150
//#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
51+
52+
#include <errno.h> // Required for: error types
5253
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL() and GetCurrentMonitor()]
5354

5455
#include <EGL/egl.h> // Native platform windowing system interface
@@ -269,6 +270,17 @@ static GamepadButton AndroidTranslateGamepadButton(int button);
269270

270271
static void SetupFramebuffer(int width, int height); // Setup main framebuffer (required by InitPlatform())
271272

273+
static int android_read(void *cookie, char *buf, int size);
274+
static int android_write(void *cookie, const char *buf, int size);
275+
static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
276+
static int android_close(void *cookie);
277+
278+
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() -> Read-only!
279+
FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
280+
fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
281+
282+
#define fopen(name, mode) android_fopen(name, mode)
283+
272284
//----------------------------------------------------------------------------------
273285
// Module Functions Declaration
274286
//----------------------------------------------------------------------------------
@@ -819,8 +831,6 @@ int InitPlatform(void)
819831

820832
// Initialize storage system
821833
//----------------------------------------------------------------------------
822-
InitAssetManager(platform.app->activity->assetManager, platform.app->activity->internalDataPath); // Initialize assets manager
823-
824834
CORE.Storage.basePath = platform.app->activity->internalDataPath; // Define base path for storage
825835
//----------------------------------------------------------------------------
826836

@@ -1514,4 +1524,66 @@ static void SetupFramebuffer(int width, int height)
15141524
}
15151525
}
15161526

1527+
// Replacement for fopen()
1528+
// REF: https://developer.android.com/ndk/reference/group/asset
1529+
FILE *android_fopen(const char *fileName, const char *mode)
1530+
{
1531+
FILE *file = NULL;
1532+
1533+
if (mode[0] == 'w')
1534+
{
1535+
// NOTE: fopen() is mapped to android_fopen() that only grants read access to
1536+
// assets directory through AAssetManager but we want to also be able to
1537+
// write data when required using the standard stdio FILE access functions
1538+
// REF: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
1539+
#undef fopen
1540+
file = fopen(TextFormat("%s/%s", platform.app->activity->internalDataPath, fileName), mode);
1541+
#define fopen(name, mode) android_fopen(name, mode)
1542+
}
1543+
else
1544+
{
1545+
// NOTE: AAsset provides access to read-only asset
1546+
AAsset *asset = AAssetManager_open(platform.app->activity->assetManager, fileName, AASSET_MODE_UNKNOWN);
1547+
1548+
if (asset != NULL)
1549+
{
1550+
// Get pointer to file in the assets
1551+
file = funopen(asset, android_read, android_write, android_seek, android_close);
1552+
}
1553+
else
1554+
{
1555+
#undef fopen
1556+
// Just do a regular open if file is not found in the assets
1557+
file = fopen(TextFormat("%s/%s", platform.app->activity->internalDataPath, fileName), mode);
1558+
if (file == NULL) file = fopen(fileName, mode);
1559+
#define fopen(name, mode) android_fopen(name, mode)
1560+
}
1561+
}
1562+
1563+
return file;
1564+
}
1565+
1566+
static int android_read(void *cookie, char *data, int dataSize)
1567+
{
1568+
return AAsset_read((AAsset *)cookie, data, dataSize);
1569+
}
1570+
1571+
static int android_write(void *cookie, const char *data, int dataSize)
1572+
{
1573+
TRACELOG(LOG_WARNING, "ANDROID: Failed to provide write access to APK");
1574+
1575+
return EACCES;
1576+
}
1577+
1578+
static fpos_t android_seek(void *cookie, fpos_t offset, int whence)
1579+
{
1580+
return AAsset_seek((AAsset *)cookie, offset, whence);
1581+
}
1582+
1583+
static int android_close(void *cookie)
1584+
{
1585+
AAsset_close((AAsset *)cookie);
1586+
return 0;
1587+
}
1588+
15171589
// EOF

src/platforms/rcore_desktop_glfw.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
* - Improvement 01
1717
* - Improvement 02
1818
*
19-
* ADDITIONAL NOTES:
20-
* - TRACELOG() function is located in raylib [utils] module
21-
*
2219
* CONFIGURATION:
2320
* #define RCORE_PLATFORM_CUSTOM_FLAG
2421
* Custom flag for rcore on target platform -not used-
@@ -1364,7 +1361,6 @@ void PollInputEvents(void)
13641361
//----------------------------------------------------------------------------------
13651362
// Function wrappers around RL_*alloc macros, used by glfwInitAllocator() inside of InitPlatform()
13661363
// We need to provide these because GLFWallocator expects function pointers with specific signatures
1367-
// Similar wrappers exist in utils.c but we cannot reuse them here due to declaration mismatch
13681364
// REF: https://www.glfw.org/docs/latest/intro_guide.html#init_allocator
13691365
static void *AllocateWrapper(size_t size, void *user)
13701366
{

src/platforms/rcore_desktop_rgfw.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
* - TODO
1414
*
1515
* POSSIBLE IMPROVEMENTS:
16-
* - TODO
17-
*
18-
* ADDITIONAL NOTES:
19-
* - TRACELOG() function is located in raylib [utils] module
16+
* - TBD
2017
*
2118
* CONFIGURATION:
2219
* #define RCORE_PLATFORM_RGFW

src/platforms/rcore_desktop_sdl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
* - Improvement 01
1616
* - Improvement 02
1717
*
18-
* ADDITIONAL NOTES:
19-
* - TRACELOG() function is located in raylib [utils] module
20-
*
2118
* CONFIGURATION:
2219
* #define RCORE_PLATFORM_CUSTOM_FLAG
2320
* Custom flag for rcore on target platform -not used-

src/platforms/rcore_desktop_win32.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* - Improvement 01
1414
* - Improvement 02
1515
*
16-
* ADDITIONAL NOTES:
17-
* - TRACELOG() function is located in raylib [utils] module
18-
*
1916
* CONFIGURATION:
2017
* #define RCORE_PLATFORM_CUSTOM_FLAG
2118
* Custom flag for rcore on target platform -not used-

0 commit comments

Comments
 (0)