Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 40 additions & 55 deletions JoltC/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

#include <stdint.h>

const int JPC_MAX_PHYSICS_JOBS = 2048;
const int JPC_MAX_PHYSICS_BARRIERS = 8;
const float JPC_DEFAULT_COLLISION_TOLERANCE = 1.0e-4f;
const float JPC_DEFAULT_PENETRATION_TOLERANCE = 1.0e-4f;
const float JPC_DEFAULT_CONVEX_RADIUS = 0.05f;
const float JPC_CAPSULE_PROJECTION_SLOP = 0.02f;

ENSURE_EQUAL(JPC_MAX_PHYSICS_JOBS, JPH::cMaxPhysicsJobs)
ENSURE_EQUAL(JPC_MAX_PHYSICS_BARRIERS, JPH::cMaxPhysicsBarriers)
ENSURE_EQUAL(JPC_DEFAULT_COLLISION_TOLERANCE, JPH::cDefaultCollisionTolerance)
ENSURE_EQUAL(JPC_DEFAULT_PENETRATION_TOLERANCE, JPH::cDefaultPenetrationTolerance)
ENSURE_EQUAL(JPC_DEFAULT_CONVEX_RADIUS, JPH::cDefaultConvexRadius)
ENSURE_EQUAL(JPC_CAPSULE_PROJECTION_SLOP, JPH::cCapsuleProjectionSlop)
#define JPC_MAX_PHYSICS_JOBS 2048
#define JPC_MAX_PHYSICS_BARRIERS 8
#define JPC_DEFAULT_COLLISION_TOLERANCE 1.0e-4f
#define JPC_DEFAULT_PENETRATION_TOLERANCE 1.0e-4f
#define JPC_DEFAULT_CONVEX_RADIUS 0.05f
#define JPC_CAPSULE_PROJECTION_SLOP 0.02f

