This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_library_buffer.hpp"
using dynamic_material_library_store = generic_dynamic_store<dynamic_material_library_buffer>;

View File

@@ -0,0 +1,37 @@
#pragma once
#include "dynamic_texture_store.hpp"
#include "generic/generic_dynamic_component_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_buffer.hpp"
class dynamic_material_store {
using store_type = generic_dynamic_component_store<
components::material::flags,
components::material::surface_properties,
components::material::transparency,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_material_buffer& data);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
private:
store_type m_store;
};

View File

@@ -0,0 +1,37 @@
#pragma once
#include "assets/dynamic_data_stores/generic/generic_dynamic_indexed_component_array_store.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_mesh_buffer.hpp"
class dynamic_mesh_store
{
using store_type = generic_dynamic_indexed_component_array_store<
components::mesh_vertex::flags,
ztu::u32,
components::mesh_vertex::position,
components::mesh_vertex::normal,
components::mesh_vertex::tex_coord,
components::mesh_vertex::color,
components::mesh_vertex::reflectance
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_mesh_buffer& mesh_buffer);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
private:
store_type m_store;
};

View File

@@ -0,0 +1,36 @@
#pragma once
#include "assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp"
class dynamic_point_cloud_store
{
using store_type = generic_dynamic_component_array_store<
components::point_cloud_vertex::flags,
components::point_cloud_vertex::position,
components::point_cloud_vertex::normal,
components::point_cloud_vertex::color,
components::point_cloud_vertex::reflectance
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_point_cloud_buffer& point_cloud_buffer);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
private:
store_type m_store;
};

View File

@@ -0,0 +1,6 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "glm/mat4x4.hpp"
using dynamic_pose_store = generic_dynamic_store<glm::mat4>;

View File

@@ -0,0 +1,9 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "glm/mat4x4.hpp"
class dynamic_shader_store {
};

View File

@@ -0,0 +1,6 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp"
using dynamic_texture_store = generic_dynamic_store<dynamic_texture_buffer>;

View File

