AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
EntityStorage.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/agx.h>
20#include <agx/agxCore_export.h>
21#include <agxData/Buffer.h>
22#include <agxData/EntityModel.h>
23#include <agxData/EntityData.h>
25#include <agxData/LocalVector.h>
26#include <agx/Vector.h>
27#include <agx/HashTable.h>
28#include <agx/Referenced.h>
29#include <agx/Component.h>
30
32#ifdef _MSC_VER
33# pragma warning(push)
34# pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
35#endif
36
38namespace agx
40 class Device;
41 class TiXmlElement;
42 class GlobalResultStorage;
43 class AliasStorage;
44}
45
46namespace agxSDK
47{
48 class SimulationFrameWriter;
49}
50
51namespace agxStream
52{
53 class InputArchive;
54 class OutputArchive;
55}
56
57namespace agxData
58{
60
61
64
73 {
74 public:
76
77 static agxData::EntityStorage *load(agx::TiXmlElement *eStorage, agx::Device *device);
78 virtual void configure(agx::TiXmlElement *eStorage) override;
79
80 public:
81 // Generated event interface, defined in EntityStorage.agxEvent
83
84#ifndef SWIG
85 void addListener(EventListener *listener);
86 void removeListener(EventListener *listener);
87 bool hasListener(EventListener *listener);
88#endif
91
92 public:
93 EntityStorage(agxData::EntityModel *entity, size_t initialCapacity = 32);
94 EntityStorage(agxData::EntityModel *entity, const agx::Name& name, size_t initialCapacity = 32);
95
99 bool empty() const;
100
104 size_t size() const;
105
109 size_t capacity() const;
110
114 size_t getNumBytes() const;
115
119 agxData::EntityModel *getEntityModel();
120 const agxData::EntityModel *getEntityModel() const;
121
125 void reserve(size_t size);
126
130 const agxData::Array<EntityPtr> getInstances() const;
131 agxData::Array<EntityPtr> getInstances();
132
133 template <typename T>
135
136 template <typename T>
138
144
150
151 void resize(size_t size, bool initializeElements = true);
152
153 size_t presize(size_t size, size_t initialSize = 0); // Resize without generating events, use with caution
154
155 void destroyInstance(agxData::EntityPtr instance);
156 void destroyInstance(size_t id);
157
158 template <typename VectorT>
159 void destroyInstances(const VectorT& instances);
160
162
163
166
169
170 // Must be followed by a matching resize...
172
175 agxData::EntityPtr copyInstance(size_t id, agxData::EntityStorage* target, size_t targetId);
176
178 static void copy(agxData::EntityStorage *target, const agxData::EntityStorage *source);
179
183 void clear();
184
188 void reset();
189
193 // void swap(EntityStorage *other);
194
195
200
205 agxData::Buffer *getBuffer(const agxData::Attribute *attribute);
206
207
211 const agxData::BufferTable& getBuffers() const;
212
214 agxData::Buffer *getIdToIndexBuffer();
215
217 const agxData::Buffer *getIdToIndexBuffer() const;
218
220 agxData::Buffer *getInstanceBuffer();
221
223 const agxData::Buffer *getInstanceBuffer() const;
224
228 size_t idToIndex(size_t id) const;
229
233 size_t indexToId(size_t index) const;
234
235
239 agxData::EntityData *getData();
240
241 template <typename T>
242 T* getData();
243
244 template <typename T>
245 const T* getData() const;
246
252 void setUseInstanceTable(bool flag);
253
257 bool useInstanceTable() const;
258
263
267 agxData::Buffer *getGlobalOrderBuffer();
268
272 const agxData::Buffer *getGlobalOrderBuffer() const;
273
278
282 void reorder(const agxData::IndexArray& permutation);
283
284
288 // void reorder(const IndexArray& permutation, agx::IndexRange range);
289
290
291 void print(std::ostream& stream) const;
292 void print() const;
293
295
296
300 template <typename T>
301 T& get(const agx::Name& attributeName, size_t index);
302
303
304
306 void commitPermutation(const agxData::IndexArray& permutation);
308
309 agxData::Byte *getPermutationBuffer(agxData::Attribute *attribute);
310 agxData::Byte *getPermutationBuffer(size_t index);
311
312
314
315 agxData::IndexArray& getIdToIndexTable();
316 const agxData::IndexArray& getIdToIndexTable() const;
317
318
319 // Moved here from EntityPtr because of include loop, see EntityPtr.h
320 template <typename T>
322
323 template <typename T>
325
326
329
330 // Internal
331 void keyFrameResize(size_t size, size_t capacity);
332
333 void setEnableEvents(bool flag);
334
335
337 void restorePermutation(agxStream::InputArchive& archive, bool skip = false);
339 void printInstanceTable() const;
340
341 protected:
343 EntityStorage(EntityModel *entity, const agx::Name& name, bool isFrameStorage, size_t capacity, size_t size);
344
345 virtual ~EntityStorage();
346 virtual agx::Object *getResourceImpl(const agx::Path& path, agx::Model *model) override;
347
349
350 private:
351 friend class EntityPtr;
352 void swapInstanceIds(agx::Index id1, agx::Index id2);
353
354 private:
355 friend class EntityData;
356 void beginBatch();
357 void commitBatch(size_t size);
358
359 private:
360 friend class Buffer;
361 friend class EntityModel;
364 void initializeInstances(const agx::IndexRange& range);
365 void swapInstances(size_t index1, size_t index2);
366 void init(size_t initialCapacity);
367
368
369 // Buffer *tryGetBuffer(const Attribute *attribute, Device *device);
370 // Buffer *tryGetBuffer(const String& name, Device* device);
371 void resizeCallback(agxData::Value* value);
372 void reserveCallback(agxData::Value* value);
373 void elementBufferReallocationCallback(Buffer* elementBuffer);
374 agxData::Buffer* createBuffer(const agxData::Attribute* attribute);
375 void registerBuffer(agxData::Buffer *buffer);
376
377 void sharedResizeCallback(agxData::Value* value);
378 void sharedReserveCallback(agxData::Value* value);
379
380
381 void destroyInstances(const EntityPtr* instances, size_t numInstances, bool triggerEvent = true);
382
389 template <typename T>
390 T& get(const ScalarAttributeT<T> *attribute, size_t index);
391
392
393
394 private:
395
396 size_t m_size;
397 size_t m_capacity;
398 bool m_useInstanceTable;
399 bool m_implicitResize;
400 bool m_initElements;
401 bool m_usedResizeMethod;
402
403 EntityModelRef m_entity;
404 BufferTable m_bufferTable;
405 BufferRefVector m_buffers;
406 BufferRef m_instanceBuffer;
407 EntityDataRef m_dataSet;
408
410 AttributeTable m_customAttributes;
411
412 agx::VectorPOD<Byte *> m_permutationBuffers;
413
414 BufferRef m_globalOrderBuffer;
415
417
418 BufferRef m_idToIndexBuffer;
419 IndexArray m_idToIndexArray;
420
422 agxData::Value::Event::CallbackType m_reserveCallback;
423 Buffer::Event::CallbackType m_elementBufferReallocationCallback;
424 EventDispatch m_eventDispatch;
425 size_t m_batchIndex;
426 bool m_enableEvents;
427 };
428
429 AGXCORE_EXPORT std::ostream& operator << (std::ostream& output, const EntityStorage& storage);
430
431
432
433
434
435
436
437
438
439 /* Implementation */
440
442 AGX_FORCE_INLINE size_t EntityStorage::size() const { return m_size; }
443 AGX_FORCE_INLINE bool EntityStorage::empty() const { return m_size == 0; }
445 AGX_FORCE_INLINE bool EntityStorage::useInstanceTable() const { return m_useInstanceTable; }
448 AGX_FORCE_INLINE const BufferTable& EntityStorage::getBuffers() const { return m_bufferTable; }
449 AGX_FORCE_INLINE const IndexArray& EntityStorage::getIdToIndexTable() const { return m_idToIndexArray; }
452 AGX_FORCE_INLINE const Buffer *EntityStorage::getGlobalOrderBuffer() const { return m_globalOrderBuffer; }
453
456
457 template <typename T>
459 {
460 agxAssert(agxData::getFormat<T>()->is(agxData::getFormat<EntityPtr>()));
461 return Array<T>::raw((T *)m_instanceBuffer->ptr(), (agx::Index)m_instanceBuffer->size());
462 }
463
464 template <typename T>
465 AGX_FORCE_INLINE const Array<T> EntityStorage::getInstances() const { return const_cast<EntityStorage *>(this)->getInstances<T>(); }
466
468 {
469 Buffer *buffer = m_buffers[attribute->getId()];
470
471 if (!buffer)
472 buffer = this->createBuffer(attribute);
473
474 return buffer;
475 }
476
477
478 template <typename T>
479 AGX_FORCE_INLINE T& EntityStorage::get(const ScalarAttributeT<T> *attribute, size_t index)
480 {
481 Buffer *buffer = this->getBuffer(attribute);
482 return buffer->getElement<T>(index);
483 }
484
485 template <typename T>
486 AGX_FORCE_INLINE T& EntityStorage::get(const agx::Name& attributeName, size_t index)
487 {
488 for (size_t i = 0; i < m_buffers.size(); ++i)
489 {
490 Buffer *buffer = m_buffers[i];
491 if (buffer->getName() == attributeName)
492 return buffer->getElement<T>(index);
493 }
494
495 agxAbort();
496 return m_buffers[0]->getElement<T>(0); // Just to make compiler happy
497 }
498
499
501 {
502 return m_idToIndexArray[id];
503 }
504
506 {
507 return m_instanceBuffer->getElement<agxData::EntityPtr>(index).getId();
508 }
509
510
512 {
513 destroyInstance(instance.getId());
514 }
515
516 // inline EntityIterator EntityStorage::iterator() { return EntityIterator(this); }
517 // inline EntityIterator EntityStorage::iterator(IndexRange range) { return EntityIterator(this, range); }
518
519
520 AGX_FORCE_INLINE EntityData *EntityStorage::getData() { return m_dataSet; }
521
522 template <typename T>
523 AGX_FORCE_INLINE T *EntityStorage::getData() { return m_dataSet->as<T>(); }
524
525 template <typename T>
526 AGX_FORCE_INLINE const T *EntityStorage::getData() const { return m_dataSet->as<const T>(); }
527
529 AGX_FORCE_INLINE const Buffer *EntityStorage::getIdToIndexBuffer() const { return m_idToIndexBuffer; }
530
532 AGX_FORCE_INLINE const Buffer *EntityStorage::getInstanceBuffer() const { return m_instanceBuffer; }
533
534
536
537 AGX_FORCE_INLINE size_t EntityData::idToIndex(size_t id) const
538 {
539 agxAssert(m_storage);
540 return m_storage->idToIndex(id);
541 }
542
543 AGX_FORCE_INLINE size_t EntityData::indexToId(size_t index) const
544 {
545 agxAssert(m_storage);
546 return m_storage->indexToId(index);
547 }
548
549 AGX_FORCE_INLINE agx::Index EntityData::createInstance()
550 {
551 return this->createInstances(1);
552 }
553
554 AGX_FORCE_INLINE agx::Index EntityData::createInstances(agx::Index numInstances)
555 {
556 if (m_numElements + numInstances >= m_storage->size())
557 {
558 if (!m_hasBatchInstances)
559 {
560 m_storage->beginBatch();
561 m_hasBatchInstances = true;
562 }
563
564 agx::UInt head = m_numElements; // Save current size as resize will implicitly update m_numElements
565 m_storage->resize(agx::align_ceil((agx::Index)(m_numElements + numInstances), (agx::Index)m_instanceBatchSize));
566 m_numElements = head;
567 }
568
569 agx::Index instanceIndex = (agx::Index)m_numElements;
570 m_numElements += numInstances;
571
572 return instanceIndex;
573 }
574
575
576 AGX_FORCE_INLINE void EntityData::commitInstanceBatch()
577 {
578 if (m_hasBatchInstances)
579 {
580 m_storage->commitBatch(m_numElements);
581 m_hasBatchInstances = false;
582 }
583 }
584
585
586
589 {
590 m_storage = storage;
591 m_id = id;
592 }
593
595 {
596 agxAssert(m_storage);
597 return m_storage->getData();
598 }
599
600 AGX_FORCE_INLINE const EntityData *EntityPtr::getData() const { return const_cast<EntityPtr *>(this)->getData(); }
601
602 template <typename T>
604 {
605 agxAssert(dynamic_cast<T *>(this->getData()));
606 return *static_cast<T *>(this->getData());
607 }
608
609 template <typename T>
610 AGX_FORCE_INLINE const T& EntityPtr::dataSet() const { return const_cast<EntityPtr *>(this)->dataSet<T>(); }
611
612
614 {
615 agxAssert1(m_storage, "This is a null ptr");
616 return (agx::Index)m_storage->idToIndex(m_id);
617 }
618
619
620 template <typename T>
621 AGX_FORCE_INLINE T& EntityPtr::getElement(const Attribute *attribute) const
622 {
623 agxAssert(attribute);
624 agxAssertN(m_storage, "Can not access attribute \'%s\' from an invalid pointer.", attribute->fullName().c_str());
625 Buffer *buffer = m_storage->getBuffer(attribute);
626 agx::Index index = this->calculateIndex();
627 agxAssertN(index < m_storage->size(), "%s: Entity (%p, %u) claims to have index %u, but storage size is %u.", m_storage->getPath().c_str(), (void *)m_storage, (unsigned)m_id, (unsigned)index, (unsigned)m_storage->size());
628 return *(T *)buffer->getElement(index);
629 }
630
632 {
633#ifdef AGX_DEBUG
634 agx::Index index = this->calculateIndex();
635 agxAssertN(index < m_storage->size(), "%s: Entity (%p, %u) claims to have index %u, but storage size is %u.", m_storage->getPath().c_str(), (void *)m_storage, (unsigned)m_id, (unsigned)index, (unsigned)m_storage->size());
636#endif
637 }
638
639
640 template <typename T>
642 {
643 return this->getElement<T>(attribute);
644 }
645
646 template <typename T>
648 {
649 return this->getElement<const T>(attribute);
650 }
651
652 template <typename T>
654 {
655 return this->getElement<T>(attribute);
656 }
657
658 template <typename T>
660 {
661 return this->getElement<const T>(attribute);
662 }
663
664
665 template <typename T>
667 {
668 return this->getElement<typename ArrayAttributeT<T>::Type>(attribute);
669 }
670
671 template <typename T>
673 {
674 return this->getElement<const typename ArrayAttributeT<T>::Type>(attribute);
675 }
676
677
678
679 template <typename T>
681 {
682 return this->getElement<typename VectorAttributeT<T>::Type>(attribute);
683 }
684
685 template <typename T>
687 {
688 return this->getElement<const typename VectorAttributeT<T>::Type>(attribute);
689 }
690
691 template <typename T>
693 {
694 return this->getElement<typename HashSetAttributeT<T>::Type>(attribute);
695 }
696
697 template <typename T>
699 {
700 return this->getElement<const typename HashSetAttributeT<T>::Type>(attribute);
701 }
702
703 template <typename T>
705 {
706 agxAssert(entity.getStorage() == this);
707 Buffer *buffer = this->getBuffer(attribute);
708 // agxAssert1(buffer->getFormat()->getSize() >= sizeof(T), "Only down-cast allowed, eg int64 -> int32");
709 agxAssertN(entity.calculateIndex() < this->size(), "%s: Entity with id %u claims to have index %u, but storage size is %u.", this->getPath().c_str(), (unsigned)entity.getId(), (unsigned)entity.calculateIndex(), (unsigned)this->size());
710 size_t arraySize = buffer->getElementArraySize();
711 size_t offset = entity.calculateIndex() * arraySize;
712 return Array<T>(buffer, agx::IndexRange(offset, offset + arraySize));
713 }
714
715 template <typename T>
717 {
718 return const_cast<EntityStorage *>(this)->dereferenceMultipliedAttribute(entity, attribute);
719 }
720
721
722
723 template <typename VectorT>
724 void EntityStorage::destroyInstances(const VectorT& instances)
725 {
726 this->destroyInstances(instances.begin(), instances.size());
727 }
728
729
731 {
732 return this->getPermutationBuffer(attribute->getId());
733 }
734
736 {
737 return m_permutationBuffers[index];
738 }
739
740 //---------------------------------------------------------------
741
742 template <typename T>
744 {
745 agxAssert(m_storage);
746 agxData::Value *value = m_storage->getObject<agxData::Value>(attribute->getName());
747 return const_cast<T&>(value->get<T>());
748 }
749
750 template <typename T>
752 {
753 return const_cast<EntityPtr *>(this)->operator()(attribute);
754 }
755
756
758 {
759 return m_storage ? m_storage->getEntityModel() : nullptr;
760 }
761
763 {
764 return m_storage ? m_storage->getEntityModel() : nullptr;
765 }
766
768 {
769 agxAssert(m_storage);
770 agxAssert(m_storage == other.m_storage);
771
772 m_storage->swapInstanceIds(m_id, other.m_id);
773 }
774
776 {
777 agxAssert(m_storage);
778 agxAssert(m_storage == other.m_storage);
779
780 m_storage->swapInstances(calculateIndex(), other.calculateIndex());
781 }
782
783
785 {
786 return m_storage && m_storage->getEntityModel()->is(model);
787 }
788
789
791 {
792 agxAssert(storage);
793 return EntityPtr(storage, (agx::Index)storage->indexToId(index));
794 }
795
796 AGX_FORCE_INLINE EntityPtr::EntityPtr(const EntityInstance& instance) : m_storage(const_cast<EntityStorage *>(instance.getStorage())), m_id(agx::InvalidIndex)
797 {
798 if (m_storage)
799 m_id = (agx::Index)m_storage->indexToId(instance.getIndex());
800 }
801
803
804 AGX_FORCE_INLINE EntityInstance::EntityInstance(agxData::EntityStorage* storage, agx::Index index) : m_data(storage->getData()), m_index(index)
805 {}
806
808 {
809 agxAssert(other);
810
811 m_data = const_cast<EntityData *>(other.getData());
812 m_index = other.calculateIndex();
813 }
814
816 {
817 agxAssert(getStorage() && getStorage()->useInstanceTable());
818 return (agx::Index)getStorage()->indexToId(m_index);
819 }
820
821
822 AGX_FORCE_INLINE agxData::EntityStorage *EntityInstance::getStorage() { return m_data ? m_data->getStorage() : nullptr; }
824
827
828
830 {
831 const agxData::EntityModel *m = getModel();
832 return m ? m->is(model) : false;
833 }
834
835
837 {
838#ifdef AGX_DEBUG
839 const EntityStorage *storage = this->getStorage();
840 agx::Index index = this->getIndex();
841 agxAssertN(index < storage->size(), "%s: Entity instance (%p, %u) is out of bounds, storage size is %u.", storage->getPath().c_str(), (void *)storage, (unsigned)index, (unsigned)storage->size());
842#endif
843 }
844
845
847
849 {}
850
851 AGX_FORCE_INLINE EntityRange::EntityRange(EntityStorage *storage, size_t start, size_t end) : agx::IndexRange(start, end), m_storage(storage)
852 {
853 }
854
855 inline EntityPtr EntityRange::at(size_t index) { return operator[](index); }
856 AGX_FORCE_INLINE EntityRange EntityRange::operator[] (agx::IndexRange subRange) { return EntityRange(m_storage, subRange.begin(), subRange.end()); }
857
859 {
860 agxAssert(m_storage);
861 agxAssert(index < this->size());
862 return EntityPtr(m_storage, (agx::UInt32)m_storage->indexToId(this->begin() + index));
863 }
864
865
866
868 template <typename T>
869 inline AttributePtr<T>::AttributePtr() : m_attribute(nullptr)
870 {
871 }
872
873 template <typename T>
874 inline AttributePtr<T>::AttributePtr(EntityPtr entity, const Attribute *attribute) : m_entityPtr(entity), m_attribute(attribute)
875 {
876 }
877
878 template <typename T>
880 {
881 agxAssert(this->isValid());
882 return m_entityPtr.getElement<T>(m_attribute);
883 }
884
885 template <typename T>
887 {
888 agxAssert(this->isValid());
889 return m_entityPtr.getElement<T>(m_attribute);
890 }
891
892 template <typename T>
894 {
895 return m_entityPtr.isValid() && m_attribute;
896 }
897
898
899 template <typename T>
901 {
902 return !this->isValid();
903 }
904
905 template <typename T>
907 {
908 return this->isValid();
909 }
910
911}
912
914
915#ifdef _MSC_VER
916# pragma warning(pop)
917#endif
918
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
#define m_size
Definition: agx/Vector.h:429
#define m_capacity
Definition: agx/Vector.h:430
Type-specific Array used for fast access into the data held by a Buffer.
Definition: Array.h:107
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
Definition: Buffer.h:733
An attribute container.
bool operator!() const
An abstract attribute description, part of an Entity.
Definition: Attribute.h:58
agx::String fullName() const
agx::Index getId() const
Definition: Attribute.h:365
Abstract representation of a data buffer.
Definition: Buffer.h:56
T & getElement(size_t index)
Definition: Buffer.h:517
size_t getElementArraySize() const
Definition: Buffer.h:466
Entity instance provides access to a single instance in an EntityStorage.
void verifyIndex() const
Check for broken ptr, by verifying that the index is active in the storage.
agx::Index calculateId() const
agxData::EntityModel * getModel()
Alias for getData()->getStorage()->getModel()
agx::Index getIndex() const
EntityInstance()
Constructors.
bool isInstanceOf(agxData::EntityModel *model) const
agxData::EntityStorage * getStorage()
Alias for getData()->getStorage()
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:64
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:52
agx::Index calculateIndex() const
Calculate the index using the indirect id.
bool isInstanceOf(agxData::EntityModel *model) const
agxData::EntityData * getData()
T & operator()(const agxData::ScalarAttributeT< T > *attribute)
Access the value of a specific attribute.
agxData::EntityInstance instance()
Definition: EntityPtr.h:269
agxData::EntityModel * getModel()
agx::Index getId() const
Definition: EntityPtr.h:273
void verifyIndex() const
Check for broken ptr, by verifying that the id is active in the storage.
agxData::EntityStorage * getStorage() const
Definition: EntityPtr.h:272
void swapIndex(EntityPtr &other)
Swap index with another instance.
static EntityPtr createWithIndex(EntityStorage *storage, agx::Index index)
void init(agxData::EntityStorage *storage, agx::Index id)
Set the target storage and id.
void swapId(EntityPtr &other)
Swap id with another instance.
EntityPtr operator[](size_t index)
EntityPtr at(size_t index)
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
EntityStorage(const agx::Name &name)
void removeListener(EventListener *listener)
agxData::IndexArray & getIdToIndexTable()
void unregisterBuffer(agxData::Buffer *buffer)
bool hasListener(EventListener *listener)
agxData::LocalVector< std::pair< size_t, size_t > > InstanceSwapLocalVector
bool useInstanceTable() const
virtual agx::Object * getResourceImpl(const agx::Path &path, agx::Model *model) override
T & get(const agx::Name &attributeName, size_t index)
Slow but convenient accessor.
agxData::Buffer * getIdToIndexBuffer()
void keyFrameResize(size_t size, size_t capacity)
void destroyInstances(const VectorT &instances)
agxData::Buffer * getGlobalOrderBuffer()
If the storage is used as a global result, we provide a permutation buffer for parallel determinism.
size_t idToIndex(size_t id) const
Convert between instance id and data index.
agxData::Array< T > getInstances()
void print(std::ostream &stream) const
Reorder a subrange.
void clear()
Clears the storage.
agxData::EntityPtr copyInstance(size_t id, agxData::EntityStorage *target, size_t targetId)
agxData::EntityPtr copyInstance(size_t id, agxData::EntityStorage *target)
agxData::EntityModel * getEntityModel()
agxData::ValueRefT< agx::UInt > capacityParameter
Definition: EntityStorage.h:90
void addCustomAttribute(agxData::Attribute *attribute)
Add a custom attribute buffer.
const agxData::BufferTable & getBuffers() const
void destroyInstance(size_t id)
static const agx::Name IdToIndexName
static agxData::EntityStorage * load(agx::TiXmlElement *eStorage, agx::Device *device)
size_t capacity() const
agxData::ValueRefT< agx::UInt > sizeParameter
Definition: EntityStorage.h:89
agxData::EntityStorage * createSharedStorage()
Swap buffers with another storage.
const agxData::Array< T > dereferenceMultipliedAttribute(const agxData::EntityPtr &entity, const agxData::ScalarAttributeT< T > *attribute) const
size_t presize(size_t size, size_t initialSize=0)
agxData::EntityPtr createInstance()
Creates a new instance and initializes it with default values.
void preDestroy(agxData::EntityPtr instance)
void resize(size_t size, bool initializeElements=true)
static agx::Model * ClassModel()
void reorder(const agxData::IndexArray &permutation)
Reorder the storage using a specified permutation.
void addListener(EventListener *listener)
void setEnableEvents(bool flag)
void explicityRegisterBuffer(agxData::Buffer *buffer, agxData::Attribute *attribute)
agxData::Buffer * getOrCreateGlobalOrderBuffer()
Create the global order buffer if not already allocated.
void reset()
Clear the storage, and reset index-id tables.
const agxData::Array< T > getInstances() const
void destroyInstance(agxData::EntityPtr instance)
virtual void configure(agx::TiXmlElement *eStorage) override
const agxData::Array< EntityPtr > getInstances() const
void swapInstances(const InstanceSwapVector &swaps)
size_t getNumBytes() const
static const agx::Name IndexToIdName
agxData::Buffer * getBuffer(const agx::Name &name)
static void extractPermutation(agx::IndexVector &result, agxStream::InputArchive &archive)
void destroyInstances(agxData::EntityRange range)
agxData::EntityStorage * clone() const
agxData::EntityData * getData()
void swapInstances(const InstanceSwapLocalVector &swaps)
agxData::Byte * getPermutationBuffer(agxData::Attribute *attribute)
agxData::EntityRange createInstances(size_t numInstances)
Create a range of entity instances.
void storePermutation(agxStream::OutputArchive &archive) const
size_t indexToId(size_t index) const
Convert between instance id and data index.
agxData::Array< T > dereferenceMultipliedAttribute(const agxData::EntityPtr &entity, const agxData::ScalarAttributeT< T > *attribute)
void printInstanceTable() const
void commitPermutation(const agxData::IndexArray &permutation)
EntityStorage(agxData::EntityModel *entity, size_t initialCapacity=32)
EntityStorage(EntityModel *entity, const agx::Name &name, bool isFrameStorage, size_t capacity, size_t size)
void restorePermutation(agxStream::InputArchive &archive, bool skip=false)
void reserve(size_t size)
Reserve capacity in the storage.
agxData::Buffer * getInstanceBuffer()
void setUseInstanceTable(bool flag)
Set to false to disable instance pointer handling.
agx::VectorPOD< std::pair< size_t, size_t > > InstanceSwapVector
void reorderAttributes(agx::IndexRange32 range, const agxData::IndexArray &permutation)
static void copy(agxData::EntityStorage *target, const agxData::EntityStorage *source)
EntityStorage(agxData::EntityModel *entity, const agx::Name &name, size_t initialCapacity=32)
agxData::EntityPtr transferInstance(size_t id, agxData::EntityStorage *target)
Local scope vector.
Definition: LocalVector.h:44
Templated value-reference.
Definition: Value.h:263
Abstract representation of a value.
Definition: Value.h:49
const T & get() const
Definition: Value.h:331
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
agx::Object * getObject(const agx::Name &name, size_t index=0)
Definition: Component.h:194
size_t size() const
Definition: Container.h:134
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
T CallbackType
Definition: Event.h:37
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
A range of indices.
Definition: IndexRange.h:33
agx::UInt size() const
Definition: IndexRange.h:168
Inheritance with partial specialization due to bug with ref_ptr containers.
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
bool is(const agx::Model *other) const
Representation of a name string.
Definition: Name.h:33
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agx::Path getPath() const
const agx::Name & getName() const
Definition: Object.h:382
agx::UInt32 getId() const
Definition: Object.h:383
Representation of a path, a list of name components.
Definition: Path.h:33
const char * c_str() const
bool is() const
Subclass test.
Vector containing 'raw' data.
Definition: agx/Vector.h:246
T * get() const
Definition: ref_ptr.h:256
#define agxAssert1(expr, msg)
Definition: debug.h:144
#define agxAbort()
Definition: debug.h:164
#define agxAssertN(expr, format,...)
Definition: debug.h:145
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::UInt8 Byte
Definition: agxData.h:45
agx::HashTable< Attribute *, BufferRef > BufferTable
Definition: EntityStorage.h:59
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
T align_ceil(T value, T alignment)
Definition: Math.h:466
uint64_t UInt
Definition: Integer.h:27
UInt32 Index
Definition: Integer.h:44