Commit Graph

66 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 b7e1b5111e jolt: fix some shape memory leaks; 2024-03-29 15:26:10 -07:00
bjorn c5d6bb6b48 jolt: rm matrix copies;
JoltC now uses floats for its RVec/RMatrix structs in single precision
mode, so we can operate on them as mat4's directly, copy/cast them, etc.
2024-03-29 15:26:03 -07:00
bjorn 87cd13d95c jolt: adjust includes; 2024-03-29 15:25:41 -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
Josip Miskovic 47c9b20542 Jolt world-level damping and sleeping allowed
The damping 0.05 value comes from Jolt's BodyCreationSettings.h.
2024-02-13 19:18:57 +01:00
Josip Miskovic 431062c345 Increase Jolt body & constraint limits
The new values come from comments in the official HelloWorld.cpp. After
the changes the any increase of memory consumption is within the
measurement error.
2024-02-13 17:25:43 +01:00
Josip Miskovic 1ad8f23fb8 Jolt physics engine integration 2024-01-30 18:22:27 +01:00
bjorn f8158744f9 Details; 2024-01-20 21:58:03 -08:00
xiejiangzhi 45a6333afb Slow movement for sim, fix bug of tag, add max number of tag to 32
Holding ctrl to slowly movement for Sim
Check null for findTag
Increment max number of tags to 32
Fix newWorld error if tags > MAX_TAGS
2024-01-21 13:50:59 +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
xiejiangzhi 1e120d3401 Auto wake up collider when calling API to apply force or change force. 2023-11-18 09:43:52 +08:00
bjorn 0d6c9a1def World:isCollisionEnabledBetween takes nils;
They act like wildcards, just like nil tags do otherwise.
2023-08-15 18:24:19 -07:00
bjorn 2f90255d1a physics no longer depends on maf;
So little is used, may as well make it more self-contained.
2023-07-28 16:16:14 -07:00
xiejiangzhi ee10e22402 World query: Rename should_stop to shouldStop, early stop queryCallback if no give a callback 2023-07-21 08:00:58 +08:00
xiejiangzhi 91e586bbd4 Fix early exit logic for raycast & querySphere 2023-07-20 16:46:40 +08:00
xiejiangzhi a4dc1d9ffb Support early exit for world:raycast world:queryBox world:querySphere 2023-07-20 16:34:56 +08:00
bjorn 534d47904e World:queryBox/World:querySphere callback is optional;
They also return a bool indicating if any intersections occurred.
2023-07-17 13:23:57 -07:00
bjorn b268cd1776 World:queryBox; World:querySphere; 2023-07-10 23:20:01 -07:00
bjorn 9bf2def86d Rename box shape dimensions to be more clear; 2023-07-10 23:11:14 -07:00
bjorn be795c0ebd Change vec3 back to 3 floats; Clean up maf/vectors;
The "vec3 is 4 floats" thing was consistently confusing to people.  It's
reverted everywhere except for Curve.

maf now has full sets of methods for vec2/vec3/vec4, for consistency.

Vector bindings now use luax_readvec* helper functions for the
number/vector variants, and use maf for most functionality, which cleans
things up a lot.
2023-07-10 17:51:24 -07:00
bjorn a511064987 Collider:isDestroyed; 2023-06-22 15:48:23 -07:00
bjorn ad4978f692 Fix prototypes; 2023-04-25 21:37:14 -07:00
bjorn 00aa4e3a23 TerrainShape mass fix; 2022-11-09 22:22:26 -08:00
bjorn f8f748320e Minor Shape improvements;
- Add helper functions for creating shapes to avoid duplication between
  newShape and newShapeCollider.
- Add lovr.physics.newMeshShape and lovr.physics.newTerrainShape
- Register TerrainShape so it has all the base Shape methods
- Smooth out a few TerrainShape warnings
2022-11-09 20:53:42 -08:00
Josip Miskovic 34611f2069 Add physics heightfield shape 2022-11-08 18:46:49 -08:00
bjorn d69ec7bff0 Default friction is infinity;
Re-apply bug behavior
2022-08-12 23:30:13 -07:00
bjorn fbe54d5dca Physics shape dimensions must be positive;
Or the world will explode.  That would be bad.
2022-06-12 18:18:48 -07:00
Josip Miskovic 24a0751c16 Add `World:setStepIterations(num)` and its getter
Physics world's "quick step" is executed in multiple iteration steps.
The getter and setter for this value is now made available as two new
methods in the World object.

