From 188c17c631a03cf4df82dcd1c1a6c1023b1be8a1 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Mon, 17 Jul 2023 20:56:28 -0400 Subject: [PATCH] fix cullFarChunks for real this time --- java/build.gradle | 2 +- src/PathfinderJNI.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/java/build.gradle b/java/build.gradle index 0f31506..fca9715 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -23,7 +23,7 @@ plugins { } group = 'dev.babbaj' -version = '0.40' +version = '0.41' java { toolchain { diff --git a/src/PathfinderJNI.cpp b/src/PathfinderJNI.cpp index 04aff2e..437f945 100644 --- a/src/PathfinderJNI.cpp +++ b/src/PathfinderJNI.cpp @@ -134,12 +134,10 @@ extern "C" { std::scoped_lock lock{ctx->cacheMutex}; const auto distSqBlocks = (maxDistanceBlocks / 16) * (maxDistanceBlocks / 16); const auto distSq = distSqBlocks; - for (auto it = ctx->chunkCache.begin(); it != ctx->chunkCache.end(); it++) { - const auto& cpos = it->first; - if (cpos.distanceToSq({chunkX, chunkZ}) > distSq) { - it = ctx->chunkCache.erase(it); - } - } + std::erase_if(ctx->chunkCache, [=](const auto& item) { + const auto cpos = item.first; + return cpos.distanceToSq({chunkX, chunkZ}) > distSq; + }); } 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) {