From 39fd0d7ee895981134ecb9f647ff02af63f51ed0 Mon Sep 17 00:00:00 2001 From: Solidor777 Date: Fri, 8 May 2026 02:17:12 -0700 Subject: [PATCH 1/2] Expose JPH::PhysicsSystem::SetGravity / GetGravity via JoltC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wraps the existing JPH::PhysicsSystem::SetGravity(Vec3Arg) and GetGravity() methods 1:1, mirroring the to_jph / to_jpc helper pattern used throughout JoltC.cpp. Vec3 conversion uses the existing helpers in JoltC.cpp lines 162-167. Motivation: the Jolt physics system's gravity is read by the integrator every step (it's not a per-body property — bodies have a GravityFactor multiplier on top). Until now there was no way to set or read system gravity from C-binding consumers, forcing them to either accept the hard-coded default (0, -9.81, 0) or apply gravity manually as per-body forces. Added in two places: - JoltC/Functions.h: declarations next to AddConstraint/RemoveConstraint - JoltCImpl/JoltC.cpp: implementations following the same `to_jph(self) -> JPH::PhysicsSystem*` -> method-call pattern as the existing PhysicsSystem wrappers PR submitted from Solidor777/JoltC:custom-gravity for upstream review. The Titan engine carries this patch locally on its mirror fork until upstream merges; once merged we sync from upstream and the local diff dissolves. --- JoltC/Functions.h | 7 +++++++ JoltCImpl/JoltC.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/JoltC/Functions.h b/JoltC/Functions.h index 580000b..0f8a0d9 100644 --- a/JoltC/Functions.h +++ b/JoltC/Functions.h @@ -1624,6 +1624,13 @@ JPC_API JPC_PhysicsUpdateError JPC_PhysicsSystem_Update( JPC_API void JPC_PhysicsSystem_AddConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint); JPC_API void JPC_PhysicsSystem_RemoveConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint); +// TITAN PATCH (2026-05-08): expose JPH::PhysicsSystem::SetGravity / +// GetGravity. Wraps the matching C++ methods 1:1; pending upstream PR +// to SecondHalfGames/JoltC. Removing this hunk is safe once upstream +// merges + we sync our fork. +JPC_API void JPC_PhysicsSystem_SetGravity(JPC_PhysicsSystem* self, JPC_Vec3 inGravity); +JPC_API JPC_Vec3 JPC_PhysicsSystem_GetGravity(const JPC_PhysicsSystem* self); + JPC_API JPC_BodyInterface* JPC_PhysicsSystem_GetBodyInterface(JPC_PhysicsSystem* self); JPC_API const JPC_BodyLockInterface* JPC_PhysicsSystem_GetBodyLockInterface(JPC_PhysicsSystem* self); diff --git a/JoltCImpl/JoltC.cpp b/JoltCImpl/JoltC.cpp index d7ca743..5030676 100644 --- a/JoltCImpl/JoltC.cpp +++ b/JoltCImpl/JoltC.cpp @@ -3024,6 +3024,16 @@ JPC_API void JPC_PhysicsSystem_RemoveConstraint(JPC_PhysicsSystem* self, JPC_Con to_jph(self)->RemoveConstraint(to_jph(constraint)); } +// TITAN PATCH (2026-05-08): expose JPH::PhysicsSystem::SetGravity / +// GetGravity. Pending upstream PR to SecondHalfGames/JoltC. +JPC_API void JPC_PhysicsSystem_SetGravity(JPC_PhysicsSystem* self, JPC_Vec3 inGravity) { + to_jph(self)->SetGravity(to_jph(inGravity)); +} + +JPC_API JPC_Vec3 JPC_PhysicsSystem_GetGravity(const JPC_PhysicsSystem* self) { + return to_jpc(to_jph(self)->GetGravity()); +} + JPC_API JPC_BodyInterface* JPC_PhysicsSystem_GetBodyInterface(JPC_PhysicsSystem* self) { return to_jpc(&to_jph(self)->GetBodyInterface()); } From ce41d9aa6f50611c02a020366c9136ea9d07fc31 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 8 May 2026 14:07:37 -0400 Subject: [PATCH 2/2] Remove extra comment --- JoltC/Functions.h | 4 ---- JoltCImpl/JoltC.cpp | 2 -- 2 files changed, 6 deletions(-) diff --git a/JoltC/Functions.h b/JoltC/Functions.h index 0f8a0d9..500106d 100644 --- a/JoltC/Functions.h +++ b/JoltC/Functions.h @@ -1624,10 +1624,6 @@ JPC_API JPC_PhysicsUpdateError JPC_PhysicsSystem_Update( JPC_API void JPC_PhysicsSystem_AddConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint); JPC_API void JPC_PhysicsSystem_RemoveConstraint(JPC_PhysicsSystem* self, JPC_Constraint* constraint); -// TITAN PATCH (2026-05-08): expose JPH::PhysicsSystem::SetGravity / -// GetGravity. Wraps the matching C++ methods 1:1; pending upstream PR -// to SecondHalfGames/JoltC. Removing this hunk is safe once upstream -// merges + we sync our fork. JPC_API void JPC_PhysicsSystem_SetGravity(JPC_PhysicsSystem* self, JPC_Vec3 inGravity); JPC_API JPC_Vec3 JPC_PhysicsSystem_GetGravity(const JPC_PhysicsSystem* self); diff --git a/JoltCImpl/JoltC.cpp b/JoltCImpl/JoltC.cpp index 5030676..e5be33a 100644 --- a/JoltCImpl/JoltC.cpp +++ b/JoltCImpl/JoltC.cpp @@ -3024,8 +3024,6 @@ JPC_API void JPC_PhysicsSystem_RemoveConstraint(JPC_PhysicsSystem* self, JPC_Con to_jph(self)->RemoveConstraint(to_jph(constraint)); } -// TITAN PATCH (2026-05-08): expose JPH::PhysicsSystem::SetGravity / -// GetGravity. Pending upstream PR to SecondHalfGames/JoltC. JPC_API void JPC_PhysicsSystem_SetGravity(JPC_PhysicsSystem* self, JPC_Vec3 inGravity) { to_jph(self)->SetGravity(to_jph(inGravity)); }