Made assets::data_stores thread safe.

This commit is contained in:
zy4n
2025-03-31 20:13:26 +02:00
parent 144126ee7a
commit 0acfe36118
39 changed files with 1772 additions and 1069 deletions

View File

@@ -10,6 +10,8 @@ namespace assets::mesh_vertex_components
using position = z3d::vec3;
using normal = z3d::vec3;
using tangent = z3d::vec3;
using bi_tangent = z3d::vec3;
using tex_coord = z3d::vec2;
using color = z3d::vec3;
using reflectance = z3d::f32;
@@ -20,6 +22,8 @@ enum : z3d::size
{
position,
normal,
tangent,
bi_tangent,
tex_coord,
color,
reflectance
@@ -31,6 +35,8 @@ enum class flags : z3d::u8
none = 0,
position = 1 << indices::position,
normal = 1 << indices::normal,
tangent = 1 << indices::tangent,
bi_tangent = 1 << indices::bi_tangent,
tex_coord = 1 << indices::tex_coord,
color = 1 << indices::color,
reflectance = 1 << indices::reflectance

View File

@@ -4,16 +4,19 @@
namespace assets::detail {
template<typename T>
template<typename C, typename T>
class component_set {};
template<typename... Ts>
class component_set<z3d::structure<Ts...>>
template<typename C, typename... Ts>
class component_set<C, z3d::structure<Ts...>>
{
public:
component_set() = default;
C component_flags{};
z3d::structure<z3d::optional<Ts...>> components{};
protected:
void clear_components()
{
@@ -25,8 +28,6 @@ protected:
components
);
}
z3d::structure<z3d::optional<Ts...>> components{};
};
}

View File

