mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 09:29:55 +00:00
Merge branch 'reduce_code_size' into 'master'
Reduce preprocessed code size See merge request OpenMW/openmw!2955
This commit is contained in:
commit
9c1a90daa5
30 changed files with 160 additions and 138 deletions
|
@ -45,13 +45,13 @@ if [[ "${GENERATE_ONLY}" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git remote add target "${CI_MERGE_REQUEST_SOURCE_PROJECT_URL:-https://gitlab.com/OpenMW/openmw.git}"
|
git remote add target "${CI_MERGE_REQUEST_PROJECT_URL:-https://gitlab.com/OpenMW/openmw.git}"
|
||||||
|
|
||||||
TARGET_BRANCH="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-master}"
|
TARGET_BRANCH="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-master}"
|
||||||
|
|
||||||
git fetch target "${TARGET_BRANCH:?}"
|
git fetch target "${TARGET_BRANCH:?}"
|
||||||
|
|
||||||
BASE_VERSION=$(git merge-base "target/${TARGET_BRANCH:?}" HEAD)
|
BASE_VERSION=$(git merge-base "target/${TARGET_BRANCH:?}" "${VERSION:?}")
|
||||||
|
|
||||||
# Save and use scripts from this commit because they may be absent or different in the base version
|
# Save and use scripts from this commit because they may be absent or different in the base version
|
||||||
cp scripts/preprocessed_file_size_stats.py scripts/preprocessed_file_size_stats.bak.py
|
cp scripts/preprocessed_file_size_stats.py scripts/preprocessed_file_size_stats.bak.py
|
||||||
|
|
|
@ -279,7 +279,7 @@ namespace NavMeshTool
|
||||||
return *it->second;
|
return *it->second;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
const TileCachedRecastMeshManager::UpdateGuard guard(navMeshInput.mTileCachedRecastMeshManager);
|
const auto guard = navMeshInput.mTileCachedRecastMeshManager.makeUpdateGuard();
|
||||||
|
|
||||||
if (exterior)
|
if (exterior)
|
||||||
{
|
{
|
||||||
|
@ -293,15 +293,15 @@ namespace NavMeshTool
|
||||||
getAabb(cellPosition, minHeight, maxHeight), navMeshInput.mAabb, navMeshInput.mAabbInitialized);
|
getAabb(cellPosition, minHeight, maxHeight), navMeshInput.mAabb, navMeshInput.mAabbInitialized);
|
||||||
|
|
||||||
navMeshInput.mTileCachedRecastMeshManager.addHeightfield(
|
navMeshInput.mTileCachedRecastMeshManager.addHeightfield(
|
||||||
cellPosition, ESM::Land::REAL_SIZE, heightfieldShape, &guard);
|
cellPosition, ESM::Land::REAL_SIZE, heightfieldShape, guard.get());
|
||||||
|
|
||||||
navMeshInput.mTileCachedRecastMeshManager.addWater(cellPosition, ESM::Land::REAL_SIZE, -1, &guard);
|
navMeshInput.mTileCachedRecastMeshManager.addWater(cellPosition, ESM::Land::REAL_SIZE, -1, guard.get());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((cell.mData.mFlags & ESM::Cell::HasWater) != 0)
|
if ((cell.mData.mFlags & ESM::Cell::HasWater) != 0)
|
||||||
navMeshInput.mTileCachedRecastMeshManager.addWater(
|
navMeshInput.mTileCachedRecastMeshManager.addWater(
|
||||||
cellPosition, std::numeric_limits<int>::max(), cell.mWater, &guard);
|
cellPosition, std::numeric_limits<int>::max(), cell.mWater, guard.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
forEachObject(cell, esmData, vfs, bulletShapeManager, readers, [&](BulletObject object) {
|
forEachObject(cell, esmData, vfs, bulletShapeManager, readers, [&](BulletObject object) {
|
||||||
|
@ -319,13 +319,13 @@ namespace NavMeshTool
|
||||||
object.getObjectTransform());
|
object.getObjectTransform());
|
||||||
|
|
||||||
navMeshInput.mTileCachedRecastMeshManager.addObject(
|
navMeshInput.mTileCachedRecastMeshManager.addObject(
|
||||||
objectId, shape, transform, DetourNavigator::AreaType_ground, &guard);
|
objectId, shape, transform, DetourNavigator::AreaType_ground, guard.get());
|
||||||
|
|
||||||
if (const btCollisionShape* avoid = object.getShapeInstance()->mAvoidCollisionShape.get())
|
if (const btCollisionShape* avoid = object.getShapeInstance()->mAvoidCollisionShape.get())
|
||||||
{
|
{
|
||||||
const CollisionShape avoidShape(object.getShapeInstance(), *avoid, object.getObjectTransform());
|
const CollisionShape avoidShape(object.getShapeInstance(), *avoid, object.getObjectTransform());
|
||||||
navMeshInput.mTileCachedRecastMeshManager.addObject(
|
navMeshInput.mTileCachedRecastMeshManager.addObject(
|
||||||
objectId, avoidShape, transform, DetourNavigator::AreaType_null, &guard);
|
objectId, avoidShape, transform, DetourNavigator::AreaType_null, guard.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
data.mObjects.emplace_back(std::move(object));
|
data.mObjects.emplace_back(std::move(object));
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <components/detournavigator/debug.hpp>
|
#include <components/detournavigator/debug.hpp>
|
||||||
#include <components/detournavigator/heightfieldshape.hpp>
|
#include <components/detournavigator/heightfieldshape.hpp>
|
||||||
#include <components/detournavigator/navigator.hpp>
|
#include <components/detournavigator/navigator.hpp>
|
||||||
#include <components/detournavigator/navigatorimpl.hpp>
|
#include <components/detournavigator/updateguard.hpp>
|
||||||
#include <components/esm/records.hpp>
|
#include <components/esm/records.hpp>
|
||||||
#include <components/loadinglistener/loadinglistener.hpp>
|
#include <components/loadinglistener/loadinglistener.hpp>
|
||||||
#include <components/misc/convert.hpp>
|
#include <components/misc/convert.hpp>
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
#include <components/detournavigator/agentbounds.hpp>
|
#include <components/detournavigator/agentbounds.hpp>
|
||||||
#include <components/detournavigator/debug.hpp>
|
#include <components/detournavigator/debug.hpp>
|
||||||
#include <components/detournavigator/navigator.hpp>
|
#include <components/detournavigator/navigator.hpp>
|
||||||
#include <components/detournavigator/navigatorimpl.hpp>
|
|
||||||
#include <components/detournavigator/settings.hpp>
|
#include <components/detournavigator/settings.hpp>
|
||||||
#include <components/detournavigator/stats.hpp>
|
#include <components/detournavigator/stats.hpp>
|
||||||
|
#include <components/detournavigator/updateguard.hpp>
|
||||||
|
|
||||||
#include <components/files/conversion.hpp>
|
#include <components/files/conversion.hpp>
|
||||||
#include <components/loadinglistener/loadinglistener.hpp>
|
#include <components/loadinglistener/loadinglistener.hpp>
|
||||||
|
|
|
@ -340,36 +340,67 @@ elseif(NOT ANDROID)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_component_dir(detournavigator
|
add_component_dir(detournavigator
|
||||||
debug
|
agentbounds
|
||||||
makenavmesh
|
areatype
|
||||||
findsmoothpath
|
|
||||||
recastmeshbuilder
|
|
||||||
navmeshmanager
|
|
||||||
navigatorimpl
|
|
||||||
asyncnavmeshupdater
|
asyncnavmeshupdater
|
||||||
recastmesh
|
bounds
|
||||||
tilecachedrecastmeshmanager
|
changetype
|
||||||
recastmeshobject
|
collisionshapetype
|
||||||
navmeshtilescache
|
commulativeaabb
|
||||||
settings
|
dbrefgeometryobject
|
||||||
navigator
|
debug
|
||||||
|
exceptions
|
||||||
findrandompointaroundcircle
|
findrandompointaroundcircle
|
||||||
raycast
|
findsmoothpath
|
||||||
|
flags
|
||||||
|
generatenavmeshtile
|
||||||
|
gettilespositions
|
||||||
|
guardednavmeshcacheitem
|
||||||
|
heightfieldshape
|
||||||
|
makenavmesh
|
||||||
|
navigator
|
||||||
|
navigatorimpl
|
||||||
|
navigatorstub
|
||||||
|
navigatorutils
|
||||||
|
navmeshcacheitem
|
||||||
|
navmeshdata
|
||||||
|
navmeshdb
|
||||||
|
navmeshdbutils
|
||||||
|
navmeshmanager
|
||||||
|
navmeshtilescache
|
||||||
navmeshtileview
|
navmeshtileview
|
||||||
|
objectid
|
||||||
|
objecttransform
|
||||||
|
offmeshconnection
|
||||||
offmeshconnectionsmanager
|
offmeshconnectionsmanager
|
||||||
preparednavmeshdata
|
preparednavmeshdata
|
||||||
navmeshcacheitem
|
preparednavmeshdatatuple
|
||||||
navigatorutils
|
raycast
|
||||||
generatenavmeshtile
|
|
||||||
navmeshdb
|
|
||||||
serialization
|
|
||||||
navmeshdbutils
|
|
||||||
recast
|
recast
|
||||||
gettilespositions
|
recastallocutils
|
||||||
collisionshapetype
|
|
||||||
stats
|
|
||||||
commulativeaabb
|
|
||||||
recastcontext
|
recastcontext
|
||||||
|
recastglobalallocator
|
||||||
|
recastmesh
|
||||||
|
recastmeshbuilder
|
||||||
|
recastmeshobject
|
||||||
|
recastmeshprovider
|
||||||
|
recastmeshtiles
|
||||||
|
recastparams
|
||||||
|
recasttempallocator
|
||||||
|
ref
|
||||||
|
serialization
|
||||||
|
settings
|
||||||
|
settingsutils
|
||||||
|
sharednavmeshcacheitem
|
||||||
|
stats
|
||||||
|
status
|
||||||
|
tilebounds
|
||||||
|
tilecachedrecastmeshmanager
|
||||||
|
tileposition
|
||||||
|
tilespositionsrange
|
||||||
|
updateguard
|
||||||
|
version
|
||||||
|
waitconditiontype
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir(loadinglistener
|
add_component_dir(loadinglistener
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include <components/loadinglistener/loadinglistener.hpp>
|
#include <components/loadinglistener/loadinglistener.hpp>
|
||||||
#include <components/misc/thread.hpp>
|
#include <components/misc/thread.hpp>
|
||||||
|
|
||||||
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
|
||||||
|
|
||||||
#include <DetourNavMesh.h>
|
#include <DetourNavMesh.h>
|
||||||
|
|
||||||
#include <osg/io_utils>
|
#include <osg/io_utils>
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
#include "tileposition.hpp"
|
#include "tileposition.hpp"
|
||||||
#include "waitconditiontype.hpp"
|
#include "waitconditiontype.hpp"
|
||||||
|
|
||||||
#include <osg/Vec3f>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_COMMULATIVEAABB_H
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_COMMULATIVEAABB_H
|
||||||
|
|
||||||
#include <BulletCollision/Gimpact/btBoxCollision.h>
|
#include <BulletCollision/Gimpact/btBoxCollision.h>
|
||||||
#include <LinearMath/btTransform.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
#include "flags.hpp"
|
#include "flags.hpp"
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class dtNavMeshQuery;
|
class dtNavMeshQuery;
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <components/misc/convert.hpp>
|
#include <components/misc/convert.hpp>
|
||||||
|
|
||||||
|
#include <DetourCommon.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "settingsutils.hpp"
|
#include "settingsutils.hpp"
|
||||||
#include "status.hpp"
|
#include "status.hpp"
|
||||||
|
|
||||||
#include <DetourCommon.h>
|
|
||||||
#include <DetourNavMesh.h>
|
#include <DetourNavMesh.h>
|
||||||
#include <DetourNavMeshQuery.h>
|
#include <DetourNavMeshQuery.h>
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
#include <osg/Vec3f>
|
|
||||||
#include <osg/io_utils>
|
#include <osg/io_utils>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
|
@ -7,10 +7,7 @@
|
||||||
|
|
||||||
#include <components/sceneutil/workqueue.hpp>
|
#include <components/sceneutil/workqueue.hpp>
|
||||||
|
|
||||||
#include <osg/Vec3f>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include <DetourNavMesh.h>
|
#include <DetourNavMesh.h>
|
||||||
#include <DetourNavMeshBuilder.h>
|
#include <DetourNavMeshBuilder.h>
|
||||||
#include <Recast.h>
|
#include <Recast.h>
|
||||||
#include <RecastAlloc.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "objecttransform.hpp"
|
#include "objecttransform.hpp"
|
||||||
#include "recastmeshtiles.hpp"
|
#include "recastmeshtiles.hpp"
|
||||||
#include "sharednavmeshcacheitem.hpp"
|
#include "sharednavmeshcacheitem.hpp"
|
||||||
|
#include "updateguard.hpp"
|
||||||
#include "waitconditiontype.hpp"
|
#include "waitconditiontype.hpp"
|
||||||
|
|
||||||
#include <components/resource/bulletshape.hpp>
|
#include <components/resource/bulletshape.hpp>
|
||||||
|
@ -58,8 +59,6 @@ namespace DetourNavigator
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class UpdateGuard;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Top level interface of detournavigator component. Navigator allows to build a scene with navmesh and find
|
* @brief Top level interface of detournavigator component. Navigator allows to build a scene with navmesh and find
|
||||||
* a path for an agent there. Scene contains agents, geometry objects and water. Agent are distinguished only by
|
* a path for an agent there. Scene contains agents, geometry objects and water. Agent are distinguished only by
|
||||||
|
@ -71,7 +70,7 @@ namespace DetourNavigator
|
||||||
{
|
{
|
||||||
virtual ~Navigator() = default;
|
virtual ~Navigator() = default;
|
||||||
|
|
||||||
virtual std::unique_ptr<const UpdateGuard> makeUpdateGuard() = 0;
|
virtual ScopedUpdateGuard makeUpdateGuard() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief addAgent should be called for each agent even if all of them has same half extents.
|
* @brief addAgent should be called for each agent even if all of them has same half extents.
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "stats.hpp"
|
#include "stats.hpp"
|
||||||
|
|
||||||
#include <components/esm3/loadpgrd.hpp>
|
#include <components/esm3/loadpgrd.hpp>
|
||||||
#include <components/misc/algorithm.hpp>
|
|
||||||
#include <components/misc/convert.hpp>
|
#include <components/misc/convert.hpp>
|
||||||
#include <components/misc/coordinateconverter.hpp>
|
#include <components/misc/coordinateconverter.hpp>
|
||||||
|
|
||||||
|
@ -36,12 +35,12 @@ namespace DetourNavigator
|
||||||
|
|
||||||
void NavigatorImpl::setWorldspace(std::string_view worldspace, const UpdateGuard* guard)
|
void NavigatorImpl::setWorldspace(std::string_view worldspace, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.setWorldspace(worldspace, getImpl(guard));
|
mNavMeshManager.setWorldspace(worldspace, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.updateBounds(playerPosition, getImpl(guard));
|
mNavMeshManager.updateBounds(playerPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::addObject(
|
void NavigatorImpl::addObject(
|
||||||
|
@ -55,12 +54,12 @@ namespace DetourNavigator
|
||||||
{
|
{
|
||||||
const CollisionShape collisionShape(
|
const CollisionShape collisionShape(
|
||||||
shapes.mShapeInstance, *shapes.mShapeInstance->mCollisionShape, shapes.mTransform);
|
shapes.mShapeInstance, *shapes.mShapeInstance->mCollisionShape, shapes.mTransform);
|
||||||
bool result = mNavMeshManager.addObject(id, collisionShape, transform, AreaType_ground, getImpl(guard));
|
bool result = mNavMeshManager.addObject(id, collisionShape, transform, AreaType_ground, guard);
|
||||||
if (const btCollisionShape* const avoidShape = shapes.mShapeInstance->mAvoidCollisionShape.get())
|
if (const btCollisionShape* const avoidShape = shapes.mShapeInstance->mAvoidCollisionShape.get())
|
||||||
{
|
{
|
||||||
const ObjectId avoidId(avoidShape);
|
const ObjectId avoidId(avoidShape);
|
||||||
const CollisionShape avoidCollisionShape(shapes.mShapeInstance, *avoidShape, shapes.mTransform);
|
const CollisionShape avoidCollisionShape(shapes.mShapeInstance, *avoidShape, shapes.mTransform);
|
||||||
if (mNavMeshManager.addObject(avoidId, avoidCollisionShape, transform, AreaType_null, getImpl(guard)))
|
if (mNavMeshManager.addObject(avoidId, avoidCollisionShape, transform, AreaType_null, guard))
|
||||||
{
|
{
|
||||||
updateAvoidShapeId(id, avoidId, guard);
|
updateAvoidShapeId(id, avoidId, guard);
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -84,11 +83,11 @@ namespace DetourNavigator
|
||||||
void NavigatorImpl::updateObject(
|
void NavigatorImpl::updateObject(
|
||||||
const ObjectId id, const ObjectShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
const ObjectId id, const ObjectShapes& shapes, const btTransform& transform, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.updateObject(id, transform, AreaType_ground, getImpl(guard));
|
mNavMeshManager.updateObject(id, transform, AreaType_ground, guard);
|
||||||
if (const btCollisionShape* const avoidShape = shapes.mShapeInstance->mAvoidCollisionShape.get())
|
if (const btCollisionShape* const avoidShape = shapes.mShapeInstance->mAvoidCollisionShape.get())
|
||||||
{
|
{
|
||||||
const ObjectId avoidId(avoidShape);
|
const ObjectId avoidId(avoidShape);
|
||||||
if (mNavMeshManager.updateObject(avoidId, transform, AreaType_null, getImpl(guard)))
|
if (mNavMeshManager.updateObject(avoidId, transform, AreaType_null, guard))
|
||||||
updateAvoidShapeId(id, avoidId, guard);
|
updateAvoidShapeId(id, avoidId, guard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,35 +100,35 @@ namespace DetourNavigator
|
||||||
|
|
||||||
void NavigatorImpl::removeObject(const ObjectId id, const UpdateGuard* guard)
|
void NavigatorImpl::removeObject(const ObjectId id, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.removeObject(id, getImpl(guard));
|
mNavMeshManager.removeObject(id, guard);
|
||||||
const auto avoid = mAvoidIds.find(id);
|
const auto avoid = mAvoidIds.find(id);
|
||||||
if (avoid != mAvoidIds.end())
|
if (avoid != mAvoidIds.end())
|
||||||
mNavMeshManager.removeObject(avoid->second, getImpl(guard));
|
mNavMeshManager.removeObject(avoid->second, guard);
|
||||||
const auto water = mWaterIds.find(id);
|
const auto water = mWaterIds.find(id);
|
||||||
if (water != mWaterIds.end())
|
if (water != mWaterIds.end())
|
||||||
mNavMeshManager.removeObject(water->second, getImpl(guard));
|
mNavMeshManager.removeObject(water->second, guard);
|
||||||
mNavMeshManager.removeOffMeshConnections(id);
|
mNavMeshManager.removeOffMeshConnections(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard)
|
void NavigatorImpl::addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.addWater(cellPosition, cellSize, level, getImpl(guard));
|
mNavMeshManager.addWater(cellPosition, cellSize, level, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
void NavigatorImpl::removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.removeWater(cellPosition, getImpl(guard));
|
mNavMeshManager.removeWater(cellPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::addHeightfield(
|
void NavigatorImpl::addHeightfield(
|
||||||
const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape, const UpdateGuard* guard)
|
const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.addHeightfield(cellPosition, cellSize, shape, getImpl(guard));
|
mNavMeshManager.addHeightfield(cellPosition, cellSize, shape, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
void NavigatorImpl::removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mNavMeshManager.removeHeightfield(cellPosition, getImpl(guard));
|
mNavMeshManager.removeHeightfield(cellPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid)
|
void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid)
|
||||||
|
@ -152,7 +151,7 @@ namespace DetourNavigator
|
||||||
void NavigatorImpl::update(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
void NavigatorImpl::update(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
removeUnusedNavMeshes();
|
removeUnusedNavMeshes();
|
||||||
mNavMeshManager.update(playerPosition, getImpl(guard));
|
mNavMeshManager.update(playerPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigatorImpl::wait(WaitConditionType waitConditionType, Loading::Listener* listener)
|
void NavigatorImpl::wait(WaitConditionType waitConditionType, Loading::Listener* listener)
|
||||||
|
@ -196,7 +195,7 @@ namespace DetourNavigator
|
||||||
auto inserted = ids.insert(std::make_pair(id, updateId));
|
auto inserted = ids.insert(std::make_pair(id, updateId));
|
||||||
if (!inserted.second)
|
if (!inserted.second)
|
||||||
{
|
{
|
||||||
mNavMeshManager.removeObject(inserted.first->second, getImpl(guard));
|
mNavMeshManager.removeObject(inserted.first->second, guard);
|
||||||
inserted.first->second = updateId;
|
inserted.first->second = updateId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
|
|
||||||
#include "navigator.hpp"
|
#include "navigator.hpp"
|
||||||
#include "navmeshmanager.hpp"
|
#include "navmeshmanager.hpp"
|
||||||
|
#include "updateguard.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
{
|
{
|
||||||
|
@ -18,10 +22,7 @@ namespace DetourNavigator
|
||||||
*/
|
*/
|
||||||
explicit NavigatorImpl(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
|
explicit NavigatorImpl(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
|
||||||
|
|
||||||
std::unique_ptr<const DetourNavigator::UpdateGuard> makeUpdateGuard() override
|
ScopedUpdateGuard makeUpdateGuard() override { return mNavMeshManager.makeUpdateGuard(); }
|
||||||
{
|
|
||||||
return std::make_unique<const UpdateGuard>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addAgent(const AgentBounds& agentBounds) override;
|
bool addAgent(const AgentBounds& agentBounds) override;
|
||||||
|
|
||||||
|
@ -94,23 +95,6 @@ namespace DetourNavigator
|
||||||
|
|
||||||
friend class UpdateGuard;
|
friend class UpdateGuard;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UpdateGuard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit UpdateGuard(NavigatorImpl& navigator)
|
|
||||||
: mImpl(navigator.mNavMeshManager)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
NavMeshManager::UpdateGuard mImpl;
|
|
||||||
|
|
||||||
friend inline const NavMeshManager::UpdateGuard* getImpl(const UpdateGuard* guard)
|
|
||||||
{
|
|
||||||
return guard == nullptr ? nullptr : &guard->mImpl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "navigator.hpp"
|
#include "navigator.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "stats.hpp"
|
#include "stats.hpp"
|
||||||
|
#include "updateguard.hpp"
|
||||||
|
|
||||||
namespace Loading
|
namespace Loading
|
||||||
{
|
{
|
||||||
|
@ -17,7 +18,7 @@ namespace DetourNavigator
|
||||||
public:
|
public:
|
||||||
NavigatorStub() = default;
|
NavigatorStub() = default;
|
||||||
|
|
||||||
std::unique_ptr<const UpdateGuard> makeUpdateGuard() override { return nullptr; }
|
ScopedUpdateGuard makeUpdateGuard() override { return nullptr; }
|
||||||
|
|
||||||
bool addAgent(const AgentBounds& /*agentBounds*/) override { return true; }
|
bool addAgent(const AgentBounds& /*agentBounds*/) override { return true; }
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "navmeshmanager.hpp"
|
#include "navmeshmanager.hpp"
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
#include "exceptions.hpp"
|
|
||||||
#include "gettilespositions.hpp"
|
#include "gettilespositions.hpp"
|
||||||
#include "makenavmesh.hpp"
|
#include "makenavmesh.hpp"
|
||||||
#include "navmeshcacheitem.hpp"
|
#include "navmeshcacheitem.hpp"
|
||||||
|
@ -8,9 +7,7 @@
|
||||||
#include "settingsutils.hpp"
|
#include "settingsutils.hpp"
|
||||||
#include "waitconditiontype.hpp"
|
#include "waitconditiontype.hpp"
|
||||||
|
|
||||||
#include <components/bullethelpers/heightfield.hpp>
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/misc/convert.hpp>
|
|
||||||
|
|
||||||
#include <osg/io_utils>
|
#include <osg/io_utils>
|
||||||
|
|
||||||
|
@ -67,7 +64,7 @@ namespace DetourNavigator
|
||||||
{
|
{
|
||||||
if (worldspace == mWorldspace)
|
if (worldspace == mWorldspace)
|
||||||
return;
|
return;
|
||||||
mRecastMeshManager.setWorldspace(worldspace, getImpl(guard));
|
mRecastMeshManager.setWorldspace(worldspace, guard);
|
||||||
for (auto& [agent, cache] : mCache)
|
for (auto& [agent, cache] : mCache)
|
||||||
cache = std::make_shared<GuardedNavMeshCacheItem>(++mGenerationCounter, mSettings);
|
cache = std::make_shared<GuardedNavMeshCacheItem>(++mGenerationCounter, mSettings);
|
||||||
mWorldspace = worldspace;
|
mWorldspace = worldspace;
|
||||||
|
@ -77,45 +74,45 @@ namespace DetourNavigator
|
||||||
{
|
{
|
||||||
const TilePosition playerTile = toNavMeshTilePosition(mSettings.mRecast, playerPosition);
|
const TilePosition playerTile = toNavMeshTilePosition(mSettings.mRecast, playerPosition);
|
||||||
const TilesPositionsRange range = makeRange(playerTile, mSettings.mMaxTilesNumber);
|
const TilesPositionsRange range = makeRange(playerTile, mSettings.mMaxTilesNumber);
|
||||||
mRecastMeshManager.setRange(range, getImpl(guard));
|
mRecastMeshManager.setRange(range, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NavMeshManager::addObject(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
bool NavMeshManager::addObject(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
||||||
const AreaType areaType, const UpdateGuard* guard)
|
const AreaType areaType, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
return mRecastMeshManager.addObject(id, shape, transform, areaType, getImpl(guard));
|
return mRecastMeshManager.addObject(id, shape, transform, areaType, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NavMeshManager::updateObject(
|
bool NavMeshManager::updateObject(
|
||||||
const ObjectId id, const btTransform& transform, const AreaType areaType, const UpdateGuard* guard)
|
const ObjectId id, const btTransform& transform, const AreaType areaType, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
return mRecastMeshManager.updateObject(id, transform, areaType, getImpl(guard));
|
return mRecastMeshManager.updateObject(id, transform, areaType, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::removeObject(const ObjectId id, const UpdateGuard* guard)
|
void NavMeshManager::removeObject(const ObjectId id, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mRecastMeshManager.removeObject(id, getImpl(guard));
|
mRecastMeshManager.removeObject(id, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard)
|
void NavMeshManager::addWater(const osg::Vec2i& cellPosition, int cellSize, float level, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mRecastMeshManager.addWater(cellPosition, cellSize, level, getImpl(guard));
|
mRecastMeshManager.addWater(cellPosition, cellSize, level, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
void NavMeshManager::removeWater(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mRecastMeshManager.removeWater(cellPosition, getImpl(guard));
|
mRecastMeshManager.removeWater(cellPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::addHeightfield(
|
void NavMeshManager::addHeightfield(
|
||||||
const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape, const UpdateGuard* guard)
|
const osg::Vec2i& cellPosition, int cellSize, const HeightfieldShape& shape, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mRecastMeshManager.addHeightfield(cellPosition, cellSize, shape, getImpl(guard));
|
mRecastMeshManager.addHeightfield(cellPosition, cellSize, shape, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
void NavMeshManager::removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard)
|
||||||
{
|
{
|
||||||
mRecastMeshManager.removeHeightfield(cellPosition, getImpl(guard));
|
mRecastMeshManager.removeHeightfield(cellPosition, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMeshManager::addAgent(const AgentBounds& agentBounds)
|
void NavMeshManager::addAgent(const AgentBounds& agentBounds)
|
||||||
|
@ -169,7 +166,7 @@ namespace DetourNavigator
|
||||||
return;
|
return;
|
||||||
mLastRecastMeshManagerRevision = mRecastMeshManager.getRevision();
|
mLastRecastMeshManagerRevision = mRecastMeshManager.getRevision();
|
||||||
mPlayerTile = playerTile;
|
mPlayerTile = playerTile;
|
||||||
const auto changedTiles = mRecastMeshManager.takeChangedTiles(getImpl(guard));
|
const auto changedTiles = mRecastMeshManager.takeChangedTiles(guard);
|
||||||
const TilesPositionsRange range = mRecastMeshManager.getLimitedObjectsRange();
|
const TilesPositionsRange range = mRecastMeshManager.getLimitedObjectsRange();
|
||||||
for (const auto& [agentBounds, cached] : mCache)
|
for (const auto& [agentBounds, cached] : mCache)
|
||||||
update(agentBounds, playerTile, range, cached, changedTiles);
|
update(agentBounds, playerTile, range, cached, changedTiles);
|
||||||
|
|
|
@ -20,25 +20,10 @@ namespace DetourNavigator
|
||||||
class NavMeshManager
|
class NavMeshManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class UpdateGuard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit UpdateGuard(NavMeshManager& manager)
|
|
||||||
: mImpl(manager.mRecastMeshManager)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
friend const TileCachedRecastMeshManager::UpdateGuard* getImpl(const UpdateGuard* guard)
|
|
||||||
{
|
|
||||||
return guard == nullptr ? nullptr : &guard->mImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const TileCachedRecastMeshManager::UpdateGuard mImpl;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit NavMeshManager(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
|
explicit NavMeshManager(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
|
||||||
|
|
||||||
|
ScopedUpdateGuard makeUpdateGuard() { return mRecastMeshManager.makeUpdateGuard(); }
|
||||||
|
|
||||||
void setWorldspace(std::string_view worldspace, const UpdateGuard* guard);
|
void setWorldspace(std::string_view worldspace, const UpdateGuard* guard);
|
||||||
|
|
||||||
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard);
|
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <unordered_map>
|
#include <functional>
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECAST_H
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECAST_H
|
||||||
|
|
||||||
#include <Recast.h>
|
#include <Recast.h>
|
||||||
#include <RecastAlloc.h>
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTALLOCUTILS_H
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTALLOCUTILS_H
|
||||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTALLOCUTILS_H
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTALLOCUTILS_H
|
||||||
|
|
||||||
#include <RecastAlloc.h>
|
#include <cstddef>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "recasttempallocator.hpp"
|
#include "recasttempallocator.hpp"
|
||||||
|
|
||||||
|
#include <RecastAlloc.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#include "recastmesh.hpp"
|
#include "recastmesh.hpp"
|
||||||
#include "exceptions.hpp"
|
#include "exceptions.hpp"
|
||||||
|
|
||||||
#include <Recast.h>
|
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
{
|
{
|
||||||
Mesh::Mesh(std::vector<int>&& indices, std::vector<float>&& vertices, std::vector<AreaType>&& areaTypes)
|
Mesh::Mesh(std::vector<int>&& indices, std::vector<float>&& vertices, std::vector<AreaType>&& areaTypes)
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <LinearMath/btTransform.h>
|
#include <LinearMath/btTransform.h>
|
||||||
|
|
||||||
#include <osg/Referenced>
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "recastallocutils.hpp"
|
#include "recastallocutils.hpp"
|
||||||
|
|
||||||
|
#include <RecastAlloc.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "gettilespositions.hpp"
|
#include "gettilespositions.hpp"
|
||||||
#include "recastmeshbuilder.hpp"
|
#include "recastmeshbuilder.hpp"
|
||||||
#include "settingsutils.hpp"
|
#include "settingsutils.hpp"
|
||||||
|
#include "updateguard.hpp"
|
||||||
|
|
||||||
#include <components/bullethelpers/aabb.hpp>
|
#include <components/bullethelpers/aabb.hpp>
|
||||||
#include <components/misc/convert.hpp>
|
#include <components/misc/convert.hpp>
|
||||||
|
@ -45,7 +46,7 @@ namespace DetourNavigator
|
||||||
class MaybeLockGuard
|
class MaybeLockGuard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MaybeLockGuard(Mutex& mutex, const TileCachedRecastMeshManager::UpdateGuard* guard)
|
explicit MaybeLockGuard(Mutex& mutex, const UpdateGuard* guard)
|
||||||
: mImpl(guard == nullptr ? std::optional<std::unique_lock<Mutex>>(mutex) : std::nullopt)
|
: mImpl(guard == nullptr ? std::optional<std::unique_lock<Mutex>>(mutex) : std::nullopt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,24 @@
|
||||||
#include "recastmesh.hpp"
|
#include "recastmesh.hpp"
|
||||||
#include "recastmeshobject.hpp"
|
#include "recastmeshobject.hpp"
|
||||||
#include "tileposition.hpp"
|
#include "tileposition.hpp"
|
||||||
|
#include "updateguard.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
|
|
||||||
#include <boost/geometry/geometries/box.hpp>
|
#include <boost/geometry/geometries/box.hpp>
|
||||||
#include <boost/geometry/geometries/point.hpp>
|
#include <boost/geometry/geometries/point.hpp>
|
||||||
#include <boost/geometry/index/rtree.hpp>
|
#include <boost/geometry/index/rtree.hpp>
|
||||||
|
|
||||||
|
#include <LinearMath/btTransform.h>
|
||||||
|
|
||||||
|
#include <osg/Vec2i>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
|
@ -28,20 +37,14 @@ namespace DetourNavigator
|
||||||
class TileCachedRecastMeshManager
|
class TileCachedRecastMeshManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class UpdateGuard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit UpdateGuard(TileCachedRecastMeshManager& manager)
|
|
||||||
: mImpl(manager.mMutex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::lock_guard<std::mutex> mImpl;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit TileCachedRecastMeshManager(const RecastSettings& settings);
|
explicit TileCachedRecastMeshManager(const RecastSettings& settings);
|
||||||
|
|
||||||
|
ScopedUpdateGuard makeUpdateGuard()
|
||||||
|
{
|
||||||
|
mMutex.lock();
|
||||||
|
return ScopedUpdateGuard(&mUpdateGuard);
|
||||||
|
}
|
||||||
|
|
||||||
void setRange(const TilesPositionsRange& range, const UpdateGuard* guard);
|
void setRange(const TilesPositionsRange& range, const UpdateGuard* guard);
|
||||||
|
|
||||||
TilesPositionsRange getLimitedObjectsRange() const;
|
TilesPositionsRange getLimitedObjectsRange() const;
|
||||||
|
@ -139,6 +142,7 @@ namespace DetourNavigator
|
||||||
std::size_t mGeneration = 0;
|
std::size_t mGeneration = 0;
|
||||||
std::size_t mRevision = 0;
|
std::size_t mRevision = 0;
|
||||||
mutable std::mutex mMutex;
|
mutable std::mutex mMutex;
|
||||||
|
UpdateGuard mUpdateGuard{ mMutex };
|
||||||
|
|
||||||
inline static IndexPoint makeIndexPoint(const TilePosition& tilePosition);
|
inline static IndexPoint makeIndexPoint(const TilePosition& tilePosition);
|
||||||
|
|
||||||
|
|
31
components/detournavigator/updateguard.hpp
Normal file
31
components/detournavigator/updateguard.hpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_UPDATEGUARD_H
|
||||||
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_UPDATEGUARD_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace DetourNavigator
|
||||||
|
{
|
||||||
|
class UpdateGuard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit UpdateGuard(std::mutex& mutex)
|
||||||
|
: mMutex(mutex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mutex& mMutex;
|
||||||
|
|
||||||
|
friend struct UnlockUpdateGuard;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UnlockUpdateGuard
|
||||||
|
{
|
||||||
|
void operator()(UpdateGuard* value) const { value->mMutex.unlock(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
using ScopedUpdateGuard = std::unique_ptr<UpdateGuard, UnlockUpdateGuard>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue