@@ -291,10 +291,73 @@ namespace ECS
291
291
LOG (" [ECS][Archetype] Move assigning {} from {}" , (void *)(this ), (void *)(&p_other));
292
292
return *this ;
293
293
}
294
+ // Copy-construct
295
+ Archetype (const Archetype& p_other)
296
+ : m_bitset{p_other.m_bitset }
297
+ , m_components{p_other.m_components }
298
+ , m_is_serialisable{p_other.m_is_serialisable }
299
+ , m_entities{p_other.m_entities }
300
+ , m_instance_size{p_other.m_instance_size }
301
+ , m_next_instance_ID{p_other.m_next_instance_ID }
302
+ , m_capacity{p_other.m_capacity }
303
+ , m_data{(std::byte*)malloc (m_instance_size * m_capacity)}
304
+ {
305
+ // Copy construct all the components from p_other into this.
306
+ if (p_other.m_data != nullptr )
307
+ {
308
+ for (ArchetypeInstanceID instance = 0 ; instance < m_next_instance_ID; instance++)
309
+ {
310
+ const auto instance_start = m_instance_size * instance;
294
311
295
- // No copying archetypes
296
- Archetype (const Archetype& p_other) = delete ;
297
- Archetype& operator =(const Archetype& p_other) = delete ;
312
+ for (const auto & comp : m_components)
313
+ {
314
+ const auto address_offset = instance_start + comp.offset ;
315
+ comp.type_info .CopyConstruct (&m_data[address_offset], &p_other.m_data [address_offset]);
316
+ }
317
+ }
318
+ }
319
+
320
+ LOG (" [ECS][Archetype] Copy constructed {} from {}" , (void *)(this ), (void *)(&p_other));
321
+ }
322
+ // Copy-assign
323
+ Archetype& operator =(const Archetype& p_other)
324
+ {
325
+ if (this != &p_other)
326
+ {
327
+ if (m_data != nullptr )
328
+ {
329
+ clear ();
330
+ free (m_data);
331
+ }
332
+
333
+ m_bitset = p_other.m_bitset ;
334
+ m_components = p_other.m_components ;
335
+ m_is_serialisable = p_other.m_is_serialisable ;
336
+ m_entities = p_other.m_entities ;
337
+ m_instance_size = p_other.m_instance_size ;
338
+ m_next_instance_ID = p_other.m_next_instance_ID ;
339
+ m_capacity = p_other.m_capacity ;
340
+ m_data = (std::byte*)malloc (m_instance_size * m_capacity);
341
+
342
+ // Copy construct all the components from p_other into this.
343
+ if (p_other.m_data != nullptr )
344
+ {
345
+ for (ArchetypeInstanceID instance = 0 ; instance < m_next_instance_ID; instance++)
346
+ {
347
+ const auto instance_start = m_instance_size * instance;
348
+
349
+ for (const auto & comp : m_components)
350
+ {
351
+ const auto address_offset = instance_start + comp.offset ;
352
+ comp.type_info .CopyConstruct (&m_data[address_offset], &p_other.m_data [address_offset]);
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ LOG (" [ECS][Archetype] Copy assigned {} from {}" , (void *)(this ), (void *)(&p_other));
359
+ return *this ;
360
+ }
298
361
299
362
// Search the m_components vector for the p_component_ID and return its ComponentLayout.
300
363
// Non-template version (when we know the ComponentID but not the Type).
@@ -450,7 +513,7 @@ namespace ECS
450
513
// Size is 0 after clear.
451
514
void clear ()
452
515
{
453
- for (size_t instance = 0 ; instance < m_next_instance_ID; instance++)
516
+ for (ArchetypeInstanceID instance = 0 ; instance < m_next_instance_ID; instance++)
454
517
{
455
518
const auto instance_start = m_instance_size * instance;
456
519
0 commit comments