mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 09:23:53 +00:00
Double key size for item cache size
This commit is contained in:
parent
696bb9adc8
commit
6e78fbb538
3 changed files with 21 additions and 16 deletions
|
@ -57,7 +57,7 @@ namespace
|
||||||
{
|
{
|
||||||
const std::size_t navMeshDataSize = 1;
|
const std::size_t navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
const std::size_t navMeshKeySize = 49;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const auto result = cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections,
|
const auto result = cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections,
|
||||||
|
@ -70,7 +70,7 @@ namespace
|
||||||
{
|
{
|
||||||
const std::size_t navMeshDataSize = 1;
|
const std::size_t navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
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);
|
NavMeshTilesCache cache(maxSize);
|
||||||
const auto anotherData = reinterpret_cast<unsigned char*>(dtAlloc(1, DT_ALLOC_PERM));
|
const auto anotherData = reinterpret_cast<unsigned char*>(dtAlloc(1, DT_ALLOC_PERM));
|
||||||
NavMeshData anotherNavMeshData {anotherData, 1};
|
NavMeshData anotherNavMeshData {anotherData, 1};
|
||||||
|
@ -86,7 +86,7 @@ namespace
|
||||||
{
|
{
|
||||||
const std::size_t navMeshDataSize = 1;
|
const std::size_t navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
const std::size_t navMeshKeySize = 49;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(mNavMeshData));
|
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, mOffMeshConnections, std::move(mNavMeshData));
|
||||||
|
@ -130,7 +130,7 @@ namespace
|
||||||
{
|
{
|
||||||
const std::size_t navMeshDataSize = 1;
|
const std::size_t navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 117;
|
const std::size_t navMeshKeySize = 117;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
const std::size_t navMeshKeySize = 49;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 117;
|
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);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> leastRecentlySetWater {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 117;
|
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);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> leastRecentlyUsedWater {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
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);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize1 = 49;
|
const std::size_t navMeshKeySize1 = 49;
|
||||||
const std::size_t navMeshKeySize2 = 117;
|
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);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> anotherWater {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
const std::size_t navMeshKeySize = 49;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
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 navMeshDataSize = 1;
|
||||||
const std::size_t navMeshKeySize = 49;
|
const std::size_t navMeshKeySize = 49;
|
||||||
const std::size_t maxSize = navMeshDataSize + navMeshKeySize;
|
const std::size_t maxSize = navMeshDataSize + 2 * navMeshKeySize;
|
||||||
NavMeshTilesCache cache(maxSize);
|
NavMeshTilesCache cache(maxSize);
|
||||||
|
|
||||||
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
const std::vector<RecastMesh::Water> water {1, RecastMesh::Water {1, btTransform::getIdentity()}};
|
||||||
|
|
|
@ -88,7 +88,7 @@ namespace DetourNavigator
|
||||||
return Value();
|
return Value();
|
||||||
|
|
||||||
const auto navMeshKey = makeNavMeshKey(recastMesh, offMeshConnections);
|
const auto navMeshKey = makeNavMeshKey(recastMesh, offMeshConnections);
|
||||||
const auto itemSize = navMeshSize + navMeshKey.size();
|
const auto itemSize = navMeshSize + 2 * navMeshKey.size();
|
||||||
|
|
||||||
if (itemSize > mFreeNavMeshDataSize + (mMaxNavMeshDataSize - mUsedNavMeshDataSize))
|
if (itemSize > mFreeNavMeshDataSize + (mMaxNavMeshDataSize - mUsedNavMeshDataSize))
|
||||||
return Value();
|
return Value();
|
||||||
|
@ -131,8 +131,8 @@ namespace DetourNavigator
|
||||||
if (value == tileValues->second.Map.end())
|
if (value == tileValues->second.Map.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mUsedNavMeshDataSize -= static_cast<std::size_t>(item.mNavMeshData.mSize) + item.mNavMeshKey.size();
|
mUsedNavMeshDataSize -= getSize(item);
|
||||||
mFreeNavMeshDataSize -= static_cast<std::size_t>(item.mNavMeshData.mSize) + item.mNavMeshKey.size();
|
mFreeNavMeshDataSize -= getSize(item);
|
||||||
mFreeItems.pop_back();
|
mFreeItems.pop_back();
|
||||||
|
|
||||||
tileValues->second.Map.erase(value);
|
tileValues->second.Map.erase(value);
|
||||||
|
@ -152,7 +152,7 @@ namespace DetourNavigator
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mBusyItems.splice(mBusyItems.end(), mFreeItems, iterator);
|
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)
|
void NavMeshTilesCache::releaseItem(ItemIterator iterator)
|
||||||
|
@ -163,6 +163,6 @@ namespace DetourNavigator
|
||||||
const std::lock_guard<std::mutex> lock(mMutex);
|
const std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
|
||||||
mFreeItems.splice(mFreeItems.begin(), mBusyItems, iterator);
|
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 acquireItemUnsafe(ItemIterator iterator);
|
||||||
|
|
||||||
void releaseItem(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…
Reference in a new issue