Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
RobLoach committed Apr 7, 2021
1 parent edb0395 commit a69f0b2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)
project (raylib-physfs
VERSION 1.1.0
VERSION 1.2.0
DESCRIPTION "raylib-physfs"
HOMEPAGE_URL "https://github.com/robloach/raylib-physfs"
LANGUAGES C)
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# raylib-physfs

Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with [raylib](https://www.raylib.com/), allowing to load images, audio and fonts from data archives.
Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with [raylib](https://www.raylib.com/), allowing to load images, audio, and fonts from data archives.

## Features

- Load the following data from archives
- Image with `LoadImageFromPhysFS()`
- Images with `LoadImageFromPhysFS()`
- Textures with `LoadTextureFromPhysFS()`
- Music with `LoadMusicStreamFromPhysFS()`
- Wave with `LoadWaveFromPhysFS()`
- Font with `LoadFontFromPhysFS()`
- Waves with `LoadWaveFromPhysFS()`
- Fonts with `LoadFontFromPhysFS()`
- Text with `LoadFileTextFromPhysFS()`
- Check if directories and files exist
- Enumerate across multiple archives and mount paths
Expand Down Expand Up @@ -46,19 +47,20 @@ bool InitPhysFS(); // Initialize the
bool ClosePhysFS(); // Close the PhysFS file system
bool IsPhysFSReady(); // Check if PhysFS has been initialized successfully
bool MountPhysFS(const char* newDir, const char* mountPoint); // Mount the given directory at a mount point
bool MountPhysFSFromMemory(const unsigned char *fileData, int dataSize, const char* newDir, const char* mountPoint); // Mount the given file data as a mount point.
bool MountPhysFSFromMemory(const unsigned char *fileData, int dataSize, const char* newDir, const char* mountPoint); // Mount the given file data as a mount point
bool UnmountPhysFS(const char* oldDir); // Unmounts the given directory
bool FileExistsInPhysFS(const char* fileName); // Check if the given file exists in PhysFS
bool DirectoryExistsInPhysFS(const char* dirPath); // Check if the given directory exists in PhysFS
unsigned char* LoadFileDataFromPhysFS(const char* fileName, unsigned int* bytesRead); // Load a data buffer from PhysFS (memory should be freed)
char* LoadFileTextFromPhysFS(const char* fileName); // Load text from a file (memory should be freed)
bool SetPhysFSWriteDirectory(const char* newDir); // Set the base directory where PhysFS should write files to.
bool SetPhysFSWriteDirectory(const char* newDir); // Set the base directory where PhysFS should write files to
bool SaveFileDataToPhysFS(const char* fileName, void* data, unsigned int bytesToWrite); // Save the given file data in PhysFS
bool SaveFileTextToPhysFS(const char* fileName, char* text); // Save the given file text in PhysFS
char** GetDirectoryFilesFromPhysFS(const char* dirPath, int* count); // Get filenames in a directory path (memory should be freed)
char** GetDirectoryFilesFromPhysFS(const char* dirPath, int* count); // Get filenames in a directory path (memory should be freed)
void ClearDirectoryFilesFromPhysFS(char** files); // Clear directory files paths buffers (free memory)
long GetFileModTimeFromPhysFS(const char* fileName); // Get file modification time (last write time) from PhysFS.
Image LoadImageFromPhysFS(const char* file); // Load an image from PhysFS
long GetFileModTimeFromPhysFS(const char* fileName); // Get file modification time (last write time) from PhysFS
Image LoadImageFromPhysFS(const char* fileName); // Load an image from PhysFS
Texture2D LoadTextureFromPhysFS(const char* fileName); // Load a texture from PhysFS
Wave LoadWaveFromPhysFS(const char* fileName); // Load wave data from PhysFS
Music LoadMusicStreamFromPhysFS(const char* fileName); // Load music data from PhysFS
Font LoadFontFromPhysFS(const char* fileName, int fontSize, int *fontChars, int charsCount); // Load a font from PhysFS
Expand Down
7 changes: 2 additions & 5 deletions examples/textures/textures_image_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ int main(void)
InitPhysFS();
MountPhysFS("resources", "res");

// Load the image from PhysFS.
Image image = LoadImageFromPhysFS("res/raylib_logo.png"); // Loaded in CPU memory (RAM)
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)

UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
// Load the image directly into a texture through PhysFS.
Texture2D texture = LoadTextureFromPhysFS("res/raylib_logo.png");
//---------------------------------------------------------------------------------------

// Main game loop
Expand Down
45 changes: 36 additions & 9 deletions include/raylib-physfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ bool InitPhysFS(); // Initialize the
bool ClosePhysFS(); // Close the PhysFS file system
bool IsPhysFSReady(); // Check if PhysFS has been initialized successfully
bool MountPhysFS(const char* newDir, const char* mountPoint); // Mount the given directory at a mount point
bool MountPhysFSFromMemory(const unsigned char *fileData, int dataSize, const char* newDir, const char* mountPoint); // Mount the given file data as a mount point.
bool MountPhysFSFromMemory(const unsigned char *fileData, int dataSize, const char* newDir, const char* mountPoint); // Mount the given file data as a mount point
bool UnmountPhysFS(const char* oldDir); // Unmounts the given directory
bool FileExistsInPhysFS(const char* fileName); // Check if the given file exists in PhysFS
bool DirectoryExistsInPhysFS(const char* dirPath); // Check if the given directory exists in PhysFS
unsigned char* LoadFileDataFromPhysFS(const char* fileName, unsigned int* bytesRead); // Load a data buffer from PhysFS (memory should be freed)
char* LoadFileTextFromPhysFS(const char* fileName); // Load text from a file (memory should be freed)
bool SetPhysFSWriteDirectory(const char* newDir); // Set the base directory where PhysFS should write files to.
bool SetPhysFSWriteDirectory(const char* newDir); // Set the base directory where PhysFS should write files to
bool SaveFileDataToPhysFS(const char* fileName, void* data, unsigned int bytesToWrite); // Save the given file data in PhysFS
bool SaveFileTextToPhysFS(const char* fileName, char* text); // Save the given file text in PhysFS
char** GetDirectoryFilesFromPhysFS(const char* dirPath, int* count); // Get filenames in a directory path (memory should be freed)
void ClearDirectoryFilesFromPhysFS(char** files); // Clear directory files paths buffers (free memory)
long GetFileModTimeFromPhysFS(const char* fileName); // Get file modification time (last write time) from PhysFS.
Image LoadImageFromPhysFS(const char* file); // Load an image from PhysFS
char** GetDirectoryFilesFromPhysFS(const char* dirPath, int* count); // Get filenames in a directory path (memory should be freed)
void ClearDirectoryFilesFromPhysFS(char** filesList); // Clear directory files paths buffers (free memory)
long GetFileModTimeFromPhysFS(const char* fileName); // Get file modification time (last write time) from PhysFS
Image LoadImageFromPhysFS(const char* fileName); // Load an image from PhysFS
Texture2D LoadTextureFromPhysFS(const char* fileName); // Load a texture from PhysFS
Wave LoadWaveFromPhysFS(const char* fileName); // Load wave data from PhysFS
Music LoadMusicStreamFromPhysFS(const char* fileName); // Load music data from PhysFS
Font LoadFontFromPhysFS(const char* fileName, int fontSize, int *fontChars, int charsCount); // Load a font from PhysFS
Expand Down Expand Up @@ -264,7 +265,7 @@ bool DirectoryExistsInPhysFS(const char* dirPath) {
}

/**
* Load image from PhysFS.
* Load an image from PhysFS.
*
* @param fileName The filename to load from the search paths.
*
Expand All @@ -288,6 +289,30 @@ Image LoadImageFromPhysFS(const char* fileName) {
return image;
}

/**
* Load a texture from PhysFS.
*
* @param fileName The filename to load from the search paths.
*
* @return The loaded texture on success. An empty texture otherwise.
*
* @see LoadImageFromPhysFS()
*/
Texture2D LoadTextureFromPhysFS(const char* fileName) {
Image image = LoadImageFromPhysFS(fileName);
if (image.data == 0) {
Texture2D output = { 0 };
output.id = 0;
output.format = 0;
output.width = 0;
output.height = 0;
return output;
}
Texture2D texture = LoadTextureFromImage(image);
UnloadImage(image);
return texture;
}

/**
* Load text data from file (read). Make sure to call UnloadFileText() when done.
*
Expand Down Expand Up @@ -474,10 +499,12 @@ char** GetDirectoryFilesFromPhysFS(const char* dirPath, int *count) {
/**
* Clears the loaded list of directory files from GetDirectoryFilesFromPhysFS().
*
* @param filesList The list of files to clear that was provided from GetDirectoryFilesFromPhysFS().
*
* @see GetDirectoryFilesFromPhysFS()
*/
void ClearDirectoryFilesFromPhysFS(char** files) {
PHYSFS_freeList(files);
void ClearDirectoryFilesFromPhysFS(char** filesList) {
PHYSFS_freeList(filesList);
}

/**
Expand Down

0 comments on commit a69f0b2

Please sign in to comment.