Commit graph

104 commits

Author SHA1 Message Date
刘皓
714c583b9f
Allow RTPs to be loaded from archives as well in libretro builds 2025-05-13 16:17:04 -04:00
刘皓
75b953d4c8
Implement loading RTPs from the libretro system directory 2025-05-13 12:28:17 -04:00
刘皓
f57568e051
Allow some libretro core options to be changed during execution 2025-05-11 18:54:56 -04:00
刘皓
3fda80275d
Implement core options in libretro builds 2025-05-11 17:04:33 -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
刘皓
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
刘皓
1c10158f2d
Add single-threaded Graphics.play_movie for platforms without multithreading 2025-05-05 11:00:27 -04:00
刘皓
82c3d7985c
Fix some Graphics.play_movie audio/video synchronization issues in libretro builds 2025-05-03 23:01:11 -04:00
刘皓
df1dbccf5a
Implement bindings for keyboard and controller button input in libretro builds 2025-05-02 14:53:21 -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
刘皓
2373a22a70
Complete the graphics bindings in libretro builds 2025-04-29 14:51:19 -04:00
刘皓
0d035702a1
Don't use atomics in libretro builds without multithreading support 2025-04-26 18:00:06 -04:00
刘皓
57a282d359
Don't ignore return value of libretro audio sample callback 2025-04-26 10:41:32 -04:00
刘皓
0d07aff3e2
Remove exceptions from the sandbox implementation in libretro builds 2025-04-25 13:31:32 -04:00
刘皓
d0b211e239
Fix audio fading in libretro builds 2025-04-25 12:16:51 -04:00
刘皓
1be7eef3c7
Fix race condition when using libretro threaded audio driver 2025-04-25 11:30:23 -04:00
刘皓
003602eff8
Only poll input in libretro builds when Input.update is called 2025-04-25 11:01:12 -04:00
刘皓
2b3a97e83c
Fix frame duping bugs in libretro builds
* Fixed a bug where frames are still duped when the frontend is
  fast-forwarding

* Fixed a bug where manual frame duping (without
  `RETRO_ENVIRONMENT_GET_CAN_DUPE`) causes screen flickering during a
  `Graphics.transition` call
2025-04-25 10:45:11 -04:00
刘皓
5c14f2352e
Implement frame duping properly in libretro builds 2025-04-24 15:36:26 -04:00
刘皓
a12e3caf77
Always run at display rate in libretro builds
Apparently we're not supposed to use
`RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO` to change the FPS. The core
should be running at the display refresh rate and resampling the game's
video output.
2025-04-24 15:08:42 -04:00
刘皓
286ae0fe4d
Fix resource starvation in deinit_sandbox() when using threaded audio 2025-04-24 11:32:04 -04:00
刘皓
784ec38b3d
Throttle the frame rate in libretro builds with threaded audio
When not using the threaded audio driver, the frontend is supposed to
block until enough audio samples have been rendered for one frame, so
the frontend throttles the frame rate automatically if the core's frame
rate is slower than the display frame rate.

However, when using the threaded audio driver, there's no more
throttling, so we have to do it ourselves.
2025-04-23 16:58:03 -04:00
刘皓
71653549f2
Add threaded audio driver in libretro builds
This adds a new driver for audio in libretro builds for devices with
multithreading support that defers audio rendering to a worker thread
provided by the libretro frontend.

