fixes
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user