Refactor native Stream serialization to new API

This commit is contained in:
Wojciech Figat
2022-10-20 17:28:12 +02:00
parent e5866a3ff4
commit 32e052a87b
34 changed files with 371 additions and 370 deletions

View File

@@ -143,7 +143,7 @@ void CookAssetsStep::CacheData::Load(CookingData& data)
LOG(Info, "Loading incremental build cooking cache (entries count: {0})", entriesCount);
file->Read(&Settings);
file->ReadBytes(&Settings, sizeof(Settings));
Entries.EnsureCapacity(Math::RoundUpToPowerOf2(static_cast<int32>(entriesCount * 3.0f)));
@@ -151,11 +151,11 @@ void CookAssetsStep::CacheData::Load(CookingData& data)
for (int32 i = 0; i < entriesCount; i++)
{
Guid id;
file->Read(&id);
file->Read(id);
String typeName;
file->ReadString(&typeName);
DateTime fileModified;
file->Read(&fileModified);
file->Read(fileModified);
int32 fileDependenciesCount;
file->ReadInt32(&fileDependenciesCount);
fileDependencies.Clear();
@@ -164,7 +164,7 @@ void CookAssetsStep::CacheData::Load(CookingData& data)
{
Pair<String, DateTime>& f = fileDependencies[j];
file->ReadString(&f.First, 10);
file->Read(&f.Second);
file->Read(f.Second);
}
// Skip missing entries
@@ -287,18 +287,18 @@ void CookAssetsStep::CacheData::Save()
// Serialize
file->WriteInt32(FLAXENGINE_VERSION_BUILD);
file->WriteInt32(Entries.Count());
file->Write(&Settings);
file->WriteBytes(&Settings, sizeof(Settings));
for (auto i = Entries.Begin(); i.IsNotEnd(); ++i)
{
auto& e = i->Value;
file->Write(&e.ID);
file->Write(e.ID);
file->WriteString(e.TypeName);
file->Write(&e.FileModified);
file->Write(e.FileModified);
file->WriteInt32(e.FileDependencies.Count());
for (auto& f : e.FileDependencies)
{
file->WriteString(f.First, 10);
file->Write(&f.Second);
file->Write(f.First, 10);
file->Write(f.Second);
}
}
file->WriteInt32(13);

View File

@@ -135,7 +135,7 @@ Asset::LoadResult SceneAnimation::load()
stream.ReadInt32(&track.ParentIndex);
stream.ReadInt32(&track.ChildrenCount);
stream.ReadString(&track.Name, -13);
stream.Read(&track.Color);
stream.Read(track.Color);
track.Disabled = (int32)track.Flag & (int32)Track::Flags::Mute || (track.ParentIndex != -1 && Tracks[track.ParentIndex].Disabled);
track.TrackStateIndex = -1;
track.Data = nullptr;

View File

@@ -404,7 +404,7 @@ bool CSGBuilderImpl::generateRawDataAsset(Scene* scene, RawData& meshData, Guid&
{
auto& surfaces = brush->Value.Surfaces;
stream.Write(&brush->Key);
stream.Write(brush->Key);
stream.WriteInt32(surfacesDataOffset);
// Calculate offset in data storage to the next brush data
@@ -426,7 +426,7 @@ bool CSGBuilderImpl::generateRawDataAsset(Scene* scene, RawData& meshData, Guid&
auto& triangles = surfaces[i].Triangles;
stream.WriteInt32(triangles.Count());
stream.Write(triangles.Get(), triangles.Count());
stream.WriteBytes(triangles.Get(), triangles.Count() * sizeof(RawData::SurfaceTriangle));
}
}
}

View File

@@ -174,7 +174,7 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(-1); // Parent Index
stream.WriteInt32(childrenCount); // Children Count
stream.WriteString(channel.NodeName, -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(Color32::White); // Color
const int32 parentIndex = trackIndex++;
auto& position = channel.Position.GetKeyframes();
@@ -186,13 +186,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(parentIndex); // Parent Index
stream.WriteInt32(0); // Children Count
stream.WriteString(String::Format(TEXT("Track_{0}_Position"), i), -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(Color32::White); // Color
stream.WriteByte(0); // Type
stream.WriteInt32(position.Count()); // Keyframes Count
for (auto& k : position)
{
stream.WriteFloat(k.Time * fpsInv);
stream.Write(&k.Value);
stream.Write(k.Value);
}
trackIndex++;
}
@@ -206,13 +206,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(parentIndex); // Parent Index
stream.WriteInt32(0); // Children Count
stream.WriteString(String::Format(TEXT("Track_{0}_Rotation"), i), -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(Color32::White); // Color
stream.WriteByte(1); // Type
stream.WriteInt32(rotation.Count()); // Keyframes Count
for (auto& k : rotation)
{
stream.WriteFloat(k.Time * fpsInv);
stream.Write(&k.Value);
stream.Write(k.Value);
}
trackIndex++;
}
@@ -226,13 +226,13 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(parentIndex); // Parent Index
stream.WriteInt32(0); // Children Count
stream.WriteString(String::Format(TEXT("Track_{0}_Scale"), i), -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(Color32::White); // Color
stream.WriteByte(2); // Type
stream.WriteInt32(scale.Count()); // Keyframes Count
for (auto& k : scale)
{
stream.WriteFloat(k.Time * fpsInv);
stream.Write(&k.Value);
stream.Write(k.Value);
}
trackIndex++;
}
@@ -253,8 +253,8 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(-1); // Parent Index
stream.WriteInt32(0); // Children Count
stream.WriteString(e.First, -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(&id);
stream.Write(Color32::White); // Color
stream.Write(id);
stream.WriteFloat(nestedAnim.Time);
stream.WriteFloat(nestedAnim.Duration);
stream.WriteFloat(nestedAnim.Speed);
@@ -268,7 +268,7 @@ void Animation::LoadTimeline(BytesContainer& result) const
stream.WriteInt32(-1); // Parent Index
stream.WriteInt32(0); // Children Count
stream.WriteString(e.First, -13); // Name
stream.Write(&Color32::White); // Color
stream.Write(Color32::White); // Color
stream.WriteInt32(e.Second.GetKeyframes().Count()); // Events Count
for (const auto& k : e.Second.GetKeyframes())
{
@@ -331,7 +331,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
String name;
stream.ReadString(&name, -13);
Color32 color;
stream.Read(&color);
stream.Read(color);
switch (trackType)
{
case 17:
@@ -365,7 +365,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
LinearCurveKeyframe<Float3>& k = channel.Position.GetKeyframes()[i];
stream.ReadFloat(&k.Time);
k.Time *= fps;
stream.Read(&k.Value);
stream.Read(k.Value);
}
break;
case 1:
@@ -375,7 +375,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
LinearCurveKeyframe<Quaternion>& k = channel.Rotation.GetKeyframes()[i];
stream.ReadFloat(&k.Time);
k.Time *= fps;
stream.Read(&k.Value);
stream.Read(k.Value);
}
break;
case 2:
@@ -385,7 +385,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
LinearCurveKeyframe<Float3>& k = channel.Scale.GetKeyframes()[i];
stream.ReadFloat(&k.Time);
k.Time *= fps;
stream.Read(&k.Value);
stream.Read(k.Value);
}
break;
}
@@ -428,7 +428,7 @@ bool Animation::SaveTimeline(BytesContainer& data)
nestedTrack.First = name;
auto& nestedAnim = nestedTrack.Second;
Guid id;
stream.Read(&id);
stream.Read(id);
stream.ReadFloat(&nestedAnim.Time);
stream.ReadFloat(&nestedAnim.Duration);
stream.ReadFloat(&nestedAnim.Speed);
@@ -524,7 +524,7 @@ bool Animation::Save(const StringView& path)
if (nestedAnim.Loop)
flags |= 2;
stream.WriteByte(flags);
stream.Write(&id);
stream.Write(id);
stream.WriteFloat(nestedAnim.Time);
stream.WriteFloat(nestedAnim.Duration);
stream.WriteFloat(nestedAnim.Speed);
@@ -700,7 +700,7 @@ Asset::LoadResult Animation::load()
nestedAnim.Enabled = flags & 1;
nestedAnim.Loop = flags & 2;
Guid id;
stream.Read(&id);
stream.Read(id);
nestedAnim.Anim = id;
stream.ReadFloat(&nestedAnim.Time);
stream.ReadFloat(&nestedAnim.Duration);

View File

@@ -215,7 +215,7 @@ Asset::LoadResult MaterialInstance::load()
// Load base material
Guid baseMaterialId;
headerStream.Read(&baseMaterialId);
headerStream.Read(baseMaterialId);
auto baseMaterial = Content::LoadAsync<MaterialBase>(baseMaterialId);
// Load parameters
@@ -316,8 +316,8 @@ bool MaterialInstance::Save(const StringView& path)
MemoryWriteStream stream(512);
{
// Save base material ID
const auto baseMaterialId = _baseMaterial ? _baseMaterial->GetID() : Guid::Empty;
stream.Write(&baseMaterialId);
const Guid baseMaterialId = _baseMaterial ? _baseMaterial->GetID() : Guid::Empty;
stream.Write(baseMaterialId);
// Save parameters
Params.Save(&stream);

View File

@@ -361,7 +361,7 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
auto& slot = MaterialSlots[materialSlotIndex];
const auto id = slot.Material.GetID();
stream->Write(&id);
stream->Write(id);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11);
}
@@ -578,7 +578,7 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
MemoryWriteStream sdfStream;
sdfStream.WriteInt32(1); // Version
ModelSDFHeader data(SDF, SDF.Texture->GetDescription());
sdfStream.Write(&data);
sdfStream.WriteBytes(&data, sizeof(data));
TextureData sdfTextureData;
if (SDF.Texture->DownloadData(sdfTextureData))
return true;
@@ -586,8 +586,8 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path)
{
auto& mip = sdfTextureData.Items[0].Mips[mipLevel];
ModelSDFMip mipData(mipLevel, mip);
sdfStream.Write(&mipData);
sdfStream.Write(mip.Data.Get(), mip.Data.Length());
sdfStream.WriteBytes(&mipData, sizeof(mipData));
sdfStream.WriteBytes(mip.Data.Get(), mip.Data.Length());
}
sdfChunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
}
@@ -889,7 +889,7 @@ Asset::LoadResult Model::load()
// Material
Guid materialId;
stream->Read(&materialId);
stream->Read(materialId);
slot.Material = materialId;
// Shadows Mode
@@ -964,7 +964,7 @@ Asset::LoadResult Model::load()
case 1:
{
ModelSDFHeader data;
sdfStream.Read(&data);
sdfStream.ReadBytes(&data, sizeof(data));
if (!SDF.Texture)
SDF.Texture = GPUTexture::New();
if (SDF.Texture->Init(GPUTextureDescription::New3D(data.Width, data.Height, data.Depth, data.Format, GPUTextureFlags::ShaderResource, data.MipLevels)))
@@ -980,7 +980,7 @@ Asset::LoadResult Model::load()
for (int32 mipLevel = 0; mipLevel < data.MipLevels; mipLevel++)
{
ModelSDFMip mipData;
sdfStream.Read(&mipData);
sdfStream.ReadBytes(&mipData, sizeof(mipData));
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();

View File

@@ -23,7 +23,7 @@ Asset::LoadResult SkeletonMask::load()
MemoryReadStream stream(dataChunk->Get(), dataChunk->Size());
Guid skeletonId;
stream.Read(&skeletonId);
stream.Read(skeletonId);
int32 maskedNodesCount;
stream.ReadInt32(&maskedNodesCount);
_maskedNodes.Resize(maskedNodesCount);
@@ -83,7 +83,7 @@ bool SkeletonMask::Save(const StringView& path)
// Write data
MemoryWriteStream stream(4096);
const auto skeletonId = Skeleton.GetID();
stream.Write(&skeletonId);
stream.Write(skeletonId);
stream.WriteInt32(_maskedNodes.Count());
for (auto& e : _maskedNodes)
{

View File

@@ -413,7 +413,7 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
auto& slot = MaterialSlots[materialSlotIndex];
const auto id = slot.Material.GetID();
stream->Write(&id);
stream->Write(id);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11);
}
@@ -470,7 +470,7 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
{
auto& node = Skeleton.Nodes[nodeIndex];
stream->Write(&node.ParentIndex);
stream->Write(node.ParentIndex);
stream->WriteTransform(node.LocalTransform);
stream->WriteString(node.Name, 71);
}
@@ -482,10 +482,10 @@ bool SkinnedModel::Save(bool withMeshDataFromGpu, const StringView& path)
{
auto& bone = Skeleton.Bones[boneIndex];
stream->Write(&bone.ParentIndex);
stream->Write(&bone.NodeIndex);
stream->Write(bone.ParentIndex);
stream->Write(bone.NodeIndex);
stream->WriteTransform(bone.LocalTransform);
stream->Write(&bone.OffsetMatrix);
stream->Write(bone.OffsetMatrix);
}
}
}
@@ -880,7 +880,7 @@ Asset::LoadResult SkinnedModel::load()
// Material
Guid materialId;
stream->Read(&materialId);
stream->Read(materialId);
slot.Material = materialId;
// Shadows Mode
@@ -967,7 +967,7 @@ Asset::LoadResult SkinnedModel::load()
{
auto& node = Skeleton.Nodes[nodeIndex];
stream->Read(&node.ParentIndex);
stream->Read(node.ParentIndex);
stream->ReadTransform(&node.LocalTransform);
stream->ReadString(&node.Name, 71);
}
@@ -983,10 +983,10 @@ Asset::LoadResult SkinnedModel::load()
{
auto& bone = Skeleton.Bones[boneIndex];
stream->Read(&bone.ParentIndex);
stream->Read(&bone.NodeIndex);
stream->Read(bone.ParentIndex);
stream->Read(bone.NodeIndex);
stream->ReadTransform(&bone.LocalTransform);
stream->Read(&bone.OffsetMatrix);
stream->Read(bone.OffsetMatrix);
}
}

