Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[multi] Avoid direct file access, read data from memory #1232

Closed
raysan5 opened this issue Apr 30, 2020 · 6 comments
Closed

[multi] Avoid direct file access, read data from memory #1232

raysan5 opened this issue Apr 30, 2020 · 6 comments

Comments

@raysan5
Copy link
Owner

raysan5 commented Apr 30, 2020

One of the big changes of raylib 3.0 was changing most of the functions reading data from files to reading data from a pre-loaded buffer, this way all external files are loaded into memory using LoadFileData()/LoadFileText() and then the buffers are processed. Consequently, multiple internal function were adapted to receive a data buffer instead of the filename.

But there are still some internal functions left:

module function type details state
text LoadBMFont() text Contains external image file reference ✔️
textures LoadDDS() bin DDS file format ✔️
textures LoadPKM() bin PKM file format ✔️
textures LoadKTX() bin KTX file format ✔️
textures LoadPVR() bin PVR file format ✔️
textures LoadASTC() bin ASTC file format ✔️
textures SaveKTX() bin KTS file format saving ✔️
textures ExportImageAsCode() text Save image data as text code file ✔️
models LoadOBJ() text Parses OBJ text data but internally access .mtl file... 💬
models LoadIQM() bin IQM mesh/anims file format ✔️
models LoadModelAnimations() bin IQM file format anims loading... ✔️
models ExportMesh() text Exports mesh data as an OBJ text file... ✔️
raudio LoadWAV() bin WAV file format ✔️
raudio SaveWAV() bin WAV file saving ✔️
raudio ExportWaveAsCode() text Exports wave data as text code file... ✔️

Those functions have not been changed because I'm considering moving that functionality out of raylib modules to external libraries.

Note that this change does not mean adding functions for the users to allow file-formats loading from a user-provided memory buffer but support that feature internally by raylib when processing external files, just to avoid FILE operations on the module.

@raysan5
Copy link
Owner Author

raysan5 commented May 21, 2020

Finally I decided not to move file-formats loading to external libraries, current raylib config.h allows disabling those files loading functionality if desired.

Probably big projects using a custom package resource fileformat prefer not using those loaders...

@raysan5
Copy link
Owner Author

raysan5 commented May 21, 2020

Some functions reviewed in commit 0e56bc2

@raysan5
Copy link
Owner Author

raysan5 commented May 23, 2020

LoadIQM(), LoadModelAnimations() reviewed in commit 0bcb892

raysan5 added a commit that referenced this issue May 23, 2020
This change could introduce an issue on dataSize precalculation...
@raysan5
Copy link
Owner Author

raysan5 commented May 23, 2020

LoadWAV() and SaveWAV() now use drwav library, it manages file open/close internally. It's possible to use memory buffers instead but for the moment we are not using them because LoadFileData() and SaveFileData() are not available on RAUDIO_STANDALONE.

Actually, LoadOGG(), LoadFLAC() and LoadMP3() should also be reviewed to use memory buffers instead of direct file access...

@raysan5
Copy link
Owner Author

raysan5 commented May 24, 2020

Redesigned ExportWaveAsCode() to use memory buffer on commit 1c5df67.

@raysan5
Copy link
Owner Author

raysan5 commented May 24, 2020

LoadOBJ() had issues with material loading when .obj was not in the working directory (for example inside a resources/models directory).

Implemented solution on raylib was using chdir() to move to .obj directory before calling tinyobj_parse_obj() and return to current directory at the end of the function. It works but I don't like that solution. Also, user has no control over the file access, in case someone wants to use memory buffers for that.

There is a related issue on tinyobjloader-c project: syoyo/tinyobjloader-c#38

@raysan5 raysan5 closed this as completed May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant