Skip to content

Commit

Permalink
Add velocitySteps/positionSteps options to newWorld;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed May 3, 2024
1 parent fcd8230 commit c23a0c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/api/l_physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
.allowSleep = true,
.stabilization = .2f,
.maxPenetration = .01f,
.minBounceVelocity = 1.f
.minBounceVelocity = 1.f,
.velocitySteps = 10,
.positionSteps = 2
};

if (lua_istable(L, 1)) {
Expand Down Expand Up @@ -81,6 +83,14 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
if (!lua_isnil(L, -1)) info.minBounceVelocity = luax_checkfloat(L, -1);
lua_pop(L, 1);

lua_getfield(L, 1, "velocitySteps");
if (!lua_isnil(L, -1)) info.velocitySteps = luax_checku32(L, -1);
lua_pop(L, 1);

lua_getfield(L, 1, "positionSteps");
if (!lua_isnil(L, -1)) info.positionSteps = luax_checku32(L, -1);
lua_pop(L, 1);

lua_getfield(L, 1, "tags");
if (!lua_isnil(L, -1)) {
lovrCheck(lua_istable(L, -1), "World tag list should be a table");
Expand Down
2 changes: 2 additions & 0 deletions src/modules/physics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef struct {
float stabilization;
float maxPenetration;
float minBounceVelocity;
uint32_t velocitySteps;
uint32_t positionSteps;
const char* tags[MAX_TAGS];
uint32_t staticTagMask;
uint32_t tagCount;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/physics/physics_jolt.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ World* lovrWorldCreate(WorldInfo* info) {
settings.baumgarte = CLAMP(info->stabilization, 0.f, 1.f);
settings.penetrationSlop = MAX(info->maxPenetration, 0.f);
settings.minVelocityForRestitution = MAX(info->minBounceVelocity, 0.f);
settings.numVelocitySteps = MAX(settings.numVelocitySteps, 2);
settings.numPositionSteps = MAX(settings.numPositionSteps, 1);
JPH_PhysicsSystem_SetPhysicsSettings(world->system, &settings);

world->bodies = info->threadSafe ?
Expand Down

0 comments on commit c23a0c0

Please sign in to comment.