mirror of https://github.com/bjornbytes/lovr.git
Add more settings to newWorld;
This commit is contained in:
parent
4dbcc15cef
commit
1115029fe0
|
@ -39,10 +39,13 @@ StringEntry lovrTargetType[] = {
|
|||
|
||||
static int l_lovrPhysicsNewWorld(lua_State* L) {
|
||||
WorldInfo info = {
|
||||
.maxColliders = 65536,
|
||||
.maxColliderPairs = 65536,
|
||||
.maxContacts = 16384,
|
||||
.allowSleep = true
|
||||
.maxColliders = 16384,
|
||||
.deterministic = true,
|
||||
.threadSafe = true,
|
||||
.allowSleep = true,
|
||||
.stabilization = .2f,
|
||||
.maxPenetration = .01f,
|
||||
.minBounceVelocity = 1.f
|
||||
};
|
||||
|
||||
if (lua_istable(L, 1)) {
|
||||
|
@ -50,18 +53,30 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
|
|||
if (!lua_isnil(L, -1)) info.maxColliders = luax_checku32(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "maxColliderPairs");
|
||||
if (!lua_isnil(L, -1)) info.maxColliderPairs = luax_checku32(L, -1);
|
||||
lua_getfield(L, 1, "deterministic");
|
||||
if (!lua_isnil(L, -1)) info.deterministic = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "maxContacts");
|
||||
if (!lua_isnil(L, -1)) info.maxContacts = luax_checku32(L, -1);
|
||||
lua_getfield(L, 1, "threadSafe");
|
||||
if (!lua_isnil(L, -1)) info.threadSafe = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "allowSleep");
|
||||
if (!lua_isnil(L, -1)) info.allowSleep = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "stabilization");
|
||||
if (!lua_isnil(L, -1)) info.stabilization = luax_checkfloat(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "maxPenetration");
|
||||
if (!lua_isnil(L, -1)) info.maxPenetration = luax_checkfloat(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 1, "minBounceVelocity");
|
||||
if (!lua_isnil(L, -1)) info.minBounceVelocity = luax_checkfloat(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");
|
||||
|
|
|
@ -35,9 +35,12 @@ void lovrPhysicsDestroy(void);
|
|||
|
||||
typedef struct {
|
||||
uint32_t maxColliders;
|
||||
uint32_t maxColliderPairs;
|
||||
uint32_t maxContacts;
|
||||
bool deterministic;
|
||||
bool threadSafe;
|
||||
bool allowSleep;
|
||||
float stabilization;
|
||||
float maxPenetration;
|
||||
float minBounceVelocity;
|
||||
const char* tags[MAX_TAGS];
|
||||
uint32_t tagCount;
|
||||
} WorldInfo;
|
||||
|
|
|
@ -126,16 +126,28 @@ World* lovrWorldCreate(WorldInfo* info) {
|
|||
broadPhaseLayerInterface, NUM_BP_LAYERS,
|
||||
world->objectLayerPairFilter, NUM_OP_LAYERS);
|
||||
|
||||
JPH_PhysicsSystemSettings settings = {
|
||||
JPH_PhysicsSystemSettings config = {
|
||||
.maxBodies = info->maxColliders,
|
||||
.maxBodyPairs = info->maxColliderPairs,
|
||||
.maxContactConstraints = info->maxContacts,
|
||||
.maxBodyPairs = info->maxColliders * 2,
|
||||
.maxContactConstraints = info->maxColliders,
|
||||
.broadPhaseLayerInterface = broadPhaseLayerInterface,
|
||||
.objectLayerPairFilter = world->objectLayerPairFilter,
|
||||
.objectVsBroadPhaseLayerFilter = broadPhaseLayerFilter
|
||||
};
|
||||
world->system = JPH_PhysicsSystem_Create(&settings);
|
||||
world->bodies = JPH_PhysicsSystem_GetBodyInterface(world->system);
|
||||
world->system = JPH_PhysicsSystem_Create(&config);
|
||||
|
||||
JPH_PhysicsSettings settings;
|
||||
JPH_PhysicsSystem_GetPhysicsSettings(world->system, &settings);
|
||||
settings.deterministicSimulation = info->deterministic;
|
||||
settings.allowSleeping = info->allowSleep;
|
||||
settings.baumgarte = CLAMP(info->stabilization, 0.f, 1.f);
|
||||
settings.penetrationSlop = MAX(info->maxPenetration, 0.f);
|
||||
settings.minVelocityForRestitution = MAX(info->minBounceVelocity, 0.f);
|
||||
JPH_PhysicsSystem_SetPhysicsSettings(world->system, &settings);
|
||||
|
||||
world->bodies = info->threadSafe ?
|
||||
JPH_PhysicsSystem_GetBodyInterface(world->system) :
|
||||
JPH_PhysicsSystem_GetBodyInterfaceNoLock(world->system);
|
||||
|
||||
for (uint32_t i = 0; i < info->tagCount; i++) {
|
||||
size_t size = strlen(info->tags[i]) + 1;
|
||||
|
|
Loading…
Reference in New Issue