Commit graph

2345 commits

Author SHA1 Message Date
刘皓
3ba12e5672
Fix handling of big-endian platforms in libretro builds
In big-endian libretro builds, the WebAssembly memory is reversed, so no
byte-swapping is required to read from/write to WebAssembly memory
(which is little-endian).

However, that means the ways to get and set values in WebAssembly memory
are endianness-dependent, so I've added the correct such ways for
big-endian platforms.
2025-05-10 18:55:14 -04:00
刘皓
09ed08c087
Fix edge case in memory reallocation algorithm in wasm-rt.cpp 2025-05-10 11:09:20 -04:00
刘皓
fc744ab6c6
Refactor locking of all tracks in AudioPrivate::bgmTracks into a custom lock guard 2025-05-10 10:48:57 -04:00
刘皓
3bceb56bd3
Merge branch 'misc-fixes' into libretro 2025-05-10 10:48:49 -04:00
刘皓
95f0f08c87
Fix memory leak in Input::getClipboardText() 2025-05-10 10:47:48 -04:00
刘皓
215046d8b4
Only use extern in embedtool.cpp if language is C++
In C, variables defined as `const` have external linkage.

In C++, variables defined as `const` have internal linkage, and we need
to define them as `extern const` for them to have external linkage like
in C.

However, in C, defining a variable as `extern const` throws a compiler
error, so we need to add `extern` only for C++ files.
2025-05-10 10:47:19 -04:00
刘皓
dafe038bb4
Merge branch 'misc-fixes' into libretro 2025-05-10 10:07:48 -04:00
刘皓
54d915860f
Fix some bugs in the ME watch thread
* BGM track streams should be locked while `extPaused` is being modified
* All BGM track streams should be locked in the `BgmFadingOut` phase
  since we need to query the states of all tracks in the middle of the
  loop
* BGM tracks should have `extPaused` set to false if the ME ends in the
  middle of the `BgmFadingOut` phase
2025-05-10 09:59:56 -04:00
刘皓
c5747f17c5
Fix minor issues in binding-sandbox/binding-base.h and binding-sandbox/binding-util.h 2025-05-10 09:25:43 -04:00
刘皓
8ec189e3d2
Remove always-false static_assert from binding-sandbox/binding-base.h
This is causing compilation errors with some compilers.
2025-05-09 23:28:17 -04:00
刘皓
b8d785b7e1
Implement growing VM memory in libretro builds
The binding coroutines in libretro builds are constructed on the VM
stack, so reallocating the VM memory would corrupt the memory of any
currently existing coroutines.

I've changed it so that the coroutines are no longer constructed on the
VM stack so that they're unaffected by VM memory reallocations, and
added a "slot" mechanism for storing variables on the VM stack. (Any
Ruby `VALUE`s used by a coroutine have to be stored on the VM stack so
that the Ruby garbage collector doesn't free them while they're being
used, which is why the slot mechanism is necessary.)
2025-05-09 22:49:13 -04:00
刘皓
d186fa97bc
Update Emscripten to 4.0.8 for the libretro Emscripten autobuild
Will be required once https://github.com/libretro/RetroArch/pull/17872
makes its way into the version of RetroArch used in the autobuild.
2025-05-09 18:02:37 -04:00
刘皓
d71cd242c7
Improve save directory creation algorithm in libretro builds
Before, if the game tried to create a save file, missing parent
directories would always be created because they could possibly exist
only in the game directory and not in the save directory, and we
wouldn't know due to the union mounting of the save and game
directories. But this is inconsistent with the behaviour of file
creation, where it should fail if parent directories don't exist.

The behaviour has been changed to only create parent directories if the
parent directories already exist. I know that sounds strange, but if the
parent directories exist, it could be that they only exist in the game
directory but not the save directory due to the union mounting, so we
need to create the parent directories, which will be created in the save
directory due to it being set as the write directory in PhysFS.
2025-05-07 22:13:45 -04:00
刘皓
66256e9156
Put saves in ./mkxp-z/Saves/ in libretro save directory
Since the libretro save directory isn't guaranteed to be private for
each core, or even private for just saves, we'd better create a
directory structure in the libretro save directory for our saves.
2025-05-07 18:35:25 -04:00
刘皓
c85e9554ec
Implement writing to filesystem (i.e. game saving) in libretro builds
Files are written to the libretro save directory, which is mounted at
/save in PhysFS. All filesystem calls made from Ruby in libretro builds
are routed through PhysFS, so the game can just use any ordinary
filesystem function provided by Ruby to interact with /save.

It's also union mounted on top of the game directory (located at /game
in PhysFS) so that games that write their save files to the current
working directory will have their save files saved to the libretro save
directory instead of the game directory.

