Skip to content

Commit 3e1837f

Browse files
committed
Update To Latest JoltC Commit
Commit 52d8c98df523f449eb3e01b1060a0fde052970d1
1 parent b726215 commit 3e1837f

17 files changed

Lines changed: 205 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ This project provides Java Bindings for [JoltPhysics](https://github.com/jrouwe/
44
This project is in a usable, working state regarding the features that the C wrapper exposes. When the wrapper exposes new features, I try to update this project as fast as possible.
55

66
# Supported Platforms
7-
Windows and Linux are directly supported. The Linux .so file was built on Linux Mint 22.2.
8-
9-
Nevertheless, you should be able to use these bindings for Mac if you provide your own `.dylib` file and load it.
7+
Windows, Linux and Mac are directly supported. The native libraries were build by [the workflow the C Wrapper provides](https://github.com/amerkoleci/joltc/blob/main/.github/workflows/build.yml).
108

119
# Building The Project
1210
1. Download [Java 26](https://www.oracle.com/de/java/technologies/downloads/)

src/main/java/generation/JoltGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,18 @@
252252
//
253253
// valueLayouts = new ArrayList<String>();
254254
// functionPointer.getParameters().forEach(parameter -> {
255-
// String layout = GeneratorUtils.stripPrefixes(config, getLayoutString(parameter.getType()), false);
255+
// String layout = GeneratorUtils.transformName(config, getLayoutString(parameter.getType()), false);
256256
// valueLayouts.add(layout);
257257
// });
258258
//
259-
// returnTypeLayout = GeneratorUtils.stripPrefixes(
259+
// returnTypeLayout = GeneratorUtils.transformName(
260260
// config,
261261
// getLayoutString(functionPointer.getReturnType().getType()),
262262
// false);
263263
//
264264
// hasReturnType = !method.getReturnType().getIsVoid();
265265
//
266-
// name = GeneratorUtils.stripPrefixes(config, functionPointer.getName(), true).replaceAll("\\*\\s*$", "").trim();
266+
// name = GeneratorUtils.transformName(config, functionPointer.getName(), true).replaceAll("\\*\\s*$", "").trim();
267267
// constantsName = name.replaceAll("([\\p{Ll}\\p{Nd}])(\\p{Lu})", "$1_$2").toUpperCase();
268268
// }
269269
//

src/main/java/volucris/bindings/jolt/Jolt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static void loadNativeLibrary() {
3939
}
4040

4141
public static void loadNativeLibrary(boolean debug) {
42-
NativeLibraryLoader.loadLibrary("natives/jolt", "jolt", debug);
42+
NativeLibraryLoader.loadLibrary("natives/jolt", "joltc", debug);
43+
}
4344
}
4445

4546
public static boolean init() {

src/main/java/volucris/bindings/jolt/physicsSystem/PhysicsSystem.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public final class PhysicsSystem {
7373
private static final LazyConstant<MethodHandle> JPH_PHYSICS_SYSTEM_DRAW_CONSTRAINT_LIMITS;
7474
private static final LazyConstant<MethodHandle> JPH_PHYSICS_SYSTEM_DRAW_CONSTRAINT_REFERENCE_FRAME;
7575
private static final LazyConstant<MethodHandle> JPH_PHYSICS_SYSTEM_GET_BODY_PTR;
76+
private static final LazyConstant<MethodHandle> JPH_PHYSICS_SYSTEM_UPDATE2;
7677

7778
private final MemorySegment segment;
7879

@@ -117,6 +118,7 @@ public final class PhysicsSystem {
117118
JPH_PHYSICS_SYSTEM_DRAW_CONSTRAINT_LIMITS = downcallHandleVoid("JPH_PhysicsSystem_DrawConstraintLimits", UNBOUNDED_ADDRESS, UNBOUNDED_ADDRESS);
118119
JPH_PHYSICS_SYSTEM_DRAW_CONSTRAINT_REFERENCE_FRAME = downcallHandleVoid("JPH_PhysicsSystem_DrawConstraintReferenceFrame", UNBOUNDED_ADDRESS, UNBOUNDED_ADDRESS);
119120
JPH_PHYSICS_SYSTEM_GET_BODY_PTR = downcallHandle("JPH_PhysicsSystem_GetBodyPtr", UNBOUNDED_ADDRESS, UNBOUNDED_ADDRESS, JAVA_INT);
121+
JPH_PHYSICS_SYSTEM_UPDATE2 = downcallHandle("JPH_PhysicsSystem_Update2", JAVA_INT, UNBOUNDED_ADDRESS, JAVA_FLOAT, JAVA_INT, UNBOUNDED_ADDRESS, UNBOUNDED_ADDRESS);
120122
//@formatter:on
121123
}
122124

@@ -1218,6 +1220,45 @@ public static MemorySegment getBodyPtr(
12181220
return new Body(segment);
12191221
}
12201222

1223+
public static int update2(
1224+
MemorySegment system,
1225+
float deltaTime,
1226+
int collisionSteps,
1227+
MemorySegment tempAllocator,
1228+
MemorySegment jobSystem
1229+
) {
1230+
MethodHandle method = JPH_PHYSICS_SYSTEM_UPDATE2.get();
1231+
try {
1232+
return (int) method.invokeExact(
1233+
system,
1234+
deltaTime,
1235+
collisionSteps,
1236+
tempAllocator,
1237+
jobSystem
1238+
);
1239+
} catch (Throwable e) {
1240+
throw new RuntimeException(e);
1241+
}
1242+
}
1243+
1244+
/**
1245+
* Typed method of {@link #update2}.
1246+
*/
1247+
public final int update2(
1248+
float deltaTime,
1249+
int collisionSteps,
1250+
TempAllocator tempAllocator,
1251+
JobSystem jobSystem
1252+
) {
1253+
return (int) update2(
1254+
this.segment,
1255+
deltaTime,
1256+
collisionSteps,
1257+
tempAllocator.memorySegment(),
1258+
jobSystem.memorySegment()
1259+
);
1260+
}
1261+
12211262
public MemorySegment memorySegment() {
12221263
return segment;
12231264
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* MACHINE GENERATED FILE, DO NOT EDIT.
3+
*/
4+
package volucris.bindings.jolt.physicsSystem;
5+
6+
import edu.umd.cs.findbugs.annotations.Nullable;
7+
import java.lang.foreign.Arena;
8+
import java.lang.foreign.MemorySegment;
9+
import java.lang.invoke.MethodHandle;
10+
11+
import static java.lang.foreign.ValueLayout.*;
12+
import static volucris.bindings.core.FFMUtils.*;;
13+
14+
/**
15+
*
16+
*/
17+
public final class TempAllocator {
18+
19+
private static final LazyConstant<MethodHandle> JPH_TEMP_ALLOCATOR_CREATE;
20+
private static final LazyConstant<MethodHandle> JPH_TEMP_ALLOCATOR_MALLOC_CREATE;
21+
private static final LazyConstant<MethodHandle> JPH_TEMP_ALLOCATOR_DESTROY;
22+
23+
private final MemorySegment segment;
24+
25+
static {
26+
//@formatter:off
27+
JPH_TEMP_ALLOCATOR_CREATE = downcallHandle("JPH_TempAllocator_Create", UNBOUNDED_ADDRESS, JAVA_INT);
28+
JPH_TEMP_ALLOCATOR_MALLOC_CREATE = downcallHandle("JPH_TempAllocatorMalloc_Create", UNBOUNDED_ADDRESS);
29+
JPH_TEMP_ALLOCATOR_DESTROY = downcallHandleVoid("JPH_TempAllocator_Destroy", UNBOUNDED_ADDRESS);
30+
//@formatter:on
31+
}
32+
33+
public TempAllocator(
34+
int size
35+
) {
36+
this(
37+
Arena.ofAuto(),
38+
size
39+
);
40+
}
41+
42+
public TempAllocator(
43+
Arena arena,
44+
int size
45+
) {
46+
MemorySegment segment = create(
47+
size
48+
);
49+
50+
this.segment = segment.reinterpret(arena, s -> destroy(s));
51+
}
52+
53+
public TempAllocator() {
54+
this(Arena.ofAuto());
55+
}
56+
57+
public TempAllocator(Arena arena) {
58+
MemorySegment segment = create();
59+
this.segment = segment.reinterpret(arena, s -> destroy(s));
60+
}
61+
62+
public TempAllocator(MemorySegment segment) {
63+
this.segment = segment;
64+
}
65+
66+
public static MemorySegment create(
67+
int size
68+
) {
69+
MethodHandle method = JPH_TEMP_ALLOCATOR_CREATE.get();
70+
try {
71+
return (MemorySegment) method.invokeExact(
72+
size
73+
);
74+
} catch (Throwable e) {
75+
throw new RuntimeException(e);
76+
}
77+
}
78+
79+
public static MemorySegment create() {
80+
MethodHandle method = JPH_TEMP_ALLOCATOR_MALLOC_CREATE.get();
81+
try {
82+
return (MemorySegment) method.invokeExact();
83+
} catch (Throwable e) {
84+
throw new RuntimeException(e);
85+
}
86+
}
87+
88+
public static void destroy(
89+
MemorySegment allocator
90+
) {
91+
MethodHandle method = JPH_TEMP_ALLOCATOR_DESTROY.get();
92+
try {
93+
method.invokeExact(
94+
allocator
95+
);
96+
} catch (Throwable e) {
97+
throw new RuntimeException(e);
98+
}
99+
}
100+
101+
public MemorySegment memorySegment() {
102+
return segment;
103+
}
104+
105+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class-description:
2+
name: TempAllocator
3+
package-name: volucris.bindings.jolt.physicsSystem
4+
directory: src/main/java/volucris/bindings/jolt/physicsSystem
5+
is-static: false
6+
parent:
7+
interfaces: []
8+
is-sealed: false
9+
permits: []
10+
is-abstract: false
11+
is-final: true
12+
instance-parameter: allocator
13+
14+
imports:
15+
static-imports:
16+
- java.lang.foreign.ValueLayout.*
17+
- volucris.bindings.core.FFMUtils.*;
18+
19+
macro-name-prefixes:
20+
excluded-macro-name-prefixes:
21+
macro-names:
22+
excluded-macro-names:
23+
24+
symbol-prefixes:
25+
symbols:
26+
27+
function-name-prefixes:
28+
- JPH_TempAllocator_
29+
- JPH_TempAllocatorMalloc_
30+
excluded-function-name-prefixes:
31+
function-name-postfixes:
32+
excluded-function-name-postfixes:
33+
34+
constructors:
35+
- native-function: JPH_TempAllocator_Create
36+
destructor: JPH_TempAllocator_Destroy
37+
- native-function: JPH_TempAllocatorMalloc_Create
38+
destructor: JPH_TempAllocator_Destroy
39+
struct:
40+
native-functions:
41+
native-function-pointers:

src/main/resources/globalConfig/globalConfig.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
naming:
22
strip-prefixes:
3+
- JPH_TempAllocator_
4+
- JPH_TempAllocatorMalloc_
35
- JPH_SkeletonPose_
46
- JPH_BodyManager_
57
- JPH_PhysicsUpdateError_

src/main/resources/headers/joltc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,4 +3167,14 @@ JPH_CAPI uint32_t JPH_LinearCurve_GetPointCount(const JPH_LinearCurve* curve);
31673167
JPH_CAPI void JPH_LinearCurve_GetPoint(const JPH_LinearCurve* curve, uint32_t index, JPH_Point* result);
31683168
JPH_CAPI void JPH_LinearCurve_GetPoints(const JPH_LinearCurve* curve, JPH_Point* points, uint32_t* count);
31693169

3170+
/* Temp Allocator */
3171+
typedef struct JPH_TempAllocator JPH_TempAllocator;
3172+
3173+
JPH_CAPI JPH_TempAllocator* JPH_TempAllocator_Create(uint32_t size);
3174+
JPH_CAPI JPH_TempAllocator* JPH_TempAllocatorMalloc_Create(void);
3175+
JPH_CAPI void JPH_TempAllocator_Destroy(JPH_TempAllocator* allocator);
3176+
3177+
/* Explicit Allocator Variants */
3178+
JPH_CAPI JPH_PhysicsUpdateError JPH_PhysicsSystem_Update2(JPH_PhysicsSystem* system, float deltaTime, int collisionSteps, JPH_TempAllocator* tempAllocator, JPH_JobSystem* jobSystem);
3179+
31703180
#endif /* JOLT_C_H_ */
-1.93 MB
Binary file not shown.
1.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)