Skip to content

Commit

Permalink
Jolt: add the newDirectShortBuffer() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 25, 2025
1 parent b0bdd47 commit 9a9c087
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Jolt.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;

/**
* Utility methods providing JNI access to Jolt Physics and the C++ {@code std}
Expand Down Expand Up @@ -367,6 +368,25 @@ public static IntBuffer newDirectIntBuffer(int numInts) {
return result;
}

/**
* Create a direct {@code ShortBuffer} with native byte order and the
* specified capacity.
*
* @param numShorts the desired capacity (in ints)
* @return a new direct buffer, zeroed and rewound but not flipped
*/
public static ShortBuffer newDirectShortBuffer(int numShorts) {
ByteBuffer byteBuffer
= ByteBuffer.allocateDirect(numShorts * Short.BYTES);
byteBuffer.order(ByteOrder.nativeOrder());
ShortBuffer result = byteBuffer.asShortBuffer();

assert result.capacity() == numShorts : result.capacity();
assert result.limit() == numShorts : result.limit();
assert result.position() == 0 : result.position();
return result;
}

/**
* Generate 3-D Perlin noise.
*
Expand Down

0 comments on commit 9a9c087

Please sign in to comment.