Commit Graph

46 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 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 8a9a05a3b9 lovr.recenter event; Use local-floor space by default; 2023-06-26 16:41:42 -07:00
Josip Miskovic f0d916787a Add wheelmoved callback 2023-06-17 12:42:18 +02:00
bjorn 8b1b262760 lovr.visible; lovr.headset.isVisible; 2023-06-13 21:06:05 -07:00
bjorn 77403a0908 rm unused prototype; 2023-05-17 20:29:46 -07:00
bjorn da107f4387 Rename lovr.event.pump to lovr.system.pollEvents; 2023-05-10 18:14:09 +01:00
bjorn cb44549205 Fix more prototypes; 2023-04-25 21:45:30 -07:00
bjorn 9c054c0515 Add mouse input to lovr.system; 2023-04-01 13:08:47 -07:00
bjorn b0c3bd6e4c Lightuserdata can be pushed to channels; 2023-02-04 14:08:22 -08:00
bjorn 8337dd9caf Vectors work with channels;
They are copied by value.  Upon popping, they are pushed as temporary
vectors.  Matrices are allocated on the heap, everything else is stored
in the Variant itself.
2023-02-04 14:03:12 -08:00
bjorn f013831b73 Reorganize thread code;
- Put channel into thread module file.
- Make thread internals private.
- Handle more thread bookkeeping in thread module instead of Lua API.
- Fix a few race conditions/leaks nobody was probably ever going to hit.
2022-12-10 20:13:39 -08:00
bjorn 4422df2a47 Variant small string optimization; 2022-11-24 15:40:43 -08:00
Josip Miskovic da9328e72c Fix sending strings with \0 through channels
A null-char is valid part of Lua string. When such a string is sent
through the channel, its length should be stored as well to be able to
correctly reconstruct it on the other thread.

The bug was triggered with this code:

    s1 = 'a \0 b'
    print(#s1) -- 5
    ch:push(s1)
    s2 = ch:pop()
    print(#s2) -- 2
2022-09-21 09:15:20 -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 4f5adbc64c lovr.system; 2021-02-25 09:00:12 -07:00
bjorn 84f65c26e4 Move utf8 back into util; 2021-02-08 20:55:51 -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 3ded60948f rm core/ref; rm lovrAlloc; util does refcounting; 2021-02-08 17:26:44 -07:00
Nevyn Bengtsson 0265babef4 Android: Ask for permissions on demand
By looking for failed start and requesting then;
and then emitting a new event type when
permission has been granted or rejected;
and then using that event in the default
boot.lua to re-start capture.
2021-02-08 16:08:29 -07:00
bjorn d2ff6c29ac Change inclusive module defines to exclusive;
This reduces the number of flags needed to get a regular build.
2021-02-07 16:45:03 -07:00
bjornbytes a81cd0d731 KeyCode -> KeyboardKey because X11 conflict; 2020-11-12 18:08:04 -07:00
bjorn 92936f6977 Fix possible double-free of event data; 2020-09-29 16:57:41 -06:00
bjorn 65470f1e0e Update webxr driver; rm webvr; 2020-08-16 00:31:20 -06:00
bjorn 40594317c3 Android textinput event; 2020-08-08 12:36:09 -06:00
bjorn 6823942e3d utf8_encode function; 2020-08-08 12:13:37 -06:00
bjorn 079338c0cc textinput event utf8 encode; 2020-08-07 16:25:56 -06:00
bjorn c24317d982 Start textinput event; 2020-08-07 15:17:19 -06:00
bjorn 682633d98b Add scancode and key repeat arguments to key events; 2020-08-07 14:15:45 -06:00
bjorn 414c5b991d Event module cleans up pending events on quit; 2020-08-06 20:09:45 -06:00
bjorn cb4281b889 Add keypressed and keyreleased events; rm t.hotkeys; 2020-08-06 19:19:45 -06:00
bjorn c0d73ab541 Add resize event; lovr.resize callback; 2020-05-02 13:09:10 -06:00
mcc fbcce7fc59 Reworked quit/restart events (compatibility break)
Based on Slack conversation, the following changes:
- lovr.event.quit("restart") no longer supported
- lovr.event.quit no longer takes restart "cookie"
- When lovr.event.restart() called, lovr.quit() is not called, instead lovr.restart() is called
- Value returned from lovr.restart(), when called, becomes the cookie
- lovr.event.quit takes the lovr.event.quit() return code as an argument

lovr.run() is unchanged, it still returns (exit code | "restart", cookie).
2020-04-16 00:32:54 -04:00
bjorn 90b605f012 Add restart cookie; lovr.event.restart; arg.restart; 2020-02-26 14:40:40 -08:00
bjorn e2d8f8c645 platform -> os;
The function names are staying the same for now.
2019-12-13 19:55:46 -08:00
bjorn 2f9400a5f7 Adjust includes; 2019-12-10 13:01:28 -08:00
bjorn 28344928c9 Simplify arr; 2019-08-21 23:16:58 -07:00
mcc a6936b5649 Fix -DLOVR_ENABLE_THREAD=OFF compile
l_event.c was processing a thread-related event and in the process using a thread struct, even when LOVR_ENABLE_THREAD is undefined and threads do not exist. I caused the thread event type to simply not exist when the thread module is not being built.

Since the event is now only sometimes present, I put it at the end of the enum as slight protection against binary mismatches with dynamically loaded modules.
2019-07-10 16:23:20 -07:00
bjorn 7ebee200ea rm strdup;
It isn't part of C, causing compiler errors on some platforms.
2019-06-20 22:21:31 -07:00
bjorn eb1e257209 Add new array implementation; Upgrade filesystem;
Filesystem:

- Uses streaming file IO.
- Uses less memory when requiring files.
- Simplifies its require path implementation.
2019-06-16 13:30:30 -07:00
bjorn 22fe333150 Update refcounting (again);
- Ref struct only stores refcount now and is more general.
- Proxy stores a hash of its type name instead of an enum.
- Variants store additional information instead of using a vtable.
- Remove the concept of superclasses from the API.
- Clean up some miscellaneous includes.
2019-06-02 01:02:26 -07:00
bjorn df6b7fc96a Ref is mostly private now;
It's really nice how objects don't need to care about how they're
allocated/managed now.
2019-05-20 15:09:06 -07:00
bjorn a17f10e273 Add modules folder; 2019-05-19 00:38:35 -07:00