typedef enum JPC_ShapeType: uint8_t {
JPC_SHAPE_TYPE_CONVEX,
Expand Down Expand Up @@ -106,10 +99,10 @@ ENSURE_ENUM_EQ(JPC_SHAPE_SUB_TYPE_USER_CONVEX7, JPH::EShapeSubType::UserConvex7)
ENSURE_ENUM_EQ(JPC_SHAPE_SUB_TYPE_USER_CONVEX8, JPH::EShapeSubType::UserConvex8)

typedef uint32_t JPC_PhysicsUpdateError;
const JPC_PhysicsUpdateError JPC_PHYSICS_UPDATE_ERROR_NONE = 0;
const JPC_PhysicsUpdateError JPC_PHYSICS_UPDATE_ERROR_MANIFOLD_CACHE_FULL = 1 << 0;
const JPC_PhysicsUpdateError JPC_PHYSICS_UPDATE_ERROR_BODY_PAIR_CACHE_FULL = 1 << 1;
const JPC_PhysicsUpdateError JPC_PHYSICS_UPDATE_ERROR_CONTACT_CONSTRAINTS_FULL = 1 << 2;
#define JPC_PHYSICS_UPDATE_ERROR_NONE 0
#define JPC_PHYSICS_UPDATE_ERROR_MANIFOLD_CACHE_FULL 1 << 0
#define JPC_PHYSICS_UPDATE_ERROR_BODY_PAIR_CACHE_FULL 1 << 1
#define JPC_PHYSICS_UPDATE_ERROR_CONTACT_CONSTRAINTS_FULL 1 << 2

ENSURE_ENUM_EQ(JPC_PHYSICS_UPDATE_ERROR_NONE, JPH::EPhysicsUpdateError::None)
ENSURE_ENUM_EQ(JPC_PHYSICS_UPDATE_ERROR_MANIFOLD_CACHE_FULL, JPH::EPhysicsUpdateError::ManifoldCacheFull)
Expand Down Expand Up @@ -239,11 +232,8 @@ ENSURE_ENUM_EQ(JPC_VALIDATE_RESULT_REJECT_ALL_CONTACTS,

// EBackFaceMode
typedef uint8_t JPC_BackFaceMode;
const JPC_BackFaceMode JPC_BACK_FACE_MODE_IGNORE = 0;
const JPC_BackFaceMode JPC_BACK_FACE_MODE_COLLIDE = 1;

ENSURE_ENUM_EQ(JPC_BACK_FACE_MODE_IGNORE, JPH::EBackFaceMode::IgnoreBackFaces)
ENSURE_ENUM_EQ(JPC_BACK_FACE_MODE_COLLIDE, JPH::EBackFaceMode::CollideWithBackFaces)
#define JPC_BACK_FACE_MODE_IGNORE 0
#define JPC_BACK_FACE_MODE_COLLIDE 1

typedef enum JPC_BodyType: uint8_t {
JPC_BODY_TYPE_RIGID_BODY = 0,
Expand Down Expand Up @@ -294,63 +284,58 @@ typedef enum JPC_Features: uint32_t {
} JPC_Features;

typedef int JPC_ShapeColor;
const JPC_ShapeColor JPC_SHAPE_COLOR_INSTANCE_COLOR = 0;
const JPC_ShapeColor JPC_SHAPE_COLOR_SHAPE_TYPE_COLOR = 1;
const JPC_ShapeColor JPC_SHAPE_COLOR_MOTION_TYPE_COLOR = 2;
const JPC_ShapeColor JPC_SHAPE_COLOR_SLEEP_COLOR = 3;
const JPC_ShapeColor JPC_SHAPE_COLOR_ISLAND_COLOR = 4;
const JPC_ShapeColor JPC_SHAPE_COLOR_MATERIAL_COLOR = 5;

#define JPC_SHAPE_COLOR_INSTANCE_COLOR 0
#define JPC_SHAPE_COLOR_SHAPE_TYPE_COLOR 1
#define JPC_SHAPE_COLOR_MOTION_TYPE_COLOR 2
#define JPC_SHAPE_COLOR_SLEEP_COLOR 3
#define JPC_SHAPE_COLOR_ISLAND_COLOR 4
#define JPC_SHAPE_COLOR_MATERIAL_COLOR 5

#ifdef JPH_DEBUG_RENDERER
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_INSTANCE_COLOR, JPH::BodyManager::EShapeColor::InstanceColor)
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_SHAPE_TYPE_COLOR, JPH::BodyManager::EShapeColor::ShapeTypeColor)
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_MOTION_TYPE_COLOR, JPH::BodyManager::EShapeColor::MotionTypeColor)
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_SLEEP_COLOR, JPH::BodyManager::EShapeColor::SleepColor)
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_ISLAND_COLOR, JPH::BodyManager::EShapeColor::IslandColor)
ENSURE_ENUM_EQ(JPC_SHAPE_COLOR_MATERIAL_COLOR, JPH::BodyManager::EShapeColor::MaterialColor)
#endif

typedef int JPC_SoftBodyConstraintColor;
const JPC_SoftBodyConstraintColor JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_TYPE = 0;
const JPC_SoftBodyConstraintColor JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_GROUP = 1;
const JPC_SoftBodyConstraintColor JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_ORDER = 2;
#define JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_TYPE 0
#define JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_GROUP 1
#define JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_ORDER 2

#ifdef JPH_DEBUG_RENDERER
ENSURE_ENUM_EQ(JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_TYPE, JPH::ESoftBodyConstraintColor::ConstraintType);
ENSURE_ENUM_EQ(JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_GROUP, JPH::ESoftBodyConstraintColor::ConstraintGroup);
ENSURE_ENUM_EQ(JPC_SOFT_BODY_CONSTRAINT_COLOR_CONSTRAINT_ORDER, JPH::ESoftBodyConstraintColor::ConstraintOrder);
#endif

