Skip to content

Commit

Permalink
Bind main part of CastShapeCollector API, now usable
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Oct 23, 2024
1 parent ae76c40 commit d756b66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
11 changes: 7 additions & 4 deletions JoltC/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,20 @@ JPC_API void JPC_ObjectLayerPairFilter_delete(JPC_ObjectLayerPairFilter* object)
// CastShapeCollector

typedef struct JPC_CastShapeCollectorFns {
void (*AddHit)(const void *self, const JPC_ShapeCastResult *Result);
void (*Reset)(void *self);
void (*AddHit)(void *self, const JPC_ShapeCastResult *Result);
} JPC_CastShapeCollectorFns;

typedef struct JPC_CastShapeCollector JPC_CastShapeCollector;

JPC_API JPC_CastShapeCollector* JPC_CastShapeCollector_new(
const void *self,
void *self,
JPC_CastShapeCollectorFns fns);

JPC_API void JPC_CastShapeCollector_delete(JPC_CastShapeCollector* object);

JPC_API void JPC_CastShapeCollector_UpdateEarlyOutFraction(JPC_CastShapeCollector *self, float inFraction);

////////////////////////////////////////////////////////////////////////////////
// DrawSettings

Expand Down Expand Up @@ -836,14 +839,14 @@ typedef struct JPC_NarrowPhaseQuery_CastShapeArgs {
JPC_RShapeCast ShapeCast;
JPC_ShapeCastSettings Settings;
JPC_RVec3 BaseOffset;
// JPC_CastShapeCollector *Collector;
JPC_CastShapeCollector *Collector;
const JPC_BroadPhaseLayerFilter *BroadPhaseLayerFilter;
const JPC_ObjectLayerFilter *ObjectLayerFilter;
const JPC_BodyFilter *BodyFilter;
// const JPC_ShapeFilter *ShapeFilter;
} JPC_NarrowPhaseQuery_CastShapeArgs;

JPC_API bool JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args);
JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args);

////////////////////////////////////////////////////////////////////////////////
// PhysicsSystem
Expand Down
32 changes: 23 additions & 9 deletions JoltC/JoltC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,28 +493,40 @@ class JPC_CastShapeCollectorBridge final : public JPH::CastShapeCollector {
using ResultType = JPH::ShapeCastResult;

public:
explicit JPC_CastShapeCollectorBridge(const void *self, JPC_CastShapeCollectorFns fns) : self(self), fns(fns) {}
explicit JPC_CastShapeCollectorBridge(void *self, JPC_CastShapeCollectorFns fns) : self(self), fns(fns) {}

virtual void AddHit(const ResultType &inResult) {
virtual void Reset() override {
JPH::CastShapeCollector::Reset();

if (fns.Reset != nullptr) {
fns.Reset(self);
}
}

virtual void AddHit(const ResultType &inResult) override {
JPC_ShapeCastResult result = to_jpc(inResult);
fns.AddHit(self, &result);
}

private:
const void* self;
void* self;
JPC_CastShapeCollectorFns fns;
};

OPAQUE_WRAPPER(JPC_CastShapeCollector, JPC_CastShapeCollectorBridge)
DESTRUCTOR(JPC_CastShapeCollector)

JPC_API JPC_CastShapeCollector* JPC_CastShapeCollector_new(
const void *self,
void *self,
JPC_CastShapeCollectorFns fns)
{
return to_jpc(new JPC_CastShapeCollectorBridge(self, fns));
}

JPC_API void JPC_CastShapeCollector_UpdateEarlyOutFraction(JPC_CastShapeCollector* self, float inFraction) {
to_jph(self)->UpdateEarlyOutFraction(inFraction);
}

////////////////////////////////////////////////////////////////////////////////
// BodyManager::DrawSettings

Expand Down Expand Up @@ -1597,10 +1609,14 @@ JPC_API void JPC_ShapeCastSettings_default(JPC_ShapeCastSettings* object) {
object->ReturnDeepestPoint = false;
}

JPC_API bool JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
JPH::ShapeCastSettings settings = to_jph(args->Settings);

JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> collector{};
JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> defaultCollector{};
JPH::CastShapeCollector* collector = &defaultCollector;
if (args->Collector != nullptr) {
collector = to_jph(args->Collector);
}

JPH::BroadPhaseLayerFilter defaultBplFilter{};
const JPH::BroadPhaseLayerFilter* bplFilter = &defaultBplFilter;
Expand Down Expand Up @@ -1630,13 +1646,11 @@ JPC_API bool JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JP
to_jph(args->ShapeCast),
settings,
to_jph(args->BaseOffset),
collector,
*collector,
*bplFilter,
*olFilter,
*bodyFilter,
*shapeFilter);

return collector.HadHit();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit d756b66

Please sign in to comment.