mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Add navmesh update status builder
This commit is contained in:
parent
14c9190f49
commit
0c16fef285
@ -32,11 +32,11 @@ namespace DetourNavigator
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case UpdateNavMeshStatus::ignore:
|
||||
case UpdateNavMeshStatus::ignored:
|
||||
return stream << "ignore";
|
||||
case UpdateNavMeshStatus::removed:
|
||||
return stream << "removed";
|
||||
case UpdateNavMeshStatus::add:
|
||||
case UpdateNavMeshStatus::added:
|
||||
return stream << "add";
|
||||
case UpdateNavMeshStatus::replaced:
|
||||
return stream << "replaced";
|
||||
|
@ -441,17 +441,47 @@ namespace
|
||||
return NavMeshData(navMeshData, navMeshDataSize);
|
||||
}
|
||||
|
||||
UpdateNavMeshStatus makeUpdateNavMeshStatus(bool removed, bool add)
|
||||
class UpdateNavMeshStatusBuilder
|
||||
{
|
||||
if (removed && add)
|
||||
return UpdateNavMeshStatus::replaced;
|
||||
else if (removed)
|
||||
return UpdateNavMeshStatus::removed;
|
||||
else if (add)
|
||||
return UpdateNavMeshStatus::add;
|
||||
else
|
||||
return UpdateNavMeshStatus::ignore;
|
||||
}
|
||||
public:
|
||||
UpdateNavMeshStatusBuilder() = default;
|
||||
|
||||
UpdateNavMeshStatusBuilder removed(bool value)
|
||||
{
|
||||
if (value)
|
||||
set(UpdateNavMeshStatus::removed);
|
||||
else
|
||||
unset(UpdateNavMeshStatus::removed);
|
||||
return *this;
|
||||
}
|
||||
|
||||
UpdateNavMeshStatusBuilder added(bool value)
|
||||
{
|
||||
if (value)
|
||||
set(UpdateNavMeshStatus::added);
|
||||
else
|
||||
unset(UpdateNavMeshStatus::added);
|
||||
return *this;
|
||||
}
|
||||
|
||||
UpdateNavMeshStatus getResult() const
|
||||
{
|
||||
return mResult;
|
||||
}
|
||||
|
||||
private:
|
||||
UpdateNavMeshStatus mResult = UpdateNavMeshStatus::ignored;
|
||||
|
||||
void set(UpdateNavMeshStatus value)
|
||||
{
|
||||
mResult = static_cast<UpdateNavMeshStatus>(static_cast<unsigned>(mResult) | static_cast<unsigned>(value));
|
||||
}
|
||||
|
||||
void unset(UpdateNavMeshStatus value)
|
||||
{
|
||||
mResult = static_cast<UpdateNavMeshStatus>(static_cast<unsigned>(mResult) & ~static_cast<unsigned>(value));
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
unsigned long getMinValuableBitsNumber(const T value)
|
||||
@ -494,14 +524,14 @@ namespace
|
||||
if (dtStatusSucceed(addStatus))
|
||||
{
|
||||
locked->setUsedTile(changedTile, std::forward<T>(navMeshData));
|
||||
return makeUpdateNavMeshStatus(removed, true);
|
||||
return UpdateNavMeshStatusBuilder().added(true).removed(removed).getResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (removed)
|
||||
locked->removeUsedTile(changedTile);
|
||||
log("failed to add tile with status=", WriteDtStatus {addStatus});
|
||||
return makeUpdateNavMeshStatus(removed, false);
|
||||
return UpdateNavMeshStatusBuilder().removed(removed).getResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -565,7 +595,7 @@ namespace DetourNavigator
|
||||
const auto removed = dtStatusSucceed(navMesh.removeTile(tileRef, nullptr, nullptr));
|
||||
if (removed)
|
||||
locked->removeUsedTile(changedTile);
|
||||
return makeUpdateNavMeshStatus(removed, false);
|
||||
return UpdateNavMeshStatusBuilder().removed(removed).getResult();
|
||||
};
|
||||
|
||||
if (!recastMesh)
|
||||
|
@ -20,12 +20,12 @@ namespace DetourNavigator
|
||||
class RecastMesh;
|
||||
struct Settings;
|
||||
|
||||
enum class UpdateNavMeshStatus
|
||||
enum class UpdateNavMeshStatus : unsigned
|
||||
{
|
||||
ignore,
|
||||
removed,
|
||||
add,
|
||||
replaced
|
||||
ignored = 0,
|
||||
removed = 1 << 0,
|
||||
added = 1 << 1,
|
||||
replaced = removed | added,
|
||||
};
|
||||
|
||||
inline float getLength(const osg::Vec2i& value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user