Merge pull request #2023 from elsid/navmesh_cache_limit

Navmesh cache limit
pull/541/head
Bret Curtis 6 years ago committed by GitHub
commit a8d944e756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<unsigned char*>(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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> 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<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};

@ -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,7 +131,8 @@ namespace DetourNavigator
if (value == tileValues->second.Map.end())
return;
mUsedNavMeshDataSize -= static_cast<std::size_t>(item.mNavMeshData.mSize) + item.mNavMeshKey.size();
mUsedNavMeshDataSize -= getSize(item);
mFreeNavMeshDataSize -= getSize(item);
mFreeItems.pop_back();
tileValues->second.Map.erase(value);
@ -151,7 +152,7 @@ namespace DetourNavigator
return;
mBusyItems.splice(mBusyItems.end(), mFreeItems, iterator);
mFreeNavMeshDataSize -= static_cast<std::size_t>(iterator->mNavMeshData.mSize) + iterator->mNavMeshKey.size();
mFreeNavMeshDataSize -= getSize(*iterator);
}
void NavMeshTilesCache::releaseItem(ItemIterator iterator)
@ -162,6 +163,6 @@ namespace DetourNavigator
const std::lock_guard<std::mutex> lock(mMutex);
mFreeItems.splice(mFreeItems.begin(), mBusyItems, iterator);
mFreeNavMeshDataSize += static_cast<std::size_t>(iterator->mNavMeshData.mSize) + iterator->mNavMeshKey.size();
mFreeNavMeshDataSize += getSize(*iterator);
}
}

@ -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<std::size_t>(item.mNavMeshData.mSize) + 2 * item.mNavMeshKey.size();
}
};
}

Loading…
Cancel
Save