From cc42885e602397adfd61a7f3615a1496caee7398 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 14 Sep 2018 05:48:56 -0400 Subject: [PATCH 1/8] Add relative mount() support Fixes #272 --- src/love/filesystem.cpp | 27 ++++++++++++++++++++++----- test/unittests/filesystem.chai | 7 +++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/love/filesystem.cpp b/src/love/filesystem.cpp index d2e701ff5..6f04dd396 100644 --- a/src/love/filesystem.cpp +++ b/src/love/filesystem.cpp @@ -227,13 +227,30 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint if (archive.length() <= 0 || mountpoint.length() <= 0) { return false; } + + // Display a message. std::cout << "[ChaiLove] [filesystem] Mounting " << archive << " as " << mountpoint << std::endl; - int returnValue = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), 0); - if (returnValue == 0) { - std::cout << "[ChaiLove] [filesystem] Error mounting: " << getLastError() << std::endl; - return false; + + // Use the simple mount method if we're mounting the root directory. + if (mountpoint == "/") { + int returnValue = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), 0); + if (returnValue == 0) { + std::cout << "[ChaiLove] [filesystem] Error mounting: " << getLastError() << std::endl; + return false; + } + return true; } - return true; + + // Mount using a handle instead, since we're doing another archive. + PHYSFS_File* file = openFile(archive); + if (file != NULL) { + if (PHYSFS_mountHandle(file, archive.c_str(), mountpoint.c_str(), 1) == 0) { + std::cout << "[ChaiLove] [filesystem] Error mounting: " << getLastError() << std::endl; + return false; + } + return true; + } + return false; } /** diff --git a/test/unittests/filesystem.chai b/test/unittests/filesystem.chai index 943224e1b..057ff65a3 100644 --- a/test/unittests/filesystem.chai +++ b/test/unittests/filesystem.chai @@ -65,8 +65,7 @@ var writeFileReturn = love.filesystem.write("test/createDirectoryTest/test.md", assert(writeFileReturn, "love.filesystem.write()") // mount() -// @TODO: Figure out how to have the mount() point be relative to the origin. -var mountResult = love.filesystem.mount("test/unittests/assets/hello.zip", "hello") +var mountResult = love.filesystem.mount("assets/hello.zip", "hello") assert(mountResult, "love.filesystem.mount()") // mount() - Load @@ -74,11 +73,11 @@ var mountLoadResult = love.filesystem.read("hello/hello.txt") var mountLoadResultType = is_type(mountLoadResult, "string") assert(mountLoadResultType, " read()") if (mountLoadResultType) { - assert_equal(mountLoadResult.trim(), "Hello World!", " contents") + assert_equal(mountLoadResult.trim(), "Hello World!", " contents") } // unmount() -love.filesystem.unmount("test/unittests/assets/hello.zip") +love.filesystem.unmount("assets/hello.zip") assert_not(love.filesystem.exists("hello/hello.txt"), "love.filesystem.unmount()") // require() From 2d7857c682ab320594210ac1a9761a9c777fd2e0 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 14 Sep 2018 05:51:45 -0400 Subject: [PATCH 2/8] Update version --- CHANGELOG.md | 4 ++++ docs/Doxyfile | 2 +- examples/snake/Snake.chai | 2 +- src/ChaiLove.h | 4 ++-- src/love/config.h | 2 +- src/love/script.h | 2 +- test/main.chai | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f826216..86c51b4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.26.1 - Unreleased +### Fixes +- Fixed `mount()` with relative paths + ## 0.26.0 - 2018-09-13 ### Features - Added a global `require()` function to load modules ([#308](https://github.com/libretro/libretro-chailove/pull/308)) diff --git a/docs/Doxyfile b/docs/Doxyfile index 44e127ada..ee1fc3823 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -23,7 +23,7 @@ PROJECT_NAME = "ChaiLove API" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "0.26.0" +PROJECT_NUMBER = "0.26.1" # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/examples/snake/Snake.chai b/examples/snake/Snake.chai index b74adf73b..a077d63c7 100644 --- a/examples/snake/Snake.chai +++ b/examples/snake/Snake.chai @@ -47,7 +47,7 @@ global T def conf(t) { t.window.width = WIDTH * gridScale t.window.height = HEIGHT * gridScale - t.version = "0.26.0" + t.version = "0.26.1" } /** diff --git a/src/ChaiLove.h b/src/ChaiLove.h index 242747b2f..ad4213ce7 100644 --- a/src/ChaiLove.h +++ b/src/ChaiLove.h @@ -48,8 +48,8 @@ #define CHAILOVE_VERSION_MAJOR 0 #define CHAILOVE_VERSION_MINOR 26 -#define CHAILOVE_VERSION_PATCH 0 -#define CHAILOVE_VERSION_STRING "0.26.0" +#define CHAILOVE_VERSION_PATCH 1 +#define CHAILOVE_VERSION_STRING "0.26.1" #include "SDL.h" #include "libretro.h" diff --git a/src/love/config.h b/src/love/config.h index 955579c11..9e97f2011 100644 --- a/src/love/config.h +++ b/src/love/config.h @@ -19,7 +19,7 @@ namespace love { * * @code * def conf(t) { - * t.version = "0.26.0" // Version of ChaiLove + * t.version = "0.26.1" // Version of ChaiLove * t.identity = "mygame" // Machine name of your game * t.window.title = "My Game" // Human-readable name * t.window.width = 1024 // Game width diff --git a/src/love/script.h b/src/love/script.h index f660f1b43..73f89eb18 100644 --- a/src/love/script.h +++ b/src/love/script.h @@ -53,7 +53,7 @@ class script { * t.console = false * * // The ChaiLove version this game was made for. - * t.version = "0.26.0" + * t.version = "0.26.1" * * // The width and height of the game. * t.window.width = 1024 diff --git a/test/main.chai b/test/main.chai index 14f7e41dc..26e605b42 100644 --- a/test/main.chai +++ b/test/main.chai @@ -15,7 +15,7 @@ def conf(t) { t.window.width = 460 t.window.height = 320 t.console = true - t.version = "0.26.0" + t.version = "0.26.1" } def load() { From 7d4009c11d751f0ad507a5ee4fa123aa605e2fbc Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 14 Sep 2018 19:01:00 -0400 Subject: [PATCH 3/8] emscripten: Compile nearest_resampler only when not STATIC_LINKING --- Makefile.common | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.common b/Makefile.common index 5c979c02b..34452289f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -28,7 +28,6 @@ SOURCES_C += $(wildcard \ $(CORE_DIR)/vendor/libretro-common/audio/audio_mixer.c \ $(CORE_DIR)/vendor/libretro-common/audio/conversion/*.c \ $(CORE_DIR)/vendor/libretro-common/audio/resampler/audio_resampler.c \ - $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/nearest_resampler.c \ $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/null_resampler.c \ $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/sinc_resampler.c \ $(CORE_DIR)/vendor/libretro-common/compat/compat_posix_string.c \ @@ -46,6 +45,11 @@ SOURCES_C += $(wildcard \ $(CORE_DIR)/vendor/libretro-common/streams/file_stream.c \ $(CORE_DIR)/vendor/libretro-common/vfs/*.c \ ) +# Only compile nearest_resampler when not STATIC_LINKING +ifneq ($(STATIC_LINKING), 1) + SOURCES_C += $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/nearest_resampler.c +endif + # stb_vorbis #SOURCES_C += $(CORE_DIR)/vendor/stb/stb_vorbis.c From 622b72cca0a53293cbdd8f0517223c93f6daa399 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 14 Sep 2018 19:44:43 -0400 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c51b4af..337b29508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 0.26.1 - Unreleased ### Fixes - Fixed `mount()` with relative paths +- Fix for compiling `nearest_resampler.c` without `STATIC_LINKING` ([#312](https://github.com/libretro/libretro-chailove/pull/312)) + - By [@twinaphex](https://github.com/twinaphex) ## 0.26.0 - 2018-09-13 ### Features From 6c835b1d33f2898c0d6135bca4807919beae2bdf Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 15 Sep 2018 00:54:17 -0400 Subject: [PATCH 5/8] Fix mounting libretro paths --- src/ChaiLove.cpp | 4 ++-- src/ChaiLove.h | 2 +- src/libretro.cpp | 2 +- src/love/filesystem.cpp | 36 +++++++++++++++++++++++++----------- src/love/filesystem.h | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/ChaiLove.cpp b/src/ChaiLove.cpp index 427da1a59..dc75b9393 100644 --- a/src/ChaiLove.cpp +++ b/src/ChaiLove.cpp @@ -56,7 +56,7 @@ void ChaiLove::quit(void) { window.unload(); } -bool ChaiLove::load(const std::string& file) { +bool ChaiLove::load(const std::string& file, const void* data) { // Display a welcome message from ChaiLove. #ifndef GIT_VERSION #define GIT_VERSION "" @@ -68,7 +68,7 @@ bool ChaiLove::load(const std::string& file) { sound.load(); // Initalize the file system. - bool loaded = filesystem.init(file); + bool loaded = filesystem.init(file, data); if (!loaded) { std::cout << "[ChaiLove] [filesystem] Error loading " << file << std::endl; return false; diff --git a/src/ChaiLove.h b/src/ChaiLove.h index ad4213ce7..e8b39e980 100644 --- a/src/ChaiLove.h +++ b/src/ChaiLove.h @@ -105,7 +105,7 @@ class ChaiLove { ~ChaiLove(); void quit(void); - bool load(const std::string& file); + bool load(const std::string& file, const void* data); void update(); void draw(); void reset(); diff --git a/src/libretro.cpp b/src/libretro.cpp index d1df823a4..5034a36e8 100644 --- a/src/libretro.cpp +++ b/src/libretro.cpp @@ -330,7 +330,7 @@ bool retro_load_game(const struct retro_game_info *info) { if (gamePath == ".") { gamePath = "main.chai"; } - return ChaiLove::getInstance()->load(gamePath); + return ChaiLove::getInstance()->load(gamePath, info->data); } /** diff --git a/src/love/filesystem.cpp b/src/love/filesystem.cpp index 6f04dd396..7df8e11f2 100644 --- a/src/love/filesystem.cpp +++ b/src/love/filesystem.cpp @@ -17,7 +17,7 @@ namespace love { /** * Initialize the file system. */ -bool filesystem::init(const std::string& file) { +bool filesystem::init(const std::string& file, const void* data) { if (PHYSFS_isInit() == 0) { // Initialize PhysFS if (PHYSFS_init(NULL) == 0) { @@ -57,16 +57,16 @@ void filesystem::mountlibretro() { const char *assets_dir = NULL; const char *save_dir = NULL; if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir) { - mount(system_dir, "libretro/system"); + mount(system_dir, "/libretro/system"); } if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY, &assets_dir) && assets_dir) { - mount(assets_dir, "libretro/assets"); + mount(assets_dir, "/libretro/assets"); } if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir) && save_dir) { save_dir = *save_dir ? save_dir : system_dir; - mount(save_dir, "libretro/saves"); + mount(save_dir, "/libretro/saves"); } else { - mount(save_dir = system_dir, "libretro/saves"); + mount(save_dir = system_dir, "/libretro/saves"); } // Ensure the write directory is set to the Save Directory. @@ -235,17 +235,31 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint if (mountpoint == "/") { int returnValue = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), 0); if (returnValue == 0) { - std::cout << "[ChaiLove] [filesystem] Error mounting: " << getLastError() << std::endl; + std::cout << "[ChaiLove] [filesystem] Error mounting /: " << getLastError() << std::endl; return false; } return true; } - // Mount using a handle instead, since we're doing another archive. - PHYSFS_File* file = openFile(archive); - if (file != NULL) { - if (PHYSFS_mountHandle(file, archive.c_str(), mountpoint.c_str(), 1) == 0) { - std::cout << "[ChaiLove] [filesystem] Error mounting: " << getLastError() << std::endl; + // See if we're mounting a file. + if (isFile(archive)) { + // Mount using a handle instead, since we're doing another archive. + PHYSFS_File* file = openFile(archive); + if (file != NULL) { + if (PHYSFS_mountHandle(file, archive.c_str(), mountpoint.c_str(), 1) == 0) { + std::cout << "[ChaiLove] [filesystem] Error mounting file: " << getLastError() << std::endl; + return false; + } + return true; + } + return false; + } + + // Check if we're mounting a directory. + if (isDirectory(archive)) { + int returnVal = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), 0); + if (returnVal == 0) { + std::cout << "[ChaiLove] [filesystem] Error mounting directory: " << getLastError() << std::endl; return false; } return true; diff --git a/src/love/filesystem.h b/src/love/filesystem.h index da400cf70..bcbaa8fb6 100644 --- a/src/love/filesystem.h +++ b/src/love/filesystem.h @@ -35,7 +35,7 @@ class filesystem { bool load(const std::string& file); void mountlibretro(); - bool init(const std::string& file); + bool init(const std::string& file, const void* data); bool unload(); SDL_RWops* openRW(const std::string& filename); char* readChar(const std::string& filename); From 85fb625f04952ed025bda86f24d8458a3232d801 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 15 Sep 2018 02:44:40 -0400 Subject: [PATCH 6/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337b29508..ea628e2be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 0.26.1 - Unreleased ### Fixes - Fixed `mount()` with relative paths +- Fixed mounting of saves and system directories - Fix for compiling `nearest_resampler.c` without `STATIC_LINKING` ([#312](https://github.com/libretro/libretro-chailove/pull/312)) - By [@twinaphex](https://github.com/twinaphex) From 506a8967ca8cd1cc0a09bab53412a391df26674d Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Sep 2018 21:34:01 -0400 Subject: [PATCH 7/8] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea628e2be..52cc1905c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed mounting of saves and system directories - Fix for compiling `nearest_resampler.c` without `STATIC_LINKING` ([#312](https://github.com/libretro/libretro-chailove/pull/312)) - By [@twinaphex](https://github.com/twinaphex) +- Fix netplay and rewind by removing compression of save states ## 0.26.0 - 2018-09-13 ### Features From 028a57811c519eee18bcb2c2e7243f409c3d5b29 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Sep 2018 21:45:42 -0400 Subject: [PATCH 8/8] 0.26.1 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52cc1905c..d0f0ad1d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,13 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## 0.26.1 - Unreleased +## 0.26.1 - 2018-09-19 ### Fixes - Fixed `mount()` with relative paths - Fixed mounting of saves and system directories - Fix for compiling `nearest_resampler.c` without `STATIC_LINKING` ([#312](https://github.com/libretro/libretro-chailove/pull/312)) - By [@twinaphex](https://github.com/twinaphex) -- Fix netplay and rewind by removing compression of save states +- Fix rewind by removing compression of save states ## 0.26.0 - 2018-09-13 ### Features