AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EntityStorage.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXDATA_ENTITY_STORAGE_H
18 #define AGXDATA_ENTITY_STORAGE_H
19 
20 #include <agx/agx.h>
21 #include <agx/agxCore_export.h>
22 #include <agxData/Buffer.h>
24 #include <agxData/EntityData.h>
26 #include <agxData/LocalVector.h>
27 #include <agx/Vector.h>
28 #include <agx/HashTable.h>
29 #include <agx/Referenced.h>
30 #include <agx/Component.h>
31 
32 
33 #ifdef _MSC_VER
34 # pragma warning(push)
35 # pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
36 #endif
37 
38 
39 namespace agx
40 {
41  class Device;
42  class TiXmlElement;
43  class GlobalResultStorage;
44  class AliasStorage;
45 }
46 
47 namespace agxSDK
48 {
49  class SimulationFrameWriter;
50 }
51 
52 namespace agxStream
53 {
54  class InputArchive;
55  class OutputArchive;
56 }
57 
58 namespace agxData
59 {
61 
62 
65 
74  {
75  public:
76  static agx::Model *ClassModel();
77 
78  static agxData::EntityStorage *load(agx::TiXmlElement *eStorage, agx::Device *device);
79  virtual void configure(agx::TiXmlElement *eStorage) override;
80 
81  public:
82  // Generated event interface, defined in EntityStorage.agxEvent
84 
85 #ifndef SWIG
86  void addListener(EventListener *listener);
87  void removeListener(EventListener *listener);
88  bool hasListener(EventListener *listener);
89 #endif
92 
93  public:
94  EntityStorage(agxData::EntityModel *entity, size_t initialCapacity = 32);
95  EntityStorage(agxData::EntityModel *entity, const agx::Name& name, size_t initialCapacity = 32);
96 
100  bool empty() const;
101 
105  size_t size() const;
106 
110  size_t capacity() const;
111 
115  size_t getNumBytes() const;
116 
120  agxData::EntityModel *getEntityModel();
121  const agxData::EntityModel *getEntityModel() const;
122 
126  void reserve(size_t size);
127 
131  const agxData::Array<EntityPtr> getInstances() const;
132  agxData::Array<EntityPtr> getInstances();
133 
134  template <typename T>
135  const agxData::Array<T> getInstances() const;
136 
137  template <typename T>
138  agxData::Array<T> getInstances();
139 
144  agxData::EntityPtr createInstance();
145 
150  agxData::EntityRange createInstances(size_t numInstances);
151 
152  void resize(size_t size, bool initializeElements = true);
153 
154  size_t presize(size_t size, size_t initialSize = 0); // Resize without generating events, use with caution
155 
156  void destroyInstance(agxData::EntityPtr instance);
157  void destroyInstance(size_t id);
158 
159  template <typename VectorT>
160  void destroyInstances(const VectorT& instances);
161 
162  void destroyInstances(agxData::EntityRange range);
163 
164 
166  void swapInstances(const InstanceSwapVector &swaps);
167 
169  void swapInstances(const InstanceSwapLocalVector& swaps);
170 
171  // Must be followed by a matching resize...
172  void preDestroy(agxData::EntityPtr instance);
173 
174  agxData::EntityPtr transferInstance(size_t id, agxData::EntityStorage* target);
175  agxData::EntityPtr copyInstance(size_t id, agxData::EntityStorage* target);
176  agxData::EntityPtr copyInstance(size_t id, agxData::EntityStorage* target, size_t targetId);
177 
178  agxData::EntityStorage *clone() const;
179  static void copy(agxData::EntityStorage *target, const agxData::EntityStorage *source);
180 
184  void clear();
185 
189  void reset();
190 
194  // void swap(EntityStorage *other);
195 
196 
200  agxData::EntityStorage *createSharedStorage();
201 
205  agxData::Buffer *getBuffer(const agx::Name& name);
206  agxData::Buffer *getBuffer(const agxData::Attribute *attribute);
207 
208 
212  const agxData::BufferTable& getBuffers() const;
213 
215  agxData::Buffer *getIdToIndexBuffer();
216 
218  const agxData::Buffer *getIdToIndexBuffer() const;
219 
221  agxData::Buffer *getInstanceBuffer();
222 
224  const agxData::Buffer *getInstanceBuffer() const;
225 
229  size_t idToIndex(size_t id) const;
230 
234  size_t indexToId(size_t index) const;
235 
236 
240  agxData::EntityData *getData();
241 
242  template <typename T>
243  T* getData();
244 
245  template <typename T>
246  const T* getData() const;
247 
253  void setUseInstanceTable(bool flag);
254 
258  bool useInstanceTable() const;
259 
263  void addCustomAttribute(agxData::Attribute *attribute);
264 
268  agxData::Buffer *getGlobalOrderBuffer();
269 
273  const agxData::Buffer *getGlobalOrderBuffer() const;
274 
278  agxData::Buffer *getOrCreateGlobalOrderBuffer();
279 
283  void reorder(const agxData::IndexArray& permutation);
284 
285 
289  // void reorder(const IndexArray& permutation, agx::IndexRange range);
290 
291 
292  void print(std::ostream& stream) const;
293  void print() const;
294 
295  void verifyConsistency();
296 
297 
301  template <typename T>
302  T& get(const agx::Name& attributeName, size_t index);
303 
304 
305 
306  void preparePermutation();
307  void commitPermutation(const agxData::IndexArray& permutation);
308  void reorderAttributes(agx::IndexRange32 range, const agxData::IndexArray& permutation);
309 
310  agxData::Byte *getPermutationBuffer(agxData::Attribute *attribute);
311  agxData::Byte *getPermutationBuffer(size_t index);
312 
313 
314  void unregisterBuffer(agxData::Buffer *buffer);
315 
316  agxData::IndexArray& getIdToIndexTable();
317  const agxData::IndexArray& getIdToIndexTable() const;
318 
319 
320  // Moved here from EntityPtr because of include loop, see EntityPtr.h
321  template <typename T>
322  agxData::Array<T> dereferenceMultipliedAttribute(const agxData::EntityPtr& entity, const agxData::ScalarAttributeT<T> *attribute);
323 
324  template <typename T>
325  const agxData::Array<T> dereferenceMultipliedAttribute(const agxData::EntityPtr& entity, const agxData::ScalarAttributeT<T> *attribute) const;
326 
327 
328  static const agx::Name IdToIndexName;
329  static const agx::Name IndexToIdName;
330 
331  // Internal
332  void keyFrameResize(size_t size, size_t capacity);
333 
334  void setEnableEvents(bool flag);
335 
336 
337  void storePermutation(agxStream::OutputArchive& archive) const;
338  void restorePermutation(agxStream::InputArchive& archive, bool skip = false);
339  static void extractPermutation(agx::IndexVector& result, agxStream::InputArchive& archive);
340  void printInstanceTable() const;
341 
342  protected:
343  EntityStorage(const agx::Name& name);
344  EntityStorage(EntityModel *entity, const agx::Name& name, bool isFrameStorage, size_t capacity, size_t size);
345 
346  virtual ~EntityStorage();
347  virtual agx::Object *getResourceImpl(const agx::Path& path, agx::Model *model) override;
348 
349  void explicityRegisterBuffer(agxData::Buffer *buffer, agxData::Attribute *attribute);
350 
351  private:
352  friend class EntityPtr;
353  void swapInstanceIds(agx::Index id1, agx::Index id2);
354 
355  private:
356  friend class EntityData;
357  void beginBatch();
358  void commitBatch(size_t size);
359 
360  private:
361  friend class Buffer;
362  friend class EntityModel;
365  void initializeInstances(const agx::IndexRange& range);
366  void swapInstances(size_t index1, size_t index2);
367  void init(size_t initialCapacity);
368 
369 
370  // Buffer *tryGetBuffer(const Attribute *attribute, Device *device);
371  // Buffer *tryGetBuffer(const String& name, Device* device);
372  void resizeCallback(agxData::Value* value);
373  void reserveCallback(agxData::Value* value);
374  void elementBufferReallocationCallback(Buffer* elementBuffer);
375  agxData::Buffer* createBuffer(const agxData::Attribute* attribute);
376  void registerBuffer(agxData::Buffer *buffer);
377 
378  void sharedResizeCallback(agxData::Value* value);
379  void sharedReserveCallback(agxData::Value* value);
380 
381 
382  void destroyInstances(const EntityPtr* instances, size_t numInstances, bool triggerEvent = true);
383 
390  template <typename T>
391  T& get(const ScalarAttributeT<T> *attribute, size_t index);
392 
393 
394 
395  private:
396 
397  size_t m_size;
398  size_t m_capacity;
399  bool m_useInstanceTable;
400  bool m_implicitResize;
401  bool m_initElements;
402  bool m_usedResizeMethod;
403 
404  EntityModelRef m_entity;
405  BufferTable m_bufferTable;
406  BufferRefVector m_buffers;
407  BufferRef m_instanceBuffer;
408  EntityDataRef m_dataSet;
409 
411  AttributeTable m_customAttributes;
412 
413  agx::VectorPOD<Byte *> m_permutationBuffers;
414 
415  BufferRef m_globalOrderBuffer;
416 
417  agx::Vector<agx::ref_ptr<agx::Referenced> > m_arrayAllocators;
418 
419  BufferRef m_idToIndexBuffer;
420  IndexArray m_idToIndexArray;
421 
422  agxData::Value::Event::CallbackType m_resizeCallback;
423  agxData::Value::Event::CallbackType m_reserveCallback;
424  Buffer::Event::CallbackType m_elementBufferReallocationCallback;
425  EventDispatch m_eventDispatch;
426  size_t m_batchIndex;
427  bool m_enableEvents;
428  };
429 
430  std::ostream& operator << (std::ostream& output, const EntityStorage& storage);
431 
432 
433 
434 
435 
436 
437 
438 
439 
440  /* Implementation */
441 
443  AGX_FORCE_INLINE size_t EntityStorage::size() const { return m_size; }
444  AGX_FORCE_INLINE bool EntityStorage::empty() const { return m_size == 0; }
446  AGX_FORCE_INLINE bool EntityStorage::useInstanceTable() const { return m_useInstanceTable; }
448  AGX_FORCE_INLINE const EntityModel *EntityStorage::getEntityModel() const { return m_entity; }
449  AGX_FORCE_INLINE const BufferTable& EntityStorage::getBuffers() const { return m_bufferTable; }
450  AGX_FORCE_INLINE const IndexArray& EntityStorage::getIdToIndexTable() const { return m_idToIndexArray; }
453  AGX_FORCE_INLINE const Buffer *EntityStorage::getGlobalOrderBuffer() const { return m_globalOrderBuffer; }
454 
457 
458  template <typename T>
460  {
461  agxAssert(agxData::getFormat<T>()->is(agxData::getFormat<EntityPtr>()));
462  return Array<T>::raw((T *)m_instanceBuffer->ptr(), (agx::Index)m_instanceBuffer->size());
463  }
464 
465  template <typename T>
466  AGX_FORCE_INLINE const Array<T> EntityStorage::getInstances() const { return const_cast<EntityStorage *>(this)->getInstances<T>(); }
467 
469  {
470  Buffer *buffer = m_buffers[attribute->getId()];
471 
472  if (!buffer)
473  buffer = this->createBuffer(attribute);
474 
475  return buffer;
476  }
477 
478 
479  template <typename T>
480  AGX_FORCE_INLINE T& EntityStorage::get(const ScalarAttributeT<T> *attribute, size_t index)
481  {
482  Buffer *buffer = this->getBuffer(attribute);
483  return buffer->getElement<T>(index);
484  }
485 
486  template <typename T>
487  AGX_FORCE_INLINE T& EntityStorage::get(const agx::Name& attributeName, size_t index)
488  {
489  for (size_t i = 0; i < m_buffers.size(); ++i)
490  {
491  Buffer *buffer = m_buffers[i];
492  if (buffer->getName() == attributeName)
493  return buffer->getElement<T>(index);
494  }
495 
496  agxAbort();
497  return m_buffers[0]->getElement<T>(0); // Just to make compiler happy
498  }
499 
500 
502  {
503  return m_idToIndexArray[id];
504  }
505 
506  AGX_FORCE_INLINE size_t EntityStorage::indexToId(size_t index) const
507  {
508  return m_instanceBuffer->getElement<agxData::EntityPtr>(index).getId();
509  }
510 
511 
513  {
514  destroyInstance(instance.getId());
515  }
516 
517  // inline EntityIterator EntityStorage::iterator() { return EntityIterator(this); }
518  // inline EntityIterator EntityStorage::iterator(IndexRange range) { return EntityIterator(this, range); }
519 
520 
521  AGX_FORCE_INLINE EntityData *EntityStorage::getData() { return m_dataSet; }
522 
523  template <typename T>
524  AGX_FORCE_INLINE T *EntityStorage::getData() { return m_dataSet->as<T>(); }
525 
526  template <typename T>
527  AGX_FORCE_INLINE const T *EntityStorage::getData() const { return m_dataSet->as<const T>(); }
528 
530  AGX_FORCE_INLINE const Buffer *EntityStorage::getIdToIndexBuffer() const { return m_idToIndexBuffer; }
531 
533  AGX_FORCE_INLINE const Buffer *EntityStorage::getInstanceBuffer() const { return m_instanceBuffer; }
534 
535 
537 
538  AGX_FORCE_INLINE size_t EntityData::idToIndex(size_t id) const
539  {
540  agxAssert(m_storage);
541  return m_storage->idToIndex(id);
542  }
543 
544  AGX_FORCE_INLINE size_t EntityData::indexToId(size_t index) const
545  {
546  agxAssert(m_storage);
547  return m_storage->indexToId(index);
548  }
549 
550  AGX_FORCE_INLINE agx::Index EntityData::createInstance()
551  {
552  return this->createInstances(1);
553  }
554 
555  AGX_FORCE_INLINE agx::Index EntityData::createInstances(agx::Index numInstances)
556  {
557  if (m_numElements + numInstances >= m_storage->size())
558  {
559  if (!m_hasBatchInstances)
560  {
561  m_storage->beginBatch();
562  m_hasBatchInstances = true;
563  }
564 
565  agx::UInt head = m_numElements; // Save current size as resize will implicitly update m_numElements
566  m_storage->resize(agx::align_ceil((agx::Index)(m_numElements + numInstances), (agx::Index)m_instanceBatchSize));
567  m_numElements = head;
568  }
569 
570  agx::Index instanceIndex = (agx::Index)m_numElements;
571  m_numElements += numInstances;
572 
573  return instanceIndex;
574  }
575 
576 
577  AGX_FORCE_INLINE void EntityData::commitInstanceBatch()
578  {
579  if (m_hasBatchInstances)
580  {
581  m_storage->commitBatch(m_numElements);
582  m_hasBatchInstances = false;
583  }
584  }
585 
586 
587 
590  {
591  m_storage = storage;
592  m_id = id;
593  }
594 
596  {
597  agxAssert(m_storage);
598  return m_storage->getData();
599  }
600 
601  AGX_FORCE_INLINE const EntityData *EntityPtr::getData() const { return const_cast<EntityPtr *>(this)->getData(); }
602 
603  template <typename T>
605  {
606  agxAssert(dynamic_cast<T *>(this->getData()));
607  return *static_cast<T *>(this->getData());
608  }
609 
610  template <typename T>
611  AGX_FORCE_INLINE const T& EntityPtr::dataSet() const { return const_cast<EntityPtr *>(this)->dataSet<T>(); }
612 
613 
615  {
616  agxAssert1(m_storage, "This is a null ptr");
617  return (agx::Index)m_storage->idToIndex(m_id);
618  }
619 
620 
621  template <typename T>
622  AGX_FORCE_INLINE T& EntityPtr::getElement(const Attribute *attribute) const
623  {
624  agxAssert(attribute);
625  agxAssertN(m_storage, "Can not access attribute \'%s\' from an invalid pointer.", attribute->fullName().c_str());
626  Buffer *buffer = m_storage->getBuffer(attribute);
627  agx::Index index = this->calculateIndex();
628  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());
629  return *(T *)buffer->getElement(index);
630  }
631 
633  {
634 #ifdef AGX_DEBUG
635  agx::Index index = this->calculateIndex();
636  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());
637 #endif
638  }
639 
640 
641  template <typename T>
643  {
644  return this->getElement<T>(attribute);
645  }
646 
647  template <typename T>
649  {
650  return this->getElement<const T>(attribute);
651  }
652 
653  template <typename T>
655  {
656  return this->getElement<T>(attribute);
657  }
658 
659  template <typename T>
661  {
662  return this->getElement<const T>(attribute);
663  }
664 
665 
666  template <typename T>
668  {
669  return this->getElement<typename ArrayAttributeT<T>::Type>(attribute);
670  }
671 
672  template <typename T>
674  {
676  }
677 
678 
679 
680  template <typename T>
682  {
683  return this->getElement<typename VectorAttributeT<T>::Type>(attribute);
684  }
685 
686  template <typename T>
688  {
690  }
691 
692  template <typename T>
694  {
695  return this->getElement<typename HashSetAttributeT<T>::Type>(attribute);
696  }
697 
698  template <typename T>
700  {
702  }
703 
704  template <typename T>
706  {
707  agxAssert(entity.getStorage() == this);
708  Buffer *buffer = this->getBuffer(attribute);
709  // agxAssert1(buffer->getFormat()->getSize() >= sizeof(T), "Only down-cast allowed, eg int64 -> int32");
710  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());
711  size_t arraySize = buffer->getElementArraySize();
712  size_t offset = entity.calculateIndex() * arraySize;
713  return Array<T>(buffer, agx::IndexRange(offset, offset + arraySize));
714  }
715 
716  template <typename T>
718  {
719  return const_cast<EntityStorage *>(this)->dereferenceMultipliedAttribute(entity, attribute);
720  }
721 
722 
723 
724  template <typename VectorT>
725  void EntityStorage::destroyInstances(const VectorT& instances)
726  {
727  this->destroyInstances(instances.begin(), instances.size());
728  }
729 
730 
732  {
733  return this->getPermutationBuffer(attribute->getId());
734  }
735 
737  {
738  return m_permutationBuffers[index];
739  }
740 
741  //---------------------------------------------------------------
742 
743  template <typename T>
745  {
746  agxAssert(m_storage);
747  agxData::Value *value = m_storage->getObject<agxData::Value>(attribute->getName());
748  return const_cast<T&>(value->get<T>());
749  }
750 
751  template <typename T>
753  {
754  return const_cast<EntityPtr *>(this)->operator()(attribute);
755  }
756 
757 
759  {
760  return m_storage ? m_storage->getEntityModel() : nullptr;
761  }
762 
764  {
765  return m_storage ? m_storage->getEntityModel() : nullptr;
766  }
767 
769  {
770  agxAssert(m_storage);
771  agxAssert(m_storage == other.m_storage);
772 
773  m_storage->swapInstanceIds(m_id, other.m_id);
774  }
775 
777  {
778  agxAssert(m_storage);
779  agxAssert(m_storage == other.m_storage);
780 
781  m_storage->swapInstances(calculateIndex(), other.calculateIndex());
782  }
783 
784 
786  {
787  return m_storage && m_storage->getEntityModel()->is(model);
788  }
789 
790 
792  {
793  agxAssert(storage);
794  return EntityPtr(storage, (agx::Index)storage->indexToId(index));
795  }
796 
797  AGX_FORCE_INLINE EntityPtr::EntityPtr(const EntityInstance& instance) : m_storage(const_cast<EntityStorage *>(instance.getStorage())), m_id(agx::InvalidIndex)
798  {
799  if (m_storage)
800  m_id = (agx::Index)m_storage->indexToId(instance.getIndex());
801  }
802 
804 
805  AGX_FORCE_INLINE EntityInstance::EntityInstance(agxData::EntityStorage* storage, agx::Index index) : m_data(storage->getData()), m_index(index)
806  {}
807 
809  {
810  agxAssert(other);
811 
812  m_data = const_cast<EntityData *>(other.getData());
813  m_index = other.calculateIndex();
814  }
815 
817  {
818  agxAssert(getStorage() && getStorage()->useInstanceTable());
819  return (agx::Index)getStorage()->indexToId(m_index);
820  }
821 
822 
823  AGX_FORCE_INLINE agxData::EntityStorage *EntityInstance::getStorage() { return m_data ? m_data->getStorage() : nullptr; }
825 
828 
829 
831  {
832  const agxData::EntityModel *m = getModel();
833  return m ? m->is(model) : false;
834  }
835 
836 
838  {
839 #ifdef AGX_DEBUG
840  const EntityStorage *storage = this->getStorage();
841  agx::Index index = this->getIndex();
842  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());
843 #endif
844  }
845 
846 
848 
850  {}
851 
852  AGX_FORCE_INLINE EntityRange::EntityRange(EntityStorage *storage, size_t start, size_t end) : agx::IndexRange(start, end), m_storage(storage)
853  {
854  }
855 
856  inline EntityPtr EntityRange::at(size_t index) { return operator[](index); }
857  AGX_FORCE_INLINE EntityRange EntityRange::operator[] (agx::IndexRange subRange) { return EntityRange(m_storage, subRange.begin(), subRange.end()); }
858 
859  inline EntityPtr EntityRange::operator[] (size_t index)
860  {
861  agxAssert(m_storage);
862  agxAssert(index < this->size());
863  return EntityPtr(m_storage, (agx::UInt32)m_storage->indexToId(this->begin() + index));
864  }
865 
866 
867 
869  template <typename T>
870  inline AttributePtr<T>::AttributePtr() : m_attribute(nullptr)
871  {
872  }
873 
874  template <typename T>
875  inline AttributePtr<T>::AttributePtr(EntityPtr entity, const Attribute *attribute) : m_entityPtr(entity), m_attribute(attribute)
876  {
877  }
878 
879  template <typename T>
881  {
882  agxAssert(this->isValid());
883  return m_entityPtr.getElement<T>(m_attribute);
884  }
885 
886  template <typename T>
888  {
889  agxAssert(this->isValid());
890  return m_entityPtr.getElement<T>(m_attribute);
891  }
892 
893  template <typename T>
895  {
896  return m_entityPtr.isValid() && m_attribute;
897  }
898 
899 
900  template <typename T>
902  {
903  return !this->isValid();
904  }
905 
906  template <typename T>
908  {
909  return this->isValid();
910  }
911 
912 }
913 
915 
916 #ifdef _MSC_VER
917 # pragma warning(pop)
918 #endif
919 
920 
921 #endif /* _AGXDATA_ENTITY_STORAGE_H_ */
agxData::EntityStorage * getStorage()
Alias for getData()-&gt;getStorage()
agxData::EntityModel * getModel()
Representation of a path, a list of name components.
Definition: Path.h:33
agx::Index getId() const
Definition: Attribute.h:365
AGXTERRAIN_EXPORT void clear()
void init(agxData::EntityStorage *storage, agx::Index id)
Set the target storage and id.
void AGXPHYSICS_EXPORT init()
Initialize agx.
An attribute container.
agxData::EntityData * getData()
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
agxData::LocalVector< std::pair< size_t, size_t > > InstanceSwapLocalVector
agx::Index calculateIndex() const
Calculate the index using the indirect id.
agxData::EntityInstance instance()
Definition: EntityPtr.h:269
static const agx::Name IdToIndexName
bool is() const
Subclass test.
size_t size() const
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
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Abstract representation of a value.
Definition: Value.h:42
agxData::EntityModel * getEntityModel()
#define agxAssertN(expr, format,...)
Definition: debug.h:145
agxData::Buffer * getBuffer(const agx::Name &name)
T & operator()(const agxData::ScalarAttributeT< T > *attribute)
Access the value of a specific attribute.
T & get(const agx::Name &attributeName, size_t index)
Slow but convenient accessor.
#define m_size
Definition: Vector.h:429
bool isInstanceOf(agxData::EntityModel *model) const
void swapIndex(EntityPtr &other)
Swap index with another instance.
Entity instance provides access to a single instance in an EntityStorage.
bool is(const agx::Model *other) const
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
Definition: EntityPtr.h:51
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
size_t indexToId(size_t index) const
Convert between instance id and data index.
#define agxAbort()
Definition: debug.h:164
agxData::Buffer * getIdToIndexBuffer()
void swapId(EntityPtr &other)
Swap id with another instance.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
T align_ceil(T value, T alignment)
Definition: Math.h:464
agxData::Array< T > dereferenceMultipliedAttribute(const agxData::EntityPtr &entity, const agxData::ScalarAttributeT< T > *attribute)
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:62
const agx::Name & getName() const
Definition: Object.h:369
agxData::EntityData * getData()
GLenum GLuint id
Definition: gl.h:5539
static EntityPtr createWithIndex(EntityStorage *storage, agx::Index index)
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agx::Index getId() const
Definition: EntityPtr.h:273
agxData::EntityStorage * getStorage() const
Definition: EntityPtr.h:272
const char * c_str() const
EntityPtr operator[](size_t index)
void destroyInstance(agxData::EntityPtr instance)
Templated vector class.
Definition: Vector.h:52
const agxData::BufferTable & getBuffers() const
void destroyInstances(const VectorT &instances)
uint32_t UInt
Definition: Integer.h:34
agxData::Buffer * getGlobalOrderBuffer()
If the storage is used as a global result, we provide a permutation buffer for parallel determinism...
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
agxData::Buffer * getInstanceBuffer()
void verifyIndex() const
Check for broken ptr, by verifying that the index is active in the storage.
AGX_DECLARE_VECTOR_TYPES(BinaryData)
bool isValid() const
agxData::EntityModel * getModel()
Alias for getData()-&gt;getStorage()-&gt;getModel()
IndexRangeT< agx::UInt > IndexRange
Definition: IndexRange.h:140
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
Abstract representation of a data buffer.
Definition: Buffer.h:55
void verifyIndex() const
Check for broken ptr, by verifying that the id is active in the storage.
UInt32 Index
Definition: Integer.h:52
size_t capacity() const
agx::Index calculateId() const
agx::UInt8 Byte
Definition: agxData.h:45
agx::VectorPOD< std::pair< size_t, size_t > > InstanceSwapVector
Callback1< Value * > CallbackType
Definition: Event.h:37
A range of indices.
Definition: IndexRange.h:32
EntityInstance()
Constructors.
#define agxAssert(expr)
Definition: debug.h:143
agx::Path getPath() const
agx::HashTable< Attribute *, BufferRef > BufferTable
Definition: EntityStorage.h:60
agxData::Byte * getPermutationBuffer(agxData::Attribute *attribute)
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition: EntityModel.h:63
bool operator!() const
T & getElement(size_t index)
Definition: Buffer.h:517
T * get() const
Definition: ref_ptr.h:256
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
bool useInstanceTable() const
bool isInstanceOf(agxData::EntityModel *model) const
agx::Index getIndex() const
EntityPtr at(size_t index)
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
agx::UInt32 getId() const
Definition: Object.h:370
Local scope vector.
Definition: LocalVector.h:43
#define agxAssert1(expr, msg)
Definition: debug.h:144
agx::String fullName() const
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
#define m_capacity
Definition: Vector.h:430
agxData::ValueRefT< agx::UInt > capacityParameter
Definition: EntityStorage.h:91
void swapInstances(const InstanceSwapVector &swaps)
agxData::IndexArray & getIdToIndexTable()
Inheritance with partial specialization due to bug with ref_ptr containers.
const T & get() const
Definition: Value.h:325
const agxData::Array< EntityPtr > getInstances() const
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Definition: Device.h:57
uint32_t UInt32
Definition: Integer.h:40
size_t idToIndex(size_t id) const
Convert between instance id and data index.
#define AGXCORE_EXPORT
agx::Object * getObject(const agx::Name &name, size_t index=0)
Definition: Component.h:194
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agxData::ValueRefT< agx::UInt > sizeParameter
Definition: EntityStorage.h:90
EntityStorage(agxData::EntityModel *entity, size_t initialCapacity=32)
static const agx::Name IndexToIdName