25 using CT = component_type_t<T>;
26 using U =
typename component_type_t<T>::Type;
27 using DescU =
typename CT::TypeFull;
29 static ComponentDescId id() {
30 return meta::type_info::id<DescU>();
34 return {meta::type_info::hash<DescU>()};
37 static constexpr auto name() {
38 return meta::type_info::name<DescU>();
41 static constexpr uint32_t size() {
42 if constexpr (std::is_empty_v<U>)
45 return (uint32_t)
sizeof(U);
48 static constexpr uint32_t alig() {
50 static_assert(alig < Component::MaxAlignment,
"Maximum supported alignment for a component is MaxAlignment");
55 if constexpr (mem::is_soa_layout_v<U>) {
57 using TTuple =
decltype(meta::struct_to_tuple(std::declval<U>()));
59 constexpr auto TTupleSize = std::tuple_size_v<TTuple>;
60 static_assert(TTupleSize > 0);
61 static_assert(TTupleSize <= meta::StructToTupleMaxTypes);
62 core::each_tuple<TTuple>([&](
auto&& item) {
63 static_assert(
sizeof(item) <= 255,
"Each member of a SoA component can be at most 255 B long!");
64 soaSizes[i] = (uint8_t)
sizeof(item);
67 GAIA_ASSERT(i <= meta::StructToTupleMaxTypes);
74 static constexpr auto func_ctor() {
75 if constexpr (!mem::is_soa_layout_v<U> && !std::is_trivially_constructible_v<U>) {
76 return [](
void* ptr, uint32_t cnt) {
77 core::call_ctor_n((U*)ptr, cnt);
84 static constexpr auto func_dtor() {
85 if constexpr (!mem::is_soa_layout_v<U> && !std::is_trivially_destructible_v<U>) {
86 return [](
void* ptr, uint32_t cnt) {
87 core::call_dtor_n((U*)ptr, cnt);
94 static constexpr auto func_copy_ctor() {
95 return [](
void* GAIA_RESTRICT dst,
const void* GAIA_RESTRICT src, uint32_t idxDst, uint32_t idxSrc,
96 uint32_t sizeDst, uint32_t sizeSrc) {
97 mem::copy_ctor_element<U>((uint8_t*)dst, (
const uint8_t*)src, idxDst, idxSrc, sizeDst, sizeSrc);
101 static constexpr auto func_move_ctor() {
102 return [](
void* GAIA_RESTRICT dst,
void* GAIA_RESTRICT src, uint32_t idxDst, uint32_t idxSrc,
103 uint32_t sizeDst, uint32_t sizeSrc) {
104 mem::move_ctor_element<U>((uint8_t*)dst, (uint8_t*)src, idxDst, idxSrc, sizeDst, sizeSrc);
108 static constexpr auto func_copy() {
109 return [](
void* GAIA_RESTRICT dst,
const void* GAIA_RESTRICT src, uint32_t idxDst, uint32_t idxSrc,
110 uint32_t sizeDst, uint32_t sizeSrc) {
111 mem::copy_element<U>((uint8_t*)dst, (
const uint8_t*)src, idxDst, idxSrc, sizeDst, sizeSrc);
115 static constexpr auto func_move() {
116 return [](
void* GAIA_RESTRICT dst,
void* GAIA_RESTRICT src, uint32_t idxDst, uint32_t idxSrc,
117 uint32_t sizeDst, uint32_t sizeSrc) {
118 mem::move_element<U>((uint8_t*)dst, (uint8_t*)src, idxDst, idxSrc, sizeDst, sizeSrc);
122 static constexpr auto func_swap() {
123 return [](
void* GAIA_RESTRICT left,
void* GAIA_RESTRICT right, uint32_t idxLeft, uint32_t idxRight,
124 uint32_t sizeLeft, uint32_t sizeRight) {
125 mem::swap_elements<U>((uint8_t*)left, (uint8_t*)right, idxLeft, idxRight, sizeLeft, sizeRight);
129 static constexpr auto func_cmp() {
130 if constexpr (mem::is_soa_layout_v<U>) {
131 return []([[maybe_unused]]
const void* left, [[maybe_unused]]
const void* right) {
132 GAIA_ASSERT(
false &&
"func_cmp for SoA not implemented yet");
138 if constexpr (hasGlobalCmp || hasMemberCmp) {
139 return [](
const void* left,
const void* right) {
140 const auto* l = (
const U*)left;
141 const auto* r = (
const U*)right;
146 return [](
const void* left,
const void* right) {
147 const auto* l = (
const U*)left;
148 const auto* r = (
const U*)right;
149 return memcmp(l, r,
sizeof(U)) == 0;
155 static constexpr auto func_save() {
156 return [](
ser::ISerializer* pSer,
const void* pSrc, uint32_t from, uint32_t to, uint32_t cap) {
157 const auto* pComponent = (
const U*)pSrc;
159#if GAIA_ASSERT_ENABLED
161 pSer->check(*pComponent);
164 if constexpr (mem::is_soa_layout_v<U>) {
166 GAIA_FOR2(from, to) {
172 GAIA_FOR2(from, to) {
173 pSer->save(*pComponent);
180 static constexpr auto func_load() {
181 return [](
ser::ISerializer* pSer,
void* pDst, uint32_t from, uint32_t to, uint32_t cap) {
182 if constexpr (mem::is_soa_layout_v<U>) {
184 GAIA_FOR2(from, to) {
190 auto* pComponent = (U*)pDst + from;
191 GAIA_FOR2(from, to) {
192 pSer->load(*pComponent);