Ported the obj parser.
This commit is contained in:
18
include/util/array_hash.hpp
Normal file
18
include/util/array_hash.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
template<class T, size_t N>
|
||||
struct std::hash<std::array<T, N>>
|
||||
{
|
||||
auto operator() (const std::array<T, N>& key) const {
|
||||
auto hasher = std::hash<T>{};
|
||||
auto result = std::size_t{};
|
||||
for (const auto& element : key)
|
||||
{
|
||||
result = result * 31 + hasher(element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -36,7 +36,7 @@
|
||||
} \
|
||||
\
|
||||
constexpr ENUM_TYPE operator<<( \
|
||||
ENUM_TYPE& lhs, \
|
||||
ENUM_TYPE lhs, \
|
||||
int shift \
|
||||
) { \
|
||||
return static_cast<ENUM_TYPE>( \
|
||||
@@ -44,8 +44,17 @@ constexpr ENUM_TYPE operator<<( \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
constexpr ENUM_TYPE operator<<( \
|
||||
ENUM_TYPE lhs, \
|
||||
std::size_t shift \
|
||||
) { \
|
||||
return static_cast<ENUM_TYPE>( \
|
||||
static_cast<std::underlying_type_t<ENUM_TYPE>>(lhs) << shift \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
constexpr ENUM_TYPE operator>>( \
|
||||
ENUM_TYPE& lhs, \
|
||||
ENUM_TYPE lhs, \
|
||||
int shift \
|
||||
) { \
|
||||
return static_cast<ENUM_TYPE>( \
|
||||
|
||||
@@ -146,5 +146,5 @@ private:
|
||||
}
|
||||
|
||||
container_type m_container;
|
||||
std::shared_mutex m_mutex;
|
||||
mutable std::shared_mutex m_mutex;
|
||||
};
|
||||
@@ -8,18 +8,24 @@ namespace ztu
|
||||
template<typename Index, int ID>
|
||||
class id_type
|
||||
{
|
||||
private:
|
||||
explicit constexpr id_type(Index index) : index{ index } {}
|
||||
|
||||
Index index{};
|
||||
|
||||
public:
|
||||
static constexpr id_type next()
|
||||
{
|
||||
static std::atomic<Index> next_index{ 1 };
|
||||
return id_type{ next_index.fetch_add(1, std::memory_order_seq_cst) };
|
||||
}
|
||||
|
||||
Index index{};
|
||||
|
||||
public:
|
||||
constexpr id_type() = default;
|
||||
constexpr id_type(const id_type& other) : index{ other.index } {}
|
||||
constexpr id_type(id_type&& other) noexcept : index{ other.index } {}
|
||||
constexpr id_type& operator=(const id_type& other) { index = other.index; return *this; }
|
||||
constexpr id_type& operator=(id_type&& other) noexcept { index = other.index; return *this; }
|
||||
|
||||
constexpr auto operator<=>(const id_type&) const = default;
|
||||
|
||||
constexpr operator bool() const
|
||||
|
||||
24
include/util/vector_hash.hpp
Normal file
24
include/util/vector_hash.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
#include <memory>
|
||||
|
||||
// Hash function for Eigen matrix and vector.
|
||||
// The code is from `hash_combine` function of the Boost library. See
|
||||
// http://www.boost.org/doc/libs/1_55_0/doc/html/hash/reference.html#boost.hash_combine .
|
||||
|
||||
template<glm::length_t L, typename T, glm::qualifier Q>
|
||||
struct std::hash<glm::vec<L, T, Q>>
|
||||
{
|
||||
auto operator() (const glm::vec<L, T, Q>& key) const
|
||||
{
|
||||
auto seed = std::size_t{};
|
||||
|
||||
for (glm::length_t i{}; i != L; ++i)
|
||||
{
|
||||
seed ^= std::hash<T>{}(key[i]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user