Skip to content

Commit 41e122d

Browse files
committed
Refactor: Bitstreams refactored to use 64-bit data types
1 parent b8bf9e9 commit 41e122d

File tree

6 files changed

+177
-173
lines changed

6 files changed

+177
-173
lines changed

Source/Foundation/bsfCore/Material/BsMaterialParams.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,17 @@ namespace bs
883883
}
884884
}
885885

886-
const UINT32 textureEntrySize = sizeof(MaterialParamTextureDataCore) + sizeof(UINT32);
887-
const UINT32 bufferEntrySize = sizeof(MaterialParamBufferDataCore) + sizeof(UINT32);
888-
const UINT32 samplerStateEntrySize = sizeof(MaterialParamSamplerStateDataCore) + sizeof(UINT32);
886+
const UINT64 textureEntrySize = sizeof(MaterialParamTextureDataCore) + sizeof(UINT32);
887+
const UINT64 bufferEntrySize = sizeof(MaterialParamBufferDataCore) + sizeof(UINT32);
888+
const UINT64 samplerStateEntrySize = sizeof(MaterialParamSamplerStateDataCore) + sizeof(UINT32);
889889

890-
const UINT32 dataParamsOffset = sizeof(UINT32) * 5;
891-
const UINT32 textureParamsOffset = dataParamsOffset + dataParamSize;
892-
const UINT32 bufferParamsOffset = textureParamsOffset + textureEntrySize * numDirtyTextureParams;
893-
const UINT32 samplerStateParamsOffset = bufferParamsOffset + bufferEntrySize * numDirtyBufferParams;
894-
const UINT32 structParamsOffset = samplerStateParamsOffset + samplerStateEntrySize * numDirtySamplerParams;
890+
const UINT64 dataParamsOffset = sizeof(UINT32) * 5;
891+
const UINT64 textureParamsOffset = dataParamsOffset + dataParamSize;
892+
const UINT64 bufferParamsOffset = textureParamsOffset + textureEntrySize * numDirtyTextureParams;
893+
const UINT64 samplerStateParamsOffset = bufferParamsOffset + bufferEntrySize * numDirtyBufferParams;
894+
const UINT64 structParamsOffset = samplerStateParamsOffset + samplerStateEntrySize * numDirtySamplerParams;
895895

896-
const UINT32 totalSize = structParamsOffset + structParamSize;
896+
const UINT32 totalSize = (UINT32)structParamsOffset + structParamSize;
897897