@@ -0,0 +1,37 @@
#pragma once
#include <tuple>
#include <vector>
#include <span>
#include "util/id_type.hpp"
#include "util/uix.hpp"
#include "GL/glew.h"
template<typename C, typename... Ts>
class dynamic_vertex_store {
public:
using id_type = ztu::id_type_for<dynamic_vertex_store, ztu::u32>;
void add(
C component_flags,
std::span<const Ts>... components
);
void build_vertex_buffer(
std::vector<ztu::u8>& vertex_buffer,
std::size_t& component_count,
std::array<GLenum, sizeof...(Ts)>& component_types,
std::array<GLint, sizeof...(Ts)>& component_lengths,
GLsizei& stride
) const;
protected:
std::tuple<std::vector<Ts>...> m_component_buffers{};
std::vector<std::size_t> vertex_counts;
std::vector<C> m_components{ 0 };
};
#define INCLUDE_DYNAMIC_MODEL_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_model_buffer.ipp"
#undef INCLUDE_DYNAMIC_MODEL_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,149 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename... Ts>
class generic_dynamic_component_array_store;
template<typename C, typename... Ts>
class component_array_iterator {
public:
using value_type = std::tuple<std::span<Ts>...>;
using size_type = std::size_t;
using count_type = ztu::u32;
using flag_count_type = std::pair<C, count_type>;
using component_array_pointer_type = std::tuple<std::add_pointer_t<Ts>...>;
using flag_count_pointer_type = const flag_count_type*;
using offsets_type = std::array<size_type, sizeof...(Ts)>;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type;
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_dynamic_component_array_store<C, Ts...>;
component_array_iterator(
component_array_pointer_type components,
flag_count_pointer_type flags,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr component_array_iterator() noexcept = default;
constexpr component_array_iterator(const component_array_iterator&) noexcept = default;
constexpr component_array_iterator(component_array_iterator&&) noexcept = default;
constexpr component_array_iterator& operator=(const component_array_iterator&) noexcept = default;
constexpr component_array_iterator& operator=(component_array_iterator&&) noexcept = default;
reference operator*() const;
component_array_iterator& operator++();
component_array_iterator operator++(int);
component_array_iterator& operator--();
component_array_iterator operator--(int);
component_array_iterator& operator+=(difference_type n);
component_array_iterator& operator-=(difference_type n);
component_array_iterator operator+(difference_type n) const;
component_array_iterator operator-(difference_type n) const;
difference_type operator-(const component_array_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const component_array_iterator& other) const;
bool operator!=(const component_array_iterator& other) const;
bool operator<(const component_array_iterator& other) const;
bool operator<=(const component_array_iterator& other) const;
bool operator>(const component_array_iterator& other) const;
bool operator>=(const component_array_iterator& other) const;
protected:
template <std::size_t I>
static bool is_component_enabled(C flag);
template <std::size_t... Is>
void calc_offsets(std::index_sequence<Is...>, difference_type n);
template <std::size_t... Is>
reference dereference(std::index_sequence<Is...>) const;
template <std::size_t N>
std::tuple_element_t<N, value_type> get_span() const;
private:
value_type m_components{};
const flag_count_type* m_flag_counts{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename... Ts>
class generic_dynamic_component_array_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_component_array_store, ztu::u32>;
using count_type = ztu::u32;
using iterator_type = component_array_iterator<C, Ts...>;
using const_iterator = component_array_iterator<C, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(const std::tuple<std::vector<Ts>...>& component_arrays);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
iterator_type begin();
iterator_type end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
std::tuple<std::add_pointer_t<Ts>...> data_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> data_ptrs() const;
std::array<std::size_t, sizeof...(Ts)> data_counts() const;
private:
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<std::pair<C, ztu::u32>> m_component_flag_counts;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_COMPONENT_ARRAY_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_COMPONENT_ARRAY_STORE_IMPLEMENTATION

View File

@@ -0,0 +1,147 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename... Ts>
class generic_dynamic_component_store;
template<typename C, typename... Ts>
class component_iterator {
public:
using value_type = std::tuple<std::add_pointer_t<Ts>...>;
using size_type = std::size_t;
using offsets_type = std::array<size_type, sizeof...(Ts)>;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type;
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_dynamic_component_store<C, Ts...>;
component_iterator(
value_type components,
const C* flags,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr component_iterator() noexcept = default;
constexpr component_iterator(const component_iterator&) noexcept = default;
constexpr component_iterator(component_iterator&&) noexcept = default;
constexpr component_iterator& operator=(const component_iterator&) noexcept = default;
constexpr component_iterator& operator=(component_iterator&&) noexcept = default;
reference operator*() const;
component_iterator& operator++();
component_iterator operator++(int);
component_iterator& operator--();
component_iterator operator--(int);
component_iterator& operator+=(difference_type n);
component_iterator& operator-=(difference_type n);
component_iterator operator+(difference_type n) const;
component_iterator operator-(difference_type n) const;
difference_type operator-(const component_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const component_iterator& other) const;
bool operator!=(const component_iterator& other) const;
bool operator<(const component_iterator& other) const;
bool operator<=(const component_iterator& other) const;
bool operator>(const component_iterator& other) const;
bool operator>=(const component_iterator& other) const;
protected:
template <std::size_t I>
static bool is_component_enabled(C flag);
template <std::size_t... Is>
void calc_offsets(std::index_sequence<Is...>, difference_type n);
template <std::size_t... Is>
reference dereference(std::index_sequence<Is...>) const;
template <std::size_t N>
std::tuple_element_t<N, value_type> get_pointer() const;
private:
value_type m_components{};
const C* m_flags{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename... Ts>
class generic_dynamic_component_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_component_store, ztu::u32>;
using iterator_type = component_iterator<C, Ts...>;
using const_iterator = component_iterator<C, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(const std::tuple<std::optional<Ts>...>& data);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
iterator_type begin();
iterator_type end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
std::tuple<std::add_pointer_t<Ts>...> data_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> data_ptrs() const;
std::array<std::size_t, sizeof...(Ts)> data_counts() const;
private:
std::tuple<std::vector<Ts>...> m_components;
std::vector<C> m_component_flags;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_COMPONENT_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic_dynamic_component_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_COMPONENT_STORE_IMPLEMENTATION

View File

@@ -0,0 +1,157 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename I, typename... Ts>
class generic_dynamic_indexed_component_array_store;
template<typename C, typename I, typename... Ts>
class indexed_component_array_iterator {
public:
using index_type = I;
using value_type = std::tuple<std::span<I>, std::span<Ts>...>;
using size_type = std::size_t;
using count_type = ztu::u32;
using flag_count_type = std::tuple<C, count_type, count_type>;
using index_array_pointer_type = const index_type*;
using component_array_pointer_type = std::tuple<std::add_pointer_t<Ts>...>;
using flag_count_pointer_type = const flag_count_type*;
using offsets_type = std::array<size_type, 1 + sizeof...(Ts)>;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type;
using iterator_category = std::random_access_iterator_tag;
private:
friend generic_dynamic_indexed_component_array_store<C, I, Ts...>;
indexed_component_array_iterator(
index_array_pointer_type indices,
const component_array_pointer_type& components,
flag_count_pointer_type flag_counts,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr indexed_component_array_iterator() noexcept = default;
constexpr indexed_component_array_iterator(const indexed_component_array_iterator&) noexcept = default;
constexpr indexed_component_array_iterator(indexed_component_array_iterator&&) noexcept = default;
constexpr indexed_component_array_iterator& operator=(const indexed_component_array_iterator&) noexcept = default;
constexpr indexed_component_array_iterator& operator=(indexed_component_array_iterator&&) noexcept = default;
reference operator*() const;
indexed_component_array_iterator& operator++();
indexed_component_array_iterator operator++(int);
indexed_component_array_iterator& operator--();
indexed_component_array_iterator operator--(int);
indexed_component_array_iterator& operator+=(difference_type n);
indexed_component_array_iterator& operator-=(difference_type n);
indexed_component_array_iterator operator+(difference_type n) const;
indexed_component_array_iterator operator-(difference_type n) const;
difference_type operator-(const indexed_component_array_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const indexed_component_array_iterator& other) const;
bool operator!=(const indexed_component_array_iterator& other) const;
bool operator<(const indexed_component_array_iterator& other) const;
bool operator<=(const indexed_component_array_iterator& other) const;
bool operator>(const indexed_component_array_iterator& other) const;
bool operator>=(const indexed_component_array_iterator& other) const;
protected:
template <std::size_t N>
static bool is_component_enabled(C flag);
template <std::size_t... Is>
void calc_offsets(std::index_sequence<Is...>, difference_type n);
template <std::size_t... Is>
reference dereference(std::index_sequence<Is...>) const;
private:
index_array_pointer_type m_indices{};
component_array_pointer_type m_components{};
flag_count_pointer_type m_flag_counts{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename I, typename... Ts>
class generic_dynamic_indexed_component_array_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_indexed_component_array_store, ztu::u32>;
using count_type = ztu::u32;
using iterator_type = indexed_component_array_iterator<C, I, Ts...>;
using const_iterator = indexed_component_array_iterator<C, I, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(
std::span<const I> indices,
const std::tuple<std::vector<Ts>...>& component_arrays
);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
void remove(const iterator_type& it);
void clear();
iterator_type begin();
iterator_type end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
std::tuple<std::add_pointer_t<Ts>...> component_array_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_array_ptrs() const;
std::array<std::size_t, 1 + sizeof...(Ts)> array_counts() const;
private:
std::vector<I> m_indices;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<std::pair<C, ztu::u32>> m_component_flag_counts;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_INDEXED_COMPONENT_ARRAY_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic/generic_dynamic_indexed_component_array_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_INDEXED_COMPONENT_ARRAY_STORE_IMPLEMENTATION

View File

@@ -0,0 +1,40 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
template<typename T>
class generic_dynamic_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_store, ztu::u32>;
using container_type = std::vector<T>;
using iterator_type = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
id_type add(const T& data);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
[[nodiscard]] std::span<T> data();
[[nodiscard]] std::span<const T> data() const;
void remove(iterator_type it);
void clear();
private:
std::vector<T> m_data;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic_dynamic_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_STORE_IMPLEMENTATION