Add ToSpan for MemoryWriteStream and simplify code with it
This commit is contained in:
@@ -433,7 +433,7 @@ bool CSGBuilderImpl::generateRawDataAsset(Scene* scene, RawData& meshData, Guid&
|
|||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
BytesContainer bytesContainer;
|
BytesContainer bytesContainer;
|
||||||
bytesContainer.Link(stream.GetHandle(), stream.GetPosition());
|
bytesContainer.Link(ToSpan(stream));
|
||||||
return AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer);
|
return AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ void Animation::LoadTimeline(BytesContainer& result) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Copy(stream.GetHandle(), stream.GetPosition());
|
result.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Animation::SaveTimeline(BytesContainer& data)
|
bool Animation::SaveTimeline(BytesContainer& data)
|
||||||
@@ -476,7 +476,7 @@ bool Animation::Save(const StringView& path)
|
|||||||
// Set data to the chunk asset
|
// Set data to the chunk asset
|
||||||
auto chunk0 = GetOrCreateChunk(0);
|
auto chunk0 = GetOrCreateChunk(0);
|
||||||
ASSERT(chunk0 != nullptr);
|
ASSERT(chunk0 != nullptr);
|
||||||
chunk0->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
chunk0->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ bool AnimationGraph::InitAsAnimation(SkinnedModel* baseModel, Animation* anim, b
|
|||||||
|
|
||||||
// Load Graph data (with initialization)
|
// Load Graph data (with initialization)
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
MemoryReadStream readStream(writeStream.GetHandle(), writeStream.GetPosition());
|
MemoryReadStream readStream(ToSpan(writeStream));
|
||||||
return Graph.Load(&readStream, USE_EDITOR);
|
return Graph.Load(&readStream, USE_EDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ BytesContainer AnimationGraph::LoadSurface()
|
|||||||
if (!Graph.Save(&stream, USE_EDITOR))
|
if (!Graph.Save(&stream, USE_EDITOR))
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
result.Copy(stream.GetHandle(), stream.GetPosition());
|
result.Copy(ToSpan(stream));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ Asset::LoadResult Material::load()
|
|||||||
// Save layer to the chunk data
|
// Save layer to the chunk data
|
||||||
MemoryWriteStream stream(512);
|
MemoryWriteStream stream(512);
|
||||||
layer->Graph.Save(&stream, false);
|
layer->Graph.Save(&stream, false);
|
||||||
surfaceChunk->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
surfaceChunk->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
generator.AddLayer(layer);
|
generator.AddLayer(layer);
|
||||||
|
|
||||||
@@ -542,7 +542,7 @@ BytesContainer Material::LoadSurface(bool createDefaultIfMissing)
|
|||||||
layer->Graph.Save(&stream, false);
|
layer->Graph.Save(&stream, false);
|
||||||
|
|
||||||
// Set output data
|
// Set output data
|
||||||
result.Copy(stream.GetHandle(), stream.GetPosition());
|
result.Copy(ToSpan(stream));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ bool MaterialInstance::Save(const StringView& path)
|
|||||||
// Save parameters
|
// Save parameters
|
||||||
Params.Save(&stream);
|
Params.Save(&stream);
|
||||||
}
|
}
|
||||||
SetChunk(0, ToSpan(stream.GetHandle(), stream.GetPosition()));
|
SetChunk(0, ToSpan(stream));
|
||||||
|
|
||||||
// Setup asset data
|
// Setup asset data
|
||||||
AssetInitData data;
|
AssetInitData data;
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ bool Model::GenerateSDF(float resolutionScale, int32 lodIndex, bool cacheData, f
|
|||||||
if (cacheData)
|
if (cacheData)
|
||||||
{
|
{
|
||||||
auto chunk = GetOrCreateChunk(15);
|
auto chunk = GetOrCreateChunk(15);
|
||||||
chunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
|
chunk->Data.Copy(ToSpan(sdfStream));
|
||||||
chunk->Flags |= FlaxChunkFlags::KeepInMemory; // Prevent GC-ing chunk data so it will be properly saved
|
chunk->Flags |= FlaxChunkFlags::KeepInMemory; // Prevent GC-ing chunk data so it will be properly saved
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -484,7 +484,7 @@ bool Model::Save(bool withMeshDataFromGpu, Function<FlaxChunk*(int32)>& getChunk
|
|||||||
sdfStream.WriteBytes(&mipData, sizeof(mipData));
|
sdfStream.WriteBytes(&mipData, sizeof(mipData));
|
||||||
sdfStream.WriteBytes(mip.Data.Get(), mip.Data.Length());
|
sdfStream.WriteBytes(mip.Data.Get(), mip.Data.Length());
|
||||||
}
|
}
|
||||||
sdfChunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition());
|
sdfChunk->Data.Copy(ToSpan(sdfStream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ bool ModelBase::Save(bool withMeshDataFromGpu, const StringView& path)
|
|||||||
auto lodChunk = getChunk(MODEL_LOD_TO_CHUNK_INDEX(lodIndex));
|
auto lodChunk = getChunk(MODEL_LOD_TO_CHUNK_INDEX(lodIndex));
|
||||||
if (lodChunk == nullptr)
|
if (lodChunk == nullptr)
|
||||||
return true;
|
return true;
|
||||||
lodChunk->Data.Copy(meshesStream.GetHandle(), meshesStream.GetPosition());
|
lodChunk->Data.Copy(ToSpan(meshesStream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!IsVirtual())
|
else if (!IsVirtual())
|
||||||
@@ -289,7 +289,7 @@ bool ModelBase::Save(bool withMeshDataFromGpu, const StringView& path)
|
|||||||
return true;
|
return true;
|
||||||
auto headerChunk = getChunk(0);
|
auto headerChunk = getChunk(0);
|
||||||
ASSERT(headerChunk != nullptr);
|
ASSERT(headerChunk != nullptr);
|
||||||
headerChunk->Data.Copy(headerStream.GetHandle(), headerStream.GetPosition());
|
headerChunk->Data.Copy(ToSpan(headerStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ bool SkeletonMask::Save(const StringView& path)
|
|||||||
Platform::MemoryClear(tmpChunks, sizeof(tmpChunks));
|
Platform::MemoryClear(tmpChunks, sizeof(tmpChunks));
|
||||||
FlaxChunk chunk;
|
FlaxChunk chunk;
|
||||||
tmpChunks[0] = &chunk;
|
tmpChunks[0] = &chunk;
|
||||||
tmpChunks[0]->Data.Link(stream.GetHandle(), stream.GetPosition());
|
tmpChunks[0]->Data.Link(ToSpan(stream));
|
||||||
|
|
||||||
AssetInitData initData;
|
AssetInitData initData;
|
||||||
initData.SerializedVersion = SerializedVersion;
|
initData.SerializedVersion = SerializedVersion;
|
||||||
@@ -109,7 +109,7 @@ bool SkeletonMask::Save(const StringView& path)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto chunk0 = GetChunk(0);
|
auto chunk0 = GetChunk(0);
|
||||||
chunk0->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
chunk0->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
AssetInitData initData;
|
AssetInitData initData;
|
||||||
initData.SerializedVersion = SerializedVersion;
|
initData.SerializedVersion = SerializedVersion;
|
||||||
|
|||||||
@@ -1700,7 +1700,7 @@ ScriptingObject* VisualScriptingBinaryModule::VisualScriptObjectSpawn(const Scri
|
|||||||
// Special case for C# object property in Visual Script so duplicate the object instead of cloning the reference to it
|
// Special case for C# object property in Visual Script so duplicate the object instead of cloning the reference to it
|
||||||
MemoryWriteStream writeStream;
|
MemoryWriteStream writeStream;
|
||||||
writeStream.Write(param);
|
writeStream.Write(param);
|
||||||
MemoryReadStream readStream(writeStream.GetHandle(), writeStream.GetPosition());
|
MemoryReadStream readStream(ToSpan(writeStream));
|
||||||
readStream.Read(param);
|
readStream.Read(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2231,7 +2231,7 @@ bool VisualScript::SaveSurface(const BytesContainer& data, const Metadata& meta)
|
|||||||
metaStream.Write(meta.BaseTypename, 31);
|
metaStream.Write(meta.BaseTypename, 31);
|
||||||
metaStream.Write((int32)meta.Flags);
|
metaStream.Write((int32)meta.Flags);
|
||||||
}
|
}
|
||||||
GetOrCreateChunk(1)->Data.Copy(metaStream.GetHandle(), metaStream.GetPosition());
|
GetOrCreateChunk(1)->Data.Copy(ToSpan(metaStream));
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
AssetInitData assetData;
|
AssetInitData assetData;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
// Copy to asset chunk
|
// Copy to asset chunk
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ CreateAssetResult CreateAnimationGraph::Create(CreateAssetContext& context)
|
|||||||
// Copy to asset chunk
|
// Copy to asset chunk
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
const BehaviorTreeGraph graph;
|
const BehaviorTreeGraph graph;
|
||||||
MemoryWriteStream stream(64);
|
MemoryWriteStream stream(64);
|
||||||
graph.Save(&stream, true);
|
graph.Save(&stream, true);
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ CreateAssetResult CreateMaterial::Create(CreateAssetContext& context)
|
|||||||
|
|
||||||
MemoryWriteStream stream(512);
|
MemoryWriteStream stream(512);
|
||||||
layer->Graph.Save(&stream, true);
|
layer->Graph.Save(&stream, true);
|
||||||
context.Data.Header.Chunks[SHADER_FILE_CHUNK_VISJECT_SURFACE]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[SHADER_FILE_CHUNK_VISJECT_SURFACE]->Data.Copy(ToSpan(stream));
|
||||||
Delete(layer);
|
Delete(layer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
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(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
graph.CreateDefault();
|
graph.CreateDefault();
|
||||||
MemoryWriteStream stream(512);
|
MemoryWriteStream stream(512);
|
||||||
graph.Save(&stream, false);
|
graph.Save(&stream, false);
|
||||||
context.Data.Header.Chunks[SHADER_FILE_CHUNK_VISJECT_SURFACE]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[SHADER_FILE_CHUNK_VISJECT_SURFACE]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
stream.WriteInt32(0); // Emitters Count
|
stream.WriteInt32(0); // Emitters Count
|
||||||
stream.WriteInt32(0); // Tracks Count
|
stream.WriteInt32(0); // Tracks Count
|
||||||
}
|
}
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
stream.WriteInt32(5 * 60); // DurationFrames
|
stream.WriteInt32(5 * 60); // DurationFrames
|
||||||
stream.WriteInt32(0); // Tracks Count
|
stream.WriteInt32(0); // Tracks Count
|
||||||
}
|
}
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
const VisualScriptGraph graph;
|
const VisualScriptGraph graph;
|
||||||
MemoryWriteStream stream(64);
|
MemoryWriteStream stream(64);
|
||||||
graph.Save(&stream, true);
|
graph.Save(&stream, true);
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk 1 - Visual Script Metadata
|
// Chunk 1 - Visual Script Metadata
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
stream.Write(1);
|
stream.Write(1);
|
||||||
stream.Write(*baseTypename, 31);
|
stream.Write(*baseTypename, 31);
|
||||||
stream.Write((int32)VisualScript::Flags::None);
|
stream.Write((int32)VisualScript::Flags::None);
|
||||||
context.Data.Header.Chunks[1]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[1]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ CreateAssetResult ImportModel::CreateModel(CreateAssetContext& context, const Mo
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
// Pack model LODs data
|
// Pack model LODs data
|
||||||
const auto lodCount = modelData.LODs.Count();
|
const auto lodCount = modelData.LODs.Count();
|
||||||
@@ -566,7 +566,7 @@ CreateAssetResult ImportModel::CreateModel(CreateAssetContext& context, const Mo
|
|||||||
const int32 chunkIndex = MODEL_LOD_TO_CHUNK_INDEX(lodIndex);
|
const int32 chunkIndex = MODEL_LOD_TO_CHUNK_INDEX(lodIndex);
|
||||||
if (context.AllocateChunk(chunkIndex))
|
if (context.AllocateChunk(chunkIndex))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[chunkIndex]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[chunkIndex]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate SDF
|
// Generate SDF
|
||||||
@@ -577,7 +577,7 @@ CreateAssetResult ImportModel::CreateModel(CreateAssetContext& context, const Mo
|
|||||||
{
|
{
|
||||||
if (context.AllocateChunk(15))
|
if (context.AllocateChunk(15))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[15]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[15]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +596,7 @@ CreateAssetResult ImportModel::CreateSkinnedModel(CreateAssetContext& context, c
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
// Pack model LODs data
|
// Pack model LODs data
|
||||||
const auto lodCount = modelData.LODs.Count();
|
const auto lodCount = modelData.LODs.Count();
|
||||||
@@ -608,7 +608,7 @@ CreateAssetResult ImportModel::CreateSkinnedModel(CreateAssetContext& context, c
|
|||||||
const int32 chunkIndex = MODEL_LOD_TO_CHUNK_INDEX(lodIndex);
|
const int32 chunkIndex = MODEL_LOD_TO_CHUNK_INDEX(lodIndex);
|
||||||
if (context.AllocateChunk(chunkIndex))
|
if (context.AllocateChunk(chunkIndex))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[chunkIndex]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[chunkIndex]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
@@ -637,7 +637,7 @@ CreateAssetResult ImportModel::CreateAnimation(CreateAssetContext& context, cons
|
|||||||
return CreateAssetResult::Error;
|
return CreateAssetResult::Error;
|
||||||
if (context.AllocateChunk(0))
|
if (context.AllocateChunk(0))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[0]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[0]->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
return CreateAssetResult::Ok;
|
return CreateAssetResult::Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
|
|||||||
}
|
}
|
||||||
if (context.AllocateChunk(15))
|
if (context.AllocateChunk(15))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[15]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[15]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save mip maps
|
// Save mip maps
|
||||||
@@ -317,7 +317,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu
|
|||||||
}
|
}
|
||||||
if (context.AllocateChunk(15))
|
if (context.AllocateChunk(15))
|
||||||
return CreateAssetResult::CannotAllocateChunk;
|
return CreateAssetResult::CannotAllocateChunk;
|
||||||
context.Data.Header.Chunks[15]->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
context.Data.Header.Chunks[15]->Data.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save mip maps
|
// Save mip maps
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ bool GameplayGlobals::Save(const StringView& path)
|
|||||||
{
|
{
|
||||||
chunk = GetOrCreateChunk(0);
|
chunk = GetOrCreateChunk(0);
|
||||||
}
|
}
|
||||||
chunk->Data.Copy(stream.GetHandle(), stream.GetPosition());
|
chunk->Data.Copy(ToSpan(stream));
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
AssetInitData data;
|
AssetInitData data;
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result)
|
|||||||
auto cacheChunk = parent->GetOrCreateChunk(cacheChunkIndex);
|
auto cacheChunk = parent->GetOrCreateChunk(cacheChunkIndex);
|
||||||
if (cacheChunk == nullptr)
|
if (cacheChunk == nullptr)
|
||||||
return true;
|
return true;
|
||||||
cacheChunk->Data.Copy(cacheStream.GetHandle(), cacheStream.GetPosition());
|
cacheChunk->Data.Copy(ToSpan(cacheStream));
|
||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
// Save chunks to the asset file
|
// Save chunks to the asset file
|
||||||
@@ -317,7 +317,7 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Use temporary generated data without caching (but read the includes from cache)
|
// Use temporary generated data without caching (but read the includes from cache)
|
||||||
result.Data.Copy(cacheStream.GetHandle(), cacheStream.GetLength());
|
result.Data.Copy(ToSpan(cacheStream));
|
||||||
IsValidShaderCache(result.Data, result.Includes);
|
IsValidShaderCache(result.Data, result.Includes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void NavMesh::SaveNavMesh()
|
|||||||
MemoryWriteStream stream(streamInitialCapacity);
|
MemoryWriteStream stream(streamInitialCapacity);
|
||||||
Data.Save(stream);
|
Data.Save(stream);
|
||||||
BytesContainer bytesContainer;
|
BytesContainer bytesContainer;
|
||||||
bytesContainer.Link(stream.GetHandle(), stream.GetPosition());
|
bytesContainer.Link(ToSpan(stream));
|
||||||
|
|
||||||
// Save asset to file
|
// Save asset to file
|
||||||
if (AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer))
|
if (AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer))
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ BytesContainer ParticleEmitter::LoadSurface(bool createDefaultIfMissing)
|
|||||||
graph.Save(&stream, false);
|
graph.Save(&stream, false);
|
||||||
|
|
||||||
// Set output data
|
// Set output data
|
||||||
result.Copy(stream.GetHandle(), stream.GetPosition());
|
result.Copy(ToSpan(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
#include "MemoryReadStream.h"
|
#include "MemoryReadStream.h"
|
||||||
|
#include "Engine/Platform/Platform.h"
|
||||||
|
|
||||||
MemoryReadStream::MemoryReadStream()
|
MemoryReadStream::MemoryReadStream()
|
||||||
: _buffer(nullptr)
|
: _buffer(nullptr)
|
||||||
@@ -22,6 +23,14 @@ void MemoryReadStream::Init(const byte* bytes, uint32 length)
|
|||||||
_length = length;
|
_length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* MemoryReadStream::Move(uint32 bytes)
|
||||||
|
{
|
||||||
|
ASSERT(GetLength() - GetPosition() >= bytes);
|
||||||
|
const auto result = (void*)_position;
|
||||||
|
_position += bytes;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryReadStream::Flush()
|
void MemoryReadStream::Flush()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ReadStream.h"
|
#include "ReadStream.h"
|
||||||
#include "Engine/Platform/Platform.h"
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Direct memory reading stream that uses a single allocation buffer.
|
/// Direct memory reading stream that uses a single allocation buffer.
|
||||||
@@ -47,7 +46,7 @@ public:
|
|||||||
/// <param name="data">Span with data to read from.</param>
|
/// <param name="data">Span with data to read from.</param>
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MemoryReadStream(const Span<T>& data)
|
MemoryReadStream(const Span<T>& data)
|
||||||
: MemoryReadStream(data.Get(), data.Count() * sizeof(T))
|
: MemoryReadStream(data.Get(), data.Length() * sizeof(T))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,13 +82,7 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes">The amount of bytes to read.</param>
|
/// <param name="bytes">The amount of bytes to read.</param>
|
||||||
/// <returns>The pointer to the data in memory.</returns>
|
/// <returns>The pointer to the data in memory.</returns>
|
||||||
void* Move(uint32 bytes)
|
void* Move(uint32 bytes);
|
||||||
{
|
|
||||||
ASSERT(GetLength() - GetPosition() >= bytes);
|
|
||||||
const auto result = (void*)_position;
|
|
||||||
_position += bytes;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward.
|
/// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WriteStream.h"
|
#include "WriteStream.h"
|
||||||
|
#include "Engine/Core/Types/Span.h"
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Direct memory writing stream that uses a single allocation buffer.
|
/// Direct memory writing stream that uses a single allocation buffer.
|
||||||
@@ -115,3 +116,8 @@ public:
|
|||||||
void SetPosition(uint32 seek) override;
|
void SetPosition(uint32 seek) override;
|
||||||
void WriteBytes(const void* data, uint32 bytes) override;
|
void WriteBytes(const void* data, uint32 bytes) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Span<byte> ToSpan(MemoryWriteStream& stream)
|
||||||
|
{
|
||||||
|
return Span<byte>(stream.GetHandle(), (int32)stream.GetPosition());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user