33 # pragma warning(push)
34 # pragma warning(disable: 6011)
42 class GlobalResultStorage;
48 class SimulationFrameWriter;
78 virtual void configure(agx::TiXmlElement *eStorage)
override;
109 size_t capacity()
const;
133 template <
typename T>
136 template <
typename T>
151 void resize(
size_t size,
bool initializeElements =
true);
153 size_t presize(
size_t size,
size_t initialSize = 0);
158 template <
typename VectorT>
159 void destroyInstances(
const VectorT& instances);
228 size_t idToIndex(
size_t id)
const;
233 size_t indexToId(
size_t index)
const;
239 agxData::EntityData *getData();
241 template <
typename T>
244 template <
typename T>
245 const T* getData()
const;
257 bool useInstanceTable()
const;
291 void print(std::ostream& stream)
const;
300 template <
typename T>
301 T& get(
const agx::Name& attributeName,
size_t index);
320 template <
typename T>
323 template <
typename T>
355 friend class EntityData;
357 void commitBatch(
size_t size);
365 void swapInstances(
size_t index1,
size_t index2);
366 void init(
size_t initialCapacity);
373 void elementBufferReallocationCallback(
Buffer* elementBuffer);
381 void destroyInstances(
const EntityPtr* instances,
size_t numInstances,
bool triggerEvent =
true);
389 template <
typename T>
398 bool m_useInstanceTable;
399 bool m_implicitResize;
401 bool m_usedResizeMethod;
407 EntityDataRef m_dataSet;
424 EventDispatch m_eventDispatch;
457 template <
typename T>
460 agxAssert(agxData::getFormat<T>()->
is(agxData::getFormat<EntityPtr>()));
464 template <
typename T>
472 buffer = this->createBuffer(attribute);
478 template <
typename T>
485 template <
typename T>
488 for (
size_t i = 0; i < m_buffers.
size(); ++i)
490 Buffer *buffer = m_buffers[i];
491 if (buffer->
getName() == attributeName)
496 return m_buffers[0]->getElement<T>(0);
502 return m_idToIndexArray[id];
522 template <
typename T>
525 template <
typename T>
540 return m_storage->idToIndex(
id);
546 return m_storage->indexToId(index);
551 return this->createInstances(1);
556 if (m_numElements + numInstances >= m_storage->size())
558 if (!m_hasBatchInstances)
560 m_storage->beginBatch();
561 m_hasBatchInstances =
true;
566 m_numElements = head;
570 m_numElements += numInstances;
572 return instanceIndex;
578 if (m_hasBatchInstances)
580 m_storage->commitBatch(m_numElements);
581 m_hasBatchInstances =
false;
602 template <
typename T>
606 return *
static_cast<T *
>(this->
getData());
609 template <
typename T>
620 template <
typename T>
624 agxAssertN(m_storage,
"Can not access attribute \'%s\' from an invalid pointer.", attribute->
fullName().c_str());
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());
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());
640 template <
typename T>
643 return this->getElement<T>(attribute);
646 template <
typename T>
649 return this->getElement<const T>(attribute);
652 template <
typename T>
655 return this->getElement<T>(attribute);
658 template <
typename T>
661 return this->getElement<const T>(attribute);
665 template <
typename T>
671 template <
typename T>
679 template <
typename T>
685 template <
typename T>
691 template <
typename T>
697 template <
typename T>
703 template <
typename T>
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());
715 template <
typename T>
723 template <
typename VectorT>
737 return m_permutationBuffers[index];
742 template <
typename T>
747 return const_cast<T&
>(value->
get<T>());
750 template <
typename T>
753 return const_cast<EntityPtr *
>(
this)->
operator()(attribute);
772 m_storage->swapInstanceIds(m_id, other.m_id);
811 m_data =
const_cast<EntityData *
>(other.
getData());
832 return m ? m->
is(model) :
false;
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());
868 template <
typename T>
873 template <
typename T>
878 template <
typename T>
882 return m_entityPtr.getElement<T>(m_attribute);
885 template <
typename T>
889 return m_entityPtr.getElement<T>(m_attribute);
892 template <
typename T>
895 return m_entityPtr.isValid() && m_attribute;
899 template <
typename T>
902 return !this->isValid();
905 template <
typename T>
908 return this->isValid();
916 # pragma warning(pop)
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGX_DECLARE_VECTOR_TYPES(type)
Type-specific Array used for fast access into the data held by a Buffer.
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
An abstract attribute description, part of an Entity.
agx::String fullName() const
Abstract representation of a data buffer.
T & getElement(size_t index)
size_t getElementArraySize() const
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...
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
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()
agxData::EntityModel * getModel()
void verifyIndex() const
Check for broken ptr, by verifying that the id is active in the storage.
agxData::EntityStorage * getStorage() const
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.
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
agxData::Array< T > getInstances()
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.
agxData::EntityStorage * createSharedStorage()
Swap buffers with another storage.
size_t idToIndex(size_t id) const
Convert between instance id and data index.
agxData::Buffer * getBuffer(const agx::Name &name)
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
void addCustomAttribute(agxData::Attribute *attribute)
Add a custom attribute buffer.
const agxData::BufferTable & getBuffers() const
void destroyInstance(size_t id)
agxData::Array< T > dereferenceMultipliedAttribute(const agxData::EntityPtr &entity, const agxData::ScalarAttributeT< T > *attribute)
static const agx::Name IdToIndexName
agxData::ValueRefT< agx::UInt > sizeParameter
size_t presize(size_t size, size_t initialSize=0)
agxData::Buffer * getOrCreateGlobalOrderBuffer()
Create the global order buffer if not already allocated.
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)
void reorder(const agxData::IndexArray &permutation)
Reorder the storage using a specified permutation.
void addListener(EventListener *listener)
const agxData::Array< T > getInstances() const
void setEnableEvents(bool flag)
void explicityRegisterBuffer(agxData::Buffer *buffer, agxData::Attribute *attribute)
void reset()
Clear the storage, and reset index-id tables.
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
static void extractPermutation(agx::IndexVector &result, agxStream::InputArchive &archive)
void destroyInstances(agxData::EntityRange range)
agxData::EntityData * getData()
virtual agx::Object * getResourceImpl(const agx::Path &path, agx::Model *model) override
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.
const agxData::Array< T > dereferenceMultipliedAttribute(const agxData::EntityPtr &entity, const agxData::ScalarAttributeT< T > *attribute) const
void printInstanceTable() const
void commitPermutation(const agxData::IndexArray &permutation)
agxData::EntityStorage * clone() const
static agx::Model * ClassModel()
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 preparePermutation()
static agxData::EntityStorage * load(agx::TiXmlElement *eStorage, agx::Device *device)
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)
Abstract representation of a value.
Class for writing serialized data in binary format to a stream.
A component is an object containing other objects, enabling hierarchical structuring.
agx::Object * getObject(const agx::Name &name, size_t index=0)
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Inheritance with partial specialization due to bug with ref_ptr containers.
Inheritance with partial specialization due to bug with ref_ptr containers.
A model is an abstract representation of the class of an agx::Object.
bool is(const agx::Model *other) const
Representation of a name string.
agx::Object is a refcounted object with a name.
agx::Path getPath() const
const agx::Name & getName() const
agx::UInt32 getId() const
Representation of a path, a list of name components.
const char * c_str() const
bool is() const
Subclass test.
Vector containing 'raw' data.
#define agxAssert1(expr, msg)
#define agxAssertN(expr, format,...)
Contains classes for low level data storage for AGX.
agx::HashTable< Attribute *, BufferRef > BufferTable
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
AGXTERRAIN_EXPORT TimingStorage & getStorage()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
T align_ceil(T value, T alignment)
IndexRangeT< agx::UInt > IndexRange
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
void AGXPHYSICS_EXPORT init()
Initialize agx.