This is allows user to balance between the less accurate but quick
simulations, and more stable behavior of physics.

Something similar was already possible, by reducing the delta time and
running the sim multiple times per frame. However, any force user applies
to collider is zeroed after each step. User would thus have to keep track
of applied forces, and re-apply them inside the physics iteration loop.

By default ODE uses 20 iterations in quick step.
2022-04-27 11:39:08 -07:00
bjorn 42e618fa00 World:getContacts; 2022-03-30 22:32:20 -07:00
bjorn 8fcdfd2bb4 Minor physics cleanup; 2022-03-30 22:05:10 -07:00
bjorn 6c9531564e Make physics structs private; 2022-03-25 12:40:29 -07:00
bjorn 56dbb346e7 ODE uses 4-component vec3s too; 2022-03-25 12:15:38 -07:00
bjorn 2da18d419b mv util src; 2022-03-22 00:13:38 -07:00
Patrik Sjöberg 766b44f77a MeshShapes gets hits on all passed surfaces. Callback for each of them.
Fixes crash due to MAX_CONTACTS being sent to dCollide as the number of 
dContacts available.
2022-03-15 15:34:16 -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 e283245dc6 Remove suspicious friction override; 2021-11-12 12:20:21 -08:00
Josip Miskovic f6fbc2ad17 Route ODE messages into LOVR log system
ODE errors, debugs and messages are redirected into LOVR's log system
by a callback mechanism for each.

The ODE submodule is updated to revision that does not crash when error
or debug occurs.
2021-03-28 17:34:11 -06:00
bjorn 57a215a0aa Minor MeshShape cleanup;
- Fix memory leak
- Minor error message improvements
2021-02-19 17:28:04 -07:00
bjorn 023067ec27 util.h no longer uses atomics; 2021-02-11 16:37:55 -07:00
bjorn f8ed6c3a34 physics: Use dReal in more places;
This makes it easier to swap between float/double.
2021-02-09 23:24:27 -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
bjornbytes eb319fdade Fix trailing whitespace; 2020-11-21 14:37:47 -07:00
Josip Miskovic 75591fde42 Support for trimesh shape colliders 2020-09-24 20:58:28 +02:00
Josip Miskovic 139808cab0 Get/set World and Joint simulation parameters
Tightness parameter is amount of force is exerted on collider to resolve
collisions and enforce joint operation. Low values make joints loose,
high values make it tight and can cause collider to overshot the joint
target. With tightness set to 0 the joint loses its function. Going
above 1 puts even more energy into joint oscillations. Tightness
parameter is called ERP in ODE manual.

The responseTime affects the time constant of physics simulation, both
for collisions and for joint inertia. Low responseTime values make
simulation tight and fast, higher values make it sluggish. For
collisions it affects how fast penetration is resolved, with higher
values resulting in spongy objects with more surface penetration and
slower collision resolving. For joints the responseTime is similar to
inertia, with higher responseTime values resulting in slow oscillations.
The oscillation frequency is also affected by collider mass, so
responseTime can be used to tweak the joint to get desired frequency
with specific collider mass. Values higher than 1 are often desirable,
especially for very light objects. Unlike tightness, responseTime is
tweaked in orders of magnitude with useful values (depending on mass)
being between 10^-8 and 10^8.

Both parameters can be applied to World for simulation-wide usage, or
specified per-joint in case of distance and ball joints. Other joints
don't allow customizing these parameters, and will use World settings
instead..
2020-06-03 19:03:38 +03:00
bjorn dab0be7055 World:getColliders; 2020-05-11 12:05:30 -06:00
bjorn 6539bc1bd2 Make physics orientation getters more consistent; 2020-05-10 02:08:36 -06:00