10 #ifndef Navigation_BlobBuffer_H
11 #define Navigation_BlobBuffer_H
26 BlobRefInfo() { Clear(); }
32 m_shallowBlobSizePtr = shallowBlobSizePtr;
33 m_offsetPtr = offsetPtr;
34 m_blobGlobalOffset = blobGlobalOffset;
37 bool IsValid() {
return m_shallowBlobSizePtr !=
KY_NULL; }
61 BlobBuffer() : m_offset(0), m_buffer(
KY_NULL) {}
64 bool IsWriteMode() {
return m_buffer !=
KY_NULL; }
68 template<
class T> T* Alloc();
72 template<
class T> T* AllocArray(BlobArray<T>* blobArray,
KyUInt32 count)
74 return AllocAndCopyArray<T>(blobArray,
KY_NULL, count);
79 template<
class T> T* AllocAndCopyArray(BlobArray<T>* blobArray,
const T* src,
KyUInt32 count);
81 template<
class T> T* AllocAndCopyReferencedBlob(BlobRef<T>* blobRef,
void* srcBlob,
KyUInt32 srcBlobDeepSize,
KyUInt32 srcBlobShallowSize);
83 template<
class T> T* AllocAndCopyReferencedBlobFromBlobHandler(BlobRef<T>* blobRef,
const BlobHandler<T>& blobHandler);
86 void SwitchToWriteMode(BaseBlobHandler& baseBlobHandler,
KyUInt32 rootShallowBlobSize, MemoryHeap* heap,
KyInt32 memStat);
90 template<
class T>
void BeginBlobRefBuffer(BlobRef<T>* blobRef);
92 void SetBlobRefInfoFromCurrentOffset();
94 void SetBlobRefInfoFromCopiedBlobRef(
KyUInt32 shallowBlobSize);
99 BlobRefInfo m_blobRefInfo;
106 T* BlobBuffer::Alloc()
108 KY_ASSERT(
sizeof(T) % 4 == 0);
110 if (IsWriteMode() ==
false)
112 m_offset +=
sizeof(T);
116 T* ptr = (T*)(m_buffer + m_offset);
118 m_offset += sizeof(T);
124 T* BlobBuffer::AllocAndCopyArray(BlobArray<T>* blobArray, const T* src,
KyUInt32 count)
127 KyUInt32 alignedSize = GetAlignedSize(size);
128 KyUInt32 paddingSize = alignedSize - size;
130 if (IsWriteMode() ==
false)
132 m_offset += alignedSize;
138 blobArray->m_count = count;
139 blobArray->m_offset = 0;
144 T* dest = (T*)(m_buffer + m_offset);
147 blobArray->m_count = count;
148 blobArray->m_offset = (
KyInt32)((
char*)dest - (
char*)&blobArray->m_offset);
152 memcpy(dest, src, size);
156 memset(dest, 0, size);
159 for (
KyUInt32 i = 0; i < count; ++i)
162 for (
KyUInt32 i = 0; i < paddingSize; ++i)
163 ((
char*)dest)[size + i] = 0;
165 m_offset += alignedSize;
171 void BlobBuffer::BeginBlobRefBuffer(BlobRef<T>* blobRef)
175 SetBlobRefInfoFromCurrentOffset();
176 m_blobRefInfo.Set(&blobRef->m_impl.m_shallowBlobSize, &blobRef->m_impl.m_offset, m_offset);
181 T* BlobBuffer::AllocAndCopyReferencedBlob(BlobRef<T>* blobRef,
void* srcBlob,
KyUInt32 srcBlobDeepSize,
KyUInt32 srcBlobShallowSize)
183 BeginBlobRefBuffer(blobRef);
185 KyUInt32 alignedSize = GetAlignedSize(srcBlobDeepSize);
186 KyUInt32 paddingSize = alignedSize - srcBlobDeepSize;
188 if (IsWriteMode() ==
false || srcBlob ==
KY_NULL || blobRef ==
KY_NULL)
190 m_offset += alignedSize;
191 SetBlobRefInfoFromCopiedBlobRef(srcBlobShallowSize);
195 char* dest = m_buffer + m_offset;
196 memcpy(dest, srcBlob, srcBlobDeepSize);
199 for (
KyUInt32 i = 0; i < paddingSize; ++i)
200 ((
char*)dest)[srcBlobDeepSize + i] = 0;
202 m_offset += alignedSize;
203 SetBlobRefInfoFromCopiedBlobRef(srcBlobShallowSize);
209 T* BlobBuffer::AllocAndCopyReferencedBlobFromBlobHandler(BlobRef<T>* blobRef,
const BlobHandler<T>& blobHandler)
211 return AllocAndCopyReferencedBlob(blobRef, (
void*)blobHandler.VoidBlob(), blobHandler.GetDeepBlobSize(), blobHandler.GetShallowBlobSize());
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36