diff --git a/Source/Engine/CSG/CSGBuilder.cpp b/Source/Engine/CSG/CSGBuilder.cpp index fa8ce6291..323c93480 100644 --- a/Source/Engine/CSG/CSGBuilder.cpp +++ b/Source/Engine/CSG/CSGBuilder.cpp @@ -433,7 +433,7 @@ bool CSGBuilderImpl::generateRawDataAsset(Scene* scene, RawData& meshData, Guid& // Serialize BytesContainer bytesContainer; - bytesContainer.Link(stream.GetHandle(), stream.GetPosition()); + bytesContainer.Link(ToSpan(stream)); return AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer); } diff --git a/Source/Engine/Content/Assets/Animation.cpp b/Source/Engine/Content/Assets/Animation.cpp index 8d4a03abb..af534d22a 100644 --- a/Source/Engine/Content/Assets/Animation.cpp +++ b/Source/Engine/Content/Assets/Animation.cpp @@ -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) @@ -476,7 +476,7 @@ bool Animation::Save(const StringView& path) // Set data to the chunk asset auto chunk0 = GetOrCreateChunk(0); ASSERT(chunk0 != nullptr); - chunk0->Data.Copy(stream.GetHandle(), stream.GetPosition()); + chunk0->Data.Copy(ToSpan(stream)); } // Save diff --git a/Source/Engine/Content/Assets/AnimationGraph.cpp b/Source/Engine/Content/Assets/AnimationGraph.cpp index f5d3a8073..8a8570435 100644 --- a/Source/Engine/Content/Assets/AnimationGraph.cpp +++ b/Source/Engine/Content/Assets/AnimationGraph.cpp @@ -123,7 +123,7 @@ bool AnimationGraph::InitAsAnimation(SkinnedModel* baseModel, Animation* anim, b // Load Graph data (with initialization) ScopeLock lock(Locker); - MemoryReadStream readStream(writeStream.GetHandle(), writeStream.GetPosition()); + MemoryReadStream readStream(ToSpan(writeStream)); return Graph.Load(&readStream, USE_EDITOR); } @@ -140,7 +140,7 @@ BytesContainer AnimationGraph::LoadSurface() if (!Graph.Save(&stream, USE_EDITOR)) { BytesContainer result; - result.Copy(stream.GetHandle(), stream.GetPosition()); + result.Copy(ToSpan(stream)); return result; } } diff --git a/Source/Engine/Content/Assets/Material.cpp b/Source/Engine/Content/Assets/Material.cpp index 3c2330c93..9b0f537af 100644 --- a/Source/Engine/Content/Assets/Material.cpp +++ b/Source/Engine/Content/Assets/Material.cpp @@ -229,7 +229,7 @@ Asset::LoadResult Material::load() // Save layer to the chunk data MemoryWriteStream stream(512); layer->Graph.Save(&stream, false); - surfaceChunk->Data.Copy(stream.GetHandle(), stream.GetPosition()); + surfaceChunk->Data.Copy(ToSpan(stream)); } generator.AddLayer(layer); @@ -542,7 +542,7 @@ BytesContainer Material::LoadSurface(bool createDefaultIfMissing) layer->Graph.Save(&stream, false); // Set output data - result.Copy(stream.GetHandle(), stream.GetPosition()); + result.Copy(ToSpan(stream)); return result; } diff --git a/Source/Engine/Content/Assets/MaterialInstance.cpp b/Source/Engine/Content/Assets/MaterialInstance.cpp index 13d46db09..28bbf8a8c 100644 --- a/Source/Engine/Content/Assets/MaterialInstance.cpp +++ b/Source/Engine/Content/Assets/MaterialInstance.cpp @@ -334,7 +334,7 @@ bool MaterialInstance::Save(const StringView& path) // Save parameters Params.Save(&stream); } - SetChunk(0, ToSpan(stream.GetHandle(), stream.GetPosition())); + SetChunk(0, ToSpan(stream)); // Setup asset data AssetInitData data; diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp index 01adbd207..915066fc2 100644 --- a/Source/Engine/Content/Assets/Model.cpp +++ b/Source/Engine/Content/Assets/Model.cpp @@ -279,7 +279,7 @@ bool Model::GenerateSDF(float resolutionScale, int32 lodIndex, bool cacheData, f if (cacheData) { 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 } #endif @@ -484,7 +484,7 @@ bool Model::Save(bool withMeshDataFromGpu, Function& getChunk sdfStream.WriteBytes(&mipData, sizeof(mipData)); sdfStream.WriteBytes(mip.Data.Get(), mip.Data.Length()); } - sdfChunk->Data.Copy(sdfStream.GetHandle(), sdfStream.GetPosition()); + sdfChunk->Data.Copy(ToSpan(sdfStream)); } } else diff --git a/Source/Engine/Content/Assets/ModelBase.cpp b/Source/Engine/Content/Assets/ModelBase.cpp index 9aa2aed6a..b194d9861 100644 --- a/Source/Engine/Content/Assets/ModelBase.cpp +++ b/Source/Engine/Content/Assets/ModelBase.cpp @@ -265,7 +265,7 @@ bool ModelBase::Save(bool withMeshDataFromGpu, const StringView& path) auto lodChunk = getChunk(MODEL_LOD_TO_CHUNK_INDEX(lodIndex)); if (lodChunk == nullptr) return true; - lodChunk->Data.Copy(meshesStream.GetHandle(), meshesStream.GetPosition()); + lodChunk->Data.Copy(ToSpan(meshesStream)); } } else if (!IsVirtual()) @@ -289,7 +289,7 @@ bool ModelBase::Save(bool withMeshDataFromGpu, const StringView& path) return true; auto headerChunk = getChunk(0); ASSERT(headerChunk != nullptr); - headerChunk->Data.Copy(headerStream.GetHandle(), headerStream.GetPosition()); + headerChunk->Data.Copy(ToSpan(headerStream)); } // Save file diff --git a/Source/Engine/Content/Assets/SkeletonMask.cpp b/Source/Engine/Content/Assets/SkeletonMask.cpp index 260e8ddf0..48fd71678 100644 --- a/Source/Engine/Content/Assets/SkeletonMask.cpp +++ b/Source/Engine/Content/Assets/SkeletonMask.cpp @@ -98,7 +98,7 @@ bool SkeletonMask::Save(const StringView& path) Platform::MemoryClear(tmpChunks, sizeof(tmpChunks)); FlaxChunk chunk; tmpChunks[0] = &chunk; - tmpChunks[0]->Data.Link(stream.GetHandle(), stream.GetPosition()); + tmpChunks[0]->Data.Link(ToSpan(stream)); AssetInitData initData; initData.SerializedVersion = SerializedVersion; @@ -109,7 +109,7 @@ bool SkeletonMask::Save(const StringView& path) else { auto chunk0 = GetChunk(0); - chunk0->Data.Copy(stream.GetHandle(), stream.GetPosition()); + chunk0->Data.Copy(ToSpan(stream)); AssetInitData initData; initData.SerializedVersion = SerializedVersion; diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index 1cba4a709..c8b0fbf7e 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -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 MemoryWriteStream writeStream; writeStream.Write(param); - MemoryReadStream readStream(writeStream.GetHandle(), writeStream.GetPosition()); + MemoryReadStream readStream(ToSpan(writeStream)); readStream.Read(param); } } @@ -2231,7 +2231,7 @@ bool VisualScript::SaveSurface(const BytesContainer& data, const Metadata& meta) metaStream.Write(meta.BaseTypename, 31); metaStream.Write((int32)meta.Flags); } - GetOrCreateChunk(1)->Data.Copy(metaStream.GetHandle(), metaStream.GetPosition()); + GetOrCreateChunk(1)->Data.Copy(ToSpan(metaStream)); // Save AssetInitData assetData; diff --git a/Source/Engine/ContentImporters/CreateAnimation.h b/Source/Engine/ContentImporters/CreateAnimation.h index dd6db2caf..8749fe98d 100644 --- a/Source/Engine/ContentImporters/CreateAnimation.h +++ b/Source/Engine/ContentImporters/CreateAnimation.h @@ -43,7 +43,7 @@ public: // Copy to asset chunk if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/CreateAnimationGraph.cpp b/Source/Engine/ContentImporters/CreateAnimationGraph.cpp index 77cb22560..da4995eca 100644 --- a/Source/Engine/ContentImporters/CreateAnimationGraph.cpp +++ b/Source/Engine/ContentImporters/CreateAnimationGraph.cpp @@ -40,7 +40,7 @@ CreateAssetResult CreateAnimationGraph::Create(CreateAssetContext& context) // Copy to asset chunk if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/CreateAnimationGraphFunction.h b/Source/Engine/ContentImporters/CreateAnimationGraphFunction.h index 1d212f0f4..f4e6b0871 100644 --- a/Source/Engine/ContentImporters/CreateAnimationGraphFunction.h +++ b/Source/Engine/ContentImporters/CreateAnimationGraphFunction.h @@ -44,7 +44,7 @@ public: return CreateAssetResult::Error; if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/CreateBehaviorTree.h b/Source/Engine/ContentImporters/CreateBehaviorTree.h index e1c77228c..1665b6726 100644 --- a/Source/Engine/ContentImporters/CreateBehaviorTree.h +++ b/Source/Engine/ContentImporters/CreateBehaviorTree.h @@ -26,7 +26,7 @@ public: const BehaviorTreeGraph graph; MemoryWriteStream stream(64); 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; diff --git a/Source/Engine/ContentImporters/CreateMaterial.cpp b/Source/Engine/ContentImporters/CreateMaterial.cpp index 96cfe6ce2..c0f89a5c8 100644 --- a/Source/Engine/ContentImporters/CreateMaterial.cpp +++ b/Source/Engine/ContentImporters/CreateMaterial.cpp @@ -191,7 +191,7 @@ CreateAssetResult CreateMaterial::Create(CreateAssetContext& context) MemoryWriteStream stream(512); 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); } else diff --git a/Source/Engine/ContentImporters/CreateMaterialFunction.h b/Source/Engine/ContentImporters/CreateMaterialFunction.h index 2bd34aeda..b9f531b54 100644 --- a/Source/Engine/ContentImporters/CreateMaterialFunction.h +++ b/Source/Engine/ContentImporters/CreateMaterialFunction.h @@ -45,7 +45,7 @@ public: return CreateAssetResult::Error; if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/CreateMaterialInstance.h b/Source/Engine/ContentImporters/CreateMaterialInstance.h index f0ef2f197..8e612e8d2 100644 --- a/Source/Engine/ContentImporters/CreateMaterialInstance.h +++ b/Source/Engine/ContentImporters/CreateMaterialInstance.h @@ -32,7 +32,7 @@ public: MemoryWriteStream stream(256); stream.Write(Guid::Empty); 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; } diff --git a/Source/Engine/ContentImporters/CreateParticleEmitter.h b/Source/Engine/ContentImporters/CreateParticleEmitter.h index e935c8b30..1bc219cb4 100644 --- a/Source/Engine/ContentImporters/CreateParticleEmitter.h +++ b/Source/Engine/ContentImporters/CreateParticleEmitter.h @@ -37,7 +37,7 @@ public: graph.CreateDefault(); MemoryWriteStream stream(512); 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; } diff --git a/Source/Engine/ContentImporters/CreateParticleEmitterFunction.h b/Source/Engine/ContentImporters/CreateParticleEmitterFunction.h index 4b5de35dc..9d3bc6a14 100644 --- a/Source/Engine/ContentImporters/CreateParticleEmitterFunction.h +++ b/Source/Engine/ContentImporters/CreateParticleEmitterFunction.h @@ -44,7 +44,7 @@ public: return CreateAssetResult::Error; if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/CreateParticleSystem.h b/Source/Engine/ContentImporters/CreateParticleSystem.h index da55d42ed..ed3a9b9c9 100644 --- a/Source/Engine/ContentImporters/CreateParticleSystem.h +++ b/Source/Engine/ContentImporters/CreateParticleSystem.h @@ -35,7 +35,7 @@ public: stream.WriteInt32(0); // Emitters 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; } diff --git a/Source/Engine/ContentImporters/CreateSceneAnimation.h b/Source/Engine/ContentImporters/CreateSceneAnimation.h index 222924cad..fa6ae03cd 100644 --- a/Source/Engine/ContentImporters/CreateSceneAnimation.h +++ b/Source/Engine/ContentImporters/CreateSceneAnimation.h @@ -34,7 +34,7 @@ public: stream.WriteInt32(5 * 60); // DurationFrames 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; } diff --git a/Source/Engine/ContentImporters/CreateVisualScript.h b/Source/Engine/ContentImporters/CreateVisualScript.h index 5d5378f3d..729fb06d2 100644 --- a/Source/Engine/ContentImporters/CreateVisualScript.h +++ b/Source/Engine/ContentImporters/CreateVisualScript.h @@ -33,7 +33,7 @@ public: const VisualScriptGraph graph; MemoryWriteStream stream(64); 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 @@ -44,7 +44,7 @@ public: stream.Write(1); stream.Write(*baseTypename, 31); 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; diff --git a/Source/Engine/ContentImporters/ImportModel.cpp b/Source/Engine/ContentImporters/ImportModel.cpp index 3d93842c7..888cc303e 100644 --- a/Source/Engine/ContentImporters/ImportModel.cpp +++ b/Source/Engine/ContentImporters/ImportModel.cpp @@ -554,7 +554,7 @@ CreateAssetResult ImportModel::CreateModel(CreateAssetContext& context, const Mo return CreateAssetResult::Error; if (context.AllocateChunk(0)) 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 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); if (context.AllocateChunk(chunkIndex)) 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 @@ -577,7 +577,7 @@ CreateAssetResult ImportModel::CreateModel(CreateAssetContext& context, const Mo { if (context.AllocateChunk(15)) 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; if (context.AllocateChunk(0)) 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 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); if (context.AllocateChunk(chunkIndex)) 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; @@ -637,7 +637,7 @@ CreateAssetResult ImportModel::CreateAnimation(CreateAssetContext& context, cons return CreateAssetResult::Error; if (context.AllocateChunk(0)) 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; } diff --git a/Source/Engine/ContentImporters/ImportTexture.cpp b/Source/Engine/ContentImporters/ImportTexture.cpp index 03a221b76..eca5e546f 100644 --- a/Source/Engine/ContentImporters/ImportTexture.cpp +++ b/Source/Engine/ContentImporters/ImportTexture.cpp @@ -178,7 +178,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu } if (context.AllocateChunk(15)) 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 @@ -317,7 +317,7 @@ CreateAssetResult ImportTexture::Create(CreateAssetContext& context, const Textu } if (context.AllocateChunk(15)) 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 diff --git a/Source/Engine/Engine/GameplayGlobals.cpp b/Source/Engine/Engine/GameplayGlobals.cpp index d5f6fae65..d6b9548d7 100644 --- a/Source/Engine/Engine/GameplayGlobals.cpp +++ b/Source/Engine/Engine/GameplayGlobals.cpp @@ -187,7 +187,7 @@ bool GameplayGlobals::Save(const StringView& path) { chunk = GetOrCreateChunk(0); } - chunk->Data.Copy(stream.GetHandle(), stream.GetPosition()); + chunk->Data.Copy(ToSpan(stream)); // Save AssetInitData data; diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp index 2869eacd9..8fd1131d1 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp @@ -292,7 +292,7 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result) auto cacheChunk = parent->GetOrCreateChunk(cacheChunkIndex); if (cacheChunk == nullptr) return true; - cacheChunk->Data.Copy(cacheStream.GetHandle(), cacheStream.GetPosition()); + cacheChunk->Data.Copy(ToSpan(cacheStream)); #if USE_EDITOR // Save chunks to the asset file @@ -317,7 +317,7 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result) else { // 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); return false; } diff --git a/Source/Engine/Navigation/NavMesh.cpp b/Source/Engine/Navigation/NavMesh.cpp index 5b5220898..7eb2b468a 100644 --- a/Source/Engine/Navigation/NavMesh.cpp +++ b/Source/Engine/Navigation/NavMesh.cpp @@ -56,7 +56,7 @@ void NavMesh::SaveNavMesh() MemoryWriteStream stream(streamInitialCapacity); Data.Save(stream); BytesContainer bytesContainer; - bytesContainer.Link(stream.GetHandle(), stream.GetPosition()); + bytesContainer.Link(ToSpan(stream)); // Save asset to file if (AssetsImportingManager::Create(AssetsImportingManager::CreateRawDataTag, assetPath, assetId, (void*)&bytesContainer)) diff --git a/Source/Engine/Particles/ParticleEmitter.cpp b/Source/Engine/Particles/ParticleEmitter.cpp index 570b026c6..8e9533474 100644 --- a/Source/Engine/Particles/ParticleEmitter.cpp +++ b/Source/Engine/Particles/ParticleEmitter.cpp @@ -369,7 +369,7 @@ BytesContainer ParticleEmitter::LoadSurface(bool createDefaultIfMissing) graph.Save(&stream, false); // Set output data - result.Copy(stream.GetHandle(), stream.GetPosition()); + result.Copy(ToSpan(stream)); } return result; diff --git a/Source/Engine/Serialization/MemoryReadStream.cpp b/Source/Engine/Serialization/MemoryReadStream.cpp index 17458a52c..167808a69 100644 --- a/Source/Engine/Serialization/MemoryReadStream.cpp +++ b/Source/Engine/Serialization/MemoryReadStream.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #include "MemoryReadStream.h" +#include "Engine/Platform/Platform.h" MemoryReadStream::MemoryReadStream() : _buffer(nullptr) @@ -22,6 +23,14 @@ void MemoryReadStream::Init(const byte* bytes, uint32 length) _length = length; } +void* MemoryReadStream::Move(uint32 bytes) +{ + ASSERT(GetLength() - GetPosition() >= bytes); + const auto result = (void*)_position; + _position += bytes; + return result; +} + void MemoryReadStream::Flush() { } diff --git a/Source/Engine/Serialization/MemoryReadStream.h b/Source/Engine/Serialization/MemoryReadStream.h index 3db90f1a6..8e7f1315c 100644 --- a/Source/Engine/Serialization/MemoryReadStream.h +++ b/Source/Engine/Serialization/MemoryReadStream.h @@ -3,7 +3,6 @@ #pragma once #include "ReadStream.h" -#include "Engine/Platform/Platform.h" /// /// Direct memory reading stream that uses a single allocation buffer. @@ -47,7 +46,7 @@ public: /// Span with data to read from. template MemoryReadStream(const Span& data) - : MemoryReadStream(data.Get(), data.Count() * sizeof(T)) + : MemoryReadStream(data.Get(), data.Length() * sizeof(T)) { } @@ -83,13 +82,7 @@ public: /// /// The amount of bytes to read. /// The pointer to the data in memory. - void* Move(uint32 bytes) - { - ASSERT(GetLength() - GetPosition() >= bytes); - const auto result = (void*)_position; - _position += bytes; - return result; - } + void* Move(uint32 bytes); /// /// Skips the data from the target buffer without reading from it. Moves the read pointer in the buffer forward. diff --git a/Source/Engine/Serialization/MemoryWriteStream.h b/Source/Engine/Serialization/MemoryWriteStream.h index 6b181d3b0..4144783ad 100644 --- a/Source/Engine/Serialization/MemoryWriteStream.h +++ b/Source/Engine/Serialization/MemoryWriteStream.h @@ -3,6 +3,7 @@ #pragma once #include "WriteStream.h" +#include "Engine/Core/Types/Span.h" /// /// Direct memory writing stream that uses a single allocation buffer. @@ -115,3 +116,8 @@ public: void SetPosition(uint32 seek) override; void WriteBytes(const void* data, uint32 bytes) override; }; + +inline Span ToSpan(MemoryWriteStream& stream) +{ + return Span(stream.GetHandle(), (int32)stream.GetPosition()); +}