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); 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))); 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++) for (int32 i = 0; i < entriesCount; i++)
{ {
Guid id; Guid id;
file->Read(&id); file->Read(id);
String typeName; String typeName;
file->ReadString(&typeName); file->ReadString(&typeName);
DateTime fileModified; DateTime fileModified;
file->Read(&fileModified); file->Read(fileModified);
int32 fileDependenciesCount; int32 fileDependenciesCount;
file->ReadInt32(&fileDependenciesCount); file->ReadInt32(&fileDependenciesCount);
fileDependencies.Clear(); fileDependencies.Clear();
@@ -164,7 +164,7 @@ void CookAssetsStep::CacheData::Load(CookingData& data)
{ {
Pair<String, DateTime>& f = fileDependencies[j]; Pair<String, DateTime>& f = fileDependencies[j];
file->ReadString(&f.First, 10); file->ReadString(&f.First, 10);
file->Read(&f.Second); file->Read(f.Second);
} }
// Skip missing entries // Skip missing entries
@@ -287,18 +287,18 @@ void CookAssetsStep::CacheData::Save()
// Serialize // Serialize
file->WriteInt32(FLAXENGINE_VERSION_BUILD); file->WriteInt32(FLAXENGINE_VERSION_BUILD);
file->WriteInt32(Entries.Count()); file->WriteInt32(Entries.Count());
file->Write(&Settings); file->WriteBytes(&Settings, sizeof(Settings));
for (auto i = Entries.Begin(); i.IsNotEnd(); ++i) for (auto i = Entries.Begin(); i.IsNotEnd(); ++i)
{ {
auto& e = i->Value; auto& e = i->Value;
file->Write(&e.ID); file->Write(e.ID);
file->WriteString(e.TypeName); file->WriteString(e.TypeName);
file->Write(&e.FileModified); file->Write(e.FileModified);
file->WriteInt32(e.FileDependencies.Count()); file->WriteInt32(e.FileDependencies.Count());
for (auto& f : e.FileDependencies) for (auto& f : e.FileDependencies)
{ {
file->WriteString(f.First, 10); file->Write(f.First, 10);
file->Write(&f.Second); file->Write(f.Second);
} }
} }
file->WriteInt32(13); file->WriteInt32(13);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -30,7 +30,7 @@ public:
if (context.AllocateChunk(0)) if (context.AllocateChunk(0))
return CreateAssetResult::CannotAllocateChunk; return CreateAssetResult::CannotAllocateChunk;
MemoryWriteStream stream(256); MemoryWriteStream stream(256);
stream.Write(&Guid::Empty); stream.Write(Guid::Empty);
MaterialParams::Save(&stream, nullptr); MaterialParams::Save(&stream, nullptr);
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition()); 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 // Load sprite
Sprite t; Sprite t;
stream.Read(&t.Area);; stream.Read(t.Area);
stream.ReadString(&t.Name, 49); stream.ReadString(&t.Name, 49);
options.Sprites.Add(t); options.Sprites.Add(t);
} }
@@ -183,7 +183,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
for (int32 i = 0; i < options.Sprites.Count(); i++) for (int32 i = 0; i < options.Sprites.Count(); i++)
{ {
auto& sprite = options.Sprites[i]; auto& sprite = options.Sprites[i];
stream.Write(&sprite.Area); stream.Write(sprite.Area);
stream.WriteString(sprite.Name, 49); stream.WriteString(sprite.Name, 49);
} }
if (context.AllocateChunk(15)) if (context.AllocateChunk(15))
@@ -322,7 +322,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
for (int32 i = 0; i < options.Sprites.Count(); i++) for (int32 i = 0; i < options.Sprites.Count(); i++)
{ {
auto& sprite = options.Sprites[i]; auto& sprite = options.Sprites[i];
stream.Write(&sprite.Area); stream.Write(sprite.Area);
stream.WriteString(sprite.Name, 49); stream.WriteString(sprite.Name, 49);
} }
if (context.AllocateChunk(15)) if (context.AllocateChunk(15))

View File

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

View File

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

View File

