29#ifndef SN_SERIALIZATION_CONTEXT_H
30#define SN_SERIALIZATION_CONTEXT_H
32#include "foundation/PxAssert.h"
33#include "foundation/PxMemory.h"
34#include "foundation/PxHash.h"
35#include "common/PxSerialFramework.h"
36#include "extensions/PxDefaultStreams.h"
38#include "foundation/PxUserAllocated.h"
39#include "CmCollection.h"
41#include "SnConvX_Align.h"
97#define SERIAL_OBJECT_INDEX_TYPE_BIT (1u<<31)
113 PX_ASSERT((index & SERIAL_OBJECT_INDEX_TYPE_BIT) == 0);
114 mObjIndex = index | (external ? SERIAL_OBJECT_INDEX_TYPE_BIT : 0);
119 PX_ASSERT(mObjIndex != PX_INVALID_U32);
120 isExternal = (mObjIndex & SERIAL_OBJECT_INDEX_TYPE_BIT) > 0;
121 return mObjIndex & ~SERIAL_OBJECT_INDEX_TYPE_BIT;
126 return mObjIndex < so.mObjIndex;
146 objIndex = _objIndex;
169 reference(_reference),
196 reference(_reference),
217 PxU8* objectDataAddress,
222 : mManifestTable(manifestTable)
223 , mImportReferences(importReferences)
224 , mObjectDataAddress(objectDataAddress)
225 , mInternalPtrReferencesMap(internalPtrReferencesMap)
226 , mInternalHandle16ReferencesMap(internalHandle16ReferencesMap)
227 , mExternalRefs(externalRefs)
229 mExtraDataAddress = extraData;
238 PxU8* mObjectDataAddress;
254 : mCollection(collection)
255 , mExternalRefs(externalRefs)
258 for (PxU32 i=0;i<mCollection.internalGetNbObjects();i++)
260 mObjToCollectionIndexMap[mCollection.internalGetObject(i)] = i;
264 virtual void writeData(
const void* buffer, PxU32 size) { mMemStream.
write(buffer, size); }
265 virtual PxU32 getTotalStoredSize() {
return mMemStream.getSize(); }
266 virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN)
271 PxI32 bytesToPad = PxI32(getPadding(mMemStream.getSize(), alignment));
272 static const PxI32 BUFSIZE = 64;
274 PxMemSet(buf, 0, bytesToPad < BUFSIZE ? PxU32(bytesToPad) : PxU32(BUFSIZE));
275 while(bytesToPad > 0)
277 mMemStream.
write(buf, bytesToPad < BUFSIZE ? PxU32(bytesToPad) : PxU32(BUFSIZE));
278 bytesToPad -= BUFSIZE;
280 PX_ASSERT(!getPadding(getTotalStoredSize(), alignment));
286 "Cannot export names during exportData.");
294 InternalPtrRefMap& getInternalPtrReferencesMap() {
return mInternalPtrReferencesMap; }
295 InternalHandle16RefMap& getInternalHandle16ReferencesMap() {
return mInternalHandle16ReferencesMap; }
297 PxU32 getSize()
const {
return mMemStream.getSize(); }
298 PxU8* getData()
const {
return mMemStream.getData(); }
304 PxHashMap<PxSerialObjectId, PxU32> mImportReferencesMap;
305 PxArray<ImportReference> mImportReferences;
308 InternalPtrRefMap mInternalPtrReferencesMap;
309 InternalHandle16RefMap mInternalHandle16ReferencesMap;
312 PxHashMap<const PxBase*, PxU32> mObjToCollectionIndexMap;
315 const Cm::Collection& mCollection;
316 const Cm::Collection* mExternalRefs;
318 PxDefaultMemoryOutputStream mMemStream;
Definition CmCollection.h:46
Definition CmCollection.h:61
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Collection class for serialization.
Definition PxCollection.h:104
virtual PxU32 write(const void *src, PxU32 count)
write to the stream. The number of bytes written may be less than the number sent.
Definition ExtDefaultStreams.cpp:57
Binary deserialization context class.
Definition PxSerialFramework.h:174
Binary serialization context class.
Definition PxSerialFramework.h:99
Definition PxUserAllocated.h:43
Definition SnSerializationContext.h:211
virtual PxBase * resolveReference(PxU32 kind, size_t reference) const
Retrieves a pointer to a deserialized PxBase object given a corresponding deserialized reference valu...
Definition SnSerializationContext.cpp:35
Definition SnSerializationContext.h:250
virtual void writeData(const void *buffer, PxU32 size)
Serializes object data and object extra data.
Definition SnSerializationContext.h:264
const PxCollection & getCollection() const
Returns the collection that is being serialized.
Definition SnSerializationContext.h:289
virtual void registerReference(PxBase &serializable, PxU32 kind, size_t reference)
Registers a reference value corresponding to a PxBase object.
Definition SnSerializationContext.cpp:72
virtual void alignData(PxU32 alignment=PX_SERIAL_ALIGN)
Aligns the serialized data.
Definition SnSerializationContext.h:266
virtual void writeName(const char *)
Helper function to write a name to the extraData if serialization is configured to save names.
Definition SnSerializationContext.h:283
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemSet(void *dest, PxI32 c, PxU32 count)
Sets the bytes of the provided buffer to the specified value.
Definition PxMemory.h:67
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition PxMemory.h:83
PX_INLINE void PxMarkSerializedMemory(void *ptr, PxU32 byteSize)
Definition PxMemory.h:111
PxU64 PxSerialObjectId
ID type for PxBase objects in a PxCollection.
Definition PxSerialFramework.h:61
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65
Definition SnSerializationContext.h:134
Definition SnSerializationContext.h:74
Definition SnSerializationContext.h:185
Definition SnSerializationContext.h:158
Definition SnSerializationContext.h:49
Definition SnSerializationContext.h:99