-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJoltPhysicsC.cpp
3445 lines (3295 loc) · 149 KB
/
JoltPhysicsC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "JoltPhysicsC.h"
#include <assert.h>
#include <stddef.h>
#include <Jolt/Jolt.h>
#include <Jolt/RegisterTypes.h>
#include <Jolt/Core/Factory.h>
#include <Jolt/Core/TempAllocator.h>
#include <Jolt/Core/Memory.h>
#include <Jolt/Core/JobSystemThreadPool.h>
#include <Jolt/Physics/PhysicsSettings.h>
#include <Jolt/Physics/PhysicsSystem.h>
#include <Jolt/Physics/EPhysicsUpdateError.h>
#include <Jolt/Physics/Collision/NarrowPhaseQuery.h>
#include <Jolt/Physics/Collision/CollideShape.h>
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include <Jolt/Physics/Collision/Shape/TriangleShape.h>
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
#include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
#include <Jolt/Physics/Collision/Shape/CylinderShape.h>
#include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
#include <Jolt/Physics/Collision/Shape/HeightFieldShape.h>
#include <Jolt/Physics/Collision/Shape/MeshShape.h>
#include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
#include <Jolt/Physics/Collision/Shape/ScaledShape.h>
#include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
#include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
#include <Jolt/Physics/Collision/PhysicsMaterial.h>
#include <Jolt/Physics/Collision/RayCast.h>
#include <Jolt/Physics/Constraints/FixedConstraint.h>
#include <Jolt/Physics/Body/BodyCreationSettings.h>
#include <Jolt/Physics/Body/BodyActivationListener.h>
#include <Jolt/Physics/Body/BodyLock.h>
#include <Jolt/Physics/Body/BodyManager.h>
#include <Jolt/Physics/Body/BodyFilter.h>
#include <Jolt/Physics/Character/Character.h>
#include <Jolt/Physics/Character/CharacterVirtual.h>
#if JPC_DEBUG_RENDERER == 1
#include <string_view>
#include <Jolt/Renderer/DebugRenderer.h>
#endif //JPC_DEBUG_RENDERER
JPH_SUPPRESS_WARNINGS
#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
#error Currently JoltPhysicsC does not support profiling. Please undef JPH_EXTERNAL_PROFILE and JPH_PROFILE_ENABLED.
#endif
#if defined(JPH_TRACK_BROADPHASE_STATS)
#error JPH_TRACK_BROADPHASE_STATS is not supported.
#endif
#define ENSURE_TYPE(o, t) \
assert(o != nullptr); \
assert(reinterpret_cast<const JPH::SerializableObject *>(o)->CastTo(JPH_RTTI(t)) != nullptr)
#define FN(name) static auto name
FN(toJph)(JPC_BodyID in) { return JPH::BodyID(in); }
FN(toJpc)(JPH::BodyID in) { return in.GetIndexAndSequenceNumber(); }
FN(toJpc)(const JPH::Body *in) { assert(in); return reinterpret_cast<const JPC_Body *>(in); }
FN(toJph)(const JPC_Body *in) { assert(in); return reinterpret_cast<const JPH::Body *>(in); }
FN(toJpc)(JPH::Body *in) { assert(in); return reinterpret_cast<JPC_Body *>(in); }
FN(toJph)(JPC_Body *in) { assert(in); return reinterpret_cast<JPH::Body *>(in); }
FN(toJph)(JPC_PhysicsMaterial *in) { return reinterpret_cast<JPH::PhysicsMaterial *>(in); }
FN(toJph)(const JPC_PhysicsMaterial *in) { return reinterpret_cast<const JPH::PhysicsMaterial *>(in); }
FN(toJpc)(JPH::PhysicsMaterial *in) { return reinterpret_cast<JPC_PhysicsMaterial *>(in); }
FN(toJpc)(const JPH::PhysicsMaterial *in) { return reinterpret_cast<const JPC_PhysicsMaterial *>(in); }
FN(toJph)(const JPC_ShapeSettings *in) {
ENSURE_TYPE(in, JPH::ShapeSettings);
return reinterpret_cast<const JPH::ShapeSettings *>(in);
}
FN(toJph)(JPC_ShapeSettings *in) {
ENSURE_TYPE(in, JPH::ShapeSettings);
return reinterpret_cast<JPH::ShapeSettings *>(in);
}
FN(toJpc)(const JPH::ShapeSettings *in) { assert(in); return reinterpret_cast<const JPC_ShapeSettings *>(in); }
FN(toJpc)(JPH::ShapeSettings *in) { assert(in); return reinterpret_cast<JPC_ShapeSettings *>(in); }
FN(toJph)(const JPC_BoxShapeSettings *in) {
ENSURE_TYPE(in, JPH::BoxShapeSettings);
return reinterpret_cast<const JPH::BoxShapeSettings *>(in);
}
FN(toJph)(JPC_BoxShapeSettings *in) {
ENSURE_TYPE(in, JPH::BoxShapeSettings);
return reinterpret_cast<JPH::BoxShapeSettings *>(in);
}
FN(toJpc)(JPH::BoxShapeSettings *in) { assert(in); return reinterpret_cast<JPC_BoxShapeSettings *>(in); }
FN(toJph)(const JPC_SphereShapeSettings *in) {
ENSURE_TYPE(in, JPH::SphereShapeSettings);
return reinterpret_cast<const JPH::SphereShapeSettings *>(in);
}
FN(toJph)(JPC_SphereShapeSettings *in) {
ENSURE_TYPE(in, JPH::SphereShapeSettings);
return reinterpret_cast<JPH::SphereShapeSettings *>(in);
}
FN(toJpc)(JPH::SphereShapeSettings *in) { assert(in); return reinterpret_cast<JPC_SphereShapeSettings *>(in); }
FN(toJph)(const JPC_TriangleShapeSettings *in) {
ENSURE_TYPE(in, JPH::TriangleShapeSettings);
return reinterpret_cast<const JPH::TriangleShapeSettings *>(in);
}
FN(toJph)(JPC_TriangleShapeSettings *in) {
ENSURE_TYPE(in, JPH::TriangleShapeSettings);
return reinterpret_cast<JPH::TriangleShapeSettings *>(in);
}
FN(toJpc)(JPH::TriangleShapeSettings *in) { assert(in); return reinterpret_cast<JPC_TriangleShapeSettings *>(in); }
FN(toJph)(const JPC_CapsuleShapeSettings *in) {
ENSURE_TYPE(in, JPH::CapsuleShapeSettings);
return reinterpret_cast<const JPH::CapsuleShapeSettings *>(in);
}
FN(toJph)(JPC_CapsuleShapeSettings *in) {
ENSURE_TYPE(in, JPH::CapsuleShapeSettings);
return reinterpret_cast<JPH::CapsuleShapeSettings *>(in);
}
FN(toJpc)(JPH::CapsuleShapeSettings *in) { assert(in); return reinterpret_cast<JPC_CapsuleShapeSettings *>(in); }
FN(toJph)(const JPC_TaperedCapsuleShapeSettings *in) {
ENSURE_TYPE(in, JPH::TaperedCapsuleShapeSettings);
return reinterpret_cast<const JPH::TaperedCapsuleShapeSettings *>(in);
}
FN(toJph)(JPC_TaperedCapsuleShapeSettings *in) {
ENSURE_TYPE(in, JPH::TaperedCapsuleShapeSettings);
return reinterpret_cast<JPH::TaperedCapsuleShapeSettings *>(in);
}
FN(toJpc)(JPH::TaperedCapsuleShapeSettings *in) {
assert(in); return reinterpret_cast<JPC_TaperedCapsuleShapeSettings *>(in);
}
FN(toJph)(const JPC_CylinderShapeSettings *in) {
ENSURE_TYPE(in, JPH::CylinderShapeSettings);
return reinterpret_cast<const JPH::CylinderShapeSettings *>(in);
}
FN(toJph)(JPC_CylinderShapeSettings *in) {
ENSURE_TYPE(in, JPH::CylinderShapeSettings);
return reinterpret_cast<JPH::CylinderShapeSettings *>(in);
}
FN(toJpc)(JPH::CylinderShapeSettings *in) { assert(in); return reinterpret_cast<JPC_CylinderShapeSettings *>(in); }
FN(toJph)(const JPC_ConvexHullShapeSettings *in) {
ENSURE_TYPE(in, JPH::ConvexHullShapeSettings);
return reinterpret_cast<const JPH::ConvexHullShapeSettings *>(in);
}
FN(toJph)(JPC_ConvexHullShapeSettings *in) {
ENSURE_TYPE(in, JPH::ConvexHullShapeSettings);
return reinterpret_cast<JPH::ConvexHullShapeSettings *>(in);
}
FN(toJpc)(JPH::ConvexHullShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_ConvexHullShapeSettings *>(in);
}
FN(toJph)(const JPC_HeightFieldShapeSettings *in) {
ENSURE_TYPE(in, JPH::HeightFieldShapeSettings);
return reinterpret_cast<const JPH::HeightFieldShapeSettings *>(in);
}
FN(toJph)(JPC_HeightFieldShapeSettings *in) {
ENSURE_TYPE(in, JPH::HeightFieldShapeSettings);
return reinterpret_cast<JPH::HeightFieldShapeSettings *>(in);
}
FN(toJpc)(JPH::HeightFieldShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_HeightFieldShapeSettings *>(in);
}
FN(toJph)(const JPC_MeshShapeSettings *in) {
ENSURE_TYPE(in, JPH::MeshShapeSettings);
return reinterpret_cast<const JPH::MeshShapeSettings *>(in);
}
FN(toJph)(JPC_MeshShapeSettings *in) {
ENSURE_TYPE(in, JPH::MeshShapeSettings);
return reinterpret_cast<JPH::MeshShapeSettings *>(in);
}
FN(toJpc)(JPH::MeshShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_MeshShapeSettings *>(in);
}
FN(toJph)(const JPC_ConvexShapeSettings *in) {
ENSURE_TYPE(in, JPH::ConvexShapeSettings);
return reinterpret_cast<const JPH::ConvexShapeSettings *>(in);
}
FN(toJph)(JPC_ConvexShapeSettings *in) {
ENSURE_TYPE(in, JPH::ConvexShapeSettings);
return reinterpret_cast<JPH::ConvexShapeSettings *>(in);
}
FN(toJpc)(JPH::RotatedTranslatedShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_DecoratedShapeSettings *>(in);
}
FN(toJpc)(JPH::ScaledShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_DecoratedShapeSettings *>(in);
}
FN(toJpc)(JPH::OffsetCenterOfMassShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_DecoratedShapeSettings *>(in);
}
FN(toJph)(JPC_DecoratedShapeSettings *in) {
ENSURE_TYPE(in, JPH::DecoratedShapeSettings);
return reinterpret_cast<JPH::DecoratedShapeSettings *>(in);
}
FN(toJpc)(JPH::StaticCompoundShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_CompoundShapeSettings *>(in);
}
FN(toJpc)(JPH::MutableCompoundShapeSettings *in) {
assert(in);
return reinterpret_cast<JPC_CompoundShapeSettings *>(in);
}
FN(toJph)(JPC_CompoundShapeSettings *in) {
ENSURE_TYPE(in, JPH::CompoundShapeSettings);
return reinterpret_cast<JPH::CompoundShapeSettings *>(in);
}
FN(toJph)(JPC_BoxShape *in) { assert(in); return reinterpret_cast<JPH::BoxShape *>(in); }
FN(toJph)(const JPC_BoxShape *in) { assert(in); return reinterpret_cast<const JPH::BoxShape *>(in); }
FN(toJpc)(JPH::BoxShape *in) { assert(in); return reinterpret_cast<JPC_BoxShape *>(in); }
FN(toJpc)(const JPH::BoxShape *in) { assert(in); return reinterpret_cast<const JPC_BoxShape *>(in); }
FN(toJph)(JPC_ConvexHullShape *in) { assert(in); return reinterpret_cast<JPH::ConvexHullShape *>(in); }
FN(toJph)(const JPC_ConvexHullShape *in) { assert(in); return reinterpret_cast<const JPH::ConvexHullShape *>(in); }
FN(toJpc)(JPH::ConvexHullShape *in) { assert(in); return reinterpret_cast<JPC_ConvexHullShape *>(in); }
FN(toJpc)(const JPH::ConvexHullShape *in) { assert(in); return reinterpret_cast<const JPC_ConvexHullShape *>(in); }
FN(toJph)(JPC_DecoratedShape *in) { assert(in); return reinterpret_cast<JPH::DecoratedShape *>(in); }
FN(toJph)(const JPC_DecoratedShape *in) { assert(in); return reinterpret_cast<const JPH::DecoratedShape *>(in); }
FN(toJpc)(JPH::DecoratedShape *in) { assert(in); return reinterpret_cast<JPC_DecoratedShape *>(in); }
FN(toJpc)(const JPH::DecoratedShape *in) { assert(in); return reinterpret_cast<const JPC_DecoratedShape *>(in); }
FN(toJph)(JPC_RotatedTranslatedShape *in) { assert(in); return reinterpret_cast<JPH::RotatedTranslatedShape *>(in); }
FN(toJph)(const JPC_RotatedTranslatedShape *in) { assert(in); return reinterpret_cast<const JPH::RotatedTranslatedShape *>(in); }
FN(toJpc)(JPH::RotatedTranslatedShape *in) { assert(in); return reinterpret_cast<JPC_RotatedTranslatedShape *>(in); }
FN(toJpc)(const JPH::RotatedTranslatedShape *in) { assert(in); return reinterpret_cast<const JPC_RotatedTranslatedShape *>(in); }
FN(toJph)(JPC_ShapeToIDMap *in) { assert(in); return reinterpret_cast<JPH::Shape::ShapeToIDMap *>(in); }
FN(toJph)(const JPC_ShapeToIDMap *in) { assert(in); return reinterpret_cast<const JPH::Shape::ShapeToIDMap *>(in); }
FN(toJpc)(JPH::Shape::ShapeToIDMap *in) { assert(in); return reinterpret_cast<JPC_ShapeToIDMap *>(in); }
FN(toJpc)(const JPH::Shape::ShapeToIDMap *in) { assert(in); return reinterpret_cast<const JPC_ShapeToIDMap *>(in); }
FN(toJph)(JPC_MaterialToIDMap *in) { assert(in); return reinterpret_cast<JPH::Shape::MaterialToIDMap *>(in); }
FN(toJph)(const JPC_MaterialToIDMap *in) { assert(in); return reinterpret_cast<const JPH::Shape::MaterialToIDMap *>(in); }
FN(toJpc)(JPH::Shape::MaterialToIDMap *in) { assert(in); return reinterpret_cast<JPC_MaterialToIDMap *>(in); }
FN(toJpc)(const JPH::Shape::MaterialToIDMap *in) { assert(in); return reinterpret_cast<const JPC_MaterialToIDMap *>(in); }
FN(toJph)(JPC_IDToShapeMap *in) { assert(in); return reinterpret_cast<JPH::Shape::IDToShapeMap *>(in); }
FN(toJph)(const JPC_IDToShapeMap *in) { assert(in); return reinterpret_cast<const JPH::Shape::IDToShapeMap *>(in); }
FN(toJpc)(JPH::Shape::IDToShapeMap *in) { assert(in); return reinterpret_cast<JPC_IDToShapeMap *>(in); }
FN(toJpc)(const JPH::Shape::IDToShapeMap *in) { assert(in); return reinterpret_cast<const JPC_IDToShapeMap *>(in); }
FN(toJph)(JPC_IDToMaterialMap *in) { assert(in); return reinterpret_cast<JPH::Shape::IDToMaterialMap *>(in); }
FN(toJph)(const JPC_IDToMaterialMap *in) { assert(in); return reinterpret_cast<const JPH::Shape::IDToMaterialMap *>(in); }
FN(toJpc)(JPH::Shape::IDToMaterialMap *in) { assert(in); return reinterpret_cast<JPC_IDToMaterialMap *>(in); }
FN(toJpc)(const JPH::Shape::IDToMaterialMap *in) { assert(in); return reinterpret_cast<const JPC_IDToMaterialMap *>(in); }
FN(toJph)(const JPC_ConstraintSettings *in) {
ENSURE_TYPE(in, JPH::ConstraintSettings);
return reinterpret_cast<const JPH::ConstraintSettings *>(in);
}
FN(toJph)(JPC_ConstraintSettings *in) {
ENSURE_TYPE(in, JPH::ConstraintSettings);
return reinterpret_cast<JPH::ConstraintSettings *>(in);
}
FN(toJpc)(const JPH::ConstraintSettings *in) { assert(in); return reinterpret_cast<const JPC_ConstraintSettings *>(in); }
FN(toJpc)(JPH::ConstraintSettings *in) { assert(in); return reinterpret_cast<JPC_ConstraintSettings *>(in); }
FN(toJph)(const JPC_TwoBodyConstraintSettings *in) {
ENSURE_TYPE(in, JPH::TwoBodyConstraintSettings);
return reinterpret_cast<const JPH::TwoBodyConstraintSettings *>(in);
}
FN(toJph)(JPC_TwoBodyConstraintSettings *in) {
ENSURE_TYPE(in, JPH::TwoBodyConstraintSettings);
return reinterpret_cast<JPH::TwoBodyConstraintSettings *>(in);
}
FN(toJpc)(const JPH::TwoBodyConstraintSettings *in) { assert(in); return reinterpret_cast<const JPC_TwoBodyConstraintSettings *>(in); }
FN(toJpc)(JPH::TwoBodyConstraintSettings *in) { assert(in); return reinterpret_cast<JPC_TwoBodyConstraintSettings *>(in); }
FN(toJph)(const JPC_FixedConstraintSettings *in) {
ENSURE_TYPE(in, JPH::FixedConstraintSettings);
return reinterpret_cast<const JPH::FixedConstraintSettings *>(in);
}
FN(toJph)(JPC_FixedConstraintSettings *in) {
ENSURE_TYPE(in, JPH::FixedConstraintSettings);
return reinterpret_cast<JPH::FixedConstraintSettings *>(in);
}
FN(toJpc)(JPH::FixedConstraintSettings *in) { assert(in); return reinterpret_cast<JPC_FixedConstraintSettings *>(in); }
FN(toJph)(const JPC_CollisionGroup *in) { assert(in); return reinterpret_cast<const JPH::CollisionGroup *>(in); }
FN(toJpc)(const JPH::CollisionGroup *in) { assert(in); return reinterpret_cast<const JPC_CollisionGroup *>(in); }
FN(toJpc)(JPH::CollisionGroup *in) { assert(in); return reinterpret_cast<JPC_CollisionGroup *>(in); }
FN(toJph)(const JPC_SubShapeID *in) { assert(in); return reinterpret_cast<const JPH::SubShapeID *>(in); }
FN(toJpc)(const JPH::SubShapeIDCreator *in) { assert(in); return reinterpret_cast<const JPC_SubShapeIDCreator *>(in); }
FN(toJph)(const JPC_SubShapeIDCreator *in) { assert(in); return reinterpret_cast<const JPH::SubShapeIDCreator *>(in); }
FN(toJpc)(JPH::SubShapeIDCreator *in) { assert(in); return reinterpret_cast<JPC_SubShapeIDCreator *>(in); }
FN(toJph)(JPC_SubShapeIDCreator *in) { assert(in); return reinterpret_cast<JPH::SubShapeIDCreator *>(in); }
FN(toJpc)(const JPH::RayCast *in) { assert(in); return reinterpret_cast<const JPC_RayCast *>(in); }
FN(toJph)(const JPC_RayCast *in) { assert(in); return reinterpret_cast<const JPH::RayCast *>(in); }
FN(toJpc)(JPH::RayCast *in) { assert(in); return reinterpret_cast<JPC_RayCast *>(in); }
FN(toJph)(JPC_RayCast *in) { assert(in); return reinterpret_cast<JPH::RayCast *>(in); }
FN(toJpc)(const JPH::RRayCast *in) { assert(in); return reinterpret_cast<const JPC_RRayCast *>(in); }
FN(toJph)(const JPC_RRayCast *in) { assert(in); return reinterpret_cast<const JPH::RRayCast *>(in); }
FN(toJpc)(JPH::RRayCast *in) { assert(in); return reinterpret_cast<JPC_RRayCast *>(in); }
FN(toJph)(JPC_RRayCast *in) { assert(in); return reinterpret_cast<JPH::RRayCast *>(in); }
FN(toJpc)(const JPH::RayCastResult *in) { assert(in); return reinterpret_cast<const JPC_RayCastResult *>(in); }
FN(toJph)(const JPC_RayCastResult *in) { assert(in); return reinterpret_cast<const JPH::RayCastResult *>(in); }
FN(toJpc)(JPH::RayCastResult *in) { assert(in); return reinterpret_cast<JPC_RayCastResult *>(in); }
FN(toJph)(JPC_RayCastResult *in) { assert(in); return reinterpret_cast<JPH::RayCastResult *>(in); }
FN(toJph)(const JPC_BodyLockInterface *in) {
assert(in); return reinterpret_cast<const JPH::BodyLockInterface *>(in);
}
FN(toJpc)(const JPH::BodyLockInterface *in) {
assert(in); return reinterpret_cast<const JPC_BodyLockInterface *>(in);
}
FN(toJpc)(const JPH::NarrowPhaseQuery *in) {
assert(in); return reinterpret_cast<const JPC_NarrowPhaseQuery *>(in);
}
FN(toJph)(const JPC_PhysicsSystem *in) { assert(in); return reinterpret_cast<const JPH::PhysicsSystem *>(in); }
FN(toJph)(JPC_PhysicsSystem *in) { assert(in); return reinterpret_cast<JPH::PhysicsSystem *>(in); }
FN(toJpc)(JPH::PhysicsSystem *in) { assert(in); return reinterpret_cast<JPC_PhysicsSystem *>(in); }
FN(toJpc)(const JPH::Shape *in) { assert(in); return reinterpret_cast<const JPC_Shape *>(in); }
FN(toJph)(const JPC_Shape *in) { assert(in); return reinterpret_cast<const JPH::Shape *>(in); }
FN(toJpc)(JPH::Shape *in) { assert(in); return reinterpret_cast<JPC_Shape *>(in); }
FN(toJph)(JPC_Shape *in) { assert(in); return reinterpret_cast<JPH::Shape *>(in); }
FN(toJpc)(const JPH::Constraint *in) { assert(in); return reinterpret_cast<const JPC_Constraint *>(in); }
FN(toJph)(const JPC_Constraint *in) { assert(in); return reinterpret_cast<const JPH::Constraint *>(in); }
FN(toJpc)(JPH::Constraint *in) { assert(in); return reinterpret_cast<JPC_Constraint *>(in); }
FN(toJph)(JPC_Constraint *in) { assert(in); return reinterpret_cast<JPH::Constraint *>(in); }
FN(toJpc)(const JPH::BodyInterface *in) { assert(in); return reinterpret_cast<const JPC_BodyInterface *>(in); }
FN(toJph)(const JPC_BodyInterface *in) { assert(in); return reinterpret_cast<const JPH::BodyInterface *>(in); }
FN(toJpc)(JPH::BodyInterface *in) { assert(in); return reinterpret_cast<JPC_BodyInterface *>(in); }
FN(toJph)(JPC_BodyInterface *in) { assert(in); return reinterpret_cast<JPH::BodyInterface *>(in); }
FN(toJpc)(const JPH::TransformedShape *in) { assert(in); return reinterpret_cast<const JPC_TransformedShape *>(in); }
FN(toJph)(const JPC_MassProperties *in) { assert(in); return reinterpret_cast<const JPH::MassProperties *>(in); }
FN(toJph)(JPC_BodyLockRead *in) { assert(in); return reinterpret_cast<const JPH::BodyLockRead *>(in); }
FN(toJph)(JPC_BodyLockWrite *in) { assert(in); return reinterpret_cast<const JPH::BodyLockWrite *>(in); }
FN(toJpc)(const JPH::BodyCreationSettings *in) {
assert(in); return reinterpret_cast<const JPC_BodyCreationSettings *>(in);
}
FN(toJph)(const JPC_BodyCreationSettings *in) {
assert(in); return reinterpret_cast<const JPH::BodyCreationSettings *>(in);
}
FN(toJpc)(const JPH::MotionProperties *in) { assert(in); return reinterpret_cast<const JPC_MotionProperties *>(in); }
FN(toJph)(const JPC_MotionProperties *in) { assert(in); return reinterpret_cast<const JPH::MotionProperties *>(in); }
FN(toJpc)(JPH::MotionProperties *in) { assert(in); return reinterpret_cast<JPC_MotionProperties *>(in); }
FN(toJph)(JPC_MotionProperties *in) { assert(in); return reinterpret_cast<JPH::MotionProperties *>(in); }
FN(toJpc)(const JPH::SubShapeIDPair *in) {
assert(in); return reinterpret_cast<const JPC_SubShapeIDPair *>(in);
}
FN(toJpc)(const JPH::ContactManifold *in) {
assert(in); return reinterpret_cast<const JPC_ContactManifold *>(in);
}
FN(toJpc)(const JPH::CollideShapeResult *in) {
assert(in); return reinterpret_cast<const JPC_CollideShapeResult *>(in);
}
FN(toJpc)(JPH::ContactSettings *in) {
assert(in); return reinterpret_cast<JPC_ContactSettings *>(in);
}
FN(toJpc)(JPH::BroadPhaseLayer in) { return static_cast<JPC_BroadPhaseLayer>(in); }
FN(toJpc)(JPH::ObjectLayer in) { return static_cast<JPC_ObjectLayer>(in); }
FN(toJpc)(JPH::EShapeType in) { return static_cast<JPC_ShapeType>(in); }
FN(toJpc)(JPH::EShapeSubType in) { return static_cast<JPC_ShapeSubType>(in); }
FN(toJpc)(JPH::EConstraintType in) { return static_cast<JPC_ConstraintType>(in); }
FN(toJpc)(JPH::EConstraintSubType in) { return static_cast<JPC_ConstraintSubType>(in); }
FN(toJpc)(JPH::EConstraintSpace in) { return static_cast<JPC_ConstraintSpace>(in); }
FN(toJpc)(JPH::EMotionType in) { return static_cast<JPC_MotionType>(in); }
FN(toJpc)(JPH::EActivation in) { return static_cast<JPC_Activation>(in); }
FN(toJpc)(JPH::EMotionQuality in) { return static_cast<JPC_MotionQuality>(in); }
FN(toJpc)(JPH::CharacterBase::EGroundState in) { return static_cast<JPC_CharacterGroundState>(in); }
FN(toJph)(JPC_ConstraintSpace in) { return static_cast<JPH::EConstraintSpace>(in); }
FN(toJph)(const JPC_Character *in) { assert(in); return reinterpret_cast<const JPH::Character *>(in); }
FN(toJph)(JPC_Character *in) { assert(in); return reinterpret_cast<JPH::Character *>(in); }
FN(toJpc)(const JPH::Character *in) { assert(in); return reinterpret_cast<const JPC_Character *>(in); }
FN(toJpc)(JPH::Character *in) { assert(in); return reinterpret_cast<JPC_Character *>(in); }
FN(toJph)(const JPC_CharacterSettings *in) { assert(in); return reinterpret_cast<const JPH::CharacterSettings *>(in); }
FN(toJph)(JPC_CharacterSettings *in) { assert(in); return reinterpret_cast<JPH::CharacterSettings *>(in); }
FN(toJpc)(const JPH::CharacterSettings *in) { assert(in); return reinterpret_cast<const JPC_CharacterSettings *>(in); }
FN(toJpc)(JPH::CharacterSettings *in) { assert(in); return reinterpret_cast<JPC_CharacterSettings *>(in); }
FN(toJph)(const JPC_CharacterVirtual *in) { assert(in); return reinterpret_cast<const JPH::CharacterVirtual *>(in); }
FN(toJph)(JPC_CharacterVirtual *in) { assert(in); return reinterpret_cast<JPH::CharacterVirtual *>(in); }
FN(toJpc)(const JPH::CharacterVirtual *in) { assert(in); return reinterpret_cast<const JPC_CharacterVirtual *>(in); }
FN(toJpc)(JPH::CharacterVirtual *in) { assert(in); return reinterpret_cast<JPC_CharacterVirtual *>(in); }
FN(toJph)(const JPC_CharacterVirtualSettings *in) { assert(in); return reinterpret_cast<const JPH::CharacterVirtualSettings *>(in); }
FN(toJph)(JPC_CharacterVirtualSettings *in) { assert(in); return reinterpret_cast<JPH::CharacterVirtualSettings *>(in); }
FN(toJpc)(const JPH::CharacterVirtualSettings *in) { assert(in); return reinterpret_cast<const JPC_CharacterVirtualSettings *>(in); }
FN(toJpc)(JPH::CharacterVirtualSettings *in) { assert(in); return reinterpret_cast<JPC_CharacterVirtualSettings *>(in); }
FN(toJpc)(const JPH::AABox *in) { assert(in); return reinterpret_cast<const JPC_AABox *>(in); }
FN(toJph)(const JPC_AABox *in) { assert(in); return reinterpret_cast<const JPH::AABox *>(in); }
FN(toJpc)(JPH::AABox *in) { assert(in); return reinterpret_cast<JPC_AABox *>(in); }
FN(toJph)(JPC_AABox *in) { assert(in); return reinterpret_cast<JPH::AABox *>(in); }
#if JPC_DEBUG_RENDERER == 1
FN(toJpc)(const JPH::BodyManager::DrawSettings *in) { assert(in); return reinterpret_cast<const JPC_BodyManager_DrawSettings *>(in); }
FN(toJph)(const JPC_BodyManager_DrawSettings *in) { assert(in); return reinterpret_cast<const JPH::BodyManager::DrawSettings *>(in); }
FN(toJpc)(JPH::BodyManager::DrawSettings *in) { assert(in); return reinterpret_cast<JPC_BodyManager_DrawSettings *>(in); }
FN(toJph)(JPC_BodyManager_DrawSettings *in) { assert(in); return reinterpret_cast<JPH::BodyManager::DrawSettings *>(in); }
FN(toJpc)(const JPH::BodyDrawFilter *in) { assert(in); return reinterpret_cast<const JPC_BodyDrawFilter *>(in); }
FN(toJph)(const JPC_BodyDrawFilter *in) { assert(in); return reinterpret_cast<const JPH::BodyDrawFilter *>(in); }
FN(toJpc)(JPH::BodyDrawFilter *in) { assert(in); return reinterpret_cast<JPC_BodyDrawFilter *>(in); }
FN(toJph)(JPC_BodyDrawFilter *in) { assert(in); return reinterpret_cast<JPH::BodyDrawFilter *>(in); }
FN(toJpc)(const JPH::ColorArg *in) { assert(in); return reinterpret_cast<const JPC_Color *>(in); }
FN(toJph)(const JPC_Color *in) { assert(in); return reinterpret_cast<const JPH::ColorArg *>(in); }
FN(toJpc)(JPH::ColorArg *in) { assert(in); return reinterpret_cast<JPC_Color *>(in); }
FN(toJph)(JPC_Color *in) { assert(in); return reinterpret_cast<JPH::ColorArg *>(in); }
FN(toJpc)(const JPH::DebugRenderer::Vertex *in) { assert(in); return reinterpret_cast<const JPC_DebugRenderer_Vertex *>(in); }
FN(toJph)(const JPC_DebugRenderer_Vertex *in) { assert(in); return reinterpret_cast<const JPH::DebugRenderer::Vertex *>(in); }
FN(toJpc)(JPH::DebugRenderer::Vertex *in) { assert(in); return reinterpret_cast<JPC_DebugRenderer_Vertex *>(in); }
FN(toJph)(JPC_DebugRenderer_Vertex *in) { assert(in); return reinterpret_cast<JPH::DebugRenderer::Vertex *>(in); }
FN(toJpc)(const JPH::DebugRenderer::Triangle *in) { assert(in); return reinterpret_cast<const JPC_DebugRenderer_Triangle *>(in); }
FN(toJph)(const JPC_DebugRenderer_Triangle *in) { assert(in); return reinterpret_cast<const JPH::DebugRenderer::Triangle *>(in); }
FN(toJpc)(JPH::DebugRenderer::Triangle *in) { assert(in); return reinterpret_cast<JPC_DebugRenderer_Triangle *>(in); }
FN(toJph)(JPC_DebugRenderer_Triangle *in) { assert(in); return reinterpret_cast<JPH::DebugRenderer::Triangle *>(in); }
FN(toJpc)(const JPH::DebugRenderer::LOD *in) { assert(in); return reinterpret_cast<const JPC_DebugRenderer_LOD *>(in); }
FN(toJph)(const JPC_DebugRenderer_LOD *in) { assert(in); return reinterpret_cast<const JPH::DebugRenderer::LOD *>(in); }
FN(toJpc)(JPH::DebugRenderer::LOD *in) { assert(in); return reinterpret_cast<JPC_DebugRenderer_LOD *>(in); }
FN(toJph)(JPC_DebugRenderer_LOD *in) { assert(in); return reinterpret_cast<JPH::DebugRenderer::LOD *>(in); }
#endif //JPC_DEBUG_RENDERER
#undef FN
static inline JPH::Vec3 loadVec3(const float in[3]) {
assert(in != nullptr);
return JPH::Vec3(*reinterpret_cast<const JPH::Float3 *>(in));
}
static inline JPH::Vec4 loadVec4(const float in[4]) {
assert(in != nullptr);
return JPH::Vec4::sLoadFloat4(reinterpret_cast<const JPH::Float4 *>(in));
}
static inline JPH::Mat44 loadMat44(const float in[16]) {
assert(in != nullptr);
return JPH::Mat44::sLoadFloat4x4(reinterpret_cast<const JPH::Float4 *>(in));
}
static inline JPH::RVec3 loadRVec3(const JPC_Real in[3]) {
assert(in != nullptr);
#if JPC_DOUBLE_PRECISION == 0
return JPH::Vec3(*reinterpret_cast<const JPH::Float3 *>(in));
#else
return JPH::DVec3(in[0], in[1], in[2]);
#endif
}
static inline void storeRVec3(JPC_Real out[3], JPH::RVec3Arg in) {
assert(out != nullptr);
#if JPC_DOUBLE_PRECISION == 0
in.StoreFloat3(reinterpret_cast<JPH::Float3 *>(out));
#else
in.StoreDouble3(reinterpret_cast<JPH::Double3 *>(out));
#endif
}
static inline void storeVec3(float out[3], JPH::Vec3Arg in) {
assert(out != nullptr);
in.StoreFloat3(reinterpret_cast<JPH::Float3 *>(out));
}
static inline void storeVec4(float out[4], JPH::Vec4Arg in) {
assert(out != nullptr);
in.StoreFloat4(reinterpret_cast<JPH::Float4 *>(out));
}
static inline void storeMat44(float out[16], JPH::Mat44Arg in) {
assert(out != nullptr);
in.StoreFloat4x4(reinterpret_cast<JPH::Float4 *>(out));
}
static JPH::TraceFunction default_trace = nullptr;
#ifdef JPH_ENABLE_ASSERTS
static JPH::AssertFailedFunction default_assert_failed = nullptr;
#endif
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_RegisterDefaultAllocator(void)
{
JPH::RegisterDefaultAllocator();
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_RegisterCustomAllocator(JPC_AllocateFunction in_alloc,
JPC_ReallocateFunction in_realloc,
JPC_FreeFunction in_free,
JPC_AlignedAllocateFunction in_aligned_alloc,
JPC_AlignedFreeFunction in_aligned_free)
{
#ifndef JPH_DISABLE_CUSTOM_ALLOCATOR
JPH::Allocate = in_alloc;
JPH::Reallocate = in_realloc;
JPH::Free = in_free;
JPH::AlignedAllocate = in_aligned_alloc;
JPH::AlignedFree = in_aligned_free;
#endif
}
JPC_API void
JPC_RegisterTrace(JPC_TraceFunction in_trace)
{
if (default_trace == nullptr)
{
default_trace = JPH::Trace;
}
JPH::Trace = in_trace ? in_trace : default_trace;
}
JPC_API void
JPC_RegisterAssertFailed(JPC_AssertFailedFunction in_assert_failed)
{
#ifdef JPH_ENABLE_ASSERTS
if (default_assert_failed == nullptr)
{
default_assert_failed = JPH::AssertFailed;
}
JPH::AssertFailed = in_assert_failed ? in_assert_failed : default_assert_failed;
#endif
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_CreateFactory(void)
{
assert(JPH::Factory::sInstance == nullptr);
JPH::Factory::sInstance = new JPH::Factory();
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_DestroyFactory(void)
{
assert(JPH::Factory::sInstance != nullptr);
JPH::PhysicsMaterial::sDefault = nullptr;
delete JPH::Factory::sInstance;
JPH::Factory::sInstance = nullptr;
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_RegisterTypes(void)
{
JPH::RegisterTypes();
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_BodyCreationSettings_SetDefault(JPC_BodyCreationSettings *out_settings)
{
assert(out_settings != nullptr);
const JPH::BodyCreationSettings settings;
*out_settings = *toJpc(&settings);
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_BodyCreationSettings_Set(JPC_BodyCreationSettings *out_settings,
const JPC_Shape *in_shape,
const JPC_Real in_position[3],
const float in_rotation[4],
JPC_MotionType in_motion_type,
JPC_ObjectLayer in_layer)
{
assert(out_settings != nullptr && in_shape != nullptr && in_position != nullptr && in_rotation != nullptr);
JPC_BodyCreationSettings settings;
JPC_BodyCreationSettings_SetDefault(&settings);
settings.position[0] = in_position[0];
settings.position[1] = in_position[1];
settings.position[2] = in_position[2];
settings.rotation[0] = in_rotation[0];
settings.rotation[1] = in_rotation[1];
settings.rotation[2] = in_rotation[2];
settings.rotation[3] = in_rotation[3];
settings.object_layer = in_layer;
settings.motion_type = in_motion_type;
settings.shape = in_shape;
*out_settings = settings;
}
//--------------------------------------------------------------------------------------------------
//
// JPC_TempAllocator
//
//--------------------------------------------------------------------------------------------------
JPC_API JPC_TempAllocator *
JPC_TempAllocator_Create(uint32_t in_size)
{
auto impl = new JPH::TempAllocatorImpl(in_size);
return reinterpret_cast<JPC_TempAllocator *>(impl);
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_TempAllocator_Destroy(JPC_TempAllocator *in_allocator)
{
assert(in_allocator != nullptr);
delete reinterpret_cast<JPH::TempAllocator *>(in_allocator);
}
//--------------------------------------------------------------------------------------------------
//
// JPC_JobSystem
//
//--------------------------------------------------------------------------------------------------
JPC_API JPC_JobSystem *
JPC_JobSystem_Create(uint32_t in_max_jobs, uint32_t in_max_barriers, int in_num_threads)
{
auto job_system = new JPH::JobSystemThreadPool(in_max_jobs, in_max_barriers, in_num_threads);
return reinterpret_cast<JPC_JobSystem *>(job_system);
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_JobSystem_Destroy(JPC_JobSystem *in_job_system)
{
assert(in_job_system != nullptr);
delete reinterpret_cast<JPH::JobSystemThreadPool *>(in_job_system);
}
//--------------------------------------------------------------------------------------------------
//
// JPC_PhysicsSystem
//
//--------------------------------------------------------------------------------------------------
class ContactListener : public JPH::ContactListener
{
public:
JPH::ValidateResult OnContactValidate(
const JPH::Body &inBody1,
const JPH::Body &inBody2,
JPH::RVec3Arg inBaseOffset,
const JPH::CollideShapeResult &inCollisionResult) override
{
if (c_listener->vtbl->OnContactValidate)
{
JPC_Real base_offset[3];
storeRVec3(base_offset, inBaseOffset);
const JPC_ValidateResult res = c_listener->vtbl->OnContactValidate(
c_listener, toJpc(&inBody1), toJpc(&inBody2), base_offset, toJpc(&inCollisionResult));
return static_cast<JPH::ValidateResult>(res);
}
return JPH::ContactListener::OnContactValidate(inBody1, inBody2, inBaseOffset, inCollisionResult);
}
void OnContactAdded(
const JPH::Body &inBody1,
const JPH::Body &inBody2,
const JPH::ContactManifold &inManifold,
JPH::ContactSettings &ioSettings) override
{
if (c_listener->vtbl->OnContactAdded)
{
c_listener->vtbl->OnContactAdded(
c_listener, toJpc(&inBody1), toJpc(&inBody2), toJpc(&inManifold), toJpc(&ioSettings));
}
}
void OnContactPersisted(
const JPH::Body &inBody1,
const JPH::Body &inBody2,
const JPH::ContactManifold &inManifold,
JPH::ContactSettings &ioSettings) override
{
if (c_listener->vtbl->OnContactPersisted)
{
c_listener->vtbl->OnContactPersisted(
c_listener, toJpc(&inBody1), toJpc(&inBody2), toJpc(&inManifold), toJpc(&ioSettings));
}
}
void OnContactRemoved(const JPH::SubShapeIDPair &inSubShapePair) override
{
if (c_listener->vtbl->OnContactRemoved)
c_listener->vtbl->OnContactRemoved(c_listener, toJpc(&inSubShapePair));
}
struct CListener
{
JPC_ContactListenerVTable *vtbl;
};
CListener *c_listener;
};
#if JPC_DEBUG_RENDERER == 1
class DebugRendererImpl final : public JPH::DebugRenderer
{
public:
class RenderPrimitive : public JPH::RefTarget<RenderPrimitive>
{
protected:
RenderPrimitive(const JPC_DebugRenderer_Primitive *prim) : c_primitive(prim) { }
const JPC_DebugRenderer_Primitive *c_primitive;
};
class BatchImpl : public JPH::RefTargetVirtual, public RenderPrimitive
{
public:
JPH_OVERRIDE_NEW_DELETE
BatchImpl(const JPC_DebugRenderer_Primitive *prim) : RenderPrimitive(prim) { }
virtual void AddRef() override
{
RenderPrimitive::AddRef();
}
virtual void Release() override
{
if (--mRefCount == 0) delete this;
}
const JPC_DebugRenderer_Primitive *GetPrimitive() const
{
return c_primitive;
}
};
class BodyDrawFilter : public JPH::BodyDrawFilter
{
JPC_BodyDrawFilterFunc func = nullptr;
public:
JPH_OVERRIDE_NEW_DELETE
BodyDrawFilter(const JPC_BodyDrawFilterFunc func) : func(func) {}
virtual bool ShouldDraw(const JPH::Body& inBody) const override
{
return func(toJpc(&inBody));
}
};
struct CRenderer
{
JPC_DebugRendererVTable *vtbl;
};
CRenderer *c_renderer;
static DebugRendererImpl *sInstance;
JPH_OVERRIDE_NEW_DELETE
DebugRendererImpl(CRenderer *in_renderer) : c_renderer(in_renderer)
{
DebugRenderer::Initialize();
}
JPC_DebugRendererResult ValidateCallbacks()
{
bool valid = true;
valid &= (c_renderer->vtbl->DrawLine != nullptr);
valid &= (c_renderer->vtbl->DrawTriangle != nullptr);
valid &= (c_renderer->vtbl->CreateTriangleBatch != nullptr);
valid &= (c_renderer->vtbl->CreateTriangleBatchIndexed != nullptr);
valid &= (c_renderer->vtbl->DrawGeometry != nullptr);
valid &= (c_renderer->vtbl->DrawText3D != nullptr);
return valid ? JPC_DEBUGRENDERER_SUCCESS : JPC_DEBUGRENDERER_INCOMPLETE_IMPL;
}
virtual void DrawLine(JPH::RVec3Arg inFrom, JPH::RVec3Arg inTo, JPH::ColorArg inColor) override
{
JPC_Real in_from[3];
storeRVec3(in_from, inFrom);
JPC_Real in_to[3];
storeRVec3(in_to, inTo);
c_renderer->vtbl->DrawLine(c_renderer, in_from, in_to, *toJpc(&inColor));
}
virtual void DrawTriangle(
JPH::RVec3Arg inV1,
JPH::RVec3Arg inV2,
JPH::RVec3Arg inV3,
JPH::ColorArg inColor,
JPH::DebugRenderer::ECastShadow inCastShadow) override
{
JPC_Real in_v1[3];
storeRVec3(in_v1, inV1);
JPC_Real in_v2[3];
storeRVec3(in_v2, inV2);
JPC_Real in_v3[3];
storeRVec3(in_v3, inV3);
c_renderer->vtbl->DrawTriangle(
c_renderer, in_v1, in_v2, in_v3, *toJpc(&inColor), static_cast<JPC_CastShadow>(inCastShadow));
}
virtual JPH::DebugRenderer::Batch CreateTriangleBatch(
const JPH::DebugRenderer::Triangle *inTriangles,
int inTriangleCount) override
{
JPC_DebugRenderer_TriangleBatch *c_batch = c_renderer->vtbl->CreateTriangleBatch(
c_renderer,
toJpc(inTriangles),
inTriangleCount);
auto jph_batch = reinterpret_cast<BatchImpl *>(c_batch);
return jph_batch;
}
virtual JPH::DebugRenderer::Batch CreateTriangleBatch(
const JPH::DebugRenderer::Vertex *inVertices,
int inVertexCount,
const uint32_t *inIndices,
int inIndexCount) override
{
JPC_DebugRenderer_TriangleBatch *c_batch = c_renderer->vtbl->CreateTriangleBatchIndexed(
c_renderer,
toJpc(inVertices),
inVertexCount,
inIndices,
inIndexCount);
auto jph_batch = reinterpret_cast<BatchImpl *>(c_batch);
return jph_batch;
}
virtual void DrawGeometry(
JPH::RMat44Arg inModelMatrix,
const JPH::AABox &inWorldSpaceBounds,
float inLODScaleSq,
JPH::ColorArg inModelColor,
const JPH::DebugRenderer::GeometryRef &inGeometry,
JPH::DebugRenderer::ECullMode inCullMode,
JPH::DebugRenderer::ECastShadow inCastShadow,
JPH::DebugRenderer::EDrawMode inDrawMode) override
{
auto in_model_matrix = reinterpret_cast<const JPC_RMatrix*>(&inModelMatrix);
JPC_DebugRenderer_Geometry in_geometry {
toJpc(&inGeometry.GetPtr()->mLODs[0]),
static_cast<uint64_t>(inGeometry.GetPtr()->mLODs.size()),
toJpc(&inGeometry.GetPtr()->mBounds)
};
c_renderer->vtbl->DrawGeometry(
c_renderer,
in_model_matrix,
toJpc(&inWorldSpaceBounds),
inLODScaleSq,
*toJpc(&inModelColor),
&in_geometry,
static_cast<JPC_CullMode>(inCullMode),
static_cast<JPC_CastShadow>(inCastShadow),
static_cast<JPC_DrawMode>(inDrawMode));
}
virtual void DrawText3D(
JPH::RVec3Arg inPosition,
const std::string_view &inString,
JPH::ColorArg inColor,
float inHeight) override
{
JPC_Real in_position[3];
storeRVec3(in_position, inPosition);
c_renderer->vtbl->DrawText3D(
c_renderer,
in_position,
std::string(inString).c_str(),
*toJpc(&inColor),
inHeight);
}
};
DebugRendererImpl *DebugRendererImpl::sInstance = nullptr;
//--------------------------------------------------------------------------------------------------
JPC_API JPC_DebugRendererResult
JPC_CreateDebugRendererSingleton(void *in_debug_renderer)
{
assert(JPH::DebugRenderer::sInstance == nullptr); //Only one instance of JPH::DebugRenderer may ever be made
if (JPH::DebugRenderer::sInstance != nullptr) return JPC_DEBUGRENDERER_DUPLICATE_SINGLETON; //No assert in release
DebugRendererImpl::sInstance =
new DebugRendererImpl(reinterpret_cast<DebugRendererImpl::CRenderer *>(in_debug_renderer));
// At this point, a pointer to the created instance is also kept in JPH::DebugRenderer::sInstance.
return DebugRendererImpl::sInstance->ValidateCallbacks();
}
JPC_API JPC_DebugRendererResult
JPC_DestroyDebugRendererSingleton()
{
assert(JPH::DebugRenderer::sInstance != nullptr); //The singleton must have already been instantiated
if (JPH::DebugRenderer::sInstance == nullptr) return JPC_DEBUGRENDERER_MISSING_SINGLETON; //No assert in release
delete DebugRendererImpl::sInstance;
return JPC_DEBUGRENDERER_SUCCESS;
}
JPC_API JPC_DebugRenderer_TriangleBatch *
JPC_DebugRenderer_TriangleBatch_Create(const void *in_c_primitive)
{
auto batch = static_cast<DebugRendererImpl::BatchImpl *>(JPH::Allocate(sizeof(DebugRendererImpl::BatchImpl)));
::new (batch) DebugRendererImpl::BatchImpl(reinterpret_cast<const JPC_DebugRenderer_Primitive *>(in_c_primitive));
return reinterpret_cast<JPC_DebugRenderer_TriangleBatch *>(batch);
}
JPC_API const JPC_DebugRenderer_Primitive *
JPC_DebugRenderer_TriangleBatch_GetPrimitive(const JPC_DebugRenderer_TriangleBatch * in_batch)
{
auto fat_batch = reinterpret_cast<const DebugRendererImpl::BatchImpl *>(in_batch);
return fat_batch->GetPrimitive();
}
JPC_API void
JPC_DebugRenderer_TriangleBatch_AddRef(JPC_DebugRenderer_TriangleBatch *in_batch)
{
assert(in_batch);
reinterpret_cast<DebugRendererImpl::BatchImpl *>(in_batch)->AddRef();
}
JPC_API void
JPC_DebugRenderer_TriangleBatch_Release(JPC_DebugRenderer_TriangleBatch *in_batch)
{
assert(in_batch);
reinterpret_cast<DebugRendererImpl::BatchImpl *>(in_batch)->Release();
}
JPC_API uint32_t
JPC_DebugRenderer_TriangleBatch_GetRefCount(const JPC_DebugRenderer_TriangleBatch *in_batch)
{
assert(in_batch);
return reinterpret_cast<const DebugRendererImpl::BatchImpl *>(in_batch)->GetRefCount();
}
#endif //JPC_DEBUG_RENDERER
struct PhysicsSystemData
{
uint64_t safety_token = 0xC0DEC0DEC0DEC0DE;
ContactListener *contact_listener = nullptr;
};
JPC_API JPC_PhysicsSystem *
JPC_PhysicsSystem_Create(uint32_t in_max_bodies,
uint32_t in_num_body_mutexes,
uint32_t in_max_body_pairs,
uint32_t in_max_contact_constraints,
const void *in_broad_phase_layer_interface,
const void *in_object_vs_broad_phase_layer_filter,
const void *in_object_layer_pair_filter)
{
assert(in_broad_phase_layer_interface != nullptr);
assert(in_object_vs_broad_phase_layer_filter != nullptr);
assert(in_object_layer_pair_filter != nullptr);
auto physics_system =
static_cast<JPH::PhysicsSystem *>(
JPH::Allocate(sizeof(JPH::PhysicsSystem) + sizeof(PhysicsSystemData)));
::new (physics_system) JPH::PhysicsSystem();
PhysicsSystemData* data =
::new (reinterpret_cast<uint8_t *>(physics_system) + sizeof(JPH::PhysicsSystem)) PhysicsSystemData();
assert(data->safety_token == 0xC0DEC0DEC0DEC0DE);
physics_system->Init(
in_max_bodies,
in_num_body_mutexes,
in_max_body_pairs,
in_max_contact_constraints,
*static_cast<const JPH::BroadPhaseLayerInterface *>(in_broad_phase_layer_interface),
*static_cast<const JPH::ObjectVsBroadPhaseLayerFilter *>(in_object_vs_broad_phase_layer_filter),
*static_cast<const JPH::ObjectLayerPairFilter *>(in_object_layer_pair_filter));
return toJpc(physics_system);
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_PhysicsSystem_Destroy(JPC_PhysicsSystem *in_physics_system)
{
auto data = reinterpret_cast<PhysicsSystemData *>(
reinterpret_cast<uint8_t *>(in_physics_system) + sizeof(JPH::PhysicsSystem));
assert(data->safety_token == 0xC0DEC0DEC0DEC0DE);
if (data->contact_listener)
{
data->contact_listener->~ContactListener();
JPH::Free(data->contact_listener);
}
toJph(in_physics_system)->~PhysicsSystem();
JPH::Free(in_physics_system);
}
//--------------------------------------------------------------------------------------------------
JPC_API void
JPC_PhysicsSystem_SetBodyActivationListener(JPC_PhysicsSystem *in_physics_system, void *in_listener)
{