Commit Graph

73 Commits

Author SHA1 Message Date
bjorn cdecc1bae7 Add defer system; Rework exceptions; util cleanup;
Defer can be used to clean up resources when an error occurs.
2024-03-29 18:10:22 -07:00
bjorn d097d9819d Add wrappers for malloc functions; 2024-03-11 14:38:00 -07:00
bjorn 2d7b636a90 Change more asserts to checks; 2024-03-11 00:58:21 -07:00
bjorn 9d55a5b222 boot.lua sets source instead of filesystem module; 2023-11-27 18:42:49 -08:00
bjorn 64950bc152 lovr.filesystem.setSource; 2023-11-27 18:42:49 -08:00
bjorn 4926362cc7 lovr.filesystem.getBundlePath; 2023-11-27 18:42:49 -08:00
bjorn 1cac651392 Inline LOVR_PATH_SEP; 2023-11-27 18:42:49 -08:00
bjorn 2e543a96de More zip fixes; 2023-11-27 18:39:27 -08:00
bjorn 399a283536 zip fixes; 2023-11-26 21:49:41 -08:00
bjorn 08d6b2ad28 Refcounted modules;
This allows them to be initialized/destroyed from multiple threads in
any order.  Previously, the first thread to require a module had to be
the last thread to use the module, otherwise it would be destroyed too
early.

There are still a few issues.  If the main thread doesn't require a
module, it won't pick up the conf.lua settings.  Also graphics isn't
handling the shader cache writing properly.  And I think this breaks the
headset-graphics refcounting.  But these will be fixed in future
commits.
2023-11-23 17:07:44 -08:00
bjorn 7ca331a5f5 Adjust fs_read/fs_write signatures; Fix seeking; 2023-11-22 16:37:31 -08:00
bjorn d949b90eea Details; 2023-11-22 16:19:40 -08:00
bjorn f04a0e6bc4 Fix zip EOF emulation;
To match regular files, the file offset should be allowed to go past the
end of the file, but reads will return 0 bytes.
2023-11-22 15:49:10 -08:00
bjorn 79abe3b1d6 Windows fixes; 2023-11-21 20:19:49 -08:00
bjorn 19ac219b0c Add File object; 2023-11-21 18:49:32 -08:00
bjorn f50e9f6fe1 Use miniz to decompress files; 2023-11-21 18:49:32 -08:00
bjorn d0f1462e51 Make Archive a refcounted object;
- Archive is now an object that has a refcount
- Archives are stored in linked list instead of array
- Not exposed to Lua yet, but could be in the future
- core/zip was merged into the filesystem module
- Mountpoints are handled centrally instead of per-archive
- Zip doesn't pre-hash with the mountpoint anymore
- mtime is truly only computed on request for zips

Mountpoints don't work properly yet.
2023-11-21 18:49:32 -08:00
bjorn ad4978f692 Fix prototypes; 2023-04-25 21:37:14 -07:00
bjorn 1d1470f042 Fix directory archive path normalization;
Fixes non-normalized paths not behaving as expected.
2023-03-09 21:27:04 -08:00
bjorn 06dad182db Fix mounted directories with non-empty mountpoints;
Mounting directories with mountpoints wasn't treating the components
in the mountpoint path as virtual directories.
2022-12-10 18:25:09 -08:00
bjorn 74a9b90e93 Fix zip archive enumeration;
Zip archives weren't enumerating in the root directory when they were
mounted with a non-empty mountpoint.  Additionally, zips mounted at the
root directory weren't listing files properly.  This fixes both by
normalizing the mountpoint prefix (it had a prepended slash when it was
empty, which messed up hashing), and ensuring there is a "root node" in
the tree with an empty string.
2022-12-10 18:25:09 -08:00
bjorn 8f74778c19 Error if require path is too long instead of truncating; 2022-11-23 14:08:32 -08:00
bjorn 53da4dd1dc rm File again;
forks please yell if you still need it
2022-11-23 11:58:42 -08:00
bjorn 4483145d53 Allow passing a file to lovr;
The file will be treated as main.lua.
Its directory will be treated as the source.
2022-04-28 17:36:05 -07:00
bjorn cd0e458af9 lovr.filesystem.write/append returns success instead of size;
We don't have a good way of returning filesystem error messages yet,
but it's still useful to return a boolean instead of a number to
detect failure of zero byte writes.  Exposing the number of bytes
written is kind of weird since it's not very actionable.
2022-03-30 22:45:09 -07:00
bjorn 5d271de91a mv map util; 2022-03-30 12:34:38 -07:00
bjorn 301f7b2cc9 Android mounts save directory earlier;
This fixes issues with conf.lua not getting read properly, and also
the weird quirk of getIdentity not working until setIdentity runs.
2022-03-23 18:27:05 -07:00
bjorn 2da18d419b mv util src; 2022-03-22 00:13:38 -07:00
bjorn c9fe026a66 Fix undefined behavior in arr_free;
Currently there is a single allocator function used in arr_t.  Its
behavior depends on the values for the pointer and size arguments:

