Skip to content

Commit

Permalink
add (hopefully) branchless version of setBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
babbaj committed Jul 10, 2023
1 parent 70dfe3a commit f6ed5da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

group = 'dev.babbaj'
version = '0.24'
version = '0.25'

java {
toolchain {
Expand Down
12 changes: 12 additions & 0 deletions java/src/main/java/dev/babbaj/pathfinder/Octree.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public static void setBlock(long pointer, int x, int y, int z, boolean solid) {
UNSAFE.putByte(x2Ptr, x2);
}

public static void initBlock(long pointer, int x, int y, int z, boolean solid) {
final long x2Ptr = getX2Ptr(pointer, x, y, z);
final int bit = bitIndex(x, y, z);
byte x2 = UNSAFE.getByte(x2Ptr);

// this is more likely to be branchless than setBlock
int b = solid ? 1 : 0;
x2 |= (b << bit);

UNSAFE.putByte(x2Ptr, x2);
}

public static boolean getBlock(long pointer, int x, int y, int z) {
final long x2Ptr = getX2Ptr(pointer, x, y, z);
final int bit = bitIndex(x, y, z);
Expand Down

0 comments on commit f6ed5da

Please sign in to comment.