Skip to content

Commit

Permalink
the native code
Browse files Browse the repository at this point in the history
  • Loading branch information
babbaj committed Jul 9, 2023
1 parent 56b50d2 commit 1b213b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ inline bool isEmpty(const T& input) {


struct Chunk {
private:
std::array<x16_t, 8> data{};
std::array<bool, 8> x16Empty{};
public:
bool isFromJava{};
private:

Expand Down Expand Up @@ -196,4 +194,4 @@ static const Chunk AIR_CHUNK = [] {
Chunk out{};
out.calcEmptyX16();
return out;
}();
}();
13 changes: 13 additions & 0 deletions src/PathfinderJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<Hit>(result);
}

EXPORT jlong JNICALL Java_dev_babbaj_pathfinder_NetherPathfinder_getX2Index(JNIEnv*, jclass) {
return (jlong) &X2_INDEX;
}
}

0 comments on commit 1b213b7

Please sign in to comment.