17 #ifndef AGXDATA_ENTITY_STORAGE_H 18 #define AGXDATA_ENTITY_STORAGE_H 34 # pragma warning(push) 35 # pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer 43 class GlobalResultStorage;
49 class SimulationFrameWriter;
79 virtual void configure(agx::TiXmlElement *eStorage)
override;
86 void addListener(EventListener *listener);
87 void removeListener(EventListener *listener);
88 bool hasListener(EventListener *listener);
110 size_t capacity()
const;
115 size_t getNumBytes()
const;
126 void reserve(
size_t size);
134 template <
typename T>
137 template <
typename T>
152 void resize(
size_t size,
bool initializeElements =
true);
154 size_t presize(
size_t size,
size_t initialSize = 0);
157 void destroyInstance(
size_t id);
159 template <
typename VectorT>
160 void destroyInstances(
const VectorT& instances);
166 void swapInstances(
const InstanceSwapVector &swaps);
169 void swapInstances(
const InstanceSwapLocalVector& swaps);
229 size_t idToIndex(
size_t id)
const;
234 size_t indexToId(
size_t index)
const;
240 agxData::EntityData *getData();
242 template <
typename T>
245 template <
typename T>
246 const T* getData()
const;
253 void setUseInstanceTable(
bool flag);
258 bool useInstanceTable()
const;
292 void print(std::ostream& stream)
const;
295 void verifyConsistency();
301 template <
typename T>
302 T&
get(
const agx::Name& attributeName,
size_t index);
306 void preparePermutation();
321 template <
typename T>
324 template <
typename T>
332 void keyFrameResize(
size_t size,
size_t capacity);
334 void setEnableEvents(
bool flag);
340 void printInstanceTable()
const;
356 friend class EntityData;
358 void commitBatch(
size_t size);
366 void swapInstances(
size_t index1,
size_t index2);
367 void init(
size_t initialCapacity);
374 void elementBufferReallocationCallback(
Buffer* elementBuffer);
382 void destroyInstances(
const EntityPtr* instances,
size_t numInstances,
bool triggerEvent =
true);
390 template <
typename T>
399 bool m_useInstanceTable;
400 bool m_implicitResize;
402 bool m_usedResizeMethod;
405 BufferTable m_bufferTable;
406 BufferRefVector m_buffers;
408 EntityDataRef m_dataSet;
411 AttributeTable m_customAttributes;
424 Buffer::Event::CallbackType m_elementBufferReallocationCallback;
425 EventDispatch m_eventDispatch;
446 AGX_FORCE_INLINE bool EntityStorage::useInstanceTable()
const {
return m_useInstanceTable; }
449 AGX_FORCE_INLINE const BufferTable& EntityStorage::getBuffers()
const {
return m_bufferTable; }
458 template <
typename T>
461 agxAssert(agxData::getFormat<T>()->
is(agxData::getFormat<EntityPtr>()));
465 template <
typename T>
473 buffer = this->createBuffer(attribute);
479 template <
typename T>
482 Buffer *buffer = this->getBuffer(attribute);
486 template <
typename T>
489 for (
size_t i = 0; i < m_buffers.size(); ++i)
491 Buffer *buffer = m_buffers[i];
492 if (buffer->
getName() == attributeName)
497 return m_buffers[0]->getElement<T>(0);
503 return m_idToIndexArray[
id];
514 destroyInstance(instance.
getId());
523 template <
typename T>
526 template <
typename T>
527 AGX_FORCE_INLINE const T *EntityStorage::getData()
const {
return m_dataSet->as<
const T>(); }
541 return m_storage->idToIndex(
id);
547 return m_storage->indexToId(index);
552 return this->createInstances(1);
557 if (m_numElements + numInstances >= m_storage->size())
559 if (!m_hasBatchInstances)
561 m_storage->beginBatch();
562 m_hasBatchInstances =
true;
567 m_numElements = head;
571 m_numElements += numInstances;
573 return instanceIndex;
579 if (m_hasBatchInstances)
581 m_storage->commitBatch(m_numElements);
582 m_hasBatchInstances =
false;
598 return m_storage->getData();
603 template <
typename T>
606 agxAssert(dynamic_cast<T *>(this->getData()));
607 return *
static_cast<T *
>(this->getData());
610 template <
typename T>
617 return (
agx::Index)m_storage->idToIndex(m_id);
621 template <
typename T>
625 agxAssertN(m_storage,
"Can not access attribute \'%s\' from an invalid pointer.", attribute->
fullName().c_str());
626 Buffer *buffer = m_storage->getBuffer(attribute);
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);
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());
641 template <
typename T>
644 return this->getElement<T>(attribute);
647 template <
typename T>
650 return this->getElement<const T>(attribute);
653 template <
typename T>
656 return this->getElement<T>(attribute);
659 template <
typename T>
662 return this->getElement<const T>(attribute);
666 template <
typename T>
672 template <
typename T>
680 template <
typename T>
686 template <
typename T>
692 template <
typename T>
698 template <
typename T>
704 template <
typename T>
708 Buffer *buffer = this->getBuffer(attribute);
711 size_t arraySize = buffer->getElementArraySize();
716 template <
typename T>
719 return const_cast<EntityStorage *
>(
this)->dereferenceMultipliedAttribute(entity, attribute);
724 template <
typename VectorT>
725 void EntityStorage::destroyInstances(
const VectorT& instances)
727 this->destroyInstances(instances.begin(), instances.size());
733 return this->getPermutationBuffer(attribute->
getId());
738 return m_permutationBuffers[index];
743 template <
typename T>
748 return const_cast<T&
>(value->
get<T>());
751 template <
typename T>
754 return const_cast<EntityPtr *
>(
this)->
operator()(attribute);
760 return m_storage ? m_storage->getEntityModel() :
nullptr;
765 return m_storage ? m_storage->getEntityModel() :
nullptr;
773 m_storage->swapInstanceIds(m_id, other.m_id);
781 m_storage->swapInstances(calculateIndex(), other.
calculateIndex());
787 return m_storage && m_storage->getEntityModel()->is(model);
812 m_data =
const_cast<EntityData *
>(other.
getData());
833 return m ? m->
is(model) :
false;
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());
869 template <
typename T>
874 template <
typename T>
879 template <
typename T>
883 return m_entityPtr.getElement<T>(m_attribute);
886 template <
typename T>
890 return m_entityPtr.getElement<T>(m_attribute);
893 template <
typename T>
896 return m_entityPtr.
isValid() && m_attribute;
900 template <
typename T>
903 return !this->isValid();
906 template <
typename T>
909 return this->isValid();
917 # pragma warning(pop) agxData::EntityStorage * getStorage()
Alias for getData()->getStorage()
Representation of a path, a list of name components.
AGXTERRAIN_EXPORT void clear()
void AGXPHYSICS_EXPORT init()
Initialize agx.
agxData::EntityData * getData()
bool is(const agx::Model *other) const
Inheritance with partial specialization due to bug with ref_ptr containers.
agxData::LocalVector< std::pair< size_t, size_t > > InstanceSwapLocalVector
static const agx::Name IdToIndexName
size_t indexToId(size_t index) const
Convert between instance id and data index.
Data storage for a collection of entity instances of a specified EntityModel.
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
A component is an object containing other objects, enabling hierarchical structuring.
A model is an abstract representation of the class of an agx::Object.
agx::Index getIndex() const
Abstract representation of a value.
agxData::EntityModel * getEntityModel()
#define agxAssertN(expr, format,...)
AGXCORE_EXPORT Model * getModel(const Path &path, const Path &_namespace=Path())
Entity instance provides access to a single instance in an EntityStorage.
agx::String fullName() const
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
#define AGX_DECLARE_POINTER_TYPES(type)
T align_ceil(T value, T alignment)
Representation of a name string.
Type-specific Array used for fast access into the data held by a Buffer.
EntityPtr operator[](size_t index)
const char * c_str() const
Vector containing 'raw' data.
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
agxData::EntityModel * getModel()
Alias for getData()->getStorage()->getModel()
IndexRangeT< agx::UInt > IndexRange
An abstract attribute description, part of an Entity.
bool is() const
Subclass test.
Abstract representation of a data buffer.
void verifyIndex() const
Check for broken ptr, by verifying that the index is active in the storage.
Contains classes for low level data storage for AGX.
T & getElement(size_t index)
agx::VectorPOD< std::pair< size_t, size_t > > InstanceSwapVector
const agx::Name & getName() const
Callback1< T1 > CallbackType
EntityInstance()
Constructors.
agx::HashTable< Attribute *, BufferRef > BufferTable
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
agx::Index calculateId() const
bool isInstanceOf(agxData::EntityModel *model) const
AGXTERRAIN_EXPORT TimingStorage & getStorage()
EntityPtr at(size_t index)
Class for writing serialized data in binary format to a stream.
#define agxAssert1(expr, msg)
agxData::ValueRefT< agx::UInt > capacityParameter
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Inheritance with partial specialization due to bug with ref_ptr containers.
agxData::EntityStorage * getStorage() const
An agx::Device is an abstract representation of a device on which data can be stored and processed...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
agx::Index calculateIndex() const
Calculate the index using the indirect id.
agx::UInt32 getId() const
agx::Object is a refcounted object with a name.
AGX_DECLARE_VECTOR_TYPES(Clock)
agx::Path getPath() const
agxData::ValueRefT< agx::UInt > sizeParameter
static const agx::Name IndexToIdName