View File

@@ -87,14 +87,14 @@ void AssetsCache::Init()
int32 rejectedCount = 0;
for (int32 i = 0; i < count; i++)
{
stream->Read(&e.Info.ID);
stream->Read(e.Info.ID);
stream->ReadString(&e.Info.TypeName, i - 13);
stream->ReadString(&e.Info.Path, i);
#if ENABLE_ASSETS_DISCOVERY
stream->Read(&e.FileModified);
stream->Read(e.FileModified);
#else
DateTime tmp1;
stream->Read(&tmp1);
stream->Read(tmp1);
#endif
if (flags & AssetsCacheFlags::RelativePaths && e.Info.Path.HasChars())
@@ -121,7 +121,7 @@ void AssetsCache::Init()
for (int32 i = 0; i < count; i++)
{
Guid id;
stream->Read(&id);
stream->Read(id);
String mappedPath;
stream->ReadString(&mappedPath, i + 73);
@@ -203,11 +203,11 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa
{
auto& e = i->Value;
stream->Write(&e.Info.ID);
stream->Write(e.Info.ID);
stream->WriteString(e.Info.TypeName, index - 13);
stream->WriteString(e.Info.Path, index);
#if ENABLE_ASSETS_DISCOVERY
stream->Write(&e.FileModified);
stream->Write(e.FileModified);
#else
stream->WriteInt64(0);
#endif
@@ -220,7 +220,7 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa
stream->WriteInt32(pathsMapping.Count());
for (auto i = pathsMapping.Begin(); i.IsNotEnd(); ++i)
{
stream->Write(&i->Value);
stream->Write(i->Value);
stream->WriteString(i->Key, index + 73);
index++;

View File

@@ -278,7 +278,7 @@ bool FlaxStorage::Load()
{
// Custom storage data
CustomData customData;
stream->Read(&customData);
stream->Read(customData);
#if USE_EDITOR
// Block loading packaged games content
@@ -298,7 +298,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < assetsCount; i++)
{
SerializedEntryV9 se;
stream->Read(&se);
stream->ReadBytes(&se, sizeof(se));
Entry e(se.ID, se.TypeName.Data, se.Address);
AddEntry(e);
}
@@ -309,7 +309,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk::Location e;
stream->Read(&e);
stream->ReadBytes(&e, sizeof(e));
if (e.Size == 0)
{
LOG(Warning, "Empty chunk found.");
@@ -329,7 +329,7 @@ bool FlaxStorage::Load()
// Custom storage data
CustomData customData;
stream->Read(&customData);
stream->Read(customData);
#if USE_EDITOR
// Block loading packaged games content
@@ -349,7 +349,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < assetsCount; i++)
{
OldSerializedEntryV7 se;
stream->Read(&se);
stream->ReadBytes(&se, sizeof(se));
Entry e(se.ID, se.TypeName.Data, se.Address);
AddEntry(e);
}
@@ -360,7 +360,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk::Location e;
stream->Read(&e);
stream->ReadBytes(&e, sizeof(e));
if (e.Size == 0)
{
LOG(Warning, "Empty chunk found.");
@@ -384,7 +384,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < assetsCount; i++)
{
OldSerializedEntryV7 se;
stream->Read(&se);
stream->ReadBytes(&se, sizeof(se));
Entry e(se.ID, se.TypeName.Data, se.Address);
AddEntry(e);
}
@@ -395,7 +395,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk::Location e;
stream->Read(&e);
stream->ReadBytes(&e, sizeof(e));
if (e.Size == 0)
{
LOG(Warning, "Empty chunk found.");
@@ -418,7 +418,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < assetsCount; i++)
{
OldEntryV6 ee;
stream->Read(&ee);
stream->ReadBytes(&ee, sizeof(ee));
Entry e(ee.ID, TypeId2TypeName(ee.TypeID), ee.Adress);
AddEntry(e);
@@ -430,7 +430,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk::Location e;
stream->Read(&e);
stream->ReadBytes(&e, sizeof(e));
if (e.Size == 0)
{
LOG(Warning, "Empty chunk found.");
@@ -449,7 +449,7 @@ bool FlaxStorage::Load()
// Package Time
DateTime packTime;
stream->Read(&packTime);
stream->Read(packTime);
// Asset Entries
int32 assetsCount;
@@ -457,7 +457,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < assetsCount; i++)
{
OldEntryV6 ee;
stream->Read(&ee);
stream->ReadBytes(&ee, sizeof(ee));
Entry e(ee.ID, TypeId2TypeName(ee.TypeID), ee.Adress);
AddEntry(e);
@@ -469,7 +469,7 @@ bool FlaxStorage::Load()
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk::Location e;
stream->Read(&e);
stream->ReadBytes(&e, sizeof(e));
if (e.Size == 0)
{
LOG(Warning, "Empty chunk found.");
@@ -498,7 +498,7 @@ bool FlaxStorage::Load()
e.Address = stream->GetPosition();
// Asset ID
stream->Read(&e.ID);
stream->Read(e.ID);
// Type ID
uint32 typeId;
@@ -511,7 +511,7 @@ bool FlaxStorage::Load()
{
DateTime tmpDate;
String strTmp;
stream->Read(&tmpDate);
stream->Read(tmpDate);
stream->ReadString(&strTmp, -76);
stream->ReadString(&strTmp, 1301);
}
@@ -871,7 +871,7 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
mainHeader.CustomData = *customData;
else
Platform::MemoryClear(&mainHeader.CustomData, sizeof(CustomData));
stream->Write(&mainHeader);
stream->Write(mainHeader);
// Write asset entries
stream->WriteInt32(dataCount);
@@ -882,7 +882,7 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
for (int32 i = 0; i < chunksCount; i++)
{
FlaxChunk* chunk = chunks[i];
stream->Write(&chunk->LocationInFile);
stream->WriteBytes(&chunk->LocationInFile, sizeof(chunk->LocationInFile));
stream->WriteInt32((int32)chunk->Flags);
}
@@ -903,7 +903,7 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
auto& header = data[i];
// ID
stream->Write(&header.Header.ID);
stream->Write(header.Header.ID);
// Type Name
SerializedTypeNameV9 typeName(header.Header.TypeName);
@@ -932,7 +932,7 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
// Asset Dependencies
stream->WriteInt32(header.Dependencies.Count());
stream->Write(header.Dependencies.Get(), header.Dependencies.Count());
stream->WriteBytes(header.Dependencies.Get(), header.Dependencies.Count() * sizeof(Pair<Guid, DateTime>));
}
#if ASSETS_LOADING_EXTRA_VERIFICATION
@@ -951,9 +951,9 @@ bool FlaxStorage::Create(WriteStream* stream, const AssetInitData* data, int32 d
{
if (compressedChunks[i].HasItems())
{
// Compressed chunk data (write additional size of the original data
// Compressed chunk data (write additional size of the original data)
stream->WriteInt32(chunks[i]->Data.Length());
stream->Write(compressedChunks[i].Get(), compressedChunks[i].Count());
stream->WriteBytes(compressedChunks[i].Get(), compressedChunks[i].Count());
}
else
{
@@ -1006,7 +1006,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
case 9:
{
// ID
stream->Read(&data.Header.ID);
stream->Read(data.Header.ID);
// Type name
SerializedTypeNameV9 typeName;
@@ -1058,7 +1058,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
int32 dependencies;
stream->ReadInt32(&dependencies);
data.Dependencies.Resize(dependencies);
stream->Read(data.Dependencies.Get(), dependencies);
stream->ReadBytes(data.Dependencies.Get(), dependencies * sizeof(Pair<Guid, DateTime>));
#endif
break;
}
@@ -1068,7 +1068,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
// [Deprecated on 4/17/2020, expires on 4/17/2022]
// ID
stream->Read(&data.Header.ID);
stream->Read(data.Header.ID);
// Type Name
OldSerializedTypeNameV7 typeName;
@@ -1123,7 +1123,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
// [Deprecated on 4/17/2020, expires on 4/17/2022]
// ID
stream->Read(&data.Header.ID);
stream->Read(data.Header.ID);
// Type ID
uint32 typeId;
@@ -1178,7 +1178,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
// Load data
data.SerializedVersion = 1;
stream->Read(&data.Header.ID);
stream->Read(data.Header.ID);
uint32 typeId;
stream->ReadUint32(&typeId);
data.Header.TypeName = TypeId2TypeName(typeId);
@@ -1187,7 +1187,7 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
{
DateTime importDate;
String importPath, importUsername;
stream->Read(&importDate);
stream->Read(importDate);
stream->ReadString(&importPath, -76);
stream->ReadString(&importUsername, 1301);

View File

@@ -195,7 +195,7 @@ private:
auto& slot = data->Materials[i];
// Material
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Shadows Mode
slot.ShadowsMode = static_cast<ShadowsCastingMode>(headerStream->ReadByte());
@@ -280,11 +280,11 @@ private:
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
// Has Lightmap UVs
bool hasLightmapUVs = headerStream->ReadBool();
@@ -312,7 +312,7 @@ private:
auto& slot = data->Materials[i];
// Material
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Shadows Mode
slot.ShadowsMode = static_cast<ShadowsCastingMode>(headerStream->ReadByte());
@@ -391,11 +391,11 @@ private:
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
// Has Lightmap UVs
bool hasLightmapUVs = headerStream->ReadBool();
@@ -420,7 +420,7 @@ private:
auto& slot = data->Materials[i];
// Material
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Shadows Mode
slot.ShadowsMode = static_cast<ShadowsCastingMode>(headerStream->ReadByte());
@@ -460,11 +460,11 @@ private:
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
}
// Get meshes data
@@ -539,15 +539,15 @@ private:
slot.ShadowsMode = castShadows ? ShadowsCastingMode::All : ShadowsCastingMode::None;
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
}
{
@@ -614,15 +614,15 @@ private:
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
}
{
@@ -689,15 +689,15 @@ private:
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Box
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
// Sphere
BoundingSphere sphere;
headerStream->Read(&sphere);
headerStream->Read(sphere);
}
// Load all LODs
@@ -767,17 +767,17 @@ private:
// Local Transform
Transform transform;
headerStream->Read(&transform);
headerStream->Read(transform);
// Force Two Sided
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Corners
BoundingBox box;
headerStream->Read(&box);
headerStream->Read(box);
}
// Load all LODs
@@ -847,18 +847,18 @@ private:
// Local Transform
Transform transform;
headerStream->Read(&transform);
headerStream->Read(transform);
// Force Two Sided
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
// Corners
Vector3 corner;
for (int32 cornerIndex = 0; cornerIndex < 8; cornerIndex++)
headerStream->Read(&corner);
headerStream->Read(corner);
}
// Load all LODs
@@ -933,13 +933,13 @@ private:
// Local Transform
Transform transform;
headerStream->Read(&transform);
headerStream->Read(transform);
// Force Two Sided
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
}
// Load all LODs
@@ -1014,13 +1014,13 @@ private:
// Local Transform
Transform transform;
headerStream->Read(&transform);
headerStream->Read(transform);
// Force Two Sided
headerStream->ReadBool();
// Default material ID
headerStream->Read(&slot.AssetID);
headerStream->Read(slot.AssetID);
}
// Load all LODs

View File

@@ -47,7 +47,7 @@ private:
MemoryReadStream stream(dataChunk->Get(), dataChunk->Size());
Guid skeletonId;
stream.Read(&skeletonId);
stream.Read(skeletonId);
int32 maskCount;
stream.ReadInt32(&maskCount);
bonesMask.Resize(maskCount, false);
@@ -85,7 +85,7 @@ private:
MemoryWriteStream stream(4096);
const Guid skeletonId = skeleton.GetID();
stream.Write(&skeletonId);
stream.Write(skeletonId);
stream.WriteInt32(nodesMask.Count());
for (auto& e : nodesMask)
{

View File

@@ -87,7 +87,7 @@ private:
const float invSum = sum > ZeroTolerance ? 1.0f / sum : 0.0f;
blendWeights *= invSum;
newVertex.BlendWeights = Half4(blendWeights);
output.Write(&newVertex);
output.WriteBytes(&newVertex, sizeof(newVertex));
}
output.WriteBytes(ib, indicesCount * ibStride);
} while (stream.CanRead());
@@ -133,8 +133,8 @@ private:
{
// Material
Guid materialId;
stream.Read(&materialId);
output.Write(&materialId);
stream.Read(materialId);
output.Write(materialId);
// Shadows Mode
output.WriteByte(stream.ReadByte());
@@ -166,13 +166,13 @@ private:
// Box
BoundingBox box;
stream.Read(&box);
output.Write(&box);
stream.Read(box);
output.Write(box);
// Sphere
BoundingSphere sphere;
stream.Read(&sphere);
output.Write(&sphere);
stream.Read(sphere);
output.Write(sphere);
}
// Skeleton
@@ -189,8 +189,8 @@ private:
output.WriteInt32(parentIndex);
Transform localTransform;
stream.Read(&localTransform);
output.Write(&localTransform);
stream.Read(localTransform);
output.Write(localTransform);
String name;
stream.ReadString(&name, 71);
@@ -213,8 +213,8 @@ private:
output.WriteInt32(nodeIndex);
Transform localTransform;
stream.Read(&localTransform);
output.Write(&localTransform);
stream.Read(localTransform);
output.Write(localTransform);
Matrix offsetMatrix;
stream.ReadBytes(&offsetMatrix, sizeof(Matrix));
@@ -263,8 +263,8 @@ private:
{
// Material
Guid materialId;
stream.Read(&materialId);
output.Write(&materialId);
stream.Read(materialId);
output.Write(materialId);
// Shadows Mode
output.WriteByte(stream.ReadByte());
@@ -304,13 +304,13 @@ private:
// Box
BoundingBox box;
stream.Read(&box);
output.Write(&box);
stream.Read(box);
output.Write(box);
// Sphere
BoundingSphere sphere;
stream.Read(&sphere);
output.Write(&sphere);
stream.Read(sphere);
output.Write(sphere);
// Blend Shapes
output.WriteUint16(0);
@@ -331,8 +331,8 @@ private:
output.WriteInt32(parentIndex);
Transform localTransform;
stream.Read(&localTransform);
output.Write(&localTransform);
stream.Read(localTransform);
output.Write(localTransform);
String name;
stream.ReadString(&name, 71);
@@ -355,8 +355,8 @@ private:
output.WriteInt32(nodeIndex);
Transform localTransform;
stream.Read(&localTransform);
output.Write(&localTransform);
stream.Read(localTransform);
output.Write(localTransform);
Matrix offsetMatrix;
stream.ReadBytes(&offsetMatrix, sizeof(Matrix));
@@ -404,9 +404,9 @@ private:
if (vertices == 0 || triangles == 0)
return true;
const auto vb0 = stream.Move<VB0SkinnedElementType>(vertices);
output.Write<VB0SkinnedElementType>(vb0, vertices);
output.WriteBytes(vb0, vertices * sizeof(VB0SkinnedElementType));
const auto ib = stream.Move<byte>(indicesCount * ibStride);
output.Write<byte>(ib, indicesCount * ibStride);
output.WriteBytes(ib, indicesCount * ibStride);
}
// Save new data

View File

@@ -30,7 +30,7 @@ public:
if (context.AllocateChunk(0))
return CreateAssetResult::CannotAllocateChunk;
MemoryWriteStream stream(256);
stream.Write(&Guid::Empty);
stream.Write(Guid::Empty);
MaterialParams::Save(&stream, nullptr);
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());

View File

@@ -59,7 +59,7 @@ bool ImportTexture::TryGetImportOptions(const StringView& path, Options& options
{
// Load sprite
Sprite t;
stream.Read(&t.Area);;
stream.Read(t.Area);
stream.ReadString(&t.Name, 49);
options.Sprites.Add(t);
}
@@ -183,7 +183,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
for (int32 i = 0; i < options.Sprites.Count(); i++)
{
auto& sprite = options.Sprites[i];
stream.Write(&sprite.Area);
stream.Write(sprite.Area);
stream.WriteString(sprite.Name, 49);
}
if (context.AllocateChunk(15))
@@ -322,7 +322,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
for (int32 i = 0; i < options.Sprites.Count(); i++)
{
auto& sprite = options.Sprites[i];
stream.Write(&sprite.Area);
stream.Write(sprite.Area);
stream.WriteString(sprite.Name, 49);
}
if (context.AllocateChunk(15))

View File

@@ -89,7 +89,7 @@ bool Log::Logger::Init()
// Write BOM (UTF-16 (LE); BOM: FF FE)
byte bom[] = { 0xFF, 0xFE };
LogFile->Write(bom, 2);
LogFile->WriteBytes(bom, 2);
// Write startup info
WriteFloor();
@@ -137,8 +137,8 @@ void Log::Logger::Write(const StringView& msg)
// Write message to log file
if (LogAfterInit)
{
LogFile->Write(ptr, length);
LogFile->Write(TEXT(PLATFORM_LINE_TERMINATOR), ARRAY_COUNT(PLATFORM_LINE_TERMINATOR) - 1);
LogFile->WriteBytes(ptr, length * sizeof(Char));
LogFile->WriteBytes(TEXT(PLATFORM_LINE_TERMINATOR), (ARRAY_COUNT(PLATFORM_LINE_TERMINATOR) - 1) * sizeof(Char));
#if LOG_ENABLE_AUTO_FLUSH
LogFile->Flush();
#endif

View File

@@ -756,35 +756,35 @@ bool MaterialParams::Load(ReadStream* stream)
stream->ReadFloat(&param->_asFloat);
break;
case MaterialParameterType::Vector2:
stream->Read(&param->_asVector2);
stream->Read(param->_asVector2);
break;
case MaterialParameterType::Vector3:
stream->Read(&param->_asVector3);
stream->Read(param->_asVector3);
break;
case MaterialParameterType::Vector4:
stream->Read((Float4*)&param->AsData);
stream->Read((Float4&)param->AsData);
break;
case MaterialParameterType::Color:
stream->Read(&param->_asColor);
stream->Read(param->_asColor);
break;
case MaterialParameterType::Matrix:
stream->Read((Matrix*)&param->AsData);
stream->Read((Matrix&)param->AsData);
break;
case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture:
case MaterialParameterType::CubeTexture:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<TextureBase>(id);
break;
case MaterialParameterType::GPUTextureVolume:
case MaterialParameterType::GPUTextureCube:
case MaterialParameterType::GPUTextureArray:
case MaterialParameterType::GPUTexture:
stream->Read(&id);
stream->Read(id);
param->_asGPUTexture = id;
break;
case MaterialParameterType::GameplayGlobal:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<GameplayGlobals>(id);
break;
default:
@@ -808,7 +808,7 @@ bool MaterialParams::Load(ReadStream* stream)
// Read properties
param->_type = static_cast<MaterialParameterType>(stream->ReadByte());
stream->Read(&param->_paramId);
stream->Read(param->_paramId);
param->_isPublic = stream->ReadBool();
param->_override = param->_isPublic;
stream->ReadString(&param->_name, 10421);
@@ -830,35 +830,35 @@ bool MaterialParams::Load(ReadStream* stream)
stream->ReadFloat(&param->_asFloat);
break;
case MaterialParameterType::Vector2:
stream->Read(&param->_asVector2);
stream->Read(param->_asVector2);
break;
case MaterialParameterType::Vector3:
stream->Read(&param->_asVector3);
stream->Read(param->_asVector3);
break;
case MaterialParameterType::Vector4:
stream->Read((Float4*)&param->AsData);
stream->Read((Float4&)param->AsData);
break;
case MaterialParameterType::Color:
stream->Read(&param->_asColor);
stream->Read(param->_asColor);
break;
case MaterialParameterType::Matrix:
stream->Read((Matrix*)&param->AsData);
stream->Read((Matrix&)param->AsData);
break;
case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture:
case MaterialParameterType::CubeTexture:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<TextureBase>(id);
break;
case MaterialParameterType::GPUTextureVolume:
case MaterialParameterType::GPUTextureCube:
case MaterialParameterType::GPUTextureArray:
case MaterialParameterType::GPUTexture:
stream->Read(&id);
stream->Read(id);
param->_asGPUTexture = id;
break;
case MaterialParameterType::GameplayGlobal:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<GameplayGlobals>(id);
break;
default:
@@ -882,7 +882,7 @@ bool MaterialParams::Load(ReadStream* stream)
// Read properties
param->_type = static_cast<MaterialParameterType>(stream->ReadByte());
stream->Read(&param->_paramId);
stream->Read(param->_paramId);
param->_isPublic = stream->ReadBool();
param->_override = stream->ReadBool();
stream->ReadString(&param->_name, 10421);
@@ -905,35 +905,35 @@ bool MaterialParams::Load(ReadStream* stream)
stream->ReadFloat(&param->_asFloat);
break;
case MaterialParameterType::Vector2:
stream->Read(&param->_asVector2);
stream->Read(param->_asVector2);
break;
case MaterialParameterType::Vector3:
stream->Read(&param->_asVector3);
stream->Read(param->_asVector3);
break;
case MaterialParameterType::Vector4:
stream->Read((Float4*)&param->AsData);
stream->Read((Float4&)param->AsData);
break;
case MaterialParameterType::Color:
stream->Read(&param->_asColor);
stream->Read(param->_asColor);
break;
case MaterialParameterType::Matrix:
stream->Read((Matrix*)&param->AsData);
stream->Read((Matrix&)param->AsData);
break;
case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture:
case MaterialParameterType::CubeTexture:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<TextureBase>(id);
break;
case MaterialParameterType::GPUTextureVolume:
case MaterialParameterType::GPUTextureCube:
case MaterialParameterType::GPUTextureArray:
case MaterialParameterType::GPUTexture:
stream->Read(&id);
stream->Read(id);
param->_asGPUTexture = id;
break;
case MaterialParameterType::GameplayGlobal:
stream->Read(&id);
stream->Read(id);
param->_asAsset = Content::LoadAsync<GameplayGlobals>(id);
break;
default:
@@ -974,7 +974,7 @@ void MaterialParams::Save(WriteStream* stream)
// Write properties
stream->WriteByte(static_cast<byte>(param->_type));
stream->Write(&param->_paramId);
stream->Write(param->_paramId);
stream->WriteBool(param->_isPublic);
stream->WriteBool(param->_override);
stream->WriteString(param->_name, 10421);
@@ -998,33 +998,33 @@ void MaterialParams::Save(WriteStream* stream)
stream->WriteFloat(param->_asFloat);
break;
case MaterialParameterType::Vector2:
stream->Write(&param->_asVector2);
stream->Write(param->_asVector2);
break;
case MaterialParameterType::Vector3:
stream->Write(&param->_asVector3);
stream->Write(param->_asVector3);
break;
case MaterialParameterType::Vector4:
stream->Write((Float4*)&param->AsData);
stream->Write((Float4&)param->AsData);
break;
case MaterialParameterType::Color:
stream->Write(&param->_asColor);
stream->Write(param->_asColor);
break;
case MaterialParameterType::Matrix:
stream->Write((Matrix*)&param->AsData);
stream->Write((Matrix&)param->AsData);
break;
case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture:
case MaterialParameterType::CubeTexture:
case MaterialParameterType::GameplayGlobal:
id = param->_asAsset.GetID();
stream->Write(&id);
stream->Write(id);
break;
case MaterialParameterType::GPUTextureVolume:
case MaterialParameterType::GPUTextureArray:
case MaterialParameterType::GPUTextureCube:
case MaterialParameterType::GPUTexture:
id = param->_asGPUTexture.GetID();
stream->Write(&id);
stream->Write(id);
break;
default:
break;
@@ -1050,7 +1050,7 @@ void MaterialParams::Save(WriteStream* stream, const Array<SerializedMaterialPar
// Write properties
stream->WriteByte(static_cast<byte>(param.Type));
stream->Write(&param.ID);
stream->Write(param.ID);
stream->WriteBool(param.IsPublic);
stream->WriteBool(param.Override);
stream->WriteString(param.Name, 10421);
@@ -1073,19 +1073,19 @@ void MaterialParams::Save(WriteStream* stream, const Array<SerializedMaterialPar
stream->WriteFloat(param.AsFloat);
break;
case MaterialParameterType::Vector2:
stream->Write(&param.AsFloat2);
stream->Write(param.AsFloat2);
break;
case MaterialParameterType::Vector3:
stream->Write(&param.AsFloat3);
stream->Write(param.AsFloat3);
break;
case MaterialParameterType::Vector4:
stream->Write((Float4*)&param.AsData);
stream->Write((Float4&)param.AsData);
break;
case MaterialParameterType::Color:
stream->Write(&param.AsColor);
stream->Write(param.AsColor);
break;
case MaterialParameterType::Matrix:
stream->Write((Matrix*)&param.AsData);
stream->Write((Matrix&)param.AsData);
break;
case MaterialParameterType::NormalMap:
case MaterialParameterType::Texture:
@@ -1095,7 +1095,7 @@ void MaterialParams::Save(WriteStream* stream, const Array<SerializedMaterialPar
case MaterialParameterType::GPUTextureCube:
case MaterialParameterType::GPUTextureArray:
case MaterialParameterType::GPUTexture:
stream->Write(&param.AsGuid);
stream->Write(param.AsGuid);
break;
default:
break;

View File

@@ -336,7 +336,7 @@ bool MeshData::Pack2Model(WriteStream* stream) const
vb1.Normal = Float1010102(normal * 0.5f + 0.5f, 0);
vb1.Tangent = Float1010102(tangent * 0.5f + 0.5f, static_cast<byte>(bitangentSign < 0 ? 1 : 0));
vb1.LightmapUVs = Half2(lightmapUV);
stream->Write(&vb1);
stream->WriteBytes(&vb1, sizeof(vb1));
// Pack TBN matrix into a quaternion
/*Quaternion quaternionTBN;
@@ -360,7 +360,7 @@ bool MeshData::Pack2Model(WriteStream* stream) const
for (uint32 i = 0; i < verticiecCount; i++)
{
vb2.Color = Color32(Colors[i]);
stream->Write(&vb2);
stream->WriteBytes(&vb2, sizeof(vb2));
}
}
@@ -470,7 +470,7 @@ bool MeshData::Pack2SkinnedModel(WriteStream* stream) const
vb.Tangent = Float1010102(tangent * 0.5f + 0.5f, static_cast<byte>(bitangentSign < 0 ? 1 : 0));
vb.BlendIndices = Color32(blendIndices.X, blendIndices.Y, blendIndices.Z, blendIndices.W);
vb.BlendWeights = Half4(blendWeights);
stream->Write(&vb);
stream->WriteBytes(&vb, sizeof(vb));
}
// Index Buffer
@@ -704,7 +704,7 @@ bool ModelData::Pack2ModelHeader(WriteStream* stream) const
{
auto& slot = Materials[materialSlotIndex];
stream->Write(&slot.AssetID);
stream->Write(slot.AssetID);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11);
}
@@ -793,7 +793,7 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{
auto& slot = Materials[materialSlotIndex];
stream->Write(&slot.AssetID);
stream->Write(slot.AssetID);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11);
}
@@ -859,7 +859,7 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{
auto& node = Skeleton.Nodes[nodeIndex];
stream->Write(&node.ParentIndex);
stream->Write(node.ParentIndex);
stream->WriteTransform(node.LocalTransform);
stream->WriteString(node.Name, 71);
}
@@ -871,10 +871,10 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{
auto& bone = Skeleton.Bones[boneIndex];
stream->Write(&bone.ParentIndex);
stream->Write(&bone.NodeIndex);
stream->Write(bone.ParentIndex);
stream->Write(bone.NodeIndex);
stream->WriteTransform(bone.LocalTransform);
stream->Write(&bone.OffsetMatrix);
stream->Write(bone.OffsetMatrix);
}
}

View File

@@ -139,7 +139,7 @@ bool IsValidShaderCache(DataContainer<byte>& shaderCache, Array<String>& include
String& include = includes.AddOne();
stream.ReadString(&include, 11);
DateTime lastEditTime;
stream.Read(&lastEditTime);
stream.Read(lastEditTime);
// Check if included file exists locally and has been modified since last compilation
if (FileSystem::FileExists(include) && FileSystem::GetFileLastEditTime(include) > lastEditTime)

View File

@@ -93,7 +93,7 @@ bool SceneCSGData::TryGetSurfaceData(const Guid& brushId, int32 brushSurfaceInde
{
Guid id;
int32 pos;
stream.Read(&id);
stream.Read(id);
stream.ReadInt32(&pos);
DataBrushLocations.Add(id, pos);
}

View File

@@ -12,7 +12,7 @@ void NavMeshData::Save(WriteStream& stream)
header.Version = 1;
header.TileSize = TileSize;
header.TilesCount = Tiles.Count();
stream.Write(&header);
stream.Write(header);
// Write tiles
for (int32 tileIndex = 0; tileIndex < Tiles.Count(); tileIndex++)
@@ -25,7 +25,7 @@ void NavMeshData::Save(WriteStream& stream)
tileHeader.PosY = tile.PosY;
tileHeader.Layer = tile.Layer;
tileHeader.DataSize = tile.Data.Length();
stream.Write(&tileHeader);
stream.Write(tileHeader);
// Write tile data
if (tileHeader.DataSize)

View File

@@ -71,14 +71,14 @@ BytesContainer ParticleSystem::LoadTimeline()
stream.WriteInt32(track.ParentIndex);
stream.WriteInt32(track.ChildrenCount);
stream.WriteString(track.Name, -13);
stream.Write(&track.Color);
stream.Write(track.Color);
Guid id;
switch (track.Type)
{
case Track::Types::Emitter:
id = Emitters[track.AsEmitter.Index].GetID();
stream.Write(&id);
stream.Write(id);
stream.WriteInt32(track.AsEmitter.Index);
stream.WriteInt32(track.AsEmitter.StartFrame);
stream.WriteInt32(track.AsEmitter.DurationFrames);
@@ -97,7 +97,7 @@ BytesContainer ParticleSystem::LoadTimeline()
for (auto i = EmittersParametersOverrides.Begin(); i.IsNotEnd(); ++i)
{
stream.WriteInt32(i->Key.First);
stream.Write(&i->Key.Second);
stream.Write(i->Key.Second);
stream.WriteVariant(i->Value);
}
}
@@ -240,14 +240,14 @@ Asset::LoadResult ParticleSystem::load()
switch (track.Type)
{
case Track::Types::Emitter:
stream.Read(&id);
stream.Read(id);
stream.ReadInt32(&track.AsEmitter.Index);
stream.ReadInt32(&track.AsEmitter.StartFrame);
stream.ReadInt32(&track.AsEmitter.DurationFrames);
Emitters[track.AsEmitter.Index] = id;
break;
case Track::Types::Folder:
stream.Read(&track.Color);
stream.Read(track.Color);
break;
default:
return LoadResult::InvalidData;
@@ -273,7 +273,7 @@ Asset::LoadResult ParticleSystem::load()
for (int32 i = 0; i < overridesCount; i++)
{
stream.ReadInt32(&key.First);
stream.Read(&key.Second);
stream.Read(key.Second);
stream.ReadCommonValue(&value);
#if USE_EDITOR
@@ -316,12 +316,12 @@ Asset::LoadResult ParticleSystem::load()
stream.ReadInt32(&track.ChildrenCount);
stream.ReadString(&track.Name, -13);
track.Disabled = (int32)track.Flag & (int32)Track::Flags::Mute || (track.ParentIndex != -1 && Tracks[track.ParentIndex].Disabled);
stream.Read(&track.Color);
stream.Read(track.Color);
switch (track.Type)
{
case Track::Types::Emitter:
stream.Read(&id);
stream.Read(id);
stream.ReadInt32(&track.AsEmitter.Index);
stream.ReadInt32(&track.AsEmitter.StartFrame);
stream.ReadInt32(&track.AsEmitter.DurationFrames);
@@ -353,7 +353,7 @@ Asset::LoadResult ParticleSystem::load()
for (int32 i = 0; i < overridesCount; i++)
{
stream.ReadInt32(&key.First);
stream.Read(&key.Second);
stream.Read(key.Second);
stream.ReadCommonValue(&value);
#if USE_EDITOR
@@ -395,12 +395,12 @@ Asset::LoadResult ParticleSystem::load()
stream.ReadInt32(&track.ChildrenCount);
stream.ReadString(&track.Name, -13);
track.Disabled = (int32)track.Flag & (int32)Track::Flags::Mute || (track.ParentIndex != -1 && Tracks[track.ParentIndex].Disabled);
stream.Read(&track.Color);
stream.Read(track.Color);
switch (track.Type)
{
case Track::Types::Emitter:
stream.Read(&id);
stream.Read(id);
stream.ReadInt32(&track.AsEmitter.Index);
stream.ReadInt32(&track.AsEmitter.StartFrame);
stream.ReadInt32(&track.AsEmitter.DurationFrames);
@@ -432,7 +432,7 @@ Asset::LoadResult ParticleSystem::load()
for (int32 i = 0; i < overridesCount; i++)
{
stream.ReadInt32(&key.First);
stream.Read(&key.Second);
stream.Read(key.Second);
stream.ReadVariant(&value);
#if USE_EDITOR

View File

@@ -106,7 +106,7 @@ bool SpriteAtlas::SaveSprites()
stream.WriteInt32(Sprites.Count()); // Sprites Count
for (Sprite& t : Sprites)
{
stream.Write(&t.Area);
stream.Write(t.Area);
stream.WriteString(t.Name, 49);
}
@@ -156,7 +156,7 @@ bool SpriteAtlas::LoadSprites(ReadStream& stream)
Sprites.Resize(tilesCount);
for (Sprite& t : Sprites)
{
stream.Read(&t.Area);
stream.Read(t.Area);
stream.ReadString(&t.Name, 49);
}

View File

@@ -9,6 +9,7 @@ struct CommonValue;
struct Variant;
struct VariantType;
class ISerializable;
extern FLAXENGINE_API class ScriptingObject* FindObject(const Guid& id, class MClass* type);
/// <summary>
/// Base class for all data read streams
@@ -23,18 +24,6 @@ public:
/// <param name="bytes">Amount of bytes to read</param>
virtual void ReadBytes(void* data, uint32 bytes) = 0;
template<typename T>
FORCE_INLINE void Read(T* data)
{
ReadBytes((void*)data, sizeof(T));
}
template<typename T>
FORCE_INLINE void Read(T* data, int32 count)
{
ReadBytes((void*)data, sizeof(T) * count);
}
public:
// Reads byte from the stream
// @returns Single byte
@@ -64,84 +53,84 @@ public:
FORCE_INLINE void ReadByte(byte* data)
{
Read(data);
ReadBytes(data, sizeof(byte));
}
// Reads Char from the stream
// @param data Data to read
FORCE_INLINE void ReadChar(Char* data)
{
Read(data);
ReadBytes(data, sizeof(Char));
}
// Reads uint8 from the stream
// @param data Data to read
FORCE_INLINE void ReadUint8(uint8* data)
{
Read(data);
ReadBytes(data, sizeof(uint8));
}
// Reads int8 from the stream
// @param data Data to read
FORCE_INLINE void ReadInt8(int8* data)
{
Read(data);
ReadBytes(data, sizeof(int8));
}
// Reads uint16 from the stream
// @param data Data to read
FORCE_INLINE void ReadUint16(uint16* data)
{
Read(data);
ReadBytes(data, sizeof(uint16));
}
// Reads int16 from the stream
// @param data Data to read
FORCE_INLINE void ReadInt16(int16* data)
{
Read(data);
ReadBytes(data, sizeof(int16));
}
// Reads uint32 from the stream
// @param data Data to read
FORCE_INLINE void ReadUint32(uint32* data)
{
Read(data);
ReadBytes(data, sizeof(uint32));
}
// Reads int32 from the stream
// @param data Data to read
FORCE_INLINE void ReadInt32(int32* data)
{
Read(data);
ReadBytes(data, sizeof(int32));
}
// Reads uint64 from the stream
// @param data Data to read
FORCE_INLINE void ReadUint64(uint64* data)
{
Read(data);
ReadBytes(data, sizeof(uint64));
}
// Reads int64 from the stream
// @param data Data to read
FORCE_INLINE void ReadInt64(int64* data)
{
Read(data);
ReadBytes(data, sizeof(int64));
}
// Reads float from the stream
// @param data Data to read
FORCE_INLINE void ReadFloat(float* data)
{
Read(data);
ReadBytes(data, sizeof(float));
}
// Reads double from the stream
// @param data Data to read
FORCE_INLINE void ReadDouble(double* data)
{
Read(data);
ReadBytes(data, sizeof(double));
}
public:
@@ -159,6 +148,14 @@ public:
ReadBytes((void*)&data, sizeof(T));
}
template<typename T>
typename TEnableIf<TIsBaseOf<ScriptingObject, T>::Value>::Type Read(T*& data)
{
Guid id;
ReadBytes(&id, sizeof(Guid));
data = (T*)::FindObject(id, T::GetStaticClass());
}
/// <summary>
/// Read data array
/// </summary>
@@ -171,7 +168,7 @@ public:
data.Resize(size, false);
if (size > 0)
{
if (TIsPODType<T>::Value)
if (TIsPODType<T>::Value && !TIsPointer<T>::Value)
ReadBytes(data.Get(), size * sizeof(T));
else
{

View File

@@ -35,7 +35,7 @@ void ReadStream::Read(StringAnsi& data)
return;
char* ptr = data.Get();
ASSERT(ptr != nullptr);
Read(ptr, length);
ReadBytes(ptr, length);
}
void ReadStream::Read(StringAnsi& data, int8 lock)
@@ -54,7 +54,7 @@ void ReadStream::Read(StringAnsi& data, int8 lock)
return;
char* ptr = data.Get();
ASSERT(ptr != nullptr);
Read(ptr, length);
ReadBytes(ptr, length);
for (int32 i = 0; i < length; i++)
{
@@ -78,7 +78,7 @@ void ReadStream::Read(String& data)
data.ReserveSpace(length);
Char* ptr = data.Get();
ASSERT(ptr != nullptr);
Read(ptr, length);
ReadBytes(ptr, length * sizeof(Char));
}
void ReadStream::Read(String& data, int16 lock)
@@ -96,7 +96,7 @@ void ReadStream::Read(String& data, int16 lock)
data.ReserveSpace(length);
Char* ptr = data.Get();
ASSERT(ptr != nullptr);
Read(ptr, length);
ReadBytes(ptr, length * sizeof(Char));
for (int32 i = 0; i < length; i++)
{
@@ -131,35 +131,35 @@ void ReadStream::Read(CommonValue& data)
case CommonType::Vector2:
{
Float2 v;
Read(&v);
Read(v);
data.Set(v);
}
break;
case CommonType::Vector3:
{
Float3 v;
Read(&v);
Read(v);
data.Set(v);
}
break;
case CommonType::Vector4:
{
Float4 v;
Read(&v);
Read(v);
data.Set(v);
}
break;
case CommonType::Color:
{
Color v;
Read(&v);
Read(v);
data.Set(v);
}
break;
case CommonType::Guid:
{
Guid v;
Read(&v);
Read(v);
data.Set(v);
}
break;
@@ -180,7 +180,7 @@ void ReadStream::Read(CommonValue& data)
case CommonType::Rotation:
{
Quaternion v;
Read(&v);
Read(v);
data.Set(v);
}
break;
@@ -201,7 +201,7 @@ void ReadStream::Read(CommonValue& data)
case CommonType::Rectangle:
{
Rectangle v;
Read(&v);
Read(v);
data.Set(v);
}
case CommonType::Ray:
@@ -214,14 +214,14 @@ void ReadStream::Read(CommonValue& data)
case CommonType::Matrix:
{
Matrix v;
Read(&v);
Read(v);
data.Set(v);
}
break;
case CommonType::Blob:
{
int32 length;
Read(&length);
Read(length);
data.SetBlob(length);
if (length > 0)
{
@@ -245,7 +245,7 @@ void ReadStream::Read(VariantType& data)
return;
data.TypeName = static_cast<char*>(Allocator::Allocate(typeNameLength + 1));
char* ptr = data.TypeName;
Read(ptr, typeNameLength);
ReadBytes(ptr, typeNameLength);
for (int32 i = 0; i < typeNameLength; i++)
{
*ptr = *ptr ^ 77;
@@ -260,7 +260,7 @@ void ReadStream::Read(VariantType& data)
Array<Char> chars;
chars.Resize(typeNameLength + 1);
Char* ptr = chars.Get();
Read(ptr, typeNameLength);
ReadBytes(ptr, typeNameLength * sizeof(Char));
for (int32 i = 0; i < typeNameLength; i++)
{
*ptr = *ptr ^ 77;
@@ -331,7 +331,7 @@ void ReadStream::Read(Variant& data)
data.AsBlob.Length = dataLength;
}
Char* ptr = (Char*)data.AsBlob.Data;
Read(ptr, length);
ReadBytes(ptr, length * sizeof(Char));
for (int32 i = 0; i < length; i++)
{
*ptr = *ptr ^ -14;
@@ -343,7 +343,7 @@ void ReadStream::Read(Variant& data)
case VariantType::Object:
{
Guid id;
Read(&id);
Read(id);
data.SetObject(FindObject(id, ScriptingObject::GetStaticClass()));
break;
}
@@ -400,7 +400,7 @@ void ReadStream::Read(Variant& data)
case VariantType::Asset:
{
Guid id;
Read(&id);
Read(id);
data.SetAsset(LoadAsset(id, Asset::TypeInitializer));
break;
}
@@ -487,7 +487,7 @@ void ReadStream::Read(Variant& data)
data.AsBlob.Length = dataLength;
}
char* ptr = (char*)data.AsBlob.Data;
Read(ptr, length);
ReadBytes(ptr, length);
for (int32 i = 0; i < length; i++)
{
*ptr = *ptr ^ -14;
@@ -567,8 +567,8 @@ void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
else
{
Float3 min, max;
Read(&min);
Read(&max);
Read(min);
Read(max);
box->Minimum = min;
box->Maximum = max;
}
@@ -576,13 +576,13 @@ void ReadStream::ReadBoundingBox(BoundingBox* box, bool useDouble)
if (useDouble)
{
Double3 min, max;
Read(&min);
Read(&max);
Read(min);
Read(max);
box->Minimum = min;
box->Maximum = max;
}
else
Read(box);
Read(*box);
#endif
}
@@ -590,13 +590,13 @@ void ReadStream::ReadBoundingSphere(BoundingSphere* sphere, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Read(sphere);
Read(*sphere);
else
{
Float3 center;
float radius;
Read(&center);
Read(&radius);
Read(center);
Read(radius);
sphere->Center = center;
sphere->Radius = radius;
}
@@ -605,13 +605,13 @@ void ReadStream::ReadBoundingSphere(BoundingSphere* sphere, bool useDouble)
{
Double3 center;
double radius;
Read(&center);
Read(&radius);
Read(center);
Read(radius);
sphere->Center = center;
sphere->Radius = (float)radius;
}
else
Read(sphere);
Read(*sphere);
#endif
}
@@ -619,26 +619,26 @@ void ReadStream::ReadTransform(Transform* transform, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Read(transform);
Read(*transform);
else
{
Float3 translation;
Read(&translation);
Read(&transform->Orientation);
Read(&transform->Scale);
Read(translation);
Read(transform->Orientation);
Read(transform->Scale);
transform->Translation = translation;
}
#else
if (useDouble)
{
Double3 translation;
Read(&translation);
Read(&transform->Orientation);
Read(&transform->Scale);
Read(translation);
Read(transform->Orientation);
Read(transform->Scale);
transform->Translation = translation;
}
else
Read(transform);
Read(*transform);
#endif
}
@@ -646,12 +646,12 @@ void ReadStream::ReadRay(Ray* ray, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Read(ray);
Read(*ray);
else
{
Float3 position, direction;
Read(&position);
Read(&direction);
Read(position);
Read(direction);
ray->Position = position;
ray->Direction = direction;
}
@@ -659,13 +659,13 @@ void ReadStream::ReadRay(Ray* ray, bool useDouble)
if (useDouble)
{
Double3 position, direction;
Read(&position);
Read(&direction);
Read(position);
Read(direction);
ray->Position = position;
ray->Direction = direction;
}
else
Read(ray);
Read(*ray);
#endif
}
@@ -684,7 +684,7 @@ void WriteStream::Write(const StringView& data)
const int32 length = data.Length();
ASSERT(length < STREAM_MAX_STRING_LENGTH);
WriteInt32(length);
Write(*data, length);
WriteBytes(*data, length * sizeof(Char));
}
void WriteStream::Write(const StringView& data, int16 lock)
@@ -700,7 +700,7 @@ void WriteStream::Write(const StringAnsiView& data)
const int32 length = data.Length();
ASSERT(length < STREAM_MAX_STRING_LENGTH);
WriteInt32(length);
Write(data.Get(), length);
WriteBytes(data.Get(), length);
}
void WriteStream::Write(const StringAnsiView& data, int8 lock)
@@ -727,19 +727,19 @@ void WriteStream::Write(const CommonValue& data)
WriteFloat(data.AsFloat);
break;
case CommonType::Vector2:
Write(&data.AsVector2);
Write(data.AsVector2);
break;
case CommonType::Vector3:
Write(&data.AsVector3);
Write(data.AsVector3);
break;
case CommonType::Vector4:
Write(&data.AsVector4);
Write(data.AsVector4);
break;
case CommonType::Color:
Write(&data.AsColor);
Write(data.AsColor);
break;
case CommonType::Guid:
Write(&data.AsGuid);
Write(data.AsGuid);
break;
case CommonType::String:
WriteString(data.AsString, 953);
@@ -748,7 +748,7 @@ void WriteStream::Write(const CommonValue& data)
WriteBoundingBox(data.AsBox);
break;
case CommonType::Rotation:
Write(&data.AsRotation);
Write(data.AsRotation);
break;
case CommonType::Transform:
WriteTransform(data.AsTransform);
@@ -757,13 +757,13 @@ void WriteStream::Write(const CommonValue& data)
WriteBoundingSphere(data.AsSphere);
break;
case CommonType::Rectangle:
Write(&data.AsRectangle);
Write(data.AsRectangle);
break;
case CommonType::Ray:
WriteRay(data.AsRay);
break;
case CommonType::Matrix:
Write(&data.AsMatrix);
Write(data.AsMatrix);
break;
case CommonType::Blob:
WriteInt32(data.AsBlob.Length);
@@ -826,7 +826,7 @@ void WriteStream::Write(const Variant& data)
break;
case VariantType::Object:
id = data.AsObject ? data.AsObject->GetID() : Guid::Empty;
Write(&id);
Write(id);
break;
case VariantType::Blob:
WriteInt32(data.AsBlob.Length);
@@ -846,7 +846,7 @@ void WriteStream::Write(const Variant& data)
break;
case VariantType::Asset:
id = data.AsAsset ? data.AsAsset->GetID() : Guid::Empty;
Write(&id);
Write(id);
break;
case VariantType::Float2:
WriteBytes(data.AsData, sizeof(Float2));
@@ -985,22 +985,22 @@ void WriteStream::WriteBoundingBox(const BoundingBox& box, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Write(&box);
Write(box);
else
{
Float3 min = box.Minimum, max = box.Maximum;
Write(&min);
Write(&max);
Write(min);
Write(max);
}
#else
if (useDouble)
{
Double3 min = box.Minimum, max = box.Maximum;
Write(&min);
Write(&max);
Write(min);
Write(max);
}
else
Write(&box);
Write(box);
#endif
}
@@ -1008,24 +1008,24 @@ void WriteStream::WriteBoundingSphere(const BoundingSphere& sphere, bool useDoub
{
#if USE_LARGE_WORLDS
if (useDouble)
Write(&sphere);
Write(sphere);
else
{
Float3 center = sphere.Center;
float radius = (float)sphere.Radius;
Write(&center);
Write(&radius);
Write(center);
Write(radius);
}
#else
if (useDouble)
{
Double3 center = sphere.Center;
float radius = (float)sphere.Radius;
Write(&center);
Write(&radius);
Write(center);
Write(radius);
}
else
Write(&sphere);
Write(sphere);
#endif
}
@@ -1033,24 +1033,24 @@ void WriteStream::WriteTransform(const Transform& transform, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Write(&transform);
Write(transform);
else
{
Float3 translation = transform.Translation;
Write(&translation);
Write(&transform.Orientation);
Write(&transform.Scale);
Write(translation);
Write(transform.Orientation);
Write(transform.Scale);
}
#else
if (useDouble)
{
Double3 translation = transform.Translation;
Write(&translation);
Write(&transform.Orientation);
Write(&transform.Scale);
Write(translation);
Write(transform.Orientation);
Write(transform.Scale);
}
else
Write(&transform);
Write(transform);
#endif
}
@@ -1058,22 +1058,22 @@ void WriteStream::WriteRay(const Ray& ray, bool useDouble)
{
#if USE_LARGE_WORLDS
if (useDouble)
Write(&ray);
Write(ray);
else
{
Float3 position = ray.Position, direction = ray.Direction;
Write(&position);
Write(&direction);
Write(position);
Write(direction);
}
#else
if (useDouble)
{
Double3 position = ray.Position, direction = ray.Direction;
Write(&position);
Write(&direction);
Write(position);
Write(direction);
}
else
Write(&ray);
Write(ray);
#endif
}

View File

@@ -9,6 +9,7 @@ struct CommonValue;
struct Variant;
struct VariantType;
class ISerializable;
class ScriptingObject;
/// <summary>
/// Base class for all data write streams
@@ -23,115 +24,103 @@ public:
/// <param name="bytes">Amount of bytes to write</param>
virtual void WriteBytes(const void* data, uint32 bytes) = 0;
template<typename T>
FORCE_INLINE void Write(const T* data)
{
WriteBytes((const void*)data, sizeof(T));
}
template<typename T>
FORCE_INLINE void Write(const T* data, int32 count)
{
WriteBytes((const void*)data, sizeof(T) * count);
}
public:
// Writes byte to the stream
// @param data Data to write
FORCE_INLINE void WriteByte(byte data)
{
Write(&data);
WriteBytes(&data, sizeof(byte));
}
// Writes bool to the stream
// @param data Data to write
FORCE_INLINE void WriteBool(bool data)
{
Write(&data);
WriteBytes(&data, sizeof(bool));
}
// Writes char to the stream
// @param data Data to write
FORCE_INLINE void WriteChar(char data)
{
Write(&data);
WriteBytes(&data, sizeof(char));
}
// Writes Char to the stream
// @param data Data to write
FORCE_INLINE void WriteChar(Char data)
{
Write(&data);
WriteBytes(&data, sizeof(Char));
}
// Writes uint8 to the stream
// @param data Data to write
FORCE_INLINE void WriteUint8(uint8 data)
{
Write(&data);
WriteBytes(&data, sizeof(uint8));
}
// Writes int8 to the stream
// @param data Data to write
FORCE_INLINE void WriteInt8(int8 data)
{
Write(&data);
WriteBytes(&data, sizeof(int8));
}
// Writes uint16 to the stream
// @param data Data to write
FORCE_INLINE void WriteUint16(uint16 data)
{
Write(&data);
WriteBytes(&data, sizeof(uint16));
}
// Writes int16 to the stream
// @param data Data to write
FORCE_INLINE void WriteInt16(int16 data)
{
Write(&data);
WriteBytes(&data, sizeof(int16));
}
// Writes uint32 to the stream
// @param data Data to write
FORCE_INLINE void WriteUint32(uint32 data)
{
Write(&data);
WriteBytes(&data, sizeof(uint32));
}
// Writes int32 to the stream
// @param data Data to write
FORCE_INLINE void WriteInt32(int32 data)
{
Write(&data);
WriteBytes(&data, sizeof(int32));
}
// Writes int64 to the stream
// @param data Data to write
FORCE_INLINE void WriteInt64(int64 data)
{
Write(&data);
WriteBytes(&data, sizeof(int64));
}
// Writes uint64 to the stream
// @param data Data to write
FORCE_INLINE void WriteUint64(uint64 data)
{
Write(&data);
WriteBytes(&data, sizeof(uint64));
}
// Writes float to the stream
// @param data Data to write
FORCE_INLINE void WriteFloat(float data)
{
Write(&data);
WriteBytes(&data, sizeof(float));
}
// Writes double to the stream
// @param data Data to write
FORCE_INLINE void WriteDouble(double data)
{
Write(&data);
WriteBytes(&data, sizeof(double));
}
public:
@@ -179,13 +168,28 @@ public:
WriteBytes((const void*)&data, sizeof(T));
}
template<typename T>
typename TEnableIf<TIsBaseOf<ScriptingObject, T>::Value>::Type Write(const T* data)
{
const Guid id = data ? data->GetID() : Guid::Empty;
WriteBytes(&id, sizeof(Guid));
}
template<typename T, typename AllocationType = HeapAllocation>
void Write(const Array<T, AllocationType>& data)
{
const int32 size = data.Count();
WriteInt32(size);
if (size > 0)
Write(data.Get(), size * sizeof(T));
{
if (TIsPODType<T>::Value && !TIsPointer<T>::Value)
WriteBytes(data.Get(), size * sizeof(T));
else
{
for (int32 i = 0; i < size; i++)
Write(data[i]);
}
}
}
template<typename KeyType, typename ValueType, typename AllocationType = HeapAllocation>
@@ -197,8 +201,8 @@ public:
{
for (const auto& e : data)
{
Write(&e.Key, sizeof(KeyType));
Write(&e.Value, sizeof(ValueType));
Write(e.Key);
Write(e.Value);
}
}
}

View File

@@ -126,7 +126,7 @@ bool ShaderCompiler::Compile(ShaderCompilationContext* context)
{
output->WriteString(include.Item, 11);
const auto date = FileSystem::GetFileLastEditTime(include.Item);
output->Write(&date);
output->Write(date);
}
return false;
@@ -387,7 +387,7 @@ bool ShaderCompiler::WriteShaderFunctionPermutation(ShaderCompilationContext* co
output->WriteBytes(cache, cacheSize);
// [Output] Shader bindings meta
output->Write(&bindings);
output->Write(bindings);
return false;
}
@@ -401,7 +401,7 @@ bool ShaderCompiler::WriteShaderFunctionPermutation(ShaderCompilationContext* co
output->WriteBytes(cache, cacheSize);
// [Output] Shader bindings meta
output->Write(&bindings);
output->Write(bindings);
return false;
}

View File

@@ -347,7 +347,7 @@ void ShadersCompilation::ExtractShaderIncludes(byte* shaderCache, int32 shaderCa
String& include = includes.AddOne();
stream.ReadString(&include, 11);
DateTime lastEditTime;
stream.Read(&lastEditTime);
stream.Read(lastEditTime);
}
}

View File

@@ -201,7 +201,7 @@ bool ShadowsOfMordor::Builder::RestoreState()
for (int32 i = 0; i < scenesCount; i++)
{
Guid id;
stream->Read(&id);
stream->Read(id);
Level::LoadScene(id);
}
@@ -235,7 +235,7 @@ void ShadowsOfMordor::Builder::saveState()
// Scenes ids
stream->WriteInt32(_scenes.Count());
for (int32 i = 0; i < _scenes.Count(); i++)
stream->Write(&_scenes[i]->Scene->GetID());
stream->Write(_scenes[i]->Scene->GetID());
// State
stream->WriteInt32(_giBounceRunningIndex);
@@ -325,7 +325,7 @@ bool ShadowsOfMordor::Builder::loadState()
for (int32 i = 0; i < scenesCount; i++)
{
Guid id;
stream->Read(&id);
stream->Read(id);
if (Level::Scenes[i]->GetID() != id || _scenes[i]->SceneIndex != i)
{
LOG(Error, "Invalid scenes.");

View File

@@ -18,7 +18,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
{
// Get sub-chunk ID and size
uint8 subChunkId[4];
mStream->Read(subChunkId, sizeof(subChunkId));
mStream->ReadBytes(subChunkId, sizeof(subChunkId));
uint32 subChunkSize = 0;
mStream->ReadUint32(&subChunkSize);
@@ -79,7 +79,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info)
mStream->ReadUint32(&channelMask);
uint8 subFormat[16];
mStream->Read(subFormat, sizeof(subFormat));
mStream->ReadBytes(subFormat, sizeof(subFormat));
Platform::MemoryCopy(&format, subFormat, sizeof(format));
if (format != WAVE_FORMAT_PCM)
@@ -136,7 +136,7 @@ void WaveDecoder::Seek(uint32 offset)
void WaveDecoder::Read(byte* samples, uint32 numSamples)
{
const uint32 numRead = numSamples * mBytesPerSample;
mStream->Read(samples, numRead);
mStream->ReadBytes(samples, numRead);
// 8-bit samples are stored as unsigned, but engine convention is to store all bit depths as signed
if (mBytesPerSample == 1)

View File

@@ -228,9 +228,9 @@ bool ModelTool::GenerateModelSDF(Model* inputModel, ModelData* modelData, float
{
outputStream->WriteInt32(1); // Version
ModelSDFHeader data(sdf, textureDesc);
outputStream->Write(&data);
outputStream->WriteBytes(&data, sizeof(data));
ModelSDFMip mipData(0, resolution.X * formatStride, voxelsSize);
outputStream->Write(&mipData);
outputStream->WriteBytes(&mipData, sizeof(mipData));
outputStream->WriteBytes(voxels, voxelsSize);
}
@@ -293,7 +293,7 @@ bool ModelTool::GenerateModelSDF(Model* inputModel, ModelData* modelData, float
if (outputStream)
{
ModelSDFMip mipData(mipLevel, resolutionMip.X * formatStride, voxelsMipSize);
outputStream->Write(&mipData);
outputStream->WriteBytes(&mipData, sizeof(mipData));
outputStream->WriteBytes(voxelsMip, voxelsMipSize);
}

View File

@@ -102,7 +102,7 @@ public:
{
const Parameter* param = &Parameters[i];
stream->WriteVariantType(param->Type);
stream->Write(&param->Identifier);
stream->Write(param->Identifier);
stream->WriteString(param->Name, 97);
stream->WriteBool(param->IsPublic);
stream->WriteVariant(param->Value);
@@ -221,7 +221,7 @@ public:
// Properties
auto type = stream->ReadByte();
stream->Read(&param->Identifier);
stream->Read(param->Identifier);
stream->ReadString(&param->Name, 97);
param->IsPublic = stream->ReadBool();
bool isStatic = stream->ReadBool();
@@ -359,7 +359,7 @@ public:
{
auto param = &Parameters[i];
stream->ReadVariantType(&param->Type);
stream->Read(&param->Identifier);
stream->Read(param->Identifier);
stream->ReadString(&param->Name, 97);
param->IsPublic = stream->ReadBool();
stream->ReadVariant(&param->Value);

View File

@@ -23,7 +23,7 @@ bool VisjectMeta::Load(ReadStream* stream, bool loadData)
stream->ReadInt32(&e.TypeID);
DateTime creationTime;
stream->Read(&creationTime);
stream->Read(creationTime);
uint32 dataSize;
stream->ReadUint32(&dataSize);

View File

@@ -135,7 +135,7 @@ namespace Flax.Build.Plugins
if (IsRawPOD(buildData, typeInfo))
{
// POD types as raw bytes
OnGenerateCppWriteRaw(contents, "&obj", serialize);
OnGenerateCppWriteRaw(contents, "obj", serialize);
}
else
{
@@ -188,7 +188,7 @@ namespace Flax.Build.Plugins
throw new Exception($"Invalid pointer type '{type}' that cannot be serialized for replication of {caller.Name}.");
if (type.IsRef)
throw new Exception($"Invalid reference type '{type}' that cannot be serialized for replication of {caller.Name}.");
OnGenerateCppWriteRaw(contents, "&" + name, serialize);
OnGenerateCppWriteRaw(contents, name, serialize);
}
else if (apiType.IsScriptingObject)
{
@@ -196,13 +196,13 @@ namespace Flax.Build.Plugins
if (serialize)
{
contents.AppendLine($" {{Guid id = {name} ? {name}->GetID() : Guid::Empty;");
OnGenerateCppWriteRaw(contents, "&id", serialize);
OnGenerateCppWriteRaw(contents, "id", serialize);
contents.AppendLine(" }");
}
else
{
contents.AppendLine($" {{Guid id;");
OnGenerateCppWriteRaw(contents, "&id", serialize);
OnGenerateCppWriteRaw(contents, "id", serialize);
contents.AppendLine($" {name} = Scripting::TryFindObject(id);}}");
}
}