// EActiveEdgeMode
typedef uint8_t JPC_ActiveEdgeMode;
const JPC_ActiveEdgeMode JPC_ACTIVE_EDGE_MODE_COLLIDE_ONLY_WITH_ACTIVE = 0;
const JPC_ActiveEdgeMode JPC_ACTIVE_EDGE_MODE_COLLIDE_WITH_ALL = 1;

ENSURE_ENUM_EQ(JPC_ACTIVE_EDGE_MODE_COLLIDE_ONLY_WITH_ACTIVE, JPH::EActiveEdgeMode::CollideOnlyWithActive);
ENSURE_ENUM_EQ(JPC_ACTIVE_EDGE_MODE_COLLIDE_WITH_ALL, JPH::EActiveEdgeMode::CollideWithAll);
#define JPC_ACTIVE_EDGE_MODE_COLLIDE_ONLY_WITH_ACTIVE 0
#define JPC_ACTIVE_EDGE_MODE_COLLIDE_WITH_ALL 1

// ECollectFacesMode
typedef uint8_t JPC_CollectFacesMode;
const JPC_CollectFacesMode JPC_COLLECT_FACES_MODE_COLLECT_FACES = 0;
const JPC_CollectFacesMode JPC_COLLECT_FACES_MODE_NO_FACES = 1;

ENSURE_ENUM_EQ(JPC_COLLECT_FACES_MODE_COLLECT_FACES, JPH::ECollectFacesMode::CollectFaces);
ENSURE_ENUM_EQ(JPC_COLLECT_FACES_MODE_NO_FACES, JPH::ECollectFacesMode::NoFaces);
#define JPC_COLLECT_FACES_MODE_COLLECT_FACES 0
#define JPC_COLLECT_FACES_MODE_NO_FACES 1

// ESwingType
typedef uint8_t JPC_SwingType;
const JPC_SwingType JPC_SWING_TYPE_CONE = 0;
const JPC_SwingType JPC_SWING_TYPE_PYRAMID = 1;

ENSURE_ENUM_EQ(JPC_SWING_TYPE_CONE, JPH::ESwingType::Cone);
ENSURE_ENUM_EQ(JPC_SWING_TYPE_PYRAMID, JPH::ESwingType::Pyramid);
#define JPC_SWING_TYPE_CONE 0
#define JPC_SWING_TYPE_PYRAMID 1

// SixDOFConstraint::EAxis
typedef uint32_t JPC_SixDOFConstraint_Axis;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_X = 0;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Y = 1;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Z = 2;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_X = 3;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_Y = 4;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_Z = 5;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_NUM = 6;
const JPC_SixDOFConstraint_Axis JPC_SIX_DOF_CONSTRAINT_AXIS_NUM_TRANSLATION = JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Z + 1;
#define JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_X 0
#define JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Y 1
#define JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Z 2
#define JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_X 3
#define JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_Y 4
#define JPC_SIX_DOF_CONSTRAINT_AXIS_ROTATION_Z 5
#define JPC_SIX_DOF_CONSTRAINT_AXIS_NUM 6
#define JPC_SIX_DOF_CONSTRAINT_AXIS_NUM_TRANSLATION JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Z + 1

ENSURE_ENUM_EQ(JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_X, JPH::SixDOFConstraint::EAxis::TranslationX);
ENSURE_ENUM_EQ(JPC_SIX_DOF_CONSTRAINT_AXIS_TRANSLATION_Y, JPH::SixDOFConstraint::EAxis::TranslationY);
Expand Down
2 changes: 2 additions & 0 deletions JoltC/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ typedef struct JPC_BodyManager_DrawSettings {
JPC_SoftBodyConstraintColor DrawSoftBodyConstraintColor;
} JPC_BodyManager_DrawSettings;

#ifdef JPH_DEBUG_RENDERER
ENSURE_SIZE_ALIGN(JPC_BodyManager_DrawSettings, JPH::BodyManager::DrawSettings)
#endif

