Skip to content

Commit

Permalink
add x4 argument
Browse files Browse the repository at this point in the history
  • Loading branch information
babbaj committed Jun 17, 2023
1 parent 41b6ae9 commit 0c8e20b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 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.11'
version = '0.12'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static int getIndex(int x, int y, int z)
*/
public static native void insertChunkData(long context, int chunkX, int chunkZ, boolean[] data);

public static native PathSegment pathFind(long context, int x1, int y1, int z1, int x2, int y2, int z2);
public static native PathSegment pathFind(long context, int x1, int y1, int z1, int x2, int y2, int z2, boolean atLeastX4);

public static native long[] raytrace(long context, long[] blocks);

Expand Down
10 changes: 7 additions & 3 deletions src/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool inGoal(const NodePos& node, const BlockPos& goal) {

std::atomic_flag cancelFlag;

std::optional<Path> findPathSegment(Context& ctx, const BlockPos& start, const BlockPos& goal) {
std::optional<Path> findPathSegment(Context& ctx, const BlockPos& start, const BlockPos& goal, bool x4Min) {
if (VERBOSE) std::cout << "distance = " << start.distanceTo(goal) << '\n';

map_t<NodePos, std::unique_ptr<PathNode>> map;
Expand Down Expand Up @@ -356,7 +356,11 @@ std::optional<Path> findPathSegment(Context& ctx, const BlockPos& start, const B
callback(neighborNodePos);
}
} else {
growThenIterateOuter<face, Size::X2>(chunk, neighborNodePos, callback);
if (x4Min) {
growThenIterateOuter<face, Size::X4>(chunk, neighborNodePos, callback);
} else {
growThenIterateOuter<face, Size::X2>(chunk, neighborNodePos, callback);
}
}
}(), ...);
}(std::make_index_sequence<ALL_FACES.size()>{});
Expand Down Expand Up @@ -451,7 +455,7 @@ std::optional<Path> findPathFull(Context& ctx, const BlockPos& start, const Bloc

while (true) {
const BlockPos lastPathEnd = !segments.empty() ? segments.back().getEndPos() : realStart;
std::optional path = findPathSegment(ctx, lastPathEnd, realGoal);
std::optional path = findPathSegment(ctx, lastPathEnd, realGoal, false);
if (!path.has_value()) {
if (cancelFlag.test()) {
cancelFlag.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/PathFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ struct Context {
};

std::optional<Path> findPathFull(Context& ctx, const BlockPos& start, const BlockPos& goal);
std::optional<Path> findPathSegment(Context& ctx, const BlockPos& start, const BlockPos& goal);
std::optional<Path> findPathSegment(Context& ctx, const BlockPos& start, const BlockPos& goal, bool x4Min);

BlockPos findAir(const BlockPos& pos, const ChunkGeneratorHell& gen);
4 changes: 2 additions & 2 deletions src/PathfinderJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ extern "C" {
ctx->chunkCache.insert_or_assign(ChunkPos{chunkX, chunkZ}, std::move(chunk_ptr));
}

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) {
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) {
if (!inBounds(y1) || !inBounds(y2)) {
throwException(env, "Invalid y1 or y2");
return nullptr;
}
ctx->cancelFlag.clear();
std::optional<Path> path = findPathSegment(*ctx, {x1, y1, z1}, {x2, y2, z2});
std::optional<Path> path = findPathSegment(*ctx, {x1, y1, z1}, {x2, y2, z2}, x4Min);
if (!path) return nullptr;

std::vector<jlong> packed;
Expand Down

0 comments on commit 0c8e20b

Please sign in to comment.