898898
if (buffer == nullptr)
899899
{
@@ -916,11 +916,11 @@ namespace bs
916916
rtti_write(numDirtySamplerParams, stream);
917917
rtti_write(numDirtyStructParams, stream);
918918

919-
UINT32 dirtyDataParamOffset = 0;
920-
UINT32 dirtyTextureParamIdx = 0;
921-
UINT32 dirtyBufferParamIdx = 0;
922-
UINT32 dirtySamplerParamIdx = 0;
923-
UINT32 dirtyStructParamOffset = 0;
919+
UINT64 dirtyDataParamOffset = 0;
920+
UINT64 dirtyTextureParamIdx = 0;
921+
UINT64 dirtyBufferParamIdx = 0;
922+
UINT64 dirtySamplerParamIdx = 0;
923+
UINT64 dirtyStructParamOffset = 0;
924924

925925
for(UINT32 i = 0; i < (UINT32)mParams.size(); i++)
926926
{
@@ -967,7 +967,7 @@ namespace bs
967967
dirtyDataParamOffset += dataSize;
968968

969969
// Param curves
970-
UINT32 numDirtyCurvesWriteDst = stream.tell();
970+
UINT64 numDirtyCurvesWriteDst = stream.tell();
971971
stream.writeBytes(0);
972972
dirtyDataParamOffset += sizeof(UINT32);
973973

Source/Foundation/bsfUtility/Reflection/BsRTTIPlain.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ namespace bs
287287
if(compress)
288288
{
289289
BitLength size = rtti_size(data);
290-
uint32_t headerSize = stream.writeVarInt(size.bytes);
290+
uint64_t headerSize = stream.writeVarInt(size.bytes);
291291
headerSize += stream.writeBits(&size.bits, 3);
292292

293293
size += BitLength::fromBits(headerSize);
@@ -297,7 +297,7 @@ namespace bs
297297
}
298298
else
299299
{
300-
uint32_t sizePos = stream.tell();
300+
uint64_t sizePos = stream.tell();
301301

302302
BitLength size = 0;
303303
stream.writeBytes(size.bytes);
@@ -323,7 +323,7 @@ namespace bs
323323
{
324324
if(compress)
325325
{
326-
uint32_t headerSizeBits = stream.readVarInt(size.bytes);
326+
uint64_t headerSizeBits = stream.readVarInt(size.bytes);
327327
size.bits = 0;
328328
headerSizeBits += stream.readBits(&size.bits, 3);
329329

Source/Foundation/bsfUtility/Serialization/BsBinarySerializer.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace bs
146146
bool objectIsBaseClass = false;
147147

148148
UINT32 bitsRead = readObjectMetaData(bufferedStream, flags, objectId, objectTypeId, objectIsBaseClass);
149-
bufferedStream.skip(-(int32_t)bitsRead);
149+
bufferedStream.skip(-(int64_t)bitsRead);
150150

151151
if (objectIsBaseClass)
152152
{
@@ -193,7 +193,7 @@ namespace bs
193193

194194
// Don't set report callback until we actually do the reads
195195
mReportProgress = std::move(progress);
196-
bufferedStream.seek((uint32_t)start * 8);
196+
bufferedStream.seek((uint64_t)start * 8);
197197

198198
// Now actually decode the objects
199199
ObjectToDecode& rootObjectToDecode = mDecodeObjectMap[rootObjectId];
@@ -205,7 +205,7 @@ namespace bs
205205
rootObjectToDecode.isDecoded = true;
206206

207207
mDecodeObjectMap.clear();
208-
bufferedStream.seek((uint32_t)endBits);
208+
bufferedStream.seek((uint64_t)endBits);
209209
stream->seek(end);
210210

211211
assert(bufferedStream.tell() == endBits);
@@ -510,7 +510,7 @@ namespace bs
510510
if (!objIsBaseClass)
511511
{
512512
// Found new object, we're done
513-
stream.skip(-(int32_t)readBits);
513+
stream.skip(-(int64_t)readBits);
514514

515515
finalizeObject(output.get());
516516
return true;
@@ -679,8 +679,8 @@ namespace bs
679679
{
680680
objToDecode.decodeInProgress = true;
681681

682-
const uint32_t curOffset = stream.tell();
683-
stream.seek((uint32_t)objToDecode.offset);
682+
const uint64_t curOffset = stream.tell();
683+
stream.seek(objToDecode.offset);
684684
decodeEntry(stream, dataEnd, flags, objToDecode.object, fieldTypeSchema);
685685
stream.seek(curOffset);
686686

@@ -729,7 +729,7 @@ namespace bs
729729
{
730730
BitLength typeSize;
731731
BitLength headerSize = rtti_read_size_header(stream, true, typeSize);
732-
stream.skip(-(int32_t)headerSize.getBits());
732+
stream.skip(-(int64_t)headerSize.getBits());
733733

734734
typeSizeBits = typeSize.getBits();
735735
}
@@ -739,7 +739,7 @@ namespace bs
739739
stream.readBytes(typeSize);
740740
stream.skipBytes(-(int32_t)sizeof(uint32_t));
741741

742-
typeSizeBits = typeSize * 8;
742+
typeSizeBits = (uint64_t)typeSize * 8;
743743
}
744744
}
745745

@@ -748,15 +748,15 @@ namespace bs
748748
stream.preload((uint32_t)Math::divideAndRoundUp(typeSizeBits, (uint64_t)8));
749749
curField->arrayElemFromBuffer(rttiInstance, output.get(), i, stream.getBitstream(), compressed);
750750

751-
stream.skip((uint32_t)typeSizeBits);
751+
stream.skip(typeSizeBits);
752752
}
753753
else
754754
{
755755
bool builtin = fieldSchema.fieldTypeId < 16;
756756
if (compressed && builtin)
757757
skipBuiltinType(fieldSchema.fieldTypeId, stream, compressed);
758758
else
759-
stream.skip((uint32_t)typeSizeBits);
759+
stream.skip(typeSizeBits);
760760
}
761761
}
762762
break;
@@ -824,10 +824,10 @@ namespace bs
824824
{
825825
objToDecode.decodeInProgress = true;
826826

827-
const size_t curOffset = stream.tell();
828-
stream.seek((uint32_t)objToDecode.offset);
827+
const uint64_t curOffset = stream.tell();
828+
stream.seek(objToDecode.offset);
829829
decodeEntry(stream, dataEnd, flags, objToDecode.object, fieldTypeSchema);
830-
stream.seek((uint32_t)curOffset);
830+
stream.seek(curOffset);
831831

832832
objToDecode.decodeInProgress = false;
833833
objToDecode.isDecoded = true;
@@ -870,7 +870,7 @@ namespace bs
870870
{
871871
BitLength typeSize;
872872
BitLength headerSize = rtti_read_size_header(stream, true, typeSize);
873-
stream.skip(-(int32_t)headerSize.getBits());
873+
stream.skip(-(int64_t)headerSize.getBits());
874874

875875
typeSizeBits = typeSize.getBits();
876876
}
@@ -880,7 +880,7 @@ namespace bs
880880
stream.readBytes(typeSize);
881881
stream.skipBytes(-(int32_t)sizeof(uint32_t));
882882

883-
typeSizeBits = typeSize * 8;
883+
typeSizeBits = (uint64_t)typeSize * 8;
884884
}
885885
}
886886

@@ -889,15 +889,15 @@ namespace bs
889889
stream.preload((uint32_t)Math::divideAndRoundUp(typeSizeBits, (uint64_t)8));
890890
curField->fromBuffer(rttiInstance, output.get(), stream.getBitstream(), compressed);
891891

892-
stream.skip((uint32_t)typeSizeBits);
892+
stream.skip(typeSizeBits);
893893
}
894894
else
895895
{
896896
bool builtin = fieldSchema.fieldTypeId < 16;
897897
if (compressed && builtin)
898898
skipBuiltinType(fieldSchema.fieldTypeId, stream, compressed);
899899
else
900-
stream.skip((uint32_t)typeSizeBits);
900+
stream.skip(typeSizeBits);
901901
}
902902

903903
break;
@@ -921,7 +921,7 @@ namespace bs
921921
const SPtr<DataStream>& dataStream = stream.getDataStream();
922922
if (dataStream->isFile()) // Allow streaming
923923
{
924-
size_t curOffset = stream.tell();
924+
uint64_t curOffset = stream.tell();
925925

926926
// Data blocks don't support data that isn't byte aligned, but encoder should take care of that
927927
assert((curOffset % 8) == 0);
@@ -954,7 +954,7 @@ namespace bs
954954
stream.clearBuffered(false);
955955
}
956956

957-
uint32_t bytesRead = Math::divideAndRoundUp(stream.tell(), 8U);
957+
UINT32 bytesRead = (UINT32)Math::divideAndRoundUp(stream.tell(), (uint64_t)8);
958958
if (mReportProgress && (bytesRead >= mNextProgressReport))
959959
{
960960
UINT32 lastReport = (bytesRead / REPORT_AFTER_BYTES) * REPORT_AFTER_BYTES;

Source/Foundation/bsfUtility/Serialization/BsBinarySerializer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ namespace bs
135135

136136
struct ObjectToDecode
137137
{
138-
ObjectToDecode(SPtr<IReflectable> object = nullptr, size_t offset = 0, SPtr<RTTISchema> schema = nullptr)
138+
ObjectToDecode(SPtr<IReflectable> object = nullptr, uint64_t offset = 0, SPtr<RTTISchema> schema = nullptr)
139139
:object(std::move(object)), offset(offset), schema(std::move(schema))
140140
{ }
141141

142142
SPtr<IReflectable> object;
143143
bool isDecoded = false;
144144
bool decodeInProgress = false; // Used for error reporting circular references
145-
size_t offset;
145+
uint64_t offset;
146146
SPtr<RTTISchema> schema;
147147
};
148148

0 commit comments

Comments
 (0)