Skip to content

Commit d73a318

Browse files
committed
AddConvexRadiusTab: refactor getSupport() to use a direct buffer
1 parent 394398c commit d73a318

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/main/java/com/github/stephengold/joltjni/AddConvexRadiusTab.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
2222
package com.github.stephengold.joltjni;
2323

2424
import com.github.stephengold.joltjni.readonly.Vec3Arg;
25+
import java.nio.FloatBuffer;
2526

2627
/**
2728
* Add convex radius to a {@code TransformedAaBox}. (native type:
@@ -58,7 +59,7 @@ public Vec3 getSupport(Vec3Arg direction) {
5859
float dx = direction.getX();
5960
float dy = direction.getY();
6061
float dz = direction.getZ();
61-
float[] storeFloats = new float[3];
62+
FloatBuffer storeFloats = Temporaries.floatBuffer1.get();
6263
getSupport(addVa, dx, dy, dz, storeFloats);
6364
Vec3 result = new Vec3(storeFloats);
6465

@@ -72,5 +73,5 @@ public Vec3 getSupport(Vec3Arg direction) {
7273
native private static void free(long addVa);
7374

7475
native private static void getSupport(
75-
long addVa, float dx, float dy, float dz, float[] storeFloats);
76+
long addVa, float dx, float dy, float dz, FloatBuffer storeFloats);
7677
}

src/main/native/glue/a/AddConvexRadiusTab.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2025 Stephen Gold
2+
Copyright (c) 2025-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -59,20 +59,18 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_AddConvexRadiusTab_fr
5959
/*
6060
* Class: com_github_stephengold_joltjni_AddConvexRadiusTab
6161
* Method: getSupport
62-
* Signature: (JFFF[F)V
62+
* Signature: (JFFFLjava/nio/FloatBuffer;)V
6363
*/
6464
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_AddConvexRadiusTab_getSupport
6565
(JNIEnv *pEnv, jclass, jlong addVa, jfloat dx, jfloat dy, jfloat dz,
66-
jfloatArray storeFloats) {
66+
jobject storeFloats) {
6767
const AddConvexRadius<TransformedConvexObject<AABox>> * const pAdd
6868
= reinterpret_cast<AddConvexRadius<TransformedConvexObject<AABox>> *> (addVa);
6969
const Vec3 direction(dx, dy, dz);
7070
const Vec3 result = pAdd->GetSupport(direction);
71-
jboolean isCopy;
72-
jfloat * const pStoreFloats
73-
= pEnv->GetFloatArrayElements(storeFloats, &isCopy);
71+
DIRECT_FLOAT_BUFFER(pEnv, storeFloats, pStoreFloats, capacityFloats);
72+
JPH_ASSERT(capacityFloats >= 3);
7473
pStoreFloats[0] = result.GetX();
7574
pStoreFloats[1] = result.GetY();
7675
pStoreFloats[2] = result.GetZ();
77-
pEnv->ReleaseFloatArrayElements(storeFloats, pStoreFloats, 0);
7876
}

0 commit comments

Comments
 (0)