JPC_API void JPC_BodyManager_DrawSettings_default(JPC_BodyManager_DrawSettings* object);

Expand Down
24 changes: 24 additions & 0 deletions JoltCImpl/JoltC.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>

#include <Jolt/Jolt.h>

#include <Jolt/Core/Factory.h>
Expand Down Expand Up @@ -35,7 +37,9 @@
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/RegisterTypes.h>

#ifdef JPH_DEBUG_RENDERER
#include <Jolt/Renderer/DebugRendererSimple.h>
#endif

#include <JoltC/JoltC.h>

Expand Down Expand Up @@ -137,7 +141,9 @@ DESTRUCTOR(JPC_IndexedTriangleList)
OPAQUE_WRAPPER(JPC_String, JPH::String)
DESTRUCTOR(JPC_String)

#ifdef JPH_DEBUG_RENDERER
LAYOUT_COMPATIBLE(JPC_BodyManager_DrawSettings, JPH::BodyManager::DrawSettings)
#endif

LAYOUT_COMPATIBLE(JPC_ShapeCastSettings, JPH::ShapeCastSettings)
LAYOUT_COMPATIBLE(JPC_CollideShapeSettings, JPH::CollideShapeSettings)
Expand Down Expand Up @@ -842,12 +848,17 @@ JPC_API void JPC_CollideShapeCollector_UpdateEarlyOutFraction(JPC_CollideShapeCo
// BodyManager::DrawSettings

JPC_API void JPC_BodyManager_DrawSettings_default(JPC_BodyManager_DrawSettings* object) {
#ifdef JPH_DEBUG_RENDERER
*object = to_jpc(JPH::BodyManager::DrawSettings());
#else
printf("JPC_BodyManager_DrawSettings_default is a debug functionality that is not supported in release build, skipping\n");
#endif
}

////////////////////////////////////////////////////////////////////////////////
// DebugRendererSimple

#ifdef JPH_DEBUG_RENDERER
class JPC_DebugRendererSimpleBridge final : public JPH::DebugRendererSimple {
public:
explicit JPC_DebugRendererSimpleBridge(const void *self, JPC_DebugRendererSimpleFns fns) : self(self), fns(fns) {}
Expand All @@ -872,12 +883,17 @@ class JPC_DebugRendererSimpleBridge final : public JPH::DebugRendererSimple {

OPAQUE_WRAPPER(JPC_DebugRendererSimple, JPC_DebugRendererSimpleBridge)
DESTRUCTOR(JPC_DebugRendererSimple)
#endif

JPC_API JPC_DebugRendererSimple* JPC_DebugRendererSimple_new(
const void *self,
JPC_DebugRendererSimpleFns fns)
{
#ifdef JPH_DEBUG_RENDERER
return to_jpc(new JPC_DebugRendererSimpleBridge(self, fns));
#else
printf("JPC_DebugRendererSimple_new is a debug functionality that is not supported in release build, skipping\n");
#endif
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2950,14 +2966,22 @@ JPC_API void JPC_PhysicsSystem_DrawBodies(
JPC_DebugRendererSimple* inRenderer,
[[maybe_unused]] const void* inBodyFilter)
{
#ifdef JPH_DEBUG_RENDERER
to_jph(self)->DrawBodies(to_jph(*inSettings), to_jph(inRenderer), nullptr);
#else
printf("JPC_PhysicsSystem_DrawBodies is a debug functionality that is not supported in release build, skipping\n");
#endif
}

JPC_API void JPC_PhysicsSystem_DrawConstraints(
JPC_PhysicsSystem* self,
JPC_DebugRendererSimple* inRenderer)
{
#ifdef JPH_DEBUG_RENDERER
to_jph(self)->DrawConstraints(to_jph(inRenderer));
#else
printf("JPC_PhysicsSystem_DrawConstraints is a debug functionality that is not supported in release build, skipping\n");
#endif
}


Expand Down