Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Apr 3, 2021
2 parents df7a992 + 4b0f3ba commit 3838020
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 97 deletions.
19 changes: 9 additions & 10 deletions 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.0.0
VERSION 1.1.0
DESCRIPTION "raylib-physfs"
HOMEPAGE_URL "https://github.com/robloach/raylib-physfs"
LANGUAGES C)
Expand All @@ -15,12 +15,11 @@ if(BUILD_RAYLIB_PHYSFS_EXAMPLES)
endif()

# Testing
# TODO: Add automated testing.
# include(CTest)
# enable_testing()
# if(BUILD_TESTING)
# set(CTEST_CUSTOM_TESTS_IGNORE
# pkg-config--static
# )
# add_subdirectory(tests)
# endif()
include(CTest)
enable_testing()
if(BUILD_TESTING)
set(CTEST_CUSTOM_TESTS_IGNORE
pkg-config--static
)
add_subdirectory(test)
endif()
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with
## Features

- Load the following data from archives
- Font with `LoadFontFromPhysFS()`
- Image with `LoadImageFromPhysFS()`
- Music with `LoadMusicStreamFromPhysFS()`
- Wave with `LoadWaveFromPhysFS()`
- Image with `LoadImageFromPhysFS()`
- Font with `LoadFontFromPhysFS()`
- Text with `LoadFileTextFromPhysFS()`
- Enumerate across multiple archives and mount paths
- Check if directories and files exist
- Register the file loading API callbacks with PhysFS
- Enumerate across multiple archives and mount paths
- Save files through PhysFS

## Usage

This is a single-file header. To use it, define `RAYLIB_PHYSFS_IMPLEMENTATION` in one `.c` source files before including [`raylib-physfs.h`](include/raylib-physfs.h). You will also have to link the PhysFS and raylib dependencies.
This is a single-file header. To use it, define `RAYLIB_PHYSFS_IMPLEMENTATION` in one `.c` source file before including [`raylib-physfs.h`](include/raylib-physfs.h). You will also have to link the PhysFS and raylib dependencies.

### Example

Expand All @@ -42,35 +42,39 @@ int main() {
### Cheatsheet

``` c
bool InitPhysFS(); // Initialize the PhysFS file system
bool ClosePhysFS(); // Close the PhysFS file system
bool MountPhysFS(const char* newDir, const char* mountPoint); // Mount the given directory at 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)
void SaveFileDataToPhysFS(const char* fileName, void* data, unsigned int bytesToWrite); // Save the given file data in PhysFS
void SaveFileTextToPhysFS(const char* fileName, char* text); // Save the given file text in PhysFS
void SetPhysFSDataCallbacks(); // Register all the PhysFS load/save file callbacks
bool InitPhysFS(); // Initialize the PhysFS file system
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 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 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)
Image LoadImageFromPhysFS(const char* file); // Load an image 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
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
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
```
## Development
To build the examples locally, use [cmake](https://cmake.org/).
To build the examples locally, and run tests, use [cmake](https://cmake.org/).
``` bash
git submodule update --init
mkdir build
cd build
cmake ..
make
make test
cd examples
./textures_image_loading
```
Expand Down
4 changes: 2 additions & 2 deletions examples/audio/audio_music_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ int main(void)

// Initialize the file system, and mount a directory.
InitPhysFS();
MountPhysFS("resources", "res");
MountPhysFS("resources", "");

InitAudioDevice(); // Initialize audio device

Music music = LoadMusicStreamFromPhysFS("res/country.mp3");
Music music = LoadMusicStreamFromPhysFS("country.mp3");

PlayMusicStream(music);

Expand Down
6 changes: 3 additions & 3 deletions examples/audio/audio_sound_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ int main(void)
InitAudioDevice(); // Initialize audio device

InitPhysFS(); // Initialize PhysFS
MountPhysFS("resources", "res");
MountPhysFS("resources", ""); // Mount the resources directory.

Wave wav = LoadWaveFromPhysFS("res/sound.wav");
Wave ogg = LoadWaveFromPhysFS("res/target.ogg");
Wave wav = LoadWaveFromPhysFS("sound.wav");
Wave ogg = LoadWaveFromPhysFS("target.ogg");

Sound fxWav = LoadSoundFromWave(wav); // Load WAV audio file
Sound fxOgg = LoadSoundFromWave(ogg); // Load OGG audio file
Expand Down
Loading

0 comments on commit 3838020

Please sign in to comment.