From 696bb9adc897884f1c3960900403b1790428a5e3 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 5 Nov 2018 02:17:54 +0300 Subject: [PATCH 1/2] Add missing decrease for free navmesh data size --- components/detournavigator/navmeshtilescache.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/detournavigator/navmeshtilescache.cpp b/components/detournavigator/navmeshtilescache.cpp index 8bbe8ed483..cd60fa7e8b 100644 --- a/components/detournavigator/navmeshtilescache.cpp +++ b/components/detournavigator/navmeshtilescache.cpp @@ -132,6 +132,7 @@ namespace DetourNavigator return; mUsedNavMeshDataSize -= static_cast(item.mNavMeshData.mSize) + item.mNavMeshKey.size(); + mFreeNavMeshDataSize -= static_cast(item.mNavMeshData.mSize) + item.mNavMeshKey.size(); mFreeItems.pop_back(); tileValues->second.Map.erase(value); From 6e78fbb538ee4e9908dd4e9c4a659df6d62de26e Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 5 Nov 2018 01:59:33 +0300 Subject: [PATCH 2/2] Double key size for item cache size --- .../detournavigator/navmeshtilescache.cpp | 22 +++++++++---------- .../detournavigator/navmeshtilescache.cpp | 10 ++++----- .../detournavigator/navmeshtilescache.hpp | 5 +++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp index 8b1ee230d1..17b17b97c4 100644 --- a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp +++ b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp @@ -57,7 +57,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); const auto result = cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, @@ -70,7 +70,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = 2 * (navMeshDataSize + navMeshKeySize); + const std::size_t maxSize = 2 * (navMeshDataSize + 2 * navMeshKeySize); NavMeshTilesCache cache(maxSize); const auto anotherData = reinterpret_cast(dtAlloc(1, DT_ALLOC_PERM)); NavMeshData anotherNavMeshData {anotherData, 1}; @@ -86,7 +86,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(mNavMeshData)); @@ -130,7 +130,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 117; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -150,7 +150,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -168,7 +168,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 117; - const std::size_t maxSize = 2 * (navMeshDataSize + navMeshKeySize); + const std::size_t maxSize = 2 * (navMeshDataSize + 2 * navMeshKeySize); NavMeshTilesCache cache(maxSize); const std::vector leastRecentlySetWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -200,7 +200,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 117; - const std::size_t maxSize = 2 * (navMeshDataSize + navMeshKeySize); + const std::size_t maxSize = 2 * (navMeshDataSize + 2 * navMeshKeySize); NavMeshTilesCache cache(maxSize); const std::vector leastRecentlyUsedWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -244,7 +244,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = 2 * (navMeshDataSize + navMeshKeySize); + const std::size_t maxSize = 2 * (navMeshDataSize + 2 * navMeshKeySize); NavMeshTilesCache cache(maxSize); const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -263,7 +263,7 @@ namespace const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize1 = 49; const std::size_t navMeshKeySize2 = 117; - const std::size_t maxSize = 2 * navMeshDataSize + navMeshKeySize1 + navMeshKeySize2; + const std::size_t maxSize = 2 * navMeshDataSize + 2 * navMeshKeySize1 + 2 * navMeshKeySize2; NavMeshTilesCache cache(maxSize); const std::vector anotherWater {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -291,7 +291,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; @@ -314,7 +314,7 @@ namespace { const std::size_t navMeshDataSize = 1; const std::size_t navMeshKeySize = 49; - const std::size_t maxSize = navMeshDataSize + navMeshKeySize; + const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize; NavMeshTilesCache cache(maxSize); const std::vector water {1, RecastMesh::Water {1, btTransform::getIdentity()}}; diff --git a/components/detournavigator/navmeshtilescache.cpp b/components/detournavigator/navmeshtilescache.cpp index cd60fa7e8b..6bfbfb3954 100644 --- a/components/detournavigator/navmeshtilescache.cpp +++ b/components/detournavigator/navmeshtilescache.cpp @@ -88,7 +88,7 @@ namespace DetourNavigator return Value(); const auto navMeshKey = makeNavMeshKey(recastMesh, offMeshConnections); - const auto itemSize = navMeshSize + navMeshKey.size(); + const auto itemSize = navMeshSize + 2 * navMeshKey.size(); if (itemSize > mFreeNavMeshDataSize + (mMaxNavMeshDataSize - mUsedNavMeshDataSize)) return Value(); @@ -131,8 +131,8 @@ namespace DetourNavigator if (value == tileValues->second.Map.end()) return; - mUsedNavMeshDataSize -= static_cast(item.mNavMeshData.mSize) + item.mNavMeshKey.size(); - mFreeNavMeshDataSize -= static_cast(item.mNavMeshData.mSize) + item.mNavMeshKey.size(); + mUsedNavMeshDataSize -= getSize(item); + mFreeNavMeshDataSize -= getSize(item); mFreeItems.pop_back(); tileValues->second.Map.erase(value); @@ -152,7 +152,7 @@ namespace DetourNavigator return; mBusyItems.splice(mBusyItems.end(), mFreeItems, iterator); - mFreeNavMeshDataSize -= static_cast(iterator->mNavMeshData.mSize) + iterator->mNavMeshKey.size(); + mFreeNavMeshDataSize -= getSize(*iterator); } void NavMeshTilesCache::releaseItem(ItemIterator iterator) @@ -163,6 +163,6 @@ namespace DetourNavigator const std::lock_guard lock(mMutex); mFreeItems.splice(mFreeItems.begin(), mBusyItems, iterator); - mFreeNavMeshDataSize += static_cast(iterator->mNavMeshData.mSize) + iterator->mNavMeshKey.size(); + mFreeNavMeshDataSize += getSize(*iterator); } } diff --git a/components/detournavigator/navmeshtilescache.hpp b/components/detournavigator/navmeshtilescache.hpp index 27ac499e85..45c0a6bb39 100644 --- a/components/detournavigator/navmeshtilescache.hpp +++ b/components/detournavigator/navmeshtilescache.hpp @@ -127,6 +127,11 @@ namespace DetourNavigator void acquireItemUnsafe(ItemIterator iterator); void releaseItem(ItemIterator iterator); + + static std::size_t getSize(const Item& item) + { + return static_cast(item.mNavMeshData.mSize) + 2 * item.mNavMeshKey.size(); + } }; }