Refactor raw data ReadSttream and WriteStream to have easier to use API with more features
This commit is contained in:
@@ -323,7 +323,7 @@ bool AnimGraphBase::onNodeLoaded(Node* n)
|
||||
|
||||
int32 ruleSize;
|
||||
stream.ReadInt32(&ruleSize);
|
||||
const auto ruleBytes = (byte*)stream.Read(ruleSize);
|
||||
const auto ruleBytes = (byte*)stream.Move(ruleSize);
|
||||
|
||||
if (static_cast<int32>(transition.Flags & AnimGraphStateTransition::FlagTypes::Enabled) == 0)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
break;
|
||||
case Track::Types::PostProcessMaterial:
|
||||
{
|
||||
const auto trackData = stream.Read<PostProcessMaterialTrack::Data>();
|
||||
const auto trackData = stream.Move<PostProcessMaterialTrack::Data>();
|
||||
track.Data = trackData;
|
||||
track.Asset = Content::LoadAsync<MaterialBase>(trackData->AssetID);
|
||||
const auto trackRuntime = _runtimeData.Move<PostProcessMaterialTrack::Runtime>();
|
||||
@@ -157,12 +157,12 @@ Asset::LoadResult SceneAnimation::load()
|
||||
{
|
||||
// [Deprecated on 03.09.2021 expires on 03.09.2023]
|
||||
trackRuntime->Count = 1;
|
||||
trackRuntime->Media = stream.Read<Media>();
|
||||
trackRuntime->Media = stream.Move<Media>();
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.ReadInt32(&trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Read<Media>(trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Move<Media>(trackRuntime->Count);
|
||||
}
|
||||
if (trackData->AssetID.IsValid() && !track.Asset)
|
||||
{
|
||||
@@ -173,7 +173,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
case Track::Types::NestedSceneAnimation:
|
||||
{
|
||||
const auto trackData = stream.Read<NestedSceneAnimationTrack::Data>();
|
||||
const auto trackData = stream.Move<NestedSceneAnimationTrack::Data>();
|
||||
track.Data = trackData;
|
||||
track.Asset = Content::LoadAsync<SceneAnimation>(trackData->AssetID);
|
||||
const auto trackRuntime = _runtimeData.Move<NestedSceneAnimationTrack::Runtime>();
|
||||
@@ -189,7 +189,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
case Track::Types::ScreenFade:
|
||||
{
|
||||
const auto trackData = stream.Read<ScreenFadeTrack::Data>();
|
||||
const auto trackData = stream.Move<ScreenFadeTrack::Data>();
|
||||
track.Data = trackData;
|
||||
if (trackData->GradientStopsCount < 0)
|
||||
{
|
||||
@@ -198,12 +198,12 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
const auto trackRuntime = _runtimeData.Move<ScreenFadeTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
trackRuntime->GradientStops = stream.Read<ScreenFadeTrack::GradientStop>(trackData->GradientStopsCount);
|
||||
trackRuntime->GradientStops = stream.Move<ScreenFadeTrack::GradientStop>(trackData->GradientStopsCount);
|
||||
break;
|
||||
}
|
||||
case Track::Types::Audio:
|
||||
{
|
||||
const auto trackData = stream.Read<AudioTrack::Data>();
|
||||
const auto trackData = stream.Move<AudioTrack::Data>();
|
||||
track.Data = trackData;
|
||||
track.Asset = Content::LoadAsync<AudioClip>(trackData->AssetID);
|
||||
const auto trackRuntime = _runtimeData.Move<AudioTrack::Runtime>();
|
||||
@@ -222,18 +222,18 @@ Asset::LoadResult SceneAnimation::load()
|
||||
else
|
||||
{
|
||||
stream.ReadInt32(&trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Read<AudioTrack::Media>(trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Move<AudioTrack::Media>(trackRuntime->Count);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Track::Types::AudioVolume:
|
||||
{
|
||||
const auto trackData = stream.Read<AudioVolumeTrack::Data>();
|
||||
const auto trackData = stream.Move<AudioVolumeTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<AudioVolumeTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
trackRuntime->KeyframesCount = trackData->KeyframesCount;
|
||||
trackRuntime->Keyframes = stream.Read<BezierCurveKeyframe<float>>(trackData->KeyframesCount);
|
||||
trackRuntime->Keyframes = stream.Move<BezierCurveKeyframe<float>>(trackData->KeyframesCount);
|
||||
if (track.ParentIndex != -1)
|
||||
{
|
||||
if (Tracks[track.ParentIndex].Type == Track::Types::Audio)
|
||||
@@ -250,7 +250,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
case Track::Types::Actor:
|
||||
{
|
||||
const auto trackData = stream.Read<ActorTrack::Data>();
|
||||
const auto trackData = stream.Move<ActorTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<ActorTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
@@ -259,7 +259,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
case Track::Types::Script:
|
||||
{
|
||||
const auto trackData = stream.Read<ScriptTrack::Data>();
|
||||
const auto trackData = stream.Move<ScriptTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<ScriptTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
@@ -274,33 +274,33 @@ Asset::LoadResult SceneAnimation::load()
|
||||
case Track::Types::KeyframesProperty:
|
||||
case Track::Types::ObjectReferenceProperty:
|
||||
{
|
||||
const auto trackData = stream.Read<KeyframesPropertyTrack::Data>();
|
||||
const auto trackData = stream.Move<KeyframesPropertyTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<KeyframesPropertyTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
track.TrackStateIndex = TrackStatesCount++;
|
||||
trackRuntime->PropertyName = stream.Read<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Read<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->PropertyName = stream.Move<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Move<char>(trackData->PropertyTypeNameLength + 1);
|
||||
const int32 keyframesDataSize = trackData->KeyframesCount * (sizeof(float) + trackData->ValueSize);
|
||||
trackRuntime->ValueSize = trackData->ValueSize;
|
||||
trackRuntime->KeyframesCount = trackData->KeyframesCount;
|
||||
trackRuntime->Keyframes = stream.Read(keyframesDataSize);
|
||||
trackRuntime->Keyframes = stream.Move(keyframesDataSize);
|
||||
needsParent = true;
|
||||
break;
|
||||
}
|
||||
case Track::Types::CurveProperty:
|
||||
{
|
||||
const auto trackData = stream.Read<CurvePropertyTrack::Data>();
|
||||
const auto trackData = stream.Move<CurvePropertyTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<CurvePropertyTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
track.TrackStateIndex = TrackStatesCount++;
|
||||
trackRuntime->PropertyName = stream.Read<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Read<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->PropertyName = stream.Move<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Move<char>(trackData->PropertyTypeNameLength + 1);
|
||||
const int32 keyframesDataSize = trackData->KeyframesCount * (sizeof(float) + trackData->ValueSize * 3);
|
||||
trackRuntime->ValueSize = trackData->ValueSize;
|
||||
trackRuntime->KeyframesCount = trackData->KeyframesCount;
|
||||
trackRuntime->Keyframes = stream.Read(keyframesDataSize);
|
||||
trackRuntime->Keyframes = stream.Move(keyframesDataSize);
|
||||
trackRuntime->DataType = CurvePropertyTrack::DataTypes::Unknown;
|
||||
trackRuntime->ValueType = CurvePropertyTrack::DataTypes::Unknown;
|
||||
if (StringUtils::Compare(trackRuntime->PropertyTypeName, "System.Single") == 0)
|
||||
@@ -367,13 +367,13 @@ Asset::LoadResult SceneAnimation::load()
|
||||
}
|
||||
case Track::Types::StringProperty:
|
||||
{
|
||||
const auto trackData = stream.Read<StringPropertyTrack::Data>();
|
||||
const auto trackData = stream.Move<StringPropertyTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = (StringPropertyTrack::Runtime*)_runtimeData.Move(sizeof(StringPropertyTrack::Runtime) + sizeof(void*) * 2 * trackData->KeyframesCount);
|
||||
track.RuntimeData = trackRuntime;
|
||||
track.TrackStateIndex = TrackStatesCount++;
|
||||
trackRuntime->PropertyName = stream.Read<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Read<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->PropertyName = stream.Move<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Move<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->ValueSize = trackData->ValueSize;
|
||||
trackRuntime->KeyframesCount = trackData->KeyframesCount;
|
||||
const auto keyframesTimes = (float*)((byte*)trackRuntime + sizeof(StringPropertyTrack::Runtime));
|
||||
@@ -383,7 +383,7 @@ Asset::LoadResult SceneAnimation::load()
|
||||
{
|
||||
stream.ReadFloat(&keyframesTimes[j]);
|
||||
stream.ReadInt32(&keyframesLengths[j]);
|
||||
keyframesValues[j] = stream.Read<Char>(keyframesLengths[j]);
|
||||
keyframesValues[j] = stream.Move<Char>(keyframesLengths[j]);
|
||||
}
|
||||
needsParent = true;
|
||||
break;
|
||||
@@ -391,13 +391,13 @@ Asset::LoadResult SceneAnimation::load()
|
||||
case Track::Types::StructProperty:
|
||||
case Track::Types::ObjectProperty:
|
||||
{
|
||||
const auto trackData = stream.Read<StructPropertyTrack::Data>();
|
||||
const auto trackData = stream.Move<StructPropertyTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<StructPropertyTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
track.TrackStateIndex = TrackStatesCount++;
|
||||
trackRuntime->PropertyName = stream.Read<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Read<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->PropertyName = stream.Move<char>(trackData->PropertyNameLength + 1);
|
||||
trackRuntime->PropertyTypeName = stream.Move<char>(trackData->PropertyTypeNameLength + 1);
|
||||
trackRuntime->ValueSize = trackData->ValueSize;
|
||||
needsParent = true;
|
||||
break;
|
||||
@@ -411,22 +411,22 @@ Asset::LoadResult SceneAnimation::load()
|
||||
stream.ReadInt32(&trackRuntime->EventParamsCount);
|
||||
stream.ReadInt32(&trackRuntime->EventsCount);
|
||||
stream.ReadInt32(&tmp);
|
||||
trackRuntime->EventName = stream.Read<char>(tmp + 1);
|
||||
trackRuntime->EventName = stream.Move<char>(tmp + 1);
|
||||
trackRuntime->EventParamsSize = 0;
|
||||
for (int j = 0; j < trackRuntime->EventParamsCount; j++)
|
||||
{
|
||||
stream.ReadInt32(&trackRuntime->EventParamSizes[j]);
|
||||
trackRuntime->EventParamsSize += trackRuntime->EventParamSizes[j];
|
||||
stream.ReadInt32(&tmp);
|
||||
trackRuntime->EventParamTypes[j] = stream.Read<char>(tmp + 1);
|
||||
trackRuntime->EventParamTypes[j] = stream.Move<char>(tmp + 1);
|
||||
}
|
||||
trackRuntime->DataBegin = stream.Read<byte>(trackRuntime->EventsCount * (sizeof(float) + trackRuntime->EventParamsSize));
|
||||
trackRuntime->DataBegin = stream.Move<byte>(trackRuntime->EventsCount * (sizeof(float) + trackRuntime->EventParamsSize));
|
||||
needsParent = true;
|
||||
break;
|
||||
}
|
||||
case Track::Types::CameraCut:
|
||||
{
|
||||
const auto trackData = stream.Read<CameraCutTrack::Data>();
|
||||
const auto trackData = stream.Move<CameraCutTrack::Data>();
|
||||
track.Data = trackData;
|
||||
const auto trackRuntime = _runtimeData.Move<CameraCutTrack::Runtime>();
|
||||
track.RuntimeData = trackRuntime;
|
||||
@@ -435,12 +435,12 @@ Asset::LoadResult SceneAnimation::load()
|
||||
{
|
||||
// [Deprecated on 03.09.2021 expires on 03.09.2023]
|
||||
trackRuntime->Count = 1;
|
||||
trackRuntime->Media = stream.Read<Media>();
|
||||
trackRuntime->Media = stream.Move<Media>();
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.ReadInt32(&trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Read<Media>(trackRuntime->Count);
|
||||
trackRuntime->Media = stream.Move<Media>(trackRuntime->Count);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -981,7 +981,7 @@ Asset::LoadResult Model::load()
|
||||
{
|
||||
ModelSDFMip mipData;
|
||||
sdfStream.Read(&mipData);
|
||||
void* mipBytes = sdfStream.Read(mipData.SlicePitch);
|
||||
void* mipBytes = sdfStream.Move(mipData.SlicePitch);
|
||||
auto task = ::New<StreamModelSDFTask>(this, SDF.Texture, Span<byte>((byte*)mipBytes, mipData.SlicePitch), mipData.MipIndex, mipData.RowPitch, mipData.SlicePitch);
|
||||
task->Start();
|
||||
}
|
||||
|
||||
@@ -239,20 +239,20 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
bool hasColors = stream.ReadBool();
|
||||
VB2ElementType18* vb2 = nullptr;
|
||||
if (hasColors)
|
||||
{
|
||||
vb2 = stream.Read<VB2ElementType18>(vertices);
|
||||
vb2 = stream.Move<VB2ElementType18>(vertices);
|
||||
}
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Allocate mesh
|
||||
lod.Meshes[meshIndex] = New<MeshData>();
|
||||
@@ -356,14 +356,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Allocate mesh
|
||||
lod.Meshes[meshIndex] = New<MeshData>();
|
||||
@@ -484,14 +484,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[lodIndex].Meshes[i];
|
||||
@@ -567,14 +567,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -642,14 +642,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -718,14 +718,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -798,14 +798,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType18>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType18>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType18>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -879,14 +879,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType15>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType15>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType15>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType15>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -960,14 +960,14 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffers
|
||||
auto vb0 = stream.Read<VB0ElementType15>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType15>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType15>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType15>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
@@ -1042,13 +1042,13 @@ private:
|
||||
return Asset::LoadResult::InvalidData;
|
||||
|
||||
// Vertex buffer
|
||||
auto vb = stream.Read<ModelVertex15>(vertices);
|
||||
auto vb = stream.Move<ModelVertex15>(vertices);
|
||||
|
||||
// Index Buffer
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Copy data
|
||||
auto& mesh = *data->LODs[0].Meshes[i];
|
||||
|
||||
@@ -67,8 +67,8 @@ private:
|
||||
const uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return true;
|
||||
const auto vb0 = stream.Read<VB0SkinnedElementType1>(vertices);
|
||||
const auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
const auto vb0 = stream.Move<VB0SkinnedElementType1>(vertices);
|
||||
const auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Write back
|
||||
output.WriteUint32(vertices);
|
||||
@@ -403,9 +403,9 @@ private:
|
||||
const uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return true;
|
||||
const auto vb0 = stream.Read<VB0SkinnedElementType>(vertices);
|
||||
const auto vb0 = stream.Move<VB0SkinnedElementType>(vertices);
|
||||
output.Write<VB0SkinnedElementType>(vb0, vertices);
|
||||
const auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
const auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
output.Write<byte>(ib, indicesCount * ibStride);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,15 +53,15 @@ ExportAssetResult AssetExporters::ExportModel(ExportAssetContext& context)
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return ExportAssetResult::Error;
|
||||
auto vb0 = stream.Read<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType>(vertices);
|
||||
bool hasColors = stream.ReadBool();
|
||||
VB2ElementType18* vb2 = nullptr;
|
||||
if (hasColors)
|
||||
{
|
||||
vb2 = stream.Read<VB2ElementType18>(vertices);
|
||||
vb2 = stream.Move<VB2ElementType18>(vertices);
|
||||
}
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
output->WriteText(StringAnsi::Format("# Mesh {0}\n", meshIndex));
|
||||
|
||||
@@ -165,8 +165,8 @@ ExportAssetResult AssetExporters::ExportSkinnedModel(ExportAssetContext& context
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return ExportAssetResult::Error;
|
||||
auto vb0 = stream.Read<VB0SkinnedElementType>(vertices);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto vb0 = stream.Move<VB0SkinnedElementType>(vertices);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
output->WriteText(StringAnsi::Format("# Mesh {0}\n", meshIndex));
|
||||
|
||||
|
||||
@@ -578,15 +578,15 @@ bool Mesh::DownloadDataCPU(MeshBufferType type, BytesContainer& result, int32& c
|
||||
LOG(Error, "Invalid mesh data.");
|
||||
return true;
|
||||
}
|
||||
auto vb0 = stream.Read<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType>(vertices);
|
||||
bool hasColors = stream.ReadBool();
|
||||
VB2ElementType18* vb2 = nullptr;
|
||||
if (hasColors)
|
||||
{
|
||||
vb2 = stream.Read<VB2ElementType18>(vertices);
|
||||
vb2 = stream.Move<VB2ElementType18>(vertices);
|
||||
}
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
if (i != _index)
|
||||
continue;
|
||||
|
||||
@@ -22,15 +22,15 @@ bool ModelLOD::Load(MemoryReadStream& stream)
|
||||
uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return true;
|
||||
auto vb0 = stream.Read<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Read<VB1ElementType>(vertices);
|
||||
auto vb0 = stream.Move<VB0ElementType>(vertices);
|
||||
auto vb1 = stream.Move<VB1ElementType>(vertices);
|
||||
bool hasColors = stream.ReadBool();
|
||||
VB2ElementType18* vb2 = nullptr;
|
||||
if (hasColors)
|
||||
{
|
||||
vb2 = stream.Read<VB2ElementType18>(vertices);
|
||||
vb2 = stream.Move<VB2ElementType18>(vertices);
|
||||
}
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Setup GPU resources
|
||||
if (Meshes[i].Load(vertices, triangles, vb0, vb1, vb2, ib, use16BitIndexBuffer))
|
||||
|
||||
@@ -289,7 +289,7 @@ bool SkinnedMesh::DownloadDataCPU(MeshBufferType type, BytesContainer& result, i
|
||||
stream.ReadUint32(&maxVertexIndex);
|
||||
uint32 blendShapeVertices;
|
||||
stream.ReadUint32(&blendShapeVertices);
|
||||
auto blendShapeVerticesData = stream.Read<byte>(blendShapeVertices * sizeof(BlendShapeVertex));
|
||||
auto blendShapeVerticesData = stream.Move<byte>(blendShapeVertices * sizeof(BlendShapeVertex));
|
||||
}
|
||||
uint32 indicesCount = triangles * 3;
|
||||
bool use16BitIndexBuffer = indicesCount <= MAX_uint16;
|
||||
@@ -299,8 +299,8 @@ bool SkinnedMesh::DownloadDataCPU(MeshBufferType type, BytesContainer& result, i
|
||||
LOG(Error, "Invalid mesh data.");
|
||||
return true;
|
||||
}
|
||||
auto vb0 = stream.Read<VB0SkinnedElementType>(vertices);
|
||||
auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
auto vb0 = stream.Move<VB0SkinnedElementType>(vertices);
|
||||
auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
if (i != _index)
|
||||
continue;
|
||||
|
||||
@@ -45,8 +45,8 @@ bool SkinnedModelLOD::Load(MemoryReadStream& stream)
|
||||
const uint32 ibStride = use16BitIndexBuffer ? sizeof(uint16) : sizeof(uint32);
|
||||
if (vertices == 0 || triangles == 0)
|
||||
return true;
|
||||
const auto vb0 = stream.Read<VB0SkinnedElementType>(vertices);
|
||||
const auto ib = stream.Read<byte>(indicesCount * ibStride);
|
||||
const auto vb0 = stream.Move<VB0SkinnedElementType>(vertices);
|
||||
const auto ib = stream.Move<byte>(indicesCount * ibStride);
|
||||
|
||||
// Setup GPU resources
|
||||
if (mesh.Load(vertices, triangles, vb0, ib, use16BitIndexBuffer))
|
||||
|
||||
@@ -109,7 +109,7 @@ bool GPUShader::Create(MemoryReadStream& stream)
|
||||
LOG(Warning, "Invalid shader cache size.");
|
||||
return true;
|
||||
}
|
||||
byte* cache = stream.Read<byte>(cacheSize);
|
||||
byte* cache = stream.Move<byte>(cacheSize);
|
||||
|
||||
// Read bindings
|
||||
stream.ReadBytes(&initializer.Bindings, sizeof(ShaderBindings));
|
||||
|
||||
@@ -1568,7 +1568,7 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
|
||||
int32 bufferSize;
|
||||
stream.ReadInt32(&bufferSize);
|
||||
const char* buffer = (const char*)stream.GetPositionHandle();
|
||||
stream.Read(bufferSize);
|
||||
stream.Move(bufferSize);
|
||||
|
||||
// Order in parent
|
||||
int32 orderInParent;
|
||||
@@ -1612,7 +1612,7 @@ bool Actor::FromBytes(const Span<byte>& data, Array<Actor*>& output, ISerializeM
|
||||
int32 bufferSize;
|
||||
stream.ReadInt32(&bufferSize);
|
||||
const char* buffer = (const char*)stream.GetPositionHandle();
|
||||
stream.Read(bufferSize);
|
||||
stream.Move(bufferSize);
|
||||
|
||||
// Order in parent
|
||||
int32 orderInParent;
|
||||
|
||||
@@ -126,7 +126,7 @@ bool SceneCSGData::TryGetSurfaceData(const Guid& brushId, int32 brushSurfaceInde
|
||||
// Invalid data
|
||||
return false;
|
||||
}
|
||||
stream.Read(trianglesCount * sizeof(Float3) * 3);
|
||||
stream.Move(trianglesCount * sizeof(Float3) * 3);
|
||||
}
|
||||
|
||||
// Read surface data
|
||||
@@ -138,7 +138,7 @@ bool SceneCSGData::TryGetSurfaceData(const Guid& brushId, int32 brushSurfaceInde
|
||||
}
|
||||
outData.Triangles.Clear();
|
||||
outData.Triangles.Resize(trianglesCount);
|
||||
Float3* src = stream.Read<Float3>(trianglesCount * 3);
|
||||
Float3* src = stream.Move<Float3>(trianglesCount * 3);
|
||||
Vector3* dst = (Vector3*)outData.Triangles.Get();
|
||||
for (int32 i = 0; i < trianglesCount * 3; i++)
|
||||
*dst++ = *src++;
|
||||
|
||||
@@ -50,7 +50,7 @@ bool NavMeshData::Load(BytesContainer& data, bool copyData)
|
||||
MemoryReadStream stream(data.Get(), data.Length());
|
||||
|
||||
// Read header
|
||||
const auto header = stream.Read<NavMeshDataHeader>(1);
|
||||
const auto header = stream.Move<NavMeshDataHeader>(1);
|
||||
if (header->Version != 1)
|
||||
{
|
||||
LOG(Warning, "Invalid valid navmesh data version {0}.", header->Version);
|
||||
@@ -70,7 +70,7 @@ bool NavMeshData::Load(BytesContainer& data, bool copyData)
|
||||
auto& tile = Tiles[tileIndex];
|
||||
|
||||
// Read tile header
|
||||
const auto tileHeader = stream.Read<NavMeshTileDataHeader>(1);
|
||||
const auto tileHeader = stream.Move<NavMeshTileDataHeader>(1);
|
||||
if (tileHeader->DataSize <= 0)
|
||||
{
|
||||
LOG(Warning, "Invalid navmesh tile data.");
|
||||
@@ -81,7 +81,7 @@ bool NavMeshData::Load(BytesContainer& data, bool copyData)
|
||||
tile.Layer = tileHeader->Layer;
|
||||
|
||||
// Read tile data
|
||||
const auto tileData = stream.Read<byte>(tileHeader->DataSize);
|
||||
const auto tileData = stream.Move<byte>(tileHeader->DataSize);
|
||||
if (copyData)
|
||||
{
|
||||
tile.Data.Copy(tileData, tileHeader->DataSize);
|
||||
|
||||
@@ -69,15 +69,12 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using ReadStream::Read;
|
||||
|
||||
/// <summary>
|
||||
/// Reads bytes without copying the data.
|
||||
/// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward.
|
||||
/// </summary>
|
||||
/// <param name="bytes">The amount of bytes to read.</param>
|
||||
/// <returns>The pointer to the data in memory.</returns>
|
||||
void* Read(uint32 bytes)
|
||||
void* Move(uint32 bytes)
|
||||
{
|
||||
ASSERT(GetLength() - GetPosition() >= bytes);
|
||||
const auto result = (void*)_position;
|
||||
@@ -86,24 +83,24 @@ public:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads given data type from the stream.
|
||||
/// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward.
|
||||
/// </summary>
|
||||
/// <returns>The pointer to the data in memory.</returns>
|
||||
template<typename T>
|
||||
FORCE_INLINE T* Read()
|
||||
FORCE_INLINE T* Move()
|
||||
{
|
||||
return static_cast<T*>(Read(sizeof(T)));
|
||||
return static_cast<T*>(Move(sizeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads array of given data type from the stream.
|
||||
/// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward.
|
||||
/// </summary>
|
||||
/// <param name="count">The amount of items to read.</param>
|
||||
/// <returns>The pointer to the data in memory.</returns>
|
||||
template<typename T>
|
||||
FORCE_INLINE T* Read(uint32 count)
|
||||
FORCE_INLINE T* Move(uint32 count)
|
||||
{
|
||||
return static_cast<T*>(Read(sizeof(T) * count));
|
||||
return static_cast<T*>(Move(sizeof(T) * count));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -145,49 +145,62 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
// Reads StringAnsi from the stream
|
||||
// @param data Data to read
|
||||
void ReadStringAnsi(StringAnsi* data);
|
||||
void Read(String& data);
|
||||
void Read(String& data, int16 lock);
|
||||
void Read(StringAnsi& data);
|
||||
void Read(StringAnsi& data, int8 lock);
|
||||
void Read(CommonValue& data);
|
||||
void Read(VariantType& data);
|
||||
void Read(Variant& data);
|
||||
|
||||
// Reads StringAnsi from the stream with a key
|
||||
// @param data Data to read
|
||||
void ReadStringAnsi(StringAnsi* data, int8 lock);
|
||||
|
||||
// Reads String from the stream
|
||||
// @param data Data to read
|
||||
void ReadString(String* data);
|
||||
|
||||
// Reads String from the stream
|
||||
// @param data Data to read
|
||||
// @param lock Characters pass in the stream
|
||||
void ReadString(String* data, int16 lock);
|
||||
|
||||
public:
|
||||
// Reads CommonValue from the stream
|
||||
// @param data Data to read
|
||||
void ReadCommonValue(CommonValue* data);
|
||||
|
||||
// Reads VariantType from the stream
|
||||
// @param data Data to read
|
||||
void ReadVariantType(VariantType* data);
|
||||
|
||||
// Reads Variant from the stream
|
||||
// @param data Data to read
|
||||
void ReadVariant(Variant* data);
|
||||
template<typename T>
|
||||
FORCE_INLINE typename TEnableIf<TIsPODType<T>::Value>::Type Read(T& data)
|
||||
{
|
||||
ReadBytes((void*)&data, sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read data array
|
||||
/// </summary>
|
||||
/// <param name="data">Array to read</param>
|
||||
template<typename T, typename AllocationType = HeapAllocation>
|
||||
void ReadArray(Array<T, AllocationType>* data)
|
||||
void Read(Array<T, AllocationType>& data)
|
||||
{
|
||||
static_assert(TIsPODType<T>::Value, "Only POD types are valid for ReadArray.");
|
||||
int32 size;
|
||||
ReadInt32(&size);
|
||||
data->Resize(size, false);
|
||||
data.Resize(size, false);
|
||||
if (size > 0)
|
||||
ReadBytes(data->Get(), size * sizeof(T));
|
||||
{
|
||||
if (TIsPODType<T>::Value)
|
||||
ReadBytes(data.Get(), size * sizeof(T));
|
||||
else
|
||||
{
|
||||
for (int32 i = 0; i < size; i++)
|
||||
Read(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read data dictionary
|
||||
/// </summary>
|
||||
/// <param name="data">Dictionary to read</param>
|
||||
template<typename KeyType, typename ValueType, typename AllocationType = HeapAllocation>
|
||||
void Read(Dictionary<KeyType, ValueType, AllocationType>& data)
|
||||
{
|
||||
int32 count;
|
||||
ReadInt32(&count);
|
||||
data.Clear();
|
||||
data.EnsureCapacity(count);
|
||||
if (count > 0)
|
||||
{
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
KeyType key;
|
||||
Read(key);
|
||||
Read(data[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -197,6 +210,54 @@ public:
|
||||
/// <param name="obj">The object to deserialize.</param>
|
||||
void ReadJson(ISerializable* obj);
|
||||
|
||||
public:
|
||||
// Reads StringAnsi from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadStringAnsi(StringAnsi* data);
|
||||
|
||||
// Reads StringAnsi from the stream with a key
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadStringAnsi(StringAnsi* data, int8 lock);
|
||||
|
||||
// Reads String from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadString(String* data);
|
||||
|
||||
// Reads String from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
// @param lock Characters pass in the stream
|
||||
void ReadString(String* data, int16 lock);
|
||||
|
||||
// Reads CommonValue from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadCommonValue(CommonValue* data);
|
||||
|
||||
// Reads VariantType from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadVariantType(VariantType* data);
|
||||
|
||||
// Reads Variant from the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to read
|
||||
void ReadVariant(Variant* data);
|
||||
|
||||
/// <summary>
|
||||
/// Read data array
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
/// </summary>
|
||||
/// <param name="data">Array to read</param>
|
||||
template<typename T, typename AllocationType = HeapAllocation>
|
||||
void ReadArray(Array<T, AllocationType>* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
public:
|
||||
// Deserialization of math types with float or double depending on the context (must match serialization)
|
||||
// Set useDouble=true to explicitly use 64-bit precision for serialized data
|
||||
|
||||
@@ -19,40 +19,40 @@
|
||||
#include "Engine/Scripting/ManagedCLR/MCore.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MUtils.h"
|
||||
|
||||
void ReadStream::ReadStringAnsi(StringAnsi* data)
|
||||
void ReadStream::Read(StringAnsi& data)
|
||||
{
|
||||
int32 length;
|
||||
ReadInt32(&length);
|
||||
if (length < 0 || length > STREAM_MAX_STRING_LENGTH)
|
||||
{
|
||||
_hasError = true;
|
||||
*data = "";
|
||||
data = "";
|
||||
return;
|
||||
}
|
||||
|
||||
data->ReserveSpace(length);
|
||||
data.ReserveSpace(length);
|
||||
if (length == 0)
|
||||
return;
|
||||
char* ptr = data->Get();
|
||||
char* ptr = data.Get();
|
||||
ASSERT(ptr != nullptr);
|
||||
Read(ptr, length);
|
||||
}
|
||||
|
||||
void ReadStream::ReadStringAnsi(StringAnsi* data, int8 lock)
|
||||
void ReadStream::Read(StringAnsi& data, int8 lock)
|
||||
{
|
||||
int32 length;
|
||||
ReadInt32(&length);
|
||||
if (length < 0 || length > STREAM_MAX_STRING_LENGTH)
|
||||
{
|
||||
_hasError = true;
|
||||
*data = "";
|
||||
data = "";
|
||||
return;
|
||||
}
|
||||
|
||||
data->ReserveSpace(length);
|
||||
data.ReserveSpace(length);
|
||||
if (length == 0)
|
||||
return;
|
||||
char* ptr = data->Get();
|
||||
char* ptr = data.Get();
|
||||
ASSERT(ptr != nullptr);
|
||||
Read(ptr, length);
|
||||
|
||||
@@ -63,7 +63,7 @@ void ReadStream::ReadStringAnsi(StringAnsi* data, int8 lock)
|
||||
}
|
||||
}
|
||||
|
||||
void ReadStream::ReadString(String* data)
|
||||
void ReadStream::Read(String& data)
|
||||
{
|
||||
int32 length;
|
||||
ReadInt32(&length);
|
||||
@@ -71,17 +71,17 @@ void ReadStream::ReadString(String* data)
|
||||
{
|
||||
if (length != 0)
|
||||
_hasError = true;
|
||||
data->Clear();
|
||||
data.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
data->ReserveSpace(length);
|
||||
Char* ptr = data->Get();
|
||||
data.ReserveSpace(length);
|
||||
Char* ptr = data.Get();
|
||||
ASSERT(ptr != nullptr);
|
||||
Read(ptr, length);
|
||||
}
|
||||
|
||||
void ReadStream::ReadString(String* data, int16 lock)
|
||||
void ReadStream::Read(String& data, int16 lock)
|
||||
{
|
||||
int32 length;
|
||||
ReadInt32(&length);
|
||||
@@ -89,12 +89,12 @@ void ReadStream::ReadString(String* data, int16 lock)
|
||||
{
|
||||
if (length != 0)
|
||||
_hasError = true;
|
||||
data->Clear();
|
||||
data.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
data->ReserveSpace(length);
|
||||
Char* ptr = data->Get();
|
||||
data.ReserveSpace(length);
|
||||
Char* ptr = data.Get();
|
||||
ASSERT(ptr != nullptr);
|
||||
Read(ptr, length);
|
||||
|
||||
@@ -105,127 +105,127 @@ void ReadStream::ReadString(String* data, int16 lock)
|
||||
}
|
||||
}
|
||||
|
||||
void ReadStream::ReadCommonValue(CommonValue* data)
|
||||
void ReadStream::Read(CommonValue& data)
|
||||
{
|
||||
byte type;
|
||||
ReadByte(&type);
|
||||
switch (static_cast<CommonType>(type))
|
||||
{
|
||||
case CommonType::Bool:
|
||||
data->Set(ReadBool());
|
||||
data.Set(ReadBool());
|
||||
break;
|
||||
case CommonType::Integer:
|
||||
{
|
||||
int32 v;
|
||||
ReadInt32(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Float:
|
||||
{
|
||||
float v;
|
||||
ReadFloat(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Vector2:
|
||||
{
|
||||
Float2 v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Vector3:
|
||||
{
|
||||
Float3 v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Vector4:
|
||||
{
|
||||
Float4 v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Color:
|
||||
{
|
||||
Color v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Guid:
|
||||
{
|
||||
Guid v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::String:
|
||||
{
|
||||
String v;
|
||||
ReadString(&v, 953);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Box:
|
||||
{
|
||||
BoundingBox v;
|
||||
ReadBoundingBox(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Rotation:
|
||||
{
|
||||
Quaternion v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Transform:
|
||||
{
|
||||
Transform v;
|
||||
ReadTransform(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Sphere:
|
||||
{
|
||||
BoundingSphere v;
|
||||
ReadBoundingSphere(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Rectangle:
|
||||
{
|
||||
Rectangle v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
case CommonType::Ray:
|
||||
{
|
||||
Ray v;
|
||||
ReadRay(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Matrix:
|
||||
{
|
||||
Matrix v;
|
||||
Read(&v);
|
||||
data->Set(v);
|
||||
data.Set(v);
|
||||
}
|
||||
break;
|
||||
case CommonType::Blob:
|
||||
{
|
||||
int32 length;
|
||||
Read(&length);
|
||||
data->SetBlob(length);
|
||||
data.SetBlob(length);
|
||||
if (length > 0)
|
||||
{
|
||||
ReadBytes(data->AsBlob.Data, length);
|
||||
ReadBytes(data.AsBlob.Data, length);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -233,9 +233,9 @@ void ReadStream::ReadCommonValue(CommonValue* data)
|
||||
}
|
||||
}
|
||||
|
||||
void ReadStream::ReadVariantType(VariantType* data)
|
||||
void ReadStream::Read(VariantType& data)
|
||||
{
|
||||
*data = VariantType((VariantType::Types)ReadByte());
|
||||
data = VariantType((VariantType::Types)ReadByte());
|
||||
int32 typeNameLength;
|
||||
ReadInt32(&typeNameLength);
|
||||
if (typeNameLength == MAX_int32)
|
||||
@@ -243,8 +243,8 @@ void ReadStream::ReadVariantType(VariantType* data)
|
||||
ReadInt32(&typeNameLength);
|
||||
if (typeNameLength == 0)
|
||||
return;
|
||||
data->TypeName = static_cast<char*>(Allocator::Allocate(typeNameLength + 1));
|
||||
char* ptr = data->TypeName;
|
||||
data.TypeName = static_cast<char*>(Allocator::Allocate(typeNameLength + 1));
|
||||
char* ptr = data.TypeName;
|
||||
Read(ptr, typeNameLength);
|
||||
for (int32 i = 0; i < typeNameLength; i++)
|
||||
{
|
||||
@@ -267,55 +267,55 @@ void ReadStream::ReadVariantType(VariantType* data)
|
||||
ptr++;
|
||||
}
|
||||
*ptr = 0;
|
||||
data->TypeName = static_cast<char*>(Allocator::Allocate(typeNameLength + 1));
|
||||
StringUtils::ConvertUTF162ANSI(chars.Get(), data->TypeName, typeNameLength);
|
||||
data->TypeName[typeNameLength] = 0;
|
||||
data.TypeName = static_cast<char*>(Allocator::Allocate(typeNameLength + 1));
|
||||
StringUtils::ConvertUTF162ANSI(chars.Get(), data.TypeName, typeNameLength);
|
||||
data.TypeName[typeNameLength] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadStream::ReadVariant(Variant* data)
|
||||
void ReadStream::Read(Variant& data)
|
||||
{
|
||||
VariantType type;
|
||||
ReadVariantType(&type);
|
||||
data->SetType(MoveTemp(type));
|
||||
switch (data->Type.Type)
|
||||
data.SetType(MoveTemp(type));
|
||||
switch (data.Type.Type)
|
||||
{
|
||||
case VariantType::Null:
|
||||
case VariantType::Void:
|
||||
break;
|
||||
case VariantType::Bool:
|
||||
data->AsBool = ReadBool();
|
||||
data.AsBool = ReadBool();
|
||||
break;
|
||||
case VariantType::Int16:
|
||||
ReadInt16(&data->AsInt16);
|
||||
ReadInt16(&data.AsInt16);
|
||||
break;
|
||||
case VariantType::Uint16:
|
||||
ReadUint16(&data->AsUint16);
|
||||
ReadUint16(&data.AsUint16);
|
||||
break;
|
||||
case VariantType::Int:
|
||||
ReadInt32(&data->AsInt);
|
||||
ReadInt32(&data.AsInt);
|
||||
break;
|
||||
case VariantType::Uint:
|
||||
ReadUint32(&data->AsUint);
|
||||
ReadUint32(&data.AsUint);
|
||||
break;
|
||||
case VariantType::Int64:
|
||||
ReadInt64(&data->AsInt64);
|
||||
ReadInt64(&data.AsInt64);
|
||||
break;
|
||||
case VariantType::Uint64:
|
||||
case VariantType::Enum:
|
||||
ReadUint64(&data->AsUint64);
|
||||
ReadUint64(&data.AsUint64);
|
||||
break;
|
||||
case VariantType::Float:
|
||||
ReadFloat(&data->AsFloat);
|
||||
ReadFloat(&data.AsFloat);
|
||||
break;
|
||||
case VariantType::Double:
|
||||
ReadDouble(&data->AsDouble);
|
||||
ReadDouble(&data.AsDouble);
|
||||
break;
|
||||
case VariantType::Pointer:
|
||||
{
|
||||
uint64 asUint64;
|
||||
ReadUint64(&asUint64);
|
||||
data->AsPointer = (void*)(uintptr)asUint64;
|
||||
data.AsPointer = (void*)(uintptr)asUint64;
|
||||
break;
|
||||
}
|
||||
case VariantType::String:
|
||||
@@ -324,13 +324,13 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
ReadInt32(&length);
|
||||
ASSERT(length < STREAM_MAX_STRING_LENGTH);
|
||||
const int32 dataLength = length * sizeof(Char) + 2;
|
||||
if (data->AsBlob.Length != dataLength)
|
||||
if (data.AsBlob.Length != dataLength)
|
||||
{
|
||||
Allocator::Free(data->AsBlob.Data);
|
||||
data->AsBlob.Data = dataLength > 0 ? Allocator::Allocate(dataLength) : nullptr;
|
||||
data->AsBlob.Length = dataLength;
|
||||
Allocator::Free(data.AsBlob.Data);
|
||||
data.AsBlob.Data = dataLength > 0 ? Allocator::Allocate(dataLength) : nullptr;
|
||||
data.AsBlob.Length = dataLength;
|
||||
}
|
||||
Char* ptr = (Char*)data->AsBlob.Data;
|
||||
Char* ptr = (Char*)data.AsBlob.Data;
|
||||
Read(ptr, length);
|
||||
for (int32 i = 0; i < length; i++)
|
||||
{
|
||||
@@ -344,7 +344,7 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
{
|
||||
Guid id;
|
||||
Read(&id);
|
||||
data->SetObject(FindObject(id, ScriptingObject::GetStaticClass()));
|
||||
data.SetObject(FindObject(id, ScriptingObject::GetStaticClass()));
|
||||
break;
|
||||
}
|
||||
case VariantType::ManagedObject:
|
||||
@@ -362,30 +362,30 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
ReadStringAnsi(&json, -71);
|
||||
#if USE_MONO
|
||||
MCore::AttachThread();
|
||||
MonoClass* klass = MUtils::GetClass(data->Type);
|
||||
MonoClass* klass = MUtils::GetClass(data.Type);
|
||||
if (!klass)
|
||||
{
|
||||
LOG(Error, "Invalid variant type {0}", data->Type);
|
||||
LOG(Error, "Invalid variant type {0}", data.Type);
|
||||
return;
|
||||
}
|
||||
MonoObject* obj = mono_object_new(mono_domain_get(), klass);
|
||||
if (!obj)
|
||||
{
|
||||
LOG(Error, "Failed to managed instance of the variant type {0}", data->Type);
|
||||
LOG(Error, "Failed to managed instance of the variant type {0}", data.Type);
|
||||
return;
|
||||
}
|
||||
if (!mono_class_is_valuetype(klass))
|
||||
mono_runtime_object_init(obj);
|
||||
ManagedSerialization::Deserialize(json, obj);
|
||||
if (data->Type.Type == VariantType::ManagedObject)
|
||||
data->SetManagedObject(obj);
|
||||
if (data.Type.Type == VariantType::ManagedObject)
|
||||
data.SetManagedObject(obj);
|
||||
else
|
||||
*data = MUtils::UnboxVariant(obj);
|
||||
data = MUtils::UnboxVariant(obj);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Error, "Invalid Variant {0) format {1}", data->Type.ToString(), format);
|
||||
LOG(Error, "Invalid Variant {0) format {1}", data.Type.ToString(), format);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -393,67 +393,67 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
{
|
||||
int32 length;
|
||||
ReadInt32(&length);
|
||||
data->SetBlob(length);
|
||||
ReadBytes(data->AsBlob.Data, length);
|
||||
data.SetBlob(length);
|
||||
ReadBytes(data.AsBlob.Data, length);
|
||||
break;
|
||||
}
|
||||
case VariantType::Asset:
|
||||
{
|
||||
Guid id;
|
||||
Read(&id);
|
||||
data->SetAsset(LoadAsset(id, Asset::TypeInitializer));
|
||||
data.SetAsset(LoadAsset(id, Asset::TypeInitializer));
|
||||
break;
|
||||
}
|
||||
case VariantType::Float2:
|
||||
ReadBytes(&data->AsData, sizeof(Float2));
|
||||
ReadBytes(&data.AsData, sizeof(Float2));
|
||||
break;
|
||||
case VariantType::Float3:
|
||||
ReadBytes(&data->AsData, sizeof(Float3));
|
||||
ReadBytes(&data.AsData, sizeof(Float3));
|
||||
break;
|
||||
case VariantType::Float4:
|
||||
ReadBytes(&data->AsData, sizeof(Float4));
|
||||
ReadBytes(&data.AsData, sizeof(Float4));
|
||||
break;
|
||||
case VariantType::Double2:
|
||||
ReadBytes(&data->AsData, sizeof(Double2));
|
||||
ReadBytes(&data.AsData, sizeof(Double2));
|
||||
break;
|
||||
case VariantType::Double3:
|
||||
ReadBytes(&data->AsData, sizeof(Double3));
|
||||
ReadBytes(&data.AsData, sizeof(Double3));
|
||||
break;
|
||||
case VariantType::Double4:
|
||||
ReadBytes(data->AsBlob.Data, sizeof(Double4));
|
||||
ReadBytes(data.AsBlob.Data, sizeof(Double4));
|
||||
break;
|
||||
case VariantType::Color:
|
||||
ReadBytes(&data->AsData, sizeof(Color));
|
||||
ReadBytes(&data.AsData, sizeof(Color));
|
||||
break;
|
||||
case VariantType::Guid:
|
||||
ReadBytes(&data->AsData, sizeof(Guid));
|
||||
ReadBytes(&data.AsData, sizeof(Guid));
|
||||
break;
|
||||
case VariantType::BoundingBox:
|
||||
ReadBoundingBox(&data->AsBoundingBox());
|
||||
ReadBoundingBox(&data.AsBoundingBox());
|
||||
break;
|
||||
case VariantType::BoundingSphere:
|
||||
ReadBoundingSphere(&data->AsBoundingSphere());
|
||||
ReadBoundingSphere(&data.AsBoundingSphere());
|
||||
break;
|
||||
case VariantType::Quaternion:
|
||||
ReadBytes(&data->AsData, sizeof(Quaternion));
|
||||
ReadBytes(&data.AsData, sizeof(Quaternion));
|
||||
break;
|
||||
case VariantType::Transform:
|
||||
ReadTransform((Transform*)&data->AsData);
|
||||
ReadTransform((Transform*)&data.AsData);
|
||||
break;
|
||||
case VariantType::Rectangle:
|
||||
ReadBytes(&data->AsData, sizeof(Rectangle));
|
||||
ReadBytes(&data.AsData, sizeof(Rectangle));
|
||||
break;
|
||||
case VariantType::Ray:
|
||||
ReadRay(&data->AsRay());
|
||||
ReadRay(&data.AsRay());
|
||||
break;
|
||||
case VariantType::Matrix:
|
||||
ReadBytes(data->AsBlob.Data, sizeof(Matrix));
|
||||
ReadBytes(data.AsBlob.Data, sizeof(Matrix));
|
||||
break;
|
||||
case VariantType::Array:
|
||||
{
|
||||
int32 count;
|
||||
ReadInt32(&count);
|
||||
auto& array = *(Array<Variant>*)data->AsData;
|
||||
auto& array = *(Array<Variant>*)data.AsData;
|
||||
array.Resize(count);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
ReadVariant(&array[i]);
|
||||
@@ -463,7 +463,7 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
{
|
||||
int32 count;
|
||||
ReadInt32(&count);
|
||||
auto& dictionary = *data->AsDictionary;
|
||||
auto& dictionary = *data.AsDictionary;
|
||||
dictionary.Clear();
|
||||
dictionary.EnsureCapacity(count);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
@@ -480,13 +480,13 @@ void ReadStream::ReadVariant(Variant* data)
|
||||
ReadInt32(&length);
|
||||
ASSERT(length < STREAM_MAX_STRING_LENGTH);
|
||||
const int32 dataLength = length + 1;
|
||||
if (data->AsBlob.Length != dataLength)
|
||||
if (data.AsBlob.Length != dataLength)
|
||||
{
|
||||
Allocator::Free(data->AsBlob.Data);
|
||||
data->AsBlob.Data = dataLength > 0 ? Allocator::Allocate(dataLength) : nullptr;
|
||||
data->AsBlob.Length = dataLength;
|
||||
Allocator::Free(data.AsBlob.Data);
|
||||
data.AsBlob.Data = dataLength > 0 ? Allocator::Allocate(dataLength) : nullptr;
|
||||
data.AsBlob.Length = dataLength;
|
||||
}
|
||||
char* ptr = (char*)data->AsBlob.Data;
|
||||
char* ptr = (char*)data.AsBlob.Data;
|
||||
Read(ptr, length);
|
||||
for (int32 i = 0; i < length; i++)
|
||||
{
|
||||
@@ -510,7 +510,7 @@ void ReadStream::ReadJson(ISerializable* obj)
|
||||
{
|
||||
if (const auto memoryStream = dynamic_cast<MemoryReadStream*>(this))
|
||||
{
|
||||
JsonSerializer::LoadFromBytes(obj, Span<byte>((byte*)memoryStream->Read(size), size), engineBuild);
|
||||
JsonSerializer::LoadFromBytes(obj, Span<byte>((byte*)memoryStream->Move(size), size), engineBuild);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -524,6 +524,41 @@ void ReadStream::ReadJson(ISerializable* obj)
|
||||
SetPosition(GetPosition() + size);
|
||||
}
|
||||
|
||||
void ReadStream::ReadStringAnsi(StringAnsi* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadStringAnsi(StringAnsi* data, int8 lock)
|
||||
{
|
||||
Read(*data, lock);
|
||||
}
|
||||
|
||||
void ReadStream::ReadString(String* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadString(String* data, int16 lock)
|
||||
{
|
||||
Read(*data, lock);
|
||||
}
|
||||
|
||||
void ReadStream::ReadCommonValue(CommonValue* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadVariantType(VariantType* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadVariant(Variant* data)
|
||||
{
|
||||
Read(*data);
|
||||
}
|
||||
|
||||
void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
@@ -644,7 +679,7 @@ void WriteStream::WriteText(const StringAnsiView& text)
|
||||
WriteBytes(text.Get(), sizeof(char) * text.Length());
|
||||
}
|
||||
|
||||
void WriteStream::WriteString(const StringView& data)
|
||||
void WriteStream::Write(const StringView& data)
|
||||
{
|
||||
const int32 length = data.Length();
|
||||
ASSERT(length < STREAM_MAX_STRING_LENGTH);
|
||||
@@ -652,7 +687,7 @@ void WriteStream::WriteString(const StringView& data)
|
||||
Write(*data, length);
|
||||
}
|
||||
|
||||
void WriteStream::WriteString(const StringView& data, int16 lock)
|
||||
void WriteStream::Write(const StringView& data, int16 lock)
|
||||
{
|
||||
ASSERT(data.Length() < STREAM_MAX_STRING_LENGTH);
|
||||
WriteInt32(data.Length());
|
||||
@@ -660,7 +695,7 @@ void WriteStream::WriteString(const StringView& data, int16 lock)
|
||||
WriteUint16((uint16)((uint16)data[i] ^ lock));
|
||||
}
|
||||
|
||||
void WriteStream::WriteStringAnsi(const StringAnsiView& data)
|
||||
void WriteStream::Write(const StringAnsiView& data)
|
||||
{
|
||||
const int32 length = data.Length();
|
||||
ASSERT(length < STREAM_MAX_STRING_LENGTH);
|
||||
@@ -668,7 +703,7 @@ void WriteStream::WriteStringAnsi(const StringAnsiView& data)
|
||||
Write(data.Get(), length);
|
||||
}
|
||||
|
||||
void WriteStream::WriteStringAnsi(const StringAnsiView& data, int8 lock)
|
||||
void WriteStream::Write(const StringAnsiView& data, int8 lock)
|
||||
{
|
||||
const int32 length = data.Length();
|
||||
ASSERT(length < STREAM_MAX_STRING_LENGTH);
|
||||
@@ -677,7 +712,7 @@ void WriteStream::WriteStringAnsi(const StringAnsiView& data, int8 lock)
|
||||
WriteUint8((uint8)((uint8)data[i] ^ lock));
|
||||
}
|
||||
|
||||
void WriteStream::WriteCommonValue(const CommonValue& data)
|
||||
void WriteStream::Write(const CommonValue& data)
|
||||
{
|
||||
WriteByte(static_cast<byte>(data.Type));
|
||||
switch (data.Type)
|
||||
@@ -739,14 +774,14 @@ void WriteStream::WriteCommonValue(const CommonValue& data)
|
||||
}
|
||||
}
|
||||
|
||||
void WriteStream::WriteVariantType(const VariantType& data)
|
||||
void WriteStream::Write(const VariantType& data)
|
||||
{
|
||||
WriteByte((byte)data.Type);
|
||||
WriteInt32(MAX_int32);
|
||||
WriteStringAnsi(StringAnsiView(data.TypeName), 77);
|
||||
}
|
||||
|
||||
void WriteStream::WriteVariant(const Variant& data)
|
||||
void WriteStream::Write(const Variant& data)
|
||||
{
|
||||
WriteVariantType(data.Type);
|
||||
Guid id;
|
||||
@@ -911,6 +946,41 @@ void WriteStream::WriteJson(ISerializable* obj, const void* otherObj)
|
||||
WriteInt32(0);
|
||||
}
|
||||
|
||||
void WriteStream::WriteString(const StringView& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteString(const StringView& data, int16 lock)
|
||||
{
|
||||
Write(data, lock);
|
||||
}
|
||||
|
||||
void WriteStream::WriteStringAnsi(const StringAnsiView& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteStringAnsi(const StringAnsiView& data, int8 lock)
|
||||
{
|
||||
Write(data, lock);
|
||||
}
|
||||
|
||||
void WriteStream::WriteCommonValue(const CommonValue& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteVariantType(const VariantType& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteVariant(const Variant& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
void WriteStream::WriteBoundingBox(const BoundingBox& box, bool useDouble)
|
||||
{
|
||||
#if USE_LARGE_WORLDS
|
||||
|
||||
@@ -164,49 +164,43 @@ public:
|
||||
void WriteText(const StringView& text);
|
||||
void WriteText(const StringAnsiView& text);
|
||||
|
||||
// Writes String to the stream
|
||||
// @param data Data to write
|
||||
void WriteString(const StringView& data);
|
||||
|
||||
// Writes String to the stream
|
||||
// @param data Data to write
|
||||
// @param lock Characters pass in the stream
|
||||
void WriteString(const StringView& data, int16 lock);
|
||||
|
||||
// Writes Ansi String to the stream
|
||||
// @param data Data to write
|
||||
void WriteStringAnsi(const StringAnsiView& data);
|
||||
|
||||
// Writes Ansi String to the stream
|
||||
// @param data Data to write
|
||||
// @param lock Characters pass in the stream
|
||||
void WriteStringAnsi(const StringAnsiView& data, int8 lock);
|
||||
|
||||
public:
|
||||
// Writes CommonValue to the stream
|
||||
// @param data Data to write
|
||||
void WriteCommonValue(const CommonValue& data);
|
||||
void Write(const StringView& data);
|
||||
void Write(const StringView& data, int16 lock);
|
||||
void Write(const StringAnsiView& data);
|
||||
void Write(const StringAnsiView& data, int8 lock);
|
||||
void Write(const CommonValue& data);
|
||||
void Write(const VariantType& data);
|
||||
void Write(const Variant& data);
|
||||
|
||||
// Writes VariantType to the stream
|
||||
// @param data Data to write
|
||||
void WriteVariantType(const VariantType& data);
|
||||
|
||||
// Writes Variant to the stream
|
||||
// @param data Data to write
|
||||
void WriteVariant(const Variant& data);
|
||||
|
||||
/// <summary>
|
||||
/// Write data array
|
||||
/// </summary>
|
||||
/// <param name="data">Array to write</param>
|
||||
template<typename T, typename AllocationType = HeapAllocation>
|
||||
void WriteArray(const Array<T, AllocationType>& data)
|
||||
template<typename T>
|
||||
FORCE_INLINE typename TEnableIf<TAnd<TIsPODType<T>, TNot<TIsPointer<T>>>::Value>::Type Write(const T& data)
|
||||
{
|
||||
WriteBytes((const void*)&data, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T, typename AllocationType = HeapAllocation>
|
||||
void Write(const Array<T, AllocationType>& data)
|
||||
{
|
||||
static_assert(TIsPODType<T>::Value, "Only POD types are valid for WriteArray.");
|
||||
const int32 size = data.Count();
|
||||
WriteInt32(size);
|
||||
if (size > 0)
|
||||
WriteBytes(data.Get(), size * sizeof(T));
|
||||
Write(data.Get(), size * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename KeyType, typename ValueType, typename AllocationType = HeapAllocation>
|
||||
void Write(const Dictionary<KeyType, ValueType, AllocationType>& data)
|
||||
{
|
||||
const int32 count = data.Count();
|
||||
WriteInt32(count);
|
||||
if (count > 0)
|
||||
{
|
||||
for (const auto& e : data)
|
||||
{
|
||||
Write(&e.Key, sizeof(KeyType));
|
||||
Write(&e.Value, sizeof(ValueType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -217,6 +211,55 @@ public:
|
||||
/// <param name="otherObj">The instance of the object to compare with and serialize only the modified properties. If null, then serialize all properties.</param>
|
||||
void WriteJson(ISerializable* obj, const void* otherObj = nullptr);
|
||||
|
||||
public:
|
||||
// Writes String to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
void WriteString(const StringView& data);
|
||||
|
||||
// Writes String to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
// @param lock Characters pass in the stream
|
||||
void WriteString(const StringView& data, int16 lock);
|
||||
|
||||
// Writes Ansi String to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
void WriteStringAnsi(const StringAnsiView& data);
|
||||
|
||||
// Writes Ansi String to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
// @param lock Characters pass in the stream
|
||||
void WriteStringAnsi(const StringAnsiView& data, int8 lock);
|
||||
|
||||
// Writes CommonValue to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
void WriteCommonValue(const CommonValue& data);
|
||||
|
||||
// Writes VariantType to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
void WriteVariantType(const VariantType& data);
|
||||
|
||||
// Writes Variant to the stream
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
// @param data Data to write
|
||||
void WriteVariant(const Variant& data);
|
||||
|
||||
/// <summary>
|
||||
/// Write data array
|
||||
/// [Deprecated on 11.10.2022, expires on 11.10.2024]
|
||||
/// </summary>
|
||||
/// <param name="data">Array to write</param>
|
||||
template<typename T, typename AllocationType = HeapAllocation>
|
||||
FORCE_INLINE void WriteArray(const Array<T, AllocationType>& data)
|
||||
{
|
||||
Write(data);
|
||||
}
|
||||
|
||||
public:
|
||||
// Serialization of math types with float or double depending on the context (must match deserialization)
|
||||
// Set useDouble=true to explicitly use 64-bit precision for serialized data
|
||||
|
||||
Reference in New Issue
Block a user