From 1b213b7b55ac9dbb745f26afd70d3a403f7034ea Mon Sep 17 00:00:00 2001 From: Babbaj Date: Sat, 8 Jul 2023 21:14:27 -0400 Subject: [PATCH] the native code --- src/Chunk.h | 4 +--- src/PathfinderJNI.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Chunk.h b/src/Chunk.h index b381749..d210f4b 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -76,10 +76,8 @@ inline bool isEmpty(const T& input) { struct Chunk { -private: std::array data{}; std::array x16Empty{}; -public: bool isFromJava{}; private: @@ -196,4 +194,4 @@ static const Chunk AIR_CHUNK = [] { Chunk out{}; out.calcEmptyX16(); return out; - }(); \ No newline at end of file + }(); diff --git a/src/PathfinderJNI.cpp b/src/PathfinderJNI.cpp index 18a535a..85ce838 100644 --- a/src/PathfinderJNI.cpp +++ b/src/PathfinderJNI.cpp @@ -119,6 +119,15 @@ extern "C" { } } + EXPORT jlong JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_getChunkPointer(JNIEnv*, jclass, Context* ctx, jint x, jint z) { + auto existing = ctx->chunkCache.find(ChunkPos{x, z}); + if (existing != ctx->chunkCache.end()) { + return (jlong) &existing->second->data; + } else { + return 0; // null pointer + } + } + EXPORT jobject JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_pathFind(JNIEnv* env, jclass, Context* ctx, jint x1, jint y1, jint z1, jint x2, jint y2, jint z2, jboolean x4Min, jint timeoutMs) { if (!inBounds(y1) || !inBounds(y2)) { throwException(env, "Invalid y1 or y2"); @@ -229,4 +238,8 @@ extern "C" { const std::variant result = raytrace({x1, y1, z1}, {x2, y2, z2}, assumeFakeChunksAreAir, ctx->generator, ctx->executors[0], ctx->chunkCache); return !std::holds_alternative(result); } + + EXPORT jlong JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_getX2Index(JNIEnv*, jclass) { + return (jlong) &X2_INDEX; + } }