@@ -6,8 +6,10 @@
namespace assets
{
struct material_data : detail::component_set<material_components::all>
{
struct material_data : public detail::component_set<
material_components::flags,
material_components::all
> {
material_data() = default;
@@ -16,9 +18,9 @@ struct material_data : detail::component_set<material_components::all>
[[nodiscard]] inline z3d::optional<material_components::specular_filter>& specular_filter();
[[nodiscard]] inline z3d::optional<material_components::shininess>& shininess();
[[nodiscard]] inline z3d::optional<material_components::alpha>& alpha();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter_texture>& ambient_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::shininess_texture>& shininess_texture_id();
[[nodiscard]] inline z3d::optional<material_components::alpha_texture>& alpha_texture_id();
[[nodiscard]] inline z3d::optional<material_components::bump_texture>& bump_texture_id();
@@ -28,10 +30,9 @@ struct material_data : detail::component_set<material_components::all>
[[nodiscard]] inline const z3d::optional<material_components::specular_filter>& specular_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess>& shininess() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& alpha() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& transparency() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter_texture>& ambient_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess_texture>& shininess_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha_texture>& alpha_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::bump_texture>& bump_texture_id() const;

View File

@@ -7,7 +7,7 @@
namespace assets
{
class mesh_data : detail::component_array_set<
class mesh_data : public detail::component_array_set<
mesh_vertex_components::flags,
mesh_vertex_components::all
> {
@@ -19,7 +19,7 @@ public:
[[nodiscard]] inline z3d::vector<mesh_vertex_components::color>& colors();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::reflectance>& reflectances();
[[nodiscard]] inline z3d::vector<z3d::index_triangle>& triangles();
[[nodiscard]] inline auto& material();
[[nodiscard]] inline material_id& material();
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::position>& positions() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::normal>& normals() const;
@@ -27,7 +27,7 @@ public:
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::color>& colors() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::reflectance>& reflectances() const;
[[nodiscard]] inline const z3d::vector<z3d::index_triangle>& triangles() const;
[[nodiscard]] inline const auto& material() const;
[[nodiscard]] inline const material_id& material() const;
inline void clear();

View File

@@ -18,6 +18,8 @@ struct shader_source_data
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
bool operator==(const metadata& meta) const = default;
} meta;
void clear()

View File

@@ -9,7 +9,7 @@
#include "util/string_list.hpp"
#include "assets/file_parsers/mtl_loader.hpp"
#include "assets/file_parsers/mtl_parser.hpp"
// TODO not implemented?!?
namespace assets
@@ -17,7 +17,7 @@ namespace assets
class material_library_loader : public base_dynamic_loader<
material_components::flags,
mtl_loader
mtl_parser
> {
public:

View File

@@ -1,38 +1,135 @@
#pragma once
#include <vector>
#include <span>
#include <mutex>
#include <shared_mutex>
#include "util/uix.hpp"
#include "util/id_type.hpp"
namespace assets::detail {
template<typename ID, typename T>
class generic_basic_store;
template<typename ID, typename T>
class generic_basic_store_iterator
{
public:
using size_type = std::size_t;
using id_type = ID;
using data_type = T;
using value_type = std::pair<id_type, data_type>;
using id_iterator_type = const id_type*;
using data_iterator_type = data_type*;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = std::pair<id_type, data_type&>;
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_basic_store<ID, T>;
generic_basic_store_iterator(
id_iterator_type ids,
data_iterator_type data,
std::size_t index
);
public:
constexpr generic_basic_store_iterator() noexcept = default;
constexpr generic_basic_store_iterator(const generic_basic_store_iterator&) noexcept = default;
constexpr generic_basic_store_iterator(generic_basic_store_iterator&&) noexcept = default;
constexpr generic_basic_store_iterator& operator=(const generic_basic_store_iterator&) noexcept = default;
constexpr generic_basic_store_iterator& operator=(generic_basic_store_iterator&&) noexcept = default;
reference operator*() const;
generic_basic_store_iterator& operator++();
generic_basic_store_iterator operator++(int);
generic_basic_store_iterator& operator--();
generic_basic_store_iterator operator--(int);
generic_basic_store_iterator& operator+=(difference_type n);
generic_basic_store_iterator& operator-=(difference_type n);
generic_basic_store_iterator operator+(difference_type n) const;
generic_basic_store_iterator operator-(difference_type n) const;
difference_type operator-(const generic_basic_store_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const generic_basic_store_iterator& other) const;
bool operator!=(const generic_basic_store_iterator& other) const;
bool operator<(const generic_basic_store_iterator& other) const;
bool operator<=(const generic_basic_store_iterator& other) const;
bool operator>(const generic_basic_store_iterator& other) const;
bool operator>=(const generic_basic_store_iterator& other) const;
protected:
reference dereference() const;
private:
id_iterator_type m_ids{};
data_iterator_type m_data{};
size_type m_index{};
};
template<typename ID, typename T>
class generic_basic_store
{
public:
using id_type = ID;
using container_type = std::vector<T>;
using iterator_type = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
using iterator = generic_basic_store_iterator<ID, T>;
using const_iterator = generic_basic_store_iterator<std::add_const_t<T>...>;
ID add(const T& data);
using size_type = std::size_t;
using data_type = T;
[[nodiscard]] std::pair<iterator_type, bool> find(ID id);
bool insert(ID id, const T& data);
[[nodiscard]] std::pair<const_iterator, bool> find(ID id) const;
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::span<T> data();
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
[[nodiscard]] std::span<const T> data() const;
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(iterator_type it);
void remove(iterator it);
void clear();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
protected:
bool unsafe_insert(iterator it, ID id, const T& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(ID id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(ID id) const;
private:
std::vector<T> m_data;
std::vector<ID> m_ids;
std::vector<T> m_data;
mutable std::shared_mutex m_mutex;
};
}
#define INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION
#include "assets/data_stores/generic/generic_basic_store.ipp"
#undef INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION

View File

@@ -3,12 +3,13 @@
#include "assets/components/material_components.hpp"
#include "assets/data/material_data.hpp"
#include "assets/data_views/material_view.hpp"
#include <mutex>
#include <shared_mutex>
namespace assets::detail
{
template<typename... Ts>
template<typename T>
class generic_material_store;
template<typename... Ts>
@@ -33,7 +34,7 @@ public:
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_material_store<Ts...>;
friend generic_material_store<z3d::structure<Ts...>>;
generic_material_store_iterator(
id_iterator_type ids,
@@ -94,32 +95,37 @@ private:
template<typename... Ts>
class generic_material_store
class generic_material_store<z3d::structure<Ts...>>
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using component_flag_type = material_components::flags;
using data_type = material_data;
using iterator_type = generic_material_store_iterator<Ts...>;
using iterator = generic_material_store_iterator<Ts...>;
using const_iterator = generic_material_store_iterator<std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
using id_type = material_id;
id_type add(const material_data& material);
bool insert(id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void remove(const iterator& it);
void clear();
iterator_type begin();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
iterator_type end();
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
iterator begin();
iterator end();
const_iterator begin() const;
@@ -129,11 +135,13 @@ public:
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
bool unsafe_insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
@@ -144,6 +152,7 @@ private:
std::vector<id_type> m_ids;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<component_flag_type> m_component_flag_counts;
mutable std::shared_mutex m_mutex;
};
}

View File

@@ -1,5 +1,8 @@
#pragma once
#include <mutex>
#include <shared_mutex>
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/data_stores/material_store.hpp"
#include "assets/data/mesh_data.hpp"
@@ -8,7 +11,7 @@
namespace assets::detail
{
template<typename... Ts>
template<typename T>
class generic_mesh_store;
template<typename... Ts>
@@ -17,7 +20,7 @@ class generic_mesh_store_iterator
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using index_type = z3d::vertex_index;
using triangle_type = z3d::index_triangle;
using material_id_type = material_store::id_type;
using component_flag_type = mesh_vertex_components::flags;
using id_type = mesh_id;
@@ -26,7 +29,7 @@ public:
using id_iterator_type = id_type*;
using component_iterator_type = std::tuple<std::add_pointer_t<Ts>...>;
using index_iterator_type = index_type*;
using triangle_iterator_type = triangle_type*;
using flag_count_iterator_type = const flag_count_type*;
using material_id_iterator_type = material_id_type*;
@@ -37,11 +40,11 @@ public:
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_mesh_store<Ts...>;
friend generic_mesh_store<z3d::structure<Ts...>>;
generic_mesh_store_iterator(
id_iterator_type ids,
index_iterator_type indices,
triangle_iterator_type triangles,
const component_iterator_type& components,
material_id_iterator_type material_ids,
flag_count_iterator_type flag_counts,
@@ -92,7 +95,7 @@ protected:
private:
id_iterator_type m_ids{};
index_iterator_type m_indices{};
triangle_iterator_type m_triangles{};
component_iterator_type m_components{};
material_id_iterator_type m_material_ids{};
flag_count_iterator_type m_flag_counts{};
@@ -102,34 +105,39 @@ private:
template<typename... Ts>
class generic_mesh_store
class generic_mesh_store<z3d::structure<Ts...>>
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using index_type = z3d::vertex_index;
using triangle_type = z3d::index_triangle;
using component_flag_type = mesh_vertex_components::flags;
using material_id_type = material_store::id_type;
using iterator_type = generic_mesh_store_iterator<Ts...>;
using const_iterator = generic_mesh_store_iterator<std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
using material_id_type = material_id;
using data_type = mesh_data;
using id_type = mesh_id;
id_type add(const mesh_data& mesh);
using iterator = generic_mesh_store_iterator<Ts...>;
using const_iterator = generic_mesh_store_iterator<std::add_const_t<Ts>...>;
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
bool insert(id_type id, const data_type& data);
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void remove(const iterator& it);
void clear();
iterator_type begin();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
iterator_type end();
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
iterator begin();
iterator end();
const_iterator begin() const;
@@ -139,11 +147,12 @@ public:
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
bool unsafe_insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
@@ -152,11 +161,11 @@ protected:
private:
std::vector<id_type> m_ids;
std::vector<index_type> m_indices;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<triangle_type> m_triangles;
std::vector<std::tuple<component_flag_type, count_type, count_type>> m_component_flag_counts;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<material_store::id_type> m_material_ids;
id_type m_next_data_id{ 1 };
mutable std::shared_mutex m_mutex{};
};
}

View File

@@ -1,19 +1,19 @@
#pragma once
#include <mutex>
#include <shared_mutex>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/data/point_cloud_data.hpp"
#include "assets/data_views/point_cloud_view.hpp"
namespace assets
namespace assets::detail
{
template<typename... Ts>
template<typename T>
class generic_point_cloud_store;
namespace detail
{
template<typename... Ts>
class generic_point_cloud_store_iterator
@@ -37,13 +37,13 @@ public:
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_point_cloud_store<Ts...>;
friend generic_point_cloud_store<z3d::structure<Ts...>>;
generic_point_cloud_store_iterator(
id_iterator_type ids,
const component_iterator_type& components,
flag_count_iterator_type flag_counts,
std::size_t index,
size_type index,
const offsets_type& offsets
);
@@ -98,31 +98,37 @@ private:
template<typename... Ts>
class generic_point_cloud_store
class generic_point_cloud_store<z3d::structure<Ts...>>
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using component_flag_type = point_cloud_vertex_components::flags;
using data_type = point_cloud_data;
using iterator_type = generic_point_cloud_store_iterator<Ts...>;
using const_iterator = generic_point_cloud_store_iterator<std::add_const_t<Ts>...>;
using id_type = point_cloud_id;
using data_type = point_cloud_data;
id_type add(id_type id, const data_type& point_cloud);
using iterator = generic_point_cloud_store_iterator<Ts...>;
using const_iterator = generic_point_cloud_store_iterator<std::add_const_t<Ts>...>;
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
bool insert(id_type id, const data_type& data);
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void remove(const iterator& it);
void clear();
iterator_type begin();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
iterator_type end();
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
iterator begin();
iterator end();
const_iterator begin() const;
@@ -133,6 +139,12 @@ public:
const_iterator cend() const;
protected:
bool unsafe_insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
@@ -143,12 +155,11 @@ private:
std::vector<id_type> m_ids;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<std::pair<component_flag_type, count_type>> m_component_flag_counts;
id_type m_next_data_id{ 1 };
mutable std::shared_mutex m_mutex;
};
}
}
#define INCLUDE_GENERIC_POINT_CLOUD_STORE_IMPLEMENTATION

View File

@@ -1,11 +1,12 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/identifiers.hpp"
#include "assets/data/material_library_data.hpp"
namespace assets
{
using material_library_store = generic_basic_store<material_library_data>;
using material_library_store = detail::generic_basic_store<material_library_id, material_library_data>;
}

View File

@@ -5,15 +5,6 @@
namespace assets
{
using material_store = detail::generic_material_store<
material_components::surface_properties,
material_components::alpha,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type
>;
using material_store = detail::generic_material_store<material_components::all>;
}

View File

@@ -6,11 +6,7 @@ namespace assets
{
using mesh_store = detail::generic_mesh_store<
mesh_vertex_components::position,
mesh_vertex_components::normal,
mesh_vertex_components::tex_coord,
mesh_vertex_components::color,
mesh_vertex_components::reflectance
mesh_vertex_components::all
>;
}

View File

@@ -8,10 +8,7 @@ namespace assets
{
using point_cloud_store = detail::generic_point_cloud_store<
point_cloud_vertex_components::position,
point_cloud_vertex_components::normal,
point_cloud_vertex_components::color,
point_cloud_vertex_components::reflectance
point_cloud_vertex_components::all
>;
}

View File

@@ -1,6 +1,8 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include <mutex>
#include <shared_mutex>
#include "assets/identifiers.hpp"
#include "assets/data/pose_list_data.hpp"
#include "assets/data_views/pose_list_view.hpp"
@@ -75,7 +77,7 @@ protected:
void calc_offset(difference_type n);
reference dereference() const;
[[nodiscard]] reference dereference() const;
private:
id_iterator_type m_ids{};
@@ -92,28 +94,30 @@ public:
using size_type = std::size_t;
using count_type = ztu::u32;
using iterator_type = pose_list_store_iterator<char>;
using iterator = pose_list_store_iterator<char>;
using const_iterator = pose_list_store_iterator<const char>;
using data_type = pose_list_data;
using id_type = pose_list_id;
// TODO not storing metadata
inline id_type add(
id_type id,
const data_type& pose_list
);
bool insert(id_type id, const data_type& data);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] inline std::pair<const_iterator, bool> find(id_type id) const;
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
inline void remove(const iterator_type& it);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
inline void remove(const iterator& it);
inline void clear();
[[nodiscard]] inline iterator_type begin();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
[[nodiscard]] inline iterator_type end();
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
[[nodiscard]] inline iterator begin();
[[nodiscard]] inline iterator end();
[[nodiscard]] inline const_iterator begin() const;
@@ -123,11 +127,18 @@ public:
[[nodiscard]] inline const_iterator cend() const;
protected:
bool unsafe_insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
private:
std::vector<id_type> m_ids;
std::vector<char> m_poses;
std::vector<count_type> m_lengths;
mutable std::shared_mutex m_mutex;
};
}

View File

@@ -1,11 +1,12 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/identifiers.hpp"
#include "assets/data/pose_data.hpp"
namespace assets
{
using pose_store = generic_basic_store<pose_data>;
using pose_store = detail::generic_basic_store<pose_id, pose_data>;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include <mutex>
#include <shared_mutex>
#include "assets/data/shader_source_data.hpp"
#include "assets/data_views/shader_source_view.hpp"
@@ -95,29 +96,33 @@ public:
using size_type = std::size_t;
using count_type = ztu::u32;
using iterator_type = shader_source_store_iterator<char>;
using iterator = shader_source_store_iterator<char>;
using const_iterator = shader_source_store_iterator<const char>;
using view_type = std::ranges::subrange<iterator_type>;
using view_type = std::ranges::subrange<iterator>;
using const_view_type = std::ranges::subrange<const_iterator>;
using id_type = shader_source_id;
using data_type = shader_source_data;
// TODO not storing metadata
inline id_type add(
shader_source_id id,
const shader_source_data& shader_source
);
bool insert(id_type id, const data_type& data);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
bool insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] inline std::pair<const_iterator, bool> find(id_type id) const;
[[nodiscard]] std::pair<iterator, bool> find(id_type id);
inline void remove(const iterator_type& it);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
inline void remove(const iterator& it);
inline void clear();
[[nodiscard]] inline iterator_type begin();
[[nodiscard]] inline std::shared_lock<std::shared_mutex> acquire_read_lock() const;
[[nodiscard]] inline iterator_type end();
[[nodiscard]] inline std::unique_lock<std::shared_mutex> acquire_write_lock();
[[nodiscard]] inline iterator begin();
[[nodiscard]] inline iterator end();
[[nodiscard]] inline const_iterator begin() const;
@@ -127,12 +132,19 @@ public:
[[nodiscard]] inline const_iterator cend() const;
protected:
bool unsafe_insert(iterator it, id_type id, const data_type& data);
[[nodiscard]] std::pair<iterator, bool> unsafe_find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> unsafe_find(id_type id) const;
private:
std::vector<id_type> m_ids;
std::vector<char> m_strings;
std::vector<count_type> m_lengths;
std::vector<shader_source_data::metadata> m_metadata;
mutable std::shared_mutex m_mutex;
};
}

View File

@@ -1,12 +1,13 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/identifiers.hpp"
#include "assets/data/texture_data.hpp"
namespace assets
{
using texture_store = generic_basic_store<texture_data>;
using texture_store = detail::generic_basic_store<texture_id, texture_data>;
}

View File

@@ -1,8 +1,7 @@
#pragma once
#include <string_view>
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
#include "assets/data/shader_source_data.hpp"
namespace assets
{
@@ -10,11 +9,7 @@ namespace assets
struct shader_source_view
{
std::string_view source;
model_geometry::types geometry_type;
shader_components::stage stage;
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
shader_source_data::metadata meta;
};
}

View File

@@ -1,60 +0,0 @@
#pragma once
#include <filesystem>
#include <system_error>
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data/material_data.hpp"
#include "assets/data/material_library_data.hpp"
#include "assets/data_stores/material_store.hpp"
#include "assets/data_stores/material_library_store.hpp"
#include "util/result.hpp"
namespace assets
{
namespace mtl_loader_error
{
enum class codes {
ok = 0,
cannot_open_file,
cannot_open_texture,
malformed_ambient_color,
malformed_diffuse_color,
malformed_specular_color,
malformed_specular_exponent,
malformed_dissolve,
unknown_line_begin
};
} // namespace mtl_loader_error
struct mtl_loader
{
static constexpr auto name = std::string_view("mtl");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
// THis is not very elegant, but right now I do not see a better solution...
[[nodiscard]] static std::error_code load(
dynamic_material_library_buffer& material_library_buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
protected:
static void find_textures(
std::span<char> buffer,
std::filesystem::path& path_buffer,
const std::filesystem::path& base_directory,
std::ifstream& in,
ztu::string_list& texture_filenames
);
};
}

View File

@@ -0,0 +1,96 @@
#pragma once
#include <filesystem>
#include <system_error>
#include "assets/data_stores.hpp"
#include "assets/path_id_lookups.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data/material_data.hpp"
#include "assets/data/material_library_data.hpp"
#include "assets/data_stores/material_store.hpp"
#include "assets/data_stores/material_library_store.hpp"
#include "util/result.hpp"
namespace assets
{
namespace mtl_parser_error
{
enum class codes {
ok = 0,
cannot_open_file,
// TODO these are incomplete
cannot_open_texture,
malformed_ambient_color,
malformed_diffuse_color,
malformed_specular_color,
malformed_specular_exponent,
malformed_dissolve,
unknown_line_begin
};
} // namespace mtl_loader_error
struct mtl_parser
{
static constexpr auto name = std::string_view("mtl");
using data_type = material_library_data;
using store_type = material_library_store;
using lookup_type = material_library_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code load(
path_id_lookups& lookups,
data_stores& stores,
bool pedantic = false
);
protected:
class parser_context
{
public:
parser_context(
const texture_id_lookup& texture_id_lookup,
material_id_lookup& material_id_lookup,
material_store& material_store,
store_type& store,
std::mutex& store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
[[nodiscard]] std::optional<texture_id> fetch_texture_id(
const std::filesystem::path& mtl_dir,
std::string_view filename,
std::string_view texture_type_name
);
private:
const texture_id_lookup* m_texture_id_lookup;
material_id_lookup* m_material_id_lookup;
material_store* m_material_store;
store_type* m_store;
std::mutex* m_store_mutex;
data_type m_buffer{};
};
static void find_textures(
std::span<char> buffer,
std::filesystem::path& path_buffer,
const std::filesystem::path& base_directory,
std::ifstream& in,
ztu::string_list& texture_filenames
);
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}