For security and portability reasons, nothing outside of the libretro
save directory can be written to, and nothing outside of the libretro
save directory, the libretro game directory and the various embedded
files used by the runtime can be read from.
2025-05-07 16:01:41 -04:00
刘皓
3e3df818aa
Use C getcwd() instead of Ruby Dir.pwd() to get CWD in libretro builds 2025-05-06 18:02:03 -04:00
刘皓
13c0657691
Handle current working directory properly in libretro builds
Any relative paths that the game tries to access in libretro builds will
now be relative to whatever is the current working directory in the Ruby
sandbox, which will also now be initialized to the game directory during
initialization. Before, all of the bindings that took paths were
hardcoded to prepend the path with the game directory.
2025-05-06 16:55:28 -04:00
刘皓
b518ca62f0
Re-add polyfill for pthread_self()
Apparently PhysFS does actually need this function to work properly.
Without it, we get weird crashes and corruptions in some of the libretro
builds.
2025-05-05 16:45:22 -04:00
刘皓
33e1328e71
Prevent usage of mkxp_thread_t on single-threaded platforms 2025-05-05 11:47:17 -04:00
刘皓
1c10158f2d
Add single-threaded Graphics.play_movie for platforms without multithreading 2025-05-05 11:00:27 -04:00
刘皓
2bec640f7f
Update TheoraPlay in the Xcode build system as well 2025-05-04 21:39:52 -04:00
刘皓
307d3d84d5
Update TheoraPlay
The version originally used by mkxp-z has a bug where TheoraPlay's
internal mutexes don't do anything on non-Windows platforms (see commit
35295146d38d389729380a691292cdb8e90bad1b in TheoraPlay), leading to race
conditions, especially when using RetroArch's fast-forwarding.

Also, this new version has support for being run single-threaded,
which'll come in handy on platforms with no multithreading support.
2025-05-04 11:41:32 -04:00
刘皓
82c3d7985c
Fix some Graphics.play_movie audio/video synchronization issues in libretro builds 2025-05-03 23:01:11 -04:00
刘皓
74e5cc763c
Implement Graphics.play_movie in libretro builds 2025-05-03 18:27:44 -04:00
刘皓
23bc6625f1
Add Theora as a dependency in libretro builds 2025-05-03 13:46:17 -04:00
刘皓
a0219e7c79
Implement loading animated GIF bitmaps in libretro builds 2025-05-03 11:07:55 -04:00
刘皓
bcfcd6df8a
Merge branch 'misc-fixes' into libretro 2025-05-02 14:56:47 -04:00
刘皓
b0e051b816
Merge branch 'dev' into misc-fixes 2025-05-02 14:56:31 -04:00
刘皓
df1dbccf5a
Implement bindings for keyboard and controller button input in libretro builds 2025-05-02 14:53:21 -04:00
Splendide Imaginarius
4bf2d9e02c
Merge pull request #240 from white-axe/cmake4
Fix builds with CMake 4
2025-05-02 17:43:29 +00:00
刘皓
c9e7c4d02d
Stub out the rest of the input bindings in libretro builds 2025-05-01 22:49:18 -04:00
刘皓
97235e068a
Use environment variable to set CMake policy instead of -D flag
This applies recursively unlike the other method.
2025-05-01 17:55:38 -04:00
Splendide Imaginarius
c9096e42ee
Merge pull request #237 from white-axe/macos
Fix macOS builds with Xcode 15 or later
2025-05-01 20:58:30 +00:00
刘皓
df559241a2
Complete almost all of the bindings in libretro builds
The only things left are the bindings for the input extensions and
possibly adding in `SANDBOX_YIELD` to the `Graphics.play_movie` binding
later.
2025-05-01 14:32:59 -04:00
刘皓
82b2ad0ef1
Add serializable-binding.h in libretro builds 2025-05-01 13:58:54 -04:00
刘皓
a40f6e7659
Fix some compiler warnings in libretro builds 2025-05-01 11:58:43 -04:00
刘皓
bdcbfd26f1
Add more helper functions for bindings in libretro builds 2025-05-01 11:18:02 -04:00
刘皓
41fc9bf7c7
Pin wasm2c version in libretro builds
To prevent incompatibilities between wasm2c and the custom wasm-rt
implementation.
2025-05-01 00:53:26 -04:00
刘皓
482f21bc2e
Fix Darwin compilation error in binding-sandbox/graphics-binding.cpp 2025-04-30 23:39:51 -04:00
刘皓
5b94ce4e80
Refactor binding-sandbox header files into .cpp files 2025-04-30 22:31:13 -04:00
刘皓
09bcb1532c
Refactor out the SANDBOX_COROUTINE() macro
Removing this macro allows the correct line numbers to show up in GDB
stack traces.
2025-04-30 19:00:48 -04:00
刘皓
2de7a050db
Use property binding helper macros in libretro builds 2025-04-30 15:47:02 -04:00
刘皓
eb0b011734
Add mouse bindings in libretro builds 2025-04-30 12:26:18 -04:00
刘皓
a001495cc5
Fix infinite loop in meWatchThread() in standalone builds 2025-04-29 16:09:19 -04:00
刘皓
2373a22a70
Complete the graphics bindings in libretro builds 2025-04-29 14:51:19 -04:00
刘皓
a3412bbe41
Fix Graphics.transition(0) being ignored in libretro builds 2025-04-29 14:13:41 -04:00
刘皓
3b017e7bb4
Fix AudioMutex constructor in standalone builds 2025-04-29 13:53:56 -04:00
刘皓
414d78a327
Remove workarounds for RetroArch 1.20.0
The next stable version of RetroArch has been released, so we don't need
to maintain workarounds for bugs in RetroArch 1.20.0 anymore.
2025-04-29 00:12:04 -04:00
刘皓
8182f3591c
Fix typo in wrap_property in libretro binding utils 2025-04-29 00:07:54 -04:00
刘皓
c51e0d2701
Complete the bitmap bindings in libretro builds 2025-04-28 16:15:11 -04:00