The threaded driver has the advantage that video lag will not also cause
the audio to lag, which is very noticeable since it manifests in the
form of audio crackling when it happens.
2025-04-22 12:17:15 -04:00
刘皓
996e47ed81
Fix geometry calculation in core.cpp 2025-04-18 10:42:30 -04:00
刘皓
b3976bf61e
Fix several bugs and missing bindings in libretro builds 2025-04-16 21:57:13 -04:00
刘皓
c7f35c96c9
Make sandbox-bindgen allocate varargs buffers on the stack
Not sure why, but this fixes crashes when calling variadic functions in
the Ruby API in libretro builds when Ruby is built without `-DNDEBUG`.
Maybe the previous way of calling varargs functions was undefined
behaviour somehow.
2025-04-14 21:04:14 -04:00
刘皓
dae17511aa
Rescue all Ruby errors in libretro builds instead of only StandardErrors
`rb_rescue` only catches `StandardError`s, which doesn't include things
like Ruby syntax errors that we'd like to catch. We need to explicitly
use `rb_rescue2` to catch `Exception` in order to catch everything.
2025-04-13 22:18:41 -04:00
刘皓
06819fb9a9
Start implementing VX/VX Ace bindings in libretro builds 2025-04-13 17:30:50 -04:00
刘皓
7a01d1cc56
Fix libretro compilation errors caused by the config-reading implementation 2025-04-12 17:09:41 -04:00
刘皓
8c16bc0092
Implement config loading in libretro builds 2025-04-11 23:12:05 -04:00
刘皓
299650159f
Implement changing the frame rate in libretro builds 2025-04-10 16:51:25 -04:00
刘皓
74f4c0e714
Downgrade OpenAL Soft from 1.24.2 to 1.23.1 in libretro builds
OpenAL Soft 1.24 introduces a lot of code that doesn't work well with
the PlayStation 3 homebrew toolchain, and also the old version of the
Wii U homebrew toolchain currently used by the libretro buildbot.
Instead of maintaining a bunch of patches to get 1.24 to work on these
toolchains, I think it'd be easier to just use 1.23.
2025-04-08 14:27:20 -04:00
刘皓
db7853d02d
Use fluidsynth-sans-glib instead of fluidlite in libretro builds
FluidLite plays one of the tracks in the intro sequence of KNight-Blade
incorrectly.
2025-04-07 21:24:27 -04:00
刘皓
8fa20c660a
Implement audio fading in libretro builds 2025-04-07 14:33:50 -04:00
刘皓
4df253e0d1
Use latest available OpenGL version in libretro builds 2025-04-06 14:43:10 -04:00
刘皓
6bbe58378d
Don't normalize game path in libretro builds
Reverts commit d6ede8bcc6 and changes the
game path parser in libretro builds to not normalize the game path as it
causes problems on consoles with weird path formats.
2025-04-06 12:11:23 -04:00
刘皓
d60b23781b
Implement Graphics.transition binding and related bindings in libretro builds 2025-04-05 14:35:43 -04:00
刘皓
dcd29f44a9
Remove dependency on libzip in libretro builds 2025-03-31 13:26:54 -04:00
刘皓
de5216c3ce
Implement loading from encrypted game archives in libretro builds 2025-03-30 23:37:19 -04:00
刘皓
79af1d7028
Reset the active OpenGL texture every frame in libretro builds
This isn't to fix any bug I've experienced on any platform thus far, but
to avoid problems showing up in the future, since the libretro API docs
say you should unbind everything every frame.
2025-03-20 12:11:57 -04:00
刘皓
eeef9ff943
Don't make sandbox_malloc into a coroutine
Okay, the coroutine implementation of `sandbox_malloc` is clearly
broken. It would be working if Asyncify instrumented the `memory.grow`
WebAssembly instruction, but it doesn't instrument it.

This commit reverts commit 42c4ff9497 and
also increases the default VM memory allocation from 64 MiB to 96 MiB to
account for the lack of ability to increase the memory allocation at run
time. I'll find some new way to implement increasing the memory
allocation later.
2025-03-18 13:49:41 -04:00
刘皓
247c9a5485
Remove unnecessary gl.BindFramebuffer != NULL check from core.cpp 2025-03-14 14:41:43 -04:00
刘皓
0bf11c857f
Merge branch 'libretro-compat' into libretro 2025-03-12 12:48:44 -04:00
刘皓
bee7716b0d
Don't get libretro callbacks if core is initialized
It seems getting performance callbacks also doesn't work except in the
specific call to `retro_set_environment` that occurs before the core is
initialized, so this seems easier than handling only the logging
callback specially.
2025-03-12 12:48:24 -04:00
刘皓
ebca366cc3
Merge branch 'libretro-compat' into libretro 2025-03-11 22:38:55 -04:00
刘皓
ca78a29ad5
Fix RetroArch logs being empty for libretro builds on certain platforms
See commit d8a6f293e01faac371a8776c1cc65755136febb8 from https://github.com/EasyRPG/Player/pull/3365
2025-03-11 22:00:26 -04:00