@@ -336,7 +336,7 @@ bool MeshData::Pack2Model(WriteStream* stream) const
vb1.Normal = Float1010102(normal * 0.5f + 0.5f, 0); 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.Tangent = Float1010102(tangent * 0.5f + 0.5f, static_cast<byte>(bitangentSign < 0 ? 1 : 0));
vb1.LightmapUVs = Half2(lightmapUV); vb1.LightmapUVs = Half2(lightmapUV);
stream->Write(&vb1); stream->WriteBytes(&vb1, sizeof(vb1));
// Pack TBN matrix into a quaternion // Pack TBN matrix into a quaternion
/*Quaternion quaternionTBN; /*Quaternion quaternionTBN;
@@ -360,7 +360,7 @@ bool MeshData::Pack2Model(WriteStream* stream) const
for (uint32 i = 0; i < verticiecCount; i++) for (uint32 i = 0; i < verticiecCount; i++)
{ {
vb2.Color = Color32(Colors[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.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.BlendIndices = Color32(blendIndices.X, blendIndices.Y, blendIndices.Z, blendIndices.W);
vb.BlendWeights = Half4(blendWeights); vb.BlendWeights = Half4(blendWeights);
stream->Write(&vb); stream->WriteBytes(&vb, sizeof(vb));
} }
// Index Buffer // Index Buffer
@@ -704,7 +704,7 @@ bool ModelData::Pack2ModelHeader(WriteStream* stream) const
{ {
auto& slot = Materials[materialSlotIndex]; auto& slot = Materials[materialSlotIndex];
stream->Write(&slot.AssetID); stream->Write(slot.AssetID);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode)); stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11); stream->WriteString(slot.Name, 11);
} }
@@ -793,7 +793,7 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{ {
auto& slot = Materials[materialSlotIndex]; auto& slot = Materials[materialSlotIndex];
stream->Write(&slot.AssetID); stream->Write(slot.AssetID);
stream->WriteByte(static_cast<byte>(slot.ShadowsMode)); stream->WriteByte(static_cast<byte>(slot.ShadowsMode));
stream->WriteString(slot.Name, 11); stream->WriteString(slot.Name, 11);
} }
@@ -859,7 +859,7 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{ {
auto& node = Skeleton.Nodes[nodeIndex]; auto& node = Skeleton.Nodes[nodeIndex];
stream->Write(&node.ParentIndex); stream->Write(node.ParentIndex);
stream->WriteTransform(node.LocalTransform); stream->WriteTransform(node.LocalTransform);
stream->WriteString(node.Name, 71); stream->WriteString(node.Name, 71);
} }
@@ -871,10 +871,10 @@ bool ModelData::Pack2SkinnedModelHeader(WriteStream* stream) const
{ {
auto& bone = Skeleton.Bones[boneIndex]; auto& bone = Skeleton.Bones[boneIndex];
stream->Write(&bone.ParentIndex); stream->Write(bone.ParentIndex);
stream->Write(&bone.NodeIndex); stream->Write(bone.NodeIndex);
stream->WriteTransform(bone.LocalTransform); 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(); String& include = includes.AddOne();
stream.ReadString(&include, 11); stream.ReadString(&include, 11);
DateTime lastEditTime; DateTime lastEditTime;
stream.Read(&lastEditTime); stream.Read(lastEditTime);
// Check if included file exists locally and has been modified since last compilation // Check if included file exists locally and has been modified since last compilation
if (FileSystem::FileExists(include) && FileSystem::GetFileLastEditTime(include) > lastEditTime) if (FileSystem::FileExists(include) && FileSystem::GetFileLastEditTime(include) > lastEditTime)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -347,7 +347,7 @@ void ShadersCompilation::ExtractShaderIncludes(byte* shaderCache, int32 shaderCa
String& include = includes.AddOne(); String& include = includes.AddOne();
stream.ReadString(&include, 11); stream.ReadString(&include, 11);
DateTime lastEditTime; 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++) for (int32 i = 0; i < scenesCount; i++)
{ {
Guid id; Guid id;
stream->Read(&id); stream->Read(id);
Level::LoadScene(id); Level::LoadScene(id);
} }
@@ -235,7 +235,7 @@ void ShadowsOfMordor::Builder::saveState()
// Scenes ids // Scenes ids
stream->WriteInt32(_scenes.Count()); stream->WriteInt32(_scenes.Count());
for (int32 i = 0; i < _scenes.Count(); i++) for (int32 i = 0; i < _scenes.Count(); i++)
stream->Write(&_scenes[i]->Scene->GetID()); stream->Write(_scenes[i]->Scene->GetID());
// State // State
stream->WriteInt32(_giBounceRunningIndex); stream->WriteInt32(_giBounceRunningIndex);
@@ -325,7 +325,7 @@ bool ShadowsOfMordor::Builder::loadState()
for (int32 i = 0; i < scenesCount; i++) for (int32 i = 0; i < scenesCount; i++)
{ {
Guid id; Guid id;
stream->Read(&id); stream->Read(id);
if (Level::Scenes[i]->GetID() != id || _scenes[i]->SceneIndex != i) if (Level::Scenes[i]->GetID() != id || _scenes[i]->SceneIndex != i)
{ {
LOG(Error, "Invalid scenes."); LOG(Error, "Invalid scenes.");

View File

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

View File

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

View File

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

View File

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

View File

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