Skip to content

Commit

Permalink
more raytrace apis
Browse files Browse the repository at this point in the history
  • Loading branch information
babbaj committed Jun 20, 2023
1 parent c1db925 commit fa7acbb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'dev.babbaj'
version = '0.16'
version = '0.17'

java {
toolchain {
Expand Down
11 changes: 11 additions & 0 deletions java/src/main/java/dev/babbaj/pathfinder/NetherPathfinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public static void raytrace(long context, boolean assumeFakeChunksAreAir, int in
}
raytrace0(context, assumeFakeChunksAreAir, inputs, start, end, hitsOut, hitPosOutCanBeNull);
}
public static native boolean isVisibleMulti0(long context, boolean assumeFakeChunksAreAir, int inputs, double[] start, double[] end, boolean anyIfTrueElseAll);

public static boolean isVisibleMulti(long context, boolean assumeFakeChunksAreAir, int inputs, double[] start, double[] end, boolean anyIfTrueElseAll) {
// % 3 check isn't necessary because it's impossible to pass this with non % 3 arrays
if (start.length != (inputs * 3) || end.length != (inputs * 3)) {
throw new IllegalArgumentException("Bad array lengths idiot");
}
return isVisibleMulti0(context, assumeFakeChunksAreAir, inputs, start, end, anyIfTrueElseAll);
}

public static native boolean isVisible(long context, boolean assumeFakeChunksAreAir, double x1, double y1, double z1, double x2, double y2, double z2);

public static native boolean cancel(long context);

Expand Down
33 changes: 32 additions & 1 deletion src/PathfinderJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extern "C" {
EXPORT void JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_raytrace0(JNIEnv* env, jclass, Context* ctx, jboolean assumeFakeChunksAreAir, jint inputs, jdoubleArray startArr, jdoubleArray endArr, jbooleanArray hitsOut, jdoubleArray hitPosOut) {
jboolean isCopy{};
jdouble* startPtr = env->GetDoubleArrayElements(startArr, &isCopy);
jdouble * endPtr = env->GetDoubleArrayElements(endArr, &isCopy);
jdouble* endPtr = env->GetDoubleArrayElements(endArr, &isCopy);
jboolean* hitsOutPtr = env->GetBooleanArrayElements(hitsOut, &isCopy);
jdouble* hitPosOutPtr = hitPosOut != nullptr ? env->GetDoubleArrayElements(hitPosOut, &isCopy) : nullptr;
for (int i = 0; i < inputs; i++) {
Expand All @@ -188,4 +188,35 @@ extern "C" {
env->ReleaseDoubleArrayElements(hitPosOut, hitPosOutPtr, 0);
}
}

EXPORT jboolean JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_isVisibleMulti0(JNIEnv* env, jclass, Context* ctx, jboolean assumeFakeChunksAreAir, jint inputs, jdoubleArray startArr, jdoubleArray endArr, jboolean modeAny) {
jboolean isCopy{};
jdouble* startPtr = env->GetDoubleArrayElements(startArr, &isCopy);
jdouble* endPtr = env->GetDoubleArrayElements(endArr, &isCopy);
bool out = true;
for (int i = 0; i < inputs; i++) {
auto& start = reinterpret_cast<const Vec3*>(startPtr)[i];
auto& end = reinterpret_cast<const Vec3*>(endPtr)[i];
const std::variant result = raytrace(start, end, assumeFakeChunksAreAir, ctx->generator, ctx->executors[0], ctx->chunkCache);
auto* hit = std::get_if<Hit>(&result);
const bool modeAll = !modeAny;
if (!hit) {
if (modeAny) {
out = true;
break;
}
} else if (modeAll) {
out = false;
break;
}
}
env->ReleaseDoubleArrayElements(startArr, startPtr, JNI_ABORT);
env->ReleaseDoubleArrayElements(endArr, endPtr, JNI_ABORT);
return out;
}

EXPORT jboolean JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_isVisible(JNIEnv*, jclass, Context* ctx, jboolean assumeFakeChunksAreAir, double x1, double y1, double z1, double x2, double y2, double z2) {
const std::variant result = raytrace({x1, y1, z1}, {x2, y2, z2}, assumeFakeChunksAreAir, ctx->generator, ctx->executors[0], ctx->chunkCache);
return !std::holds_alternative<Hit>(result);
}
}

0 comments on commit fa7acbb

Please sign in to comment.