diff --git a/sources/assets/Stride.Core.Assets.CompilerApp/BundlePacker.cs b/sources/assets/Stride.Core.Assets.CompilerApp/BundlePacker.cs index 2df7ccc67..885a4f7e3 100644 --- a/sources/assets/Stride.Core.Assets.CompilerApp/BundlePacker.cs +++ b/sources/assets/Stride.Core.Assets.CompilerApp/BundlePacker.cs @@ -313,7 +313,7 @@ namespace Stride.Core.Assets.CompilerApp if (header.OffsetToReferences != -1) { // Seek to where references are stored and deserialize them - streamReader.NativeStream.Seek(header.OffsetToReferences, SeekOrigin.Begin); + streamReader.UnderlyingStream.Seek(header.OffsetToReferences, SeekOrigin.Begin); List chunkReferences = null; streamReader.Serialize(ref chunkReferences, ArchiveMode.Deserialize); diff --git a/sources/buildengine/Stride.Core.BuildEngine.Common/Command.cs b/sources/buildengine/Stride.Core.BuildEngine.Common/Command.cs index d7859a058..c9b0c9275 100644 --- a/sources/buildengine/Stride.Core.BuildEngine.Common/Command.cs +++ b/sources/buildengine/Stride.Core.BuildEngine.Common/Command.cs @@ -147,11 +147,11 @@ namespace Stride.Core.BuildEngine var hash = prepareContext.ComputeInputHash(inputFile.Type, inputFile.Path); if (hash == ObjectId.Empty) { - writer.NativeStream.WriteByte(0); + writer.UnderlyingStream.WriteByte(0); } else { - writer.NativeStream.Write((byte[])hash, 0, ObjectId.HashSize); + writer.UnderlyingStream.Write((byte[])hash, 0, ObjectId.HashSize); } } } diff --git a/sources/core/Stride.Core.Design.Tests/TestShadowObject.cs b/sources/core/Stride.Core.Design.Tests/TestShadowObject.cs index d0011c4d8..0f67681a3 100644 --- a/sources/core/Stride.Core.Design.Tests/TestShadowObject.cs +++ b/sources/core/Stride.Core.Design.Tests/TestShadowObject.cs @@ -1,10 +1,8 @@ // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; using Xunit; using Stride.Core.Reflection; -using System.Collections.Generic; namespace Stride.Core.Design.Tests { @@ -25,32 +23,5 @@ namespace Stride.Core.Design.Tests var shadowObject2 = ShadowObject.GetOrCreate(obj); Assert.Equal(shadowObject, shadowObject2); } - - // IdentifierHelper is now obsolete - //[Fact] - //public void TestIdentifierHelper() - //{ - // // Has IdentifierHelper is using ShadowObject, we will test it here - // ShadowObject.Enable = true; - // var obj = new object(); - - // var id = IdentifiableHelper.GetId(obj); - // Assert.NotEqual(Guid.Empty, id); - - // var id1 = IdentifiableHelper.GetId(obj); - // Assert.Equal(id, id1); - - // // We should not get an id for a collection - // var idCollection = IdentifiableHelper.GetId(new List()); - // Assert.Equal(Guid.Empty, idCollection); - - // // We should not get an id for a dictionary - // var idDict = IdentifiableHelper.GetId(new MyDictionary()); - // Assert.Equal(Guid.Empty, idDict); - //} - - private class MyDictionary : Dictionary - { - } } } diff --git a/sources/core/Stride.Core.Mathematics/Matrix.cs b/sources/core/Stride.Core.Mathematics/Matrix.cs index c044971f6..2d47faac7 100644 --- a/sources/core/Stride.Core.Mathematics/Matrix.cs +++ b/sources/core/Stride.Core.Mathematics/Matrix.cs @@ -1007,35 +1007,6 @@ namespace Stride.Core.Mathematics return result; } - /// - /// Determines the product of two matrices. - /// Variables passed as or must not be used as the out parameter - /// , because is calculated in-place. - /// - /// The first matrix to multiply. - /// The second matrix to multiply. - /// The product of the two matrices. - [Obsolete($"Use {nameof(Multiply)} instead, this signature will be removed")] - public static void MultiplyTo(ref Matrix left, ref Matrix right, out Matrix result) - { - result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); - result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); - result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); - result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); - result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); - result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); - result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); - result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); - result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); - result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); - result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); - result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); - result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); - result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); - result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); - result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); - } - /// /// Determines the product of two matrices. /// Variables passed as or must not be used as the out parameter @@ -1068,20 +1039,6 @@ namespace Stride.Core.Mathematics UnsafeRefAsDotNet(in result) = LayoutIsRowMajor ? l * r : r * l; } - /// - /// Determines the product of two matrices. - /// Variables passed as or must not be used as the out parameter - /// , because is calculated in-place. - /// - /// The first matrix to multiply. - /// The second matrix to multiply. - /// The product of the two matrices. - [Obsolete($"Use {nameof(Multiply)} instead")] - public static void MultiplyRef(ref Matrix left, ref Matrix right, ref Matrix result) - { - Multiply(ref left, ref right, out result); - } - /// /// Determines the product of two matrices, equivalent to the '*' operator. /// diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs index 46c1d02df..88d516b3c 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/CollectionDescriptor.cs @@ -24,7 +24,28 @@ namespace Stride.Core.Reflection /// true if the specified type is collection; otherwise, false. public static bool IsCollection(Type type) { - return TypeHelper.IsCollection(type); + if (type == null) throw new ArgumentNullException(nameof(type)); + var typeInfo = type.GetTypeInfo(); + if (typeInfo.IsArray) + { + return false; + } + + if (typeof(IList).GetTypeInfo().IsAssignableFrom(typeInfo)) + { + return true; + } + + foreach (var iType in typeInfo.ImplementedInterfaces) + { + var iTypeInfo = iType.GetTypeInfo(); + if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(ICollection<>)) + { + return true; + } + } + + return false; } /// diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/DictionaryDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/DictionaryDescriptor.cs index db50f5fa5..9d456965e 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/DictionaryDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/DictionaryDescriptor.cs @@ -272,7 +272,23 @@ namespace Stride.Core.Reflection /// true if the specified type is dictionary; otherwise, false. public static bool IsDictionary(Type type) { - return TypeHelper.IsDictionary(type); + if (type == null) throw new ArgumentNullException(nameof(type)); + var typeInfo = type.GetTypeInfo(); + if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(typeInfo)) + { + return true; + } + + foreach (var iType in typeInfo.ImplementedInterfaces) + { + var iTypeInfo = iType.GetTypeInfo(); + if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(IDictionary<,>)) + { + return true; + } + } + + return false; } public static IEnumerable> GetGenericEnumerable(IDictionary dictionary) diff --git a/sources/core/Stride.Core.Serialization/Serialization/Contents/ChunkHeader.cs b/sources/core/Stride.Core.Serialization/Serialization/Contents/ChunkHeader.cs index 963d414ff..d717b1421 100644 --- a/sources/core/Stride.Core.Serialization/Serialization/Contents/ChunkHeader.cs +++ b/sources/core/Stride.Core.Serialization/Serialization/Contents/ChunkHeader.cs @@ -50,7 +50,7 @@ namespace Stride.Core.Serialization.Contents if (magic != Magic) { // Rewind - stream.NativeStream.Seek(-4, SeekOrigin.Current); + stream.UnderlyingStream.Seek(-4, SeekOrigin.Current); return null; } diff --git a/sources/core/Stride.Core.Serialization/Serialization/Contents/ContentManager.cs b/sources/core/Stride.Core.Serialization/Serialization/Contents/ContentManager.cs index 6b5182e2d..c09318039 100644 --- a/sources/core/Stride.Core.Serialization/Serialization/Contents/ContentManager.cs +++ b/sources/core/Stride.Core.Serialization/Serialization/Contents/ContentManager.cs @@ -518,9 +518,9 @@ namespace Stride.Core.Serialization.Contents if (chunkHeader != null && chunkHeader.OffsetToReferences != -1) { // Seek to where references are stored and deserialize them - streamReader.NativeStream.Seek(chunkHeader.OffsetToReferences, SeekOrigin.Begin); + streamReader.UnderlyingStream.Seek(chunkHeader.OffsetToReferences, SeekOrigin.Begin); contentSerializerContext.SerializeReferences(streamReader); - streamReader.NativeStream.Seek(chunkHeader.OffsetToObject, SeekOrigin.Begin); + streamReader.UnderlyingStream.Seek(chunkHeader.OffsetToObject, SeekOrigin.Begin); } if (reference == null) @@ -631,7 +631,7 @@ namespace Stride.Core.Serialization.Contents { header = new ChunkHeader { Type = serializer.SerializationType.AssemblyQualifiedName }; header.Write(streamWriter); - header.OffsetToObject = (int)streamWriter.NativeStream.Position; + header.OffsetToObject = (int)streamWriter.UnderlyingStream.Position; } contentSerializerContext.SerializeContent(streamWriter, serializer, obj); @@ -639,7 +639,7 @@ namespace Stride.Core.Serialization.Contents // Write references and updated header if (header != null) { - header.OffsetToReferences = (int)streamWriter.NativeStream.Position; + header.OffsetToReferences = (int)streamWriter.UnderlyingStream.Position; contentSerializerContext.SerializeReferences(streamWriter); // Move back to the pre-allocated header position in the steam diff --git a/sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs b/sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs index 6d593d298..d9dc3f498 100644 --- a/sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs +++ b/sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs @@ -47,42 +47,6 @@ namespace Stride.Core.Annotations LargeStep = largeStep; } - /// - /// Initializes a new instance of the class. - /// - /// The minimum. - /// The maximum. - [Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")] - public DataMemberRangeAttribute(double minimum, double maximum) - : this(minimum, maximum, 1, 2, 3) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The minimum. - /// The maximum. - /// The decimal places - [Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")] - public DataMemberRangeAttribute(double minimum, double maximum, int decimalPlaces) - : this(minimum, maximum, 1, 2, decimalPlaces) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The minimum. - /// The maximum. - /// The minimum step used to go from minimum to maximum. - /// The maximum step. - [Obsolete("This method will be removed in a future release. Use DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces) instead")] - public DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep) - : this(minimum, maximum, smallStep, largeStep, 3) - { - } - /// /// Gets the minimum inclusive. /// diff --git a/sources/core/Stride.Core/Collections/ArrayHelper.cs b/sources/core/Stride.Core/Collections/ArrayHelper.cs deleted file mode 100644 index 1d76170dc..000000000 --- a/sources/core/Stride.Core/Collections/ArrayHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; - -namespace Stride.Core.Collections -{ - /// - /// Array helper for a particular type, useful to get an empty array. - /// - /// Type of the array element - [Obsolete("This method is deprecated and may be removed in future versions. Please use Array.Empty() instead. See https://docs.microsoft.com/en-us/dotnet/api/system.array.empty?view=net-5.0 for details.")] - public struct ArrayHelper - { - /// - /// An empty array of the specified element type. - /// - public static readonly T[] Empty = Array.Empty(); - } -} diff --git a/sources/core/Stride.Core/IL/RemoveInitLocalsAttribute.cs b/sources/core/Stride.Core/IL/RemoveInitLocalsAttribute.cs deleted file mode 100644 index 0efc33e49..000000000 --- a/sources/core/Stride.Core/IL/RemoveInitLocalsAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; - -namespace Stride.Core.IL -{ - /// - /// Using this optimization attribute will prevent local variables in this method to be zero-ed in the prologue (if the runtime supports it). - /// - [AttributeUsage(AttributeTargets.Method), Obsolete("Use System.Runtime.CompilerServices.SkipLocalsInitAttribute")] - public class RemoveInitLocalsAttribute : Attribute - { - } -} diff --git a/sources/core/Stride.Core/IO/NativeMemoryStream.cs b/sources/core/Stride.Core/IO/NativeMemoryStream.cs deleted file mode 100644 index d49dd74f8..000000000 --- a/sources/core/Stride.Core/IO/NativeMemoryStream.cs +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.CompilerServices; - -namespace Stride.Core.IO -{ - /// - /// A over a native memory region. - /// - [Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")] - public unsafe class NativeMemoryStream : Stream - { - private readonly byte* dataStart; - private readonly byte* dataEnd; - private byte* dataCurrent; - - /// - /// Initializes a new instance of the class. - /// - /// The native data pointer. - /// The data length. - [Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")] - public NativeMemoryStream(IntPtr data, long length) - : this((byte*)data, length) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The native data pointer. - /// The data length. - [Obsolete("Consider using MemoryStream or UnmanagedMemoryStream.")] - public NativeMemoryStream(byte* data, long length) - { - this.dataStart = data; - this.dataCurrent = data; - this.dataEnd = data + length; - } - - /// - public override void Flush() - { - } - - /// - public override long Seek(long offset, SeekOrigin origin) - { - switch (origin) - { - case SeekOrigin.Begin: - dataCurrent = dataStart + offset; - break; - case SeekOrigin.Current: - dataCurrent += offset; - break; - case SeekOrigin.End: - dataCurrent = dataEnd + offset; - break; - default: - throw new ArgumentOutOfRangeException(nameof(origin)); - } - return dataCurrent - dataStart; - } - - /// - public override void SetLength(long value) - { - throw new NotSupportedException("Length can't be changed."); - } - - /// - public override int Read(Span buffer) - { - Debug.Assert(dataEnd >= dataCurrent); - var read = (nint)(dataEnd - dataCurrent); - if (read > buffer.Length) read = buffer.Length; - var src = new Span(dataCurrent, (int)read); - src.CopyTo(buffer); - dataCurrent += read; - return (int)read; - } - - /// - public override unsafe int Read(byte[] buffer, int offset, int count) - { - Debug.Assert( - (offset | count) >= 0 && - (uint)offset + (uint)count <= (uint)buffer.Length); - var bytesLeft = (int)(dataEnd - dataCurrent); - if (count > bytesLeft) - count = bytesLeft; - fixed (byte* pinned = &buffer[0]) - Unsafe.CopyBlockUnaligned(pinned + offset, dataCurrent, (uint)count); - dataCurrent += count; - return count; - } - - /// - /// The remaining capacity in the stream - /// is not large enough to write the specified . - public override void Write(ReadOnlySpan buffer) - { - Debug.Assert(dataEnd >= dataCurrent); - var written = (nint)(dataEnd - dataCurrent); - if (written < buffer.Length) - throw new IOException("Can't write beyond end of stream."); - else - written = buffer.Length; - var dst = new Span(dataCurrent, (int)written); - buffer.CopyTo(dst); - dataCurrent += written; - } - - /// - /// The remaining capacity in the stream - /// is not large enough to write the specified . - public override void Write(byte[] buffer, int offset, int count) - { - Debug.Assert( - (offset | count) >= 0 && - (uint)offset + (uint)count <= (uint)buffer.Length); - var bytesLeft = (int)(dataEnd - dataCurrent); - if (count > bytesLeft) - throw new IOException("Can't write beyond end of stream."); - - fixed (byte* pinned = &buffer[0]) - Unsafe.CopyBlockUnaligned(dataCurrent, pinned + offset, (uint)count); - dataCurrent += count; - } - - /// - public override int ReadByte() - { - if (dataCurrent >= dataEnd) - return -1; - - return *dataCurrent++; - } - - /// - /// The remaining capacity in the stream - /// is not large enough to write the specified . - public override void WriteByte(byte value) - { - if (dataCurrent >= dataEnd) - throw new IOException("Cannot write beyond end of stream."); - - *dataCurrent++ = value; - } - - /// - public override bool CanRead => true; - - /// - public override bool CanSeek => true; - - /// - public override bool CanWrite => true; - - /// - public override long Length => dataEnd - dataStart; - - /// - public override long Position - { - get => dataCurrent - dataStart; - set => dataCurrent = dataStart + value; - } - } -} diff --git a/sources/core/Stride.Core/IO/NativeStream.cs b/sources/core/Stride.Core/IO/NativeStream.cs index 18b0c1d08..ba9b13bcf 100644 --- a/sources/core/Stride.Core/IO/NativeStream.cs +++ b/sources/core/Stride.Core/IO/NativeStream.cs @@ -108,68 +108,5 @@ namespace Stride.Core.IO Write(temporaryBuffer, 0, sizeof(ulong)); } - - /// - /// Reads a block of bytes from the stream and writes the data in a given buffer. - /// - /// When this method returns, contains the specified buffer with the values between 0 and (count - 1) replaced by the bytes read from the current source. - /// The maximum number of bytes to read. - /// array is null. - /// The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached. - [Obsolete("Use Stream.Read(Span).")] - public virtual unsafe int Read(nint buffer, int count) - { - var temporaryBuffer = nativeStreamBuffer; - if (temporaryBuffer == null) - temporaryBuffer = nativeStreamBuffer = new byte[NativeStreamBufferSize]; - - var readSize = 0; - fixed (byte* temporaryBufferStart = temporaryBuffer) { - for (var offset = 0; offset < count; offset += NativeStreamBufferSize, buffer += NativeStreamBufferSize) - { - // Compute missing bytes in this block - var blockSize = count - offset; - if (blockSize > NativeStreamBufferSize) - blockSize = NativeStreamBufferSize; - - var currentReadSize = Read(temporaryBuffer, 0, blockSize); - readSize += currentReadSize; - Unsafe.CopyBlockUnaligned((void*)buffer, temporaryBufferStart, (uint)currentReadSize); - - // Reached end of stream? - if (currentReadSize < blockSize) - break; - } - } - - return readSize; - } - - /// - /// Writes a block of bytes to this stream using data from a buffer. - /// - /// The buffer containing data to write to the stream. - /// The number of bytes to be written to the current stream. - [Obsolete("Use Stream.Write(ReadOnlySpan).")] - public virtual unsafe void Write(nint buffer, int count) - { - var temporaryBuffer = nativeStreamBuffer; - if (temporaryBuffer == null) - temporaryBuffer = nativeStreamBuffer = new byte[NativeStreamBufferSize]; - - fixed (byte* temporaryBufferStart = temporaryBuffer) { - for (var offset = 0; offset < count; offset += NativeStreamBufferSize, buffer += NativeStreamBufferSize) - { - // Compute missing bytes in this block - var blockSize = count - offset; - if (blockSize > NativeStreamBufferSize) - blockSize = NativeStreamBufferSize; - - Unsafe.CopyBlockUnaligned(temporaryBufferStart, (void*)buffer, (uint)blockSize); - - Write(temporaryBuffer, 0, blockSize); - } - } - } } } diff --git a/sources/core/Stride.Core/IO/NativeStreamExtensions.cs b/sources/core/Stride.Core/IO/NativeStreamExtensions.cs deleted file mode 100644 index 844931093..000000000 --- a/sources/core/Stride.Core/IO/NativeStreamExtensions.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.IO; -using Stride.Core.Annotations; - -namespace Stride.Core.IO -{ - /// - /// Extension methods concerning . - /// - [Obsolete] - public static class NativeStreamExtensions - { - /// - /// Converts a to a . - /// - /// - /// If is already a , it will be returned as is. - /// Otherwise, a around it will be created. - /// - /// The stream. - /// - [NotNull, Obsolete] - public static NativeStream ToNativeStream(this Stream stream) - { - if (stream is not NativeStream nativeStream) - nativeStream = new NativeStreamWrapper(stream); - - return nativeStream; - } - } -} diff --git a/sources/core/Stride.Core/IO/NativeStreamWrapper.cs b/sources/core/Stride.Core/IO/NativeStreamWrapper.cs deleted file mode 100644 index 46d1794ce..000000000 --- a/sources/core/Stride.Core/IO/NativeStreamWrapper.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace Stride.Core.IO -{ - [Obsolete] - public class NativeStreamWrapper : NativeStream - { - private readonly Stream stream; - - public NativeStreamWrapper(Stream stream) - { - this.stream = stream; - } - - /// - public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) - { - return stream.CopyToAsync(destination, bufferSize, cancellationToken); - } - - /// - public override void Flush() - { - stream.Flush(); - } - - /// - public override Task FlushAsync(CancellationToken cancellationToken) - { - return stream.FlushAsync(cancellationToken); - } - - /// - public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) - => stream.ReadAsync(buffer, cancellationToken); - - /// - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return stream.ReadAsync(buffer, offset, count, cancellationToken); - } - - /// - public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) - => stream.WriteAsync(buffer, cancellationToken); - - /// - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return stream.WriteAsync(buffer, offset, count, cancellationToken); - } - - /// - public override long Seek(long offset, SeekOrigin origin) - { - return stream.Seek(offset, origin); - } - - /// - public override void SetLength(long value) - { - stream.SetLength(value); - } - - /// - public override int Read(Span buffer) => stream.Read(buffer); - - /// - public override int Read(byte[] buffer, int offset, int count) - { - return stream.Read(buffer, offset, count); - } - - /// - public override int ReadByte() - { - return stream.ReadByte(); - } - - /// - public override void Write(ReadOnlySpan buffer) => stream.Write(buffer); - - /// - public override void Write(byte[] buffer, int offset, int count) - { - stream.Write(buffer, offset, count); - } - - /// - public override void WriteByte(byte value) - { - stream.WriteByte(value); - } - - /// - public override bool CanRead - { - get { return stream.CanRead; } - } - - /// - public override bool CanSeek - { - get { return stream.CanSeek; } - } - - /// - public override bool CanTimeout - { - get { return stream.CanTimeout; } - } - - /// - public override bool CanWrite - { - get { return stream.CanWrite; } - } - - /// - public override long Length - { - get { return stream.Length; } - } - - /// - public override long Position - { - get { return stream.Position; } - set { stream.Position = value; } - } - - /// - public override int ReadTimeout - { - get { return stream.ReadTimeout; } - set { stream.ReadTimeout = value; } - } - - /// - public override int WriteTimeout - { - get { return stream.WriteTimeout; } - set { stream.WriteTimeout = value; } - } - } -} diff --git a/sources/core/Stride.Core/NullDisposable.cs b/sources/core/Stride.Core/NullDisposable.cs deleted file mode 100644 index 65ea92dbf..000000000 --- a/sources/core/Stride.Core/NullDisposable.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; - -namespace Stride.Core -{ - /// - /// This class is an implementation of the interface that does nothing when disposed. - /// - [Obsolete] // not used, shouldn't be public - public class NullDisposable : IDisposable - { - /// - /// A static instance of the class. - /// - public static readonly NullDisposable Instance = new(); - - /// - /// Implementation of the method. This method does nothing. - /// - public void Dispose() - { - } - } -} diff --git a/sources/core/Stride.Core/Reflection/TypeHelper.cs b/sources/core/Stride.Core/Reflection/TypeHelper.cs deleted file mode 100644 index 930fbd270..000000000 --- a/sources/core/Stride.Core/Reflection/TypeHelper.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using Stride.Core.Annotations; - -namespace Stride.Core.Reflection -{ - // TODO: these methods should be compilant with collection/dictionary descriptors. Since they're used only for design-time, they should be removed from here anyway - [Obsolete("This class will be removed in a future version")] - public static class TypeHelper - { - [Obsolete("This method will be removed in a future version")] - public static bool IsCollection([NotNull] this Type type) - { - if (type == null) throw new ArgumentNullException(nameof(type)); - var typeInfo = type.GetTypeInfo(); - if (typeInfo.IsArray) - { - return false; - } - - if (typeof(IList).GetTypeInfo().IsAssignableFrom(typeInfo)) - { - return true; - } - - foreach (var iType in typeInfo.ImplementedInterfaces) - { - var iTypeInfo = iType.GetTypeInfo(); - if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(ICollection<>)) - { - return true; - } - } - - return false; - } - - [Obsolete("This method will be removed in a future version")] - public static bool IsDictionary([NotNull] this Type type) - { - if (type == null) throw new ArgumentNullException(nameof(type)); - var typeInfo = type.GetTypeInfo(); - if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(typeInfo)) - { - return true; - } - - foreach (var iType in typeInfo.ImplementedInterfaces) - { - var iTypeInfo = iType.GetTypeInfo(); - if (iTypeInfo.IsGenericType && iTypeInfo.GetGenericTypeDefinition() == typeof(IDictionary<,>)) - { - return true; - } - } - - return false; - } - } -} diff --git a/sources/core/Stride.Core/Serialization/Binary/BinarySerialization.cs b/sources/core/Stride.Core/Serialization/Binary/BinarySerialization.cs deleted file mode 100644 index 2b32293fd..000000000 --- a/sources/core/Stride.Core/Serialization/Binary/BinarySerialization.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.IO; -using Stride.Core.Annotations; - -namespace Stride.Core.Serialization -{ - /// - /// Binary serialization method helpers to easily read/write data from a stream. - /// - /// - /// This class is a simple front end to and . - /// - [Obsolete] // inefficient, not recommended - public class BinarySerialization - { - /// - /// Reads an object instance from the specified stream. - /// - /// Type of the object to read - /// The stream to read the object instance. - /// An object instance of type T. - [Obsolete("Use BinarySerializationReader.Read instead.")] - public static T Read([NotNull] Stream stream) - { - var reader = new BinarySerializationReader(stream); - return reader.Read(); - } - - /// - /// Reads an object instance from the specified byte buffer. - /// - /// Type of the object to read - /// The byte buffer to read the object instance. - /// An object instance of type T. - [Obsolete("Use BinarySerializationReader.Read with a MemoryStream instead.")] - public static T Read([NotNull] byte[] buffer) - { - var reader = new BinarySerializationReader(new MemoryStream(buffer)); - return reader.Read(); - } - - /// - /// Writes an object instance to the specified stream. - /// - /// Type of the object to write - /// The stream to write the object instance to. - /// The value to write. - [Obsolete("Use BinarySerializationWriter.Write instead.")] - public static void Write([NotNull] Stream stream, T value) - { - var writer = new BinarySerializationWriter(stream); - writer.Write(value); - } - } -} diff --git a/sources/core/Stride.Core/Serialization/Binary/BinarySerializationReader.cs b/sources/core/Stride.Core/Serialization/Binary/BinarySerializationReader.cs index 7052d0c47..f0dcbe224 100644 --- a/sources/core/Stride.Core/Serialization/Binary/BinarySerializationReader.cs +++ b/sources/core/Stride.Core/Serialization/Binary/BinarySerializationReader.cs @@ -19,7 +19,7 @@ namespace Stride.Core.Serialization public BinarySerializationReader([NotNull] Stream inputStream) { Reader = new BinaryReader(inputStream); - NativeStream = inputStream; + UnderlyingStream = inputStream; } private BinaryReader Reader { get; } @@ -27,7 +27,7 @@ namespace Stride.Core.Serialization /// public override void Serialize(ref bool value) { - var result = NativeStream.ReadByte(); + var result = UnderlyingStream.ReadByte(); if (result == -1) throw new EndOfStreamException(); value = result != 0; @@ -38,50 +38,50 @@ namespace Stride.Core.Serialization public override unsafe void Serialize(ref float value) { fixed (float* valuePtr = &value) - *((uint*)valuePtr) = NativeStream.ReadUInt32(); + *((uint*)valuePtr) = UnderlyingStream.ReadUInt32(); } /// public override unsafe void Serialize(ref double value) { fixed (double* valuePtr = &value) - *((ulong*)valuePtr) = NativeStream.ReadUInt64(); + *((ulong*)valuePtr) = UnderlyingStream.ReadUInt64(); } /// public override void Serialize(ref short value) { - value = (short)NativeStream.ReadUInt16(); + value = (short)UnderlyingStream.ReadUInt16(); } /// public override void Serialize(ref int value) { - value = (int)NativeStream.ReadUInt32(); + value = (int)UnderlyingStream.ReadUInt32(); } /// public override void Serialize(ref long value) { - value = (long)NativeStream.ReadUInt64(); + value = (long)UnderlyingStream.ReadUInt64(); } /// public override void Serialize(ref ushort value) { - value = NativeStream.ReadUInt16(); + value = UnderlyingStream.ReadUInt16(); } /// public override void Serialize(ref uint value) { - value = NativeStream.ReadUInt32(); + value = UnderlyingStream.ReadUInt32(); } /// public override void Serialize(ref ulong value) { - value = NativeStream.ReadUInt64(); + value = UnderlyingStream.ReadUInt64(); } #pragma warning restore CS0618 // Type or member is obsolete @@ -100,7 +100,7 @@ namespace Stride.Core.Serialization /// public override void Serialize(ref byte value) { - var result = NativeStream.ReadByte(); + var result = UnderlyingStream.ReadByte(); if (result == -1) throw new EndOfStreamException(); value = (byte)result; @@ -109,7 +109,7 @@ namespace Stride.Core.Serialization /// public override void Serialize(ref sbyte value) { - var result = NativeStream.ReadByte(); + var result = UnderlyingStream.ReadByte(); if (result == -1) throw new EndOfStreamException(); value = (sbyte)(byte)result; @@ -121,7 +121,7 @@ namespace Stride.Core.Serialization Reader.Read(values, offset, count); } /// - public override void Serialize(Span buffer) => NativeStream.Read(buffer); + public override void Serialize(Span buffer) => UnderlyingStream.Read(buffer); /// public override void Flush() diff --git a/sources/core/Stride.Core/Serialization/Binary/BinarySerializationWriter.cs b/sources/core/Stride.Core/Serialization/Binary/BinarySerializationWriter.cs index 83fae960d..69d448b15 100644 --- a/sources/core/Stride.Core/Serialization/Binary/BinarySerializationWriter.cs +++ b/sources/core/Stride.Core/Serialization/Binary/BinarySerializationWriter.cs @@ -20,7 +20,7 @@ namespace Stride.Core.Serialization public BinarySerializationWriter([NotNull] Stream outputStream) { Writer = new BinaryWriter(outputStream); - NativeStream = outputStream; + UnderlyingStream = outputStream; } private BinaryWriter Writer { get; } @@ -28,56 +28,56 @@ namespace Stride.Core.Serialization /// public override void Serialize(ref bool value) { - NativeStream.WriteByte(value ? (byte)1 : (byte)0); + UnderlyingStream.WriteByte(value ? (byte)1 : (byte)0); } #pragma warning disable CS0618 // Type or member is obsolete /// public override unsafe void Serialize(ref float value) { - NativeStream.Write(Unsafe.As(ref value)); + UnderlyingStream.Write(Unsafe.As(ref value)); } /// public override unsafe void Serialize(ref double value) { - NativeStream.Write(Unsafe.As(ref value)); + UnderlyingStream.Write(Unsafe.As(ref value)); } /// public override void Serialize(ref short value) { - NativeStream.Write((ushort)value); + UnderlyingStream.Write((ushort)value); } /// public override void Serialize(ref int value) { - NativeStream.Write((uint)value); + UnderlyingStream.Write((uint)value); } /// public override void Serialize(ref long value) { - NativeStream.Write((ulong)value); + UnderlyingStream.Write((ulong)value); } /// public override void Serialize(ref ushort value) { - NativeStream.Write(value); + UnderlyingStream.Write(value); } /// public override void Serialize(ref uint value) { - NativeStream.Write(value); + UnderlyingStream.Write(value); } /// public override void Serialize(ref ulong value) { - NativeStream.Write(value); + UnderlyingStream.Write(value); } #pragma warning restore CS0618 // Type or member is obsolete @@ -96,28 +96,28 @@ namespace Stride.Core.Serialization /// public override void Serialize(ref byte value) { - NativeStream.WriteByte(value); + UnderlyingStream.WriteByte(value); } /// public override void Serialize(ref sbyte value) { - NativeStream.WriteByte((byte)value); + UnderlyingStream.WriteByte((byte)value); } /// public override void Serialize([NotNull] byte[] values, int offset, int count) { - NativeStream.Write(values, offset, count); + UnderlyingStream.Write(values, offset, count); } /// - public override void Serialize(Span buffer) => NativeStream.Write(buffer); + public override void Serialize(Span buffer) => UnderlyingStream.Write(buffer); /// public override void Flush() { - NativeStream.Flush(); + UnderlyingStream.Flush(); } } } diff --git a/sources/core/Stride.Core/Serialization/NullSerializationStream.cs b/sources/core/Stride.Core/Serialization/NullSerializationStream.cs deleted file mode 100644 index c3018debf..000000000 --- a/sources/core/Stride.Core/Serialization/NullSerializationStream.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; - -namespace Stride.Core.Serialization -{ - /// - /// Empty implementation of . - /// - [Obsolete] // not used - public class NullSerializationStream : SerializationStream - { - /// - public override void Serialize(ref bool value) - { - } - - /// - public override void Serialize(ref float value) - { - } - - /// - public override void Serialize(ref double value) - { - } - - /// - public override void Serialize(ref short value) - { - } - - /// - public override void Serialize(ref int value) - { - } - - /// - public override void Serialize(ref long value) - { - } - - /// - public override void Serialize(ref ushort value) - { - } - - /// - public override void Serialize(ref uint value) - { - } - - /// - public override void Serialize(ref ulong value) - { - } - - /// - public override void Serialize(ref string value) - { - } - - /// - public override void Serialize(ref char value) - { - } - - /// - public override void Serialize(ref byte value) - { - } - - /// - public override void Serialize(ref sbyte value) - { - } - - /// - public override void Serialize(byte[] values, int offset, int count) - { - } - - /// - public override void Serialize(Span memory) - { - } - - /// - public override void Flush() - { - } - } -} diff --git a/sources/core/Stride.Core/Serialization/SerializationStream.cs b/sources/core/Stride.Core/Serialization/SerializationStream.cs index 639447504..9c3feff7b 100644 --- a/sources/core/Stride.Core/Serialization/SerializationStream.cs +++ b/sources/core/Stride.Core/Serialization/SerializationStream.cs @@ -13,19 +13,6 @@ namespace Stride.Core.Serialization { protected const int BufferTLSSize = 1024; - // Helper buffer for classes needing it. - // If null, it should be initialized with BufferTLSSize constant. - [Obsolete("Let the caller provide a buffer.")] - protected static byte[] bufferTLS; - - /// - /// The from which this serializer reads or to which it writes. - /// - [Obsolete("Use UnderlyingStream instead.")] - public Stream NativeStream { - get => UnderlyingStream; - protected set => UnderlyingStream = value; - } /// /// The from which this serializer reads or to which it writes. /// diff --git a/sources/core/Stride.Core/Serialization/Serializers/CollectionSerializers.cs b/sources/core/Stride.Core/Serialization/Serializers/CollectionSerializers.cs index cb43c6efe..c18449d40 100644 --- a/sources/core/Stride.Core/Serialization/Serializers/CollectionSerializers.cs +++ b/sources/core/Stride.Core/Serialization/Serializers/CollectionSerializers.cs @@ -326,9 +326,9 @@ namespace Stride.Core.Serialization.Serializers { var span = MemoryMarshal.Cast(array.AsSpan()); if (mode == ArchiveMode.Deserialize) - stream.NativeStream.Read(span); + stream.UnderlyingStream.Read(span); else if (mode == ArchiveMode.Serialize) - stream.NativeStream.Write(span); + stream.UnderlyingStream.Write(span); } } diff --git a/sources/core/Stride.Core/ServiceRegistryExtensions.cs b/sources/core/Stride.Core/ServiceRegistryExtensions.cs index 8b481464e..45e5d0284 100644 --- a/sources/core/Stride.Core/ServiceRegistryExtensions.cs +++ b/sources/core/Stride.Core/ServiceRegistryExtensions.cs @@ -8,20 +8,6 @@ namespace Stride.Core { public static class ServiceRegistryExtensions { - /// - /// Gets a service instance from a specified interface contract. - /// - /// Type of the interface contract of the service - /// The registry. - /// An instance of the requested service registered to this registry. - [CanBeNull] - [Obsolete("Use the generic overload of IServiceRegistry.GetService instead")] - public static T GetServiceAs([NotNull] this IServiceRegistry registry) - where T : class - { - return registry.GetService(); - } - /// /// Gets a service instance from a specified interface contract. /// diff --git a/sources/core/Stride.Core/Storage/ObjectIdBuilder.cs b/sources/core/Stride.Core/Storage/ObjectIdBuilder.cs index a85955b72..3244f0ecd 100644 --- a/sources/core/Stride.Core/Storage/ObjectIdBuilder.cs +++ b/sources/core/Stride.Core/Storage/ObjectIdBuilder.cs @@ -234,25 +234,6 @@ namespace Stride.Core.Storage public void Write(ReadOnlySpan buffer) where T : unmanaged => Write(MemoryMarshal.AsBytes(buffer)); - /// - /// Writes the specified buffer to this instance. - /// - /// The buffer. - [Obsolete("Use Write(ReadOnlySpan)")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Write(ref byte buffer, int length) - => Write(MemoryMarshal.CreateReadOnlySpan(ref buffer, length)); - - /// - /// Writes the specified buffer to this instance. - /// - /// Type must be a struct - /// The data. - [Obsolete("Use Write(T) or Write(ReadOnlySpan)")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Write(ref T data) where T : unmanaged - => Write(data); - /// /// Writes a buffer of byte to this builder. /// diff --git a/sources/core/Stride.Core/UnmanagedArray.cs b/sources/core/Stride.Core/UnmanagedArray.cs index 6bab2a6b8..b0d37810a 100644 --- a/sources/core/Stride.Core/UnmanagedArray.cs +++ b/sources/core/Stride.Core/UnmanagedArray.cs @@ -22,15 +22,6 @@ namespace Stride.Core isShared = false; } - [Obsolete("Obtain Memory using GC.Allocate*Array or a Stride-specific allocator mechanism.")] - public UnmanagedArray(int length, IntPtr unmanagedDataPtr) - { - Length = length; - sizeOfT = Unsafe.SizeOf(); - Pointer = unmanagedDataPtr; - isShared = true; - } - public void Dispose() { if (!isShared) diff --git a/sources/core/Stride.Core/Utilities.cs b/sources/core/Stride.Core/Utilities.cs index 252ae6829..5f0145e5d 100644 --- a/sources/core/Stride.Core/Utilities.cs +++ b/sources/core/Stride.Core/Utilities.cs @@ -39,243 +39,6 @@ namespace Stride.Core /// public static class Utilities { - /// Copies bytes from the source address to the destination address. - /// A thin wrapper around . - /// The destination address. - /// The source address. - /// The number of bytes to copy. - /// This API corresponds to the unaligned.1 cpblk opcode sequence. - /// No alignment assumptions are made about the or pointers. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void CopyMemory(nint destination, nint source, int byteCount) - => Unsafe.CopyBlockUnaligned((void*)destination, (void*)source, (uint)byteCount); - - /// - /// Compares two block of memory. - /// - /// The pointer to compare from. - /// The pointer to compare against. - /// The size in bytes to compare. - /// True if the buffers are equivalent, false otherwise. - [Obsolete("Use Span.SequenceEqual.")] - public static unsafe bool CompareMemory(nint from, nint against, int sizeToCompare) - { - var lhs = new Span((void*)from, sizeToCompare); - var rhs = new Span((void*)against, sizeToCompare); - return lhs.SequenceEqual(rhs); - } - - /// Clears the memory. - /// The destination address. - /// The byte value to fill the memory with. - /// The size in bytes to clear. - [Obsolete("Use Span.Fill or System.Runtime.CompilerServices.Unsafe.InitBlockUnaligned")] - public static unsafe void ClearMemory(nint destination, byte value, int sizeInBytesToClear) - => Unsafe.InitBlockUnaligned((void*)destination, value, (uint)sizeInBytesToClear); - - /// - /// Return the sizeof a struct from a CLR. Equivalent to sizeof operator but works on generics too. - /// - /// a struct to evaluate - /// sizeof this struct - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.SizeOf()")] - public static int SizeOf() where T : struct => Unsafe.SizeOf(); - - /// - /// Return the sizeof an array of struct. Equivalent to sizeof operator but works on generics too. - /// - /// a struct - /// The array of struct to evaluate. - /// sizeof in bytes of this array of struct - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.SizeOf() * array.Length")] - public static int SizeOf(T[] array) where T : struct - => array is null ? 0 : array.Length * Unsafe.SizeOf(); - - /// - /// Pins the specified source and call an action with the pinned pointer. - /// - /// The type of the structure to pin - /// The source. - /// The pin action to perform on the pinned pointer. - [Obsolete("Use fixed statement with `unmanaged` type constraint. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement")] - public static unsafe void Pin(ref T source, Action pinAction) where T : unmanaged - { - fixed (void* ptr = &source) - pinAction((nint)ptr); - } - - /// - /// Pins the specified source and call an action with the pinned pointer. - /// - /// The type of the structure to pin - /// The source array. - /// The pin action to perform on the pinned pointer. - [Obsolete("Use fixed statement with `unmanaged` type constraint. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement")] - public static unsafe void Pin(T[] source, [NotNull] Action pinAction) where T : unmanaged - { - // null if source is null or empty - fixed (void* ptr = source) - pinAction((nint)ptr); - } - - /// - /// Covnerts a structured array to an equivalent byte array. - /// - /// The source. - /// The byte array. - [Obsolete("Allocates. Consider using System.Runtime.InteropServices.MemoryMarshal.Cast or System.Buffers.ArrayPool.Shared")] - public static unsafe byte[] ToByteArray(T[] source) where T : struct - { - if (source is null) return null; - var bytes = MemoryMarshal.Cast(source.AsSpan()); - var result = new byte[bytes.Length]; - bytes.CopyTo(result); - return result; - } - - /// - /// Reads the specified T data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data read from the memory location - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")] - public static unsafe T Read(nint source) where T : struct - => Unsafe.ReadUnaligned((void*)source); - - /// - /// Reads the specified T data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data write to. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Read(nint source, ref T data) where T : struct - => data = Unsafe.ReadUnaligned((void*)source); - - /// - /// Reads the specified T data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data write to. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")] - public static unsafe void ReadOut(nint source, out T data) where T : struct - => data = Unsafe.ReadUnaligned((void*)source); - - /// - /// Reads the specified T data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data write to. - /// source pointer + sizeof(T) - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned. Consider pointer arithmetic or System.Runtime.CompilerServices.Unsafe.Add.")] - public static unsafe nint ReadAndPosition(nint source, ref T data) where T : struct - { - data = Unsafe.ReadUnaligned((void*)source); - return (nint)source + Unsafe.SizeOf(); - } - - /// - /// Reads the specified array T[] data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data write to. - /// The offset in the array to write to. - /// The number of T element to read from the memory location - /// source pointer + sizeof(T) * count - [Obsolete("Use Span.Copy or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")] - public static unsafe nint Read(nint source, T[] data, int offset, int count) where T : struct - { - var src = new Span((void*)source, count); - src.CopyTo(data.AsSpan(offset)); - return (nint)source + count * Unsafe.SizeOf(); - } - - /// - /// Reads the specified T data from a memory location. - /// - /// Type of a data to read - /// Memory location to read from. - /// The data write to. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.ReadUnaligned")] - internal static unsafe void UnsafeReadOut(nint source, out T data) - => data = Unsafe.ReadUnaligned((void*)source); - - /// - /// Writes the specified T data to a memory location. - /// - /// Type of a data to write - /// Memory location to write to. - /// The data to write. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Write(nint destination, ref T data) where T : struct - => Unsafe.WriteUnaligned((void*)destination, data); - - /// - /// Writes the specified T data to a memory location. - /// - /// Type of a data to write - /// Memory location to write to. - /// The data to write. - /// destination pointer + sizeof(T) - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned. Consider pointer arithmetic or System.Runtime.CompilerServices.Unsafe.Add.")] - public static unsafe nint WriteAndPosition(nint destination, ref T data) where T : struct - { - Unsafe.WriteUnaligned((void*)destination, data); - return (nint)destination + Unsafe.SizeOf(); - } - - /// - /// Writes the specified T data to a memory location. - /// - /// Type of a data to write - /// Memory location to write to. - /// The data to write. - [Obsolete("Use System.Runtime.CompilerServices.Unsafe.WriteUnaligned")] - internal static unsafe void UnsafeWrite(nint destination, ref T data) - => Unsafe.WriteUnaligned((void*)destination, data); - - /// - /// Writes the specified array T[] data to a memory location. - /// - /// Type of a data to write - /// Memory location to write to. - /// The array of T data to write. - /// The offset in the array to read from. - /// The number of T element to write to the memory location - [Obsolete("Use Span.CopyTo or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")] - public static void Write(byte[] destination, T[] data, int offset, int count) where T : struct - { - var src = MemoryMarshal.Cast(data.AsSpan(offset, count)); - if (destination.Length < src.Length) - throw new ArgumentException("The destination array is too short.", nameof(destination)); - src.CopyTo(destination); - } - - /// - /// Writes the specified array T[] data to a memory location. - /// - /// Type of a data to write - /// Memory location to write to. - /// The array of T data to write. - /// The offset in the array to read from. - /// The number of T element to write to the memory location - /// destination pointer + sizeof(T) * count - [Obsolete("Use Span.CopyTo or System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned")] - public static unsafe nint Write(nint destination, T[] data, int offset, int count) where T : struct - { - var src = MemoryMarshal.Cast(data.AsSpan(offset, count)); - var dst = new Span((void*)destination, src.Length); - src.CopyTo(dst); - return (nint)destination + src.Length; - } - /// /// Allocate an aligned memory buffer. /// @@ -348,90 +111,34 @@ namespace Stride.Core } } - /// - /// String helper join method to display an array of object as a single string. - /// - /// The separator. - /// The array. - /// a string with array elements serparated by the seperator - [Obsolete("Use string.Join")] - [NotNull] - public static string Join(string separator, T[] array) - => string.Join(separator, array); - - /// - /// String helper join method to display an enumrable of object as a single string. - /// - /// The separator. - /// The enumerable. - /// a string with array elements serparated by the seperator - [Obsolete("Use string.Join")] - [NotNull] - public static string Join(string separator, [NotNull] IEnumerable elements) - => string.Join(separator, elements); - - /// - /// String helper join method to display an enumrable of object as a single string. - /// - /// The separator. - /// The enumerable. - /// a string with array elements serparated by the seperator - [Obsolete("Use string.Join")] - [NotNull] - public static string Join(string separator, [NotNull] IEnumerator elements) - { - static IEnumerable Enumerate(IEnumerator elements) - { - while (elements.MoveNext()) yield return elements.Current; - } - return string.Join(separator, Enumerate(elements)); - } - /// /// Read stream to a byte[] buffer /// /// input stream /// a byte[] buffer [Obsolete("Allocates. Read into the destination.")] - [NotNull] public static byte[] ReadStream([NotNull] Stream stream) - { - var readLength = 0; - return ReadStream(stream, ref readLength); - } - - /// - /// Read stream to a byte[] buffer - /// - /// input stream - /// length to read - /// a byte[] buffer - [Obsolete("Allocates. Read into the destination.")] - [NotNull] - public static byte[] ReadStream([NotNull] Stream stream, ref int readLength) { Debug.Assert(stream != null); Debug.Assert(stream.CanRead); - var count = readLength; - Debug.Assert(count <= (stream.Length - stream.Position)); - if (count == 0) { - readLength = (int)(stream.Length - stream.Position); - count = readLength; - } - Debug.Assert(count >= 0); - if (count == 0) - return Array.Empty(); + var readLength = (int)(stream.Length - stream.Position); - var buffer = new byte[count]; - var bytesRead = 0; - if (count > 0) + Debug.Assert(readLength <= (stream.Length - stream.Position)); + + if (readLength == 0) { - do - { - bytesRead += stream.Read(buffer, bytesRead, readLength - bytesRead); - } while (bytesRead < readLength); + return Array.Empty(); } + + var buffer = new byte[readLength]; + var bytesRead = 0; + + while (bytesRead < readLength) + { + bytesRead += stream.Read(buffer, bytesRead, readLength - bytesRead); + } + return buffer; } @@ -490,54 +197,6 @@ namespace Stride.Core return hashCode; } - /// - /// Compares two collection, element by elements. - /// - /// A "from" enumerator. - /// A "to" enumerator. - /// True if lists are identical. False otherwise. - [Obsolete("Use SequenceEqualAllowNull")] - public static bool Compare(IEnumerable left, IEnumerable right) - { - if (ReferenceEquals(left, right)) return true; - if (left is null || right is null) return false; - return left.Cast().SequenceEqual(right.Cast()); - } - - /// - /// Compares two collection, element by elements. - /// - /// A "from" enumerator. - /// A "to" enumerator. - /// True if lists are identical. False otherwise. - [Obsolete("Use SequenceEqualAllowNull")] - public static bool Compare(IEnumerator leftIt, IEnumerator rightIt) - { - if (ReferenceEquals(leftIt, rightIt)) - return true; - if (leftIt is null || rightIt is null) - return false; - - bool hasLeftNext; - bool hasRightNext; - while (true) - { - hasLeftNext = leftIt.MoveNext(); - hasRightNext = rightIt.MoveNext(); - if (!hasLeftNext || !hasRightNext) - break; - - if (!Equals(leftIt.Current, rightIt.Current)) - return false; - } - - // If there is any left element - if (hasLeftNext != hasRightNext) - return false; - - return true; - } - /// /// Compares two collection, element by elements. /// @@ -586,31 +245,6 @@ namespace Stride.Core return true; } - [Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")] - public static bool Compare(T[] left, T[] right) - => left.SequenceEqualAllowNull(right, null); - - /// - /// Compares two collection, element by elements. - /// - /// The collection to compare from. - /// The colllection to compare to. - /// True if lists are identical (but no necessarely of the same time). False otherwise. - [Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")] - public static bool Compare(ICollection left, ICollection right) - => left.SequenceEqualAllowNull(right, null); - - /// - /// Compares two list, element by elements. - /// - /// The list to compare from. - /// The colllection to compare to. - /// True if lists are sequentially equal. False otherwise. - /// Concrete List is favored over interface to avoid enumerator object allocation. - [Obsolete("Use StrideCoreExtensions.SequenceEqualAllowNull")] - public static bool Compare(List left, List right) - => left.SequenceEqualAllowNull(right, null); - /// /// Swaps the value between two references. /// @@ -619,24 +253,6 @@ namespace Stride.Core /// The right value. public static void Swap(ref T left, ref T right) => (right, left) = (left, right); - /// Suspends the current thread for a duration. - /// The duration of sleep. Must be non-negative. - public static void Sleep(TimeSpan duration) - { - if (duration.Ticks < 0) - throw new ArgumentOutOfRangeException(nameof(duration)); - Thread.Sleep(duration); - } - - /// Suspends the current thread for a number of milliseconds. - /// The duration in milliseconds. Must be non-negative. - public static void Sleep(int ms) - { - if (ms < 0) - throw new ArgumentOutOfRangeException(nameof(ms)); - Thread.Sleep(ms); - } - /// /// Linq assisted full tree iteration and collection in a single line. /// Warning, could be slow. diff --git a/sources/engine/Stride.Graphics/Data/ImageTextureSerializer.cs b/sources/engine/Stride.Graphics/Data/ImageTextureSerializer.cs index 0b195fe87..f26223635 100644 --- a/sources/engine/Stride.Graphics/Data/ImageTextureSerializer.cs +++ b/sources/engine/Stride.Graphics/Data/ImageTextureSerializer.cs @@ -21,7 +21,7 @@ namespace Stride.Graphics.Data var isStreamable = stream.ReadBoolean(); if (!isStreamable) { - var image = Image.Load(stream.NativeStream); + var image = Image.Load(stream.UnderlyingStream); textureData.InitializeFrom(image); } else @@ -41,7 +41,7 @@ namespace Stride.Graphics.Data } else { - textureData.Save(stream.NativeStream, ImageFileType.Stride); + textureData.Save(stream.UnderlyingStream, ImageFileType.Stride); } } diff --git a/sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs b/sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs index fd889429a..110279401 100644 --- a/sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs +++ b/sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs @@ -30,7 +30,7 @@ namespace Stride.Graphics.Data texturesStreamingProvider?.UnregisterTexture(texture); // TODO: Error handling? - using (var textureData = Image.Load(stream.NativeStream)) + using (var textureData = Image.Load(stream.UnderlyingStream)) { if (texture.GraphicsDevice != null) texture.OnDestroyed(); //Allows fast reloading todo review maybe? @@ -75,7 +75,7 @@ namespace Stride.Graphics.Data // Load initial texture (with limited number of mipmaps) if (storageHeader.InitialImage) { - using (var textureData = Image.Load(stream.NativeStream)) + using (var textureData = Image.Load(stream.UnderlyingStream)) { if (texture.GraphicsDevice != null) texture.OnDestroyed(); //Allows fast reloading todo review maybe? @@ -102,7 +102,7 @@ namespace Stride.Graphics.Data // Load initial texture and discard it (we are going to load the full chunk texture right after) if (storageHeader.InitialImage) { - using (var textureData = Image.Load(stream.NativeStream)) + using (var textureData = Image.Load(stream.UnderlyingStream)) { } } diff --git a/sources/engine/Stride.Graphics/Data/TextureImageSerializer.cs b/sources/engine/Stride.Graphics/Data/TextureImageSerializer.cs index 79bd75f3c..0a0873175 100644 --- a/sources/engine/Stride.Graphics/Data/TextureImageSerializer.cs +++ b/sources/engine/Stride.Graphics/Data/TextureImageSerializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using Stride.Core; @@ -22,7 +22,7 @@ namespace Stride.Graphics.Data var graphicsDeviceService = services.GetSafeServiceAs(); // TODO: Error handling? - using (var textureData = Image.Load(stream.NativeStream)) + using (var textureData = Image.Load(stream.UnderlyingStream)) { if (texture.GraphicsDevice != null) texture.OnDestroyed(); //Allows fast reloading todo review maybe? @@ -51,7 +51,7 @@ namespace Stride.Graphics.Data if (textureData == null) throw new InvalidOperationException("Trying to serialize a Texture without CPU info."); - textureData.Image.Save(stream.NativeStream, ImageFileType.Stride); + textureData.Image.Save(stream.UnderlyingStream, ImageFileType.Stride); } } diff --git a/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs b/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs index 91868abaa..b4f0ea841 100644 --- a/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs +++ b/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs @@ -117,13 +117,13 @@ namespace Stride.Graphics.Data PixelBuffers = pixelBuffers, }; // TODO: We end up duplicating some of the texture data; we could find a way to avoid that by saving only the chunks of higher level mips? - initialImage.Save(stream.NativeStream, ImageFileType.Stride); + initialImage.Save(stream.UnderlyingStream, ImageFileType.Stride); } } else { // Write whole image (old texture content serialization) - Image.Save(stream.NativeStream, ImageFileType.Stride); + Image.Save(stream.UnderlyingStream, ImageFileType.Stride); } } } diff --git a/sources/engine/Stride.Shaders.Compiler/OpenGL/ShaderCompiler.cs b/sources/engine/Stride.Shaders.Compiler/OpenGL/ShaderCompiler.cs index 9b30359f2..60ed120f4 100644 --- a/sources/engine/Stride.Shaders.Compiler/OpenGL/ShaderCompiler.cs +++ b/sources/engine/Stride.Shaders.Compiler/OpenGL/ShaderCompiler.cs @@ -149,7 +149,8 @@ namespace Stride.Shaders.Compiler.OpenGL using (var stream = new MemoryStream()) { - BinarySerialization.Write(stream, shaderBytecodes); + var writer = new BinarySerializationWriter(stream); + writer.Write(shaderBytecodes); rawData = stream.ToArray(); } diff --git a/sources/engine/Stride/Graphics/ImageSerializer.cs b/sources/engine/Stride/Graphics/ImageSerializer.cs index 85f9ecff3..1fa5cc408 100644 --- a/sources/engine/Stride/Graphics/ImageSerializer.cs +++ b/sources/engine/Stride/Graphics/ImageSerializer.cs @@ -13,12 +13,12 @@ namespace Stride.Graphics { if (context.Mode == ArchiveMode.Deserialize) { - var image = Image.Load(stream.NativeStream); + var image = Image.Load(stream.UnderlyingStream); textureData.InitializeFrom(image); } else { - textureData.Save(stream.NativeStream, ImageFileType.Stride); + textureData.Save(stream.UnderlyingStream, ImageFileType.Stride); } }