Commit graph

172 commits

Author SHA1 Message Date
刘皓
c802e24f1b
Fix WASI file descriptor deserialization bugs in libretro builds 2025-05-28 17:07:22 -04:00
刘皓
b664b3c8c7
Disconnect dispose watches before deserializing save states in libretro builds 2025-05-28 16:01:32 -04:00
刘皓
6f472fb732
Handle disposal when deserializing save states in libretro builds 2025-05-28 15:32:43 -04:00
刘皓
1f5d90822c
Remove designated initializers
Apparently these are not valid until C++20.
2025-05-27 21:28:29 -04:00
刘皓
ede42dbb1b
Fix serialization of Tilemap::Autotiles and TilemapVX::BitmapArray in libretro builds, for real this time 2025-05-27 19:11:58 -04:00
刘皓
8ca753d85d
Continue implementing save state deserialization in libretro builds 2025-05-27 16:59:41 -04:00
刘皓
290ce15875
Fix typos in binding-sandbox/sandbox-serial-util.h 2025-05-26 21:29:10 -04:00
刘皓
d383889d4e
Start implementing save state deserialization in libretro builds 2025-05-25 16:07:40 -04:00
刘皓
c8dc6792b2
Improve pointer deserialization utilities in libretro builds 2025-05-25 14:58:59 -04:00
刘皓
cf11a0ed14
Also change void *& to const void *& in sandbox_serialize_member_declaration 2025-05-25 12:39:04 -04:00
刘皓
58e3ec2035
Change second argument of sandbox_deserialize from void *& to const void *& 2025-05-25 09:33:12 -04:00
刘皓
7558f3fbcb
Add utilities for deserializing save states in libretro builds 2025-05-24 22:16:26 -04:00
刘皓
bc0bd7fe65
Make some small improvements to save state serialization in libretro builds 2025-05-24 19:19:57 -04:00
刘皓
b1ba7e1606
Fix coroutine state being changed on read in libretro builds 2025-05-24 17:05:11 -04:00
刘皓
0b27c24bd5
Implement save state serialization for stack pointer and Asyncify state/data in libretro builds 2025-05-24 13:25:40 -04:00
刘皓
e957af931c
Implement save state serialization for WASI file descriptors in libretro builds 2025-05-23 23:59:29 -04:00
刘皓
057b6dc95d
Serialize the path of the currently playing movie in libretro builds 2025-05-23 12:06:03 -04:00
刘皓
01ff2ec75a
Apply some small fixes to save state serialization in libretro builds 2025-05-22 19:20:28 -04:00
刘皓
941e0e1cef
Fix linker error in binding-sandbox/sandbox-serial-util.h on some platforms 2025-05-22 13:35:58 -04:00
刘皓
2896ec5abd
Implement save state serialization for C++ objects owned by the bindings in libretro builds 2025-05-22 12:49:01 -04:00
刘皓
4561a0b0f8
Fix edge case in set_private_data in libretro builds 2025-05-20 19:16:20 -04:00
刘皓
551206e7b4
Don't set private data if an exception has occurred in the bindings 2025-05-20 18:58:44 -04:00
刘皓
39567dd0ea
Add fiber stack indices into libretro save state 2025-05-20 18:34:55 -04:00
刘皓
80b3833fff
Start implementing save state serialization in libretro builds 2025-05-20 17:42:35 -04:00
刘皓
b8fb59e558
Make sure stack_index is initialized in binding-sandbox/binding-base.h
This field needs to be initialized when `struct frame` is constructed,
or its value may be random.

I also changed the type of `stack_index` to `wasm_size_t` so that it's
the same size on every platform.
2025-05-20 15:51:50 -04:00
刘皓
ecfaa4eebf
Add a safety check to mkxp_sandbox::binding_base::object::~object() 2025-05-19 21:14:50 -04:00
刘皓
cd628048ef
Store destructors in a global table instead of in the object itself in libretro builds 2025-05-19 19:27:30 -04:00
刘皓
16e701fc7c
Rearrange typenums in binding-sandbox/binding-util.h in lexicographic order 2025-05-19 16:19:57 -04:00
刘皓
1d88c068fb
Fix libretro PlayStation 3 compilation error in binding-sandbox/binding-base.cpp 2025-05-19 15:48:06 -04:00
刘皓
031245491f
Keep track of all C++ objects allocated by bindings in libretro builds
This commit adds `sb()->create_object()`, `sb()->get_object()`,
`sb()->check_object_type()` and `sb()->destroy_object()` in libretro
builds to keep track of all C++ objects allocated by the bindings in
libretro builds. This has some benefits:

* Any C++ objects allocated by the bindings that are still alive when
  the game terminates can now be deallocated instead of being leaked
  like before.
* We now keep track of the types of all objects allocated by the
  bindings, so we will be able to detect when the bindings attempt to
  access objects of mismatching type.
* Keeping track of all allocated objects is required to implement
  libretro save states.
* Objects are now kept track of using numeric keys whose sizes are the
  same on every platform rather than pointers, which helps with making
  save states portable across platforms.
2025-05-19 14:44:44 -04:00
刘皓
5b5ffd6f18
Handle game shutdown properly in libretro builds 2025-05-18 10:03:08 -04:00
刘皓
ef58df103a
Remember to actually initialize exception classes in libretro builds 2025-05-18 09:42:42 -04:00
刘皓
83a6b7a1f1
Re-add missing GFX_LOCK/GFX_UNLOCK calls in binding-sandbox 2025-05-17 19:41:43 -04:00
刘皓
134e08ce6a
Allow the entire codebase to build with -fno-exceptions -fno-rtti in libretro builds 2025-05-16 21:59:54 -04:00
刘皓
3b564efd79
Remove direct dependency on Boost.Core in libretro builds 2025-05-16 15:51:51 -04:00
刘皓
e3cbed2fb3
Remove unused next_func_ptr field of binding_base 2025-05-14 21:16:50 -04:00
刘皓
28fb36af98
Capitalize /Dist, /Game, /Save and /System in libretro builds for consistency 2025-05-13 17:53:59 -04:00
刘皓
d62d6aef3e
Remove WASI_DEBUG macro 2025-05-12 13:50:48 -04:00
刘皓
67e61917a7
Apply big-endian fixes to binding-sandbox/wasi.cpp as well 2025-05-12 12:39:08 -04:00
刘皓
7347afed21
Revert "Make sure sandbox stack grows upwards in big-endian libretro builds"
This reverts commit 58e6f71ef3.

The original behaviour was the correct one. The stack should always grow
downwards.
2025-05-10 23:37:39 -04:00
刘皓
68b2067a45
Remove void pointer arithmetic in binding-sandbox/binding-base.h 2025-05-10 20:44:46 -04:00
刘皓
58e6f71ef3
Make sure sandbox stack grows upwards in big-endian libretro builds 2025-05-10 19:23:43 -04:00
刘皓
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
刘皓
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
刘皓
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
刘皓
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