mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-29 03:19:44 +00:00
beeb882ea8
To reduce cache size and make it more flexible. Adding off mesh connections to the navmesh is the last step of navmesh generation and it's very fast comparing to other steps (microseconds vs milliseconds). Having less cache size makes get and set operations almost 2x times faster that also have an order of microseconds. So in total there is no performance impact.
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_REF_H
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_REF_H
|
|
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
|
|
namespace DetourNavigator
|
|
{
|
|
template <typename T>
|
|
struct Ref
|
|
{
|
|
T& mRef;
|
|
|
|
constexpr explicit Ref(T& ref) noexcept : mRef(ref) {}
|
|
|
|
friend bool operator==(const Ref& lhs, const Ref& rhs)
|
|
{
|
|
return lhs.mRef == rhs.mRef;
|
|
}
|
|
};
|
|
|
|
template <typename T, std::size_t size>
|
|
struct ArrayRef
|
|
{
|
|
T (&mRef)[size];
|
|
|
|
constexpr explicit ArrayRef(T (&ref)[size]) noexcept : mRef(ref) {}
|
|
|
|
friend bool operator==(const ArrayRef& lhs, const ArrayRef& rhs)
|
|
{
|
|
return std::equal(std::begin(lhs.mRef), std::end(lhs.mRef), std::begin(rhs.mRef));
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
struct Span
|
|
{
|
|
T* mBegin;
|
|
T* mEnd;
|
|
|
|
constexpr explicit Span(T* data, int size) noexcept
|
|
: mBegin(data)
|
|
, mEnd(data + static_cast<std::size_t>(size))
|
|
{}
|
|
|
|
friend bool operator==(const Span& lhs, const Span& rhs)
|
|
{
|
|
// size is already equal if headers are equal
|
|
assert((lhs.mEnd - lhs.mBegin) == (rhs.mEnd - rhs.mBegin));
|
|
return std::equal(lhs.mBegin, lhs.mEnd, rhs.mBegin);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|