- If pointer is NULL, it should allocate new memory.
- If pointer is non-NULL and size is positive, it should resize memory.
- If size is zero, it should free memory.

All instances of arr_t use realloc for this right now.  The problem
is that realloc's behavior is undefined when the size argument is zero.
On Windows and Linux, realloc will free the pointer, but on macOS this
isn't the case.  This means that arr_t leaks memory on macOS.

It's best to not rely on undefined behavior like this, so let's instead
use a helper function that behaves the way we want.
2022-03-14 12:27:58 -07:00
bjorn 895589c914 Add even more padding to stb zlib; 2021-03-24 21:13:04 -06:00
bjorn 0bb556554d Probably work around stb_image bug that breaks zips;
30e01f upgraded stb_image to include its 95560b commit from its #960
pull request.  This made stb_image fail more aggressively on EOF
conditions when refilling huffman buffers in deflate streams.  I think
it might be failing _too_ aggressively, though.  We are able to pad our
input compressed buffers since the zip file format is guaranteed to have
extra data at the end (for, e.g., the end of central directory record).
This appears to be sufficient to fix compressed zip archives for the
time being.  It's possible that more virtual padding needs to be added,
and it may be good to try to fix this in stb_image itself.
2021-03-18 00:05:34 -06:00
bjorn f82e8112fe Simplify filesystem arguments; 2021-02-25 10:45:45 -07:00
bjorn 4f5adbc64c lovr.system; 2021-02-25 09:00:12 -07:00
bjorn 6d92d54079 Try having arr_t in util; 2021-02-08 18:25:05 -07:00
bjorn bc4cde1653 Adjust lovrRelease signature; 2021-02-08 17:52:26 -07:00
bjorn b356ce2546 Plugins;
- The plugins folder can contain native plugins.
- CMake will build plugins with CMakeLists in them
  - They can check the LOVR variable to see if they are being built inside LOVR.
  - They can set the LOVR_PLUGIN_TARGETS variable to a list of targets they build.
    - If blank, all non-imported targets added in the folder will be used.
  - The libraries built by their targets will be moved next to the executable or into the apk.
- The library loader now tries to load libraries next to the executable or in the APK.
  - It is "fixed function" now, this may be improved in the future.
- The lovr.filesystem C require path has been removed.
- enet and cjson have been removed.  Use plugins.
2020-12-28 12:37:35 -07:00
bjorn 25811f1c01 Change default require paths;
The lua_modules+deps paths were added for a LuaRocks experiment.
2020-12-25 12:20:58 -07:00
bjorn a055caaae4 Fix file permissions; 2020-08-22 13:36:39 -06:00
bjorn 4160743b77 Fix desktop game packaging issue;
Accidentally hardcoded it to "assets" when updating Android.
2020-07-29 16:30:14 -06:00
bjorn 826fc098bc Set identity to empty string if save mount fails; 2020-07-29 16:27:17 -06:00
Bjorn 617d508d68
Merge pull request #269 from jmiskovic/savemount
Config parameter for save directory precedence
2020-07-29 16:26:07 -06:00
bjorn ae2e14f98f rm save directory mount failure fix;
This is a temporary revert to make a merge easier.
2020-07-29 16:25:29 -06:00
bjorn c423b1292a Fix save directory to use system path separator; 2020-07-27 18:15:16 -06:00
bjorn 0dd4a1191c rm getApplicationId; 2020-06-29 18:10:03 -06:00
bjorn afaae2febb Remaining android filesystem work; 2020-06-25 18:18:44 -06:00
bjorn 2042010b5b Move core/fs paths to core/os;
Usually these are more of a platform-specific concept, and they
don't really interact with files or do any io.

There is a little bit of duplication among the *nix platforms since
they're similar, but overall this organization feels a bit better.
2020-06-25 13:28:40 -06:00
Josip Miskovic 66d7e887c7 Config parameter for save directory precedence 2020-06-21 18:02:36 +03:00
bjorn 75e26f0051 Move core/hash to core/util; 2020-05-19 13:49:40 -06:00
bjorn 7d316d6218 Add internal filesystem module comment; 2020-04-22 01:47:16 -06:00
bjorn 93d556b603 zip: read compressed size from central directory;
Some zip writers do not write the compressed size to the local file
headers.
2020-02-21 15:44:48 -08:00