c-o
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using StgSharp.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class StgSharp
|
||||
{
|
||||
private static SSD defaultIdProvider = new SSD();
|
||||
private static List<Area> root = new List<Area>();
|
||||
|
||||
private static byte leastUnusedArea;
|
||||
|
||||
public static byte NewArea()
|
||||
{
|
||||
byte ret = leastUnusedArea;
|
||||
leastUnusedArea++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}//------------------ end of class ---------------------
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IMemoryType.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public interface IMemoryType
|
||||
{
|
||||
|
||||
public T Read<T>(int index) where T : struct
|
||||
#if NET8_0_OR_GREATER
|
||||
, INumber
|
||||
#else
|
||||
, IConvertible
|
||||
#endif
|
||||
;
|
||||
|
||||
public void Write<T>(int index, T value) where T : struct
|
||||
#if NET8_0_OR_GREATER
|
||||
, INumber
|
||||
#else
|
||||
, IConvertible
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal partial class InternalIO
|
||||
{
|
||||
internal const string CollisionTextureVertexShader ="#version 430 core\r\n\r\nlayout(location = 0) in vec2 localCollisionCoord;\r\nlayout(location = 1) in vec2 spaceCoord;\r\nlayout(location = 2) in float rotation;\r\nlayout(location = 3) in float scaling;\r\n\r\nuniform vec2 target;\r\nuniform mat2 projection;\r\n\r\nvoid main()\r\n{\r\n mat2 scaling = mat2(\r\n scaling,0,\r\n 0,scaling\r\n );\r\n mat2 rotation = mat2(\r\n cos(rotation),-sin(rotation),\r\n sin(rotation),cos(rotation) \r\n );\r\n vec2 realCoord = (rotation * scaling * localCollisionCoord) + spaceCoord - target;\r\n realCoord = projection * realCoord;\r\n\r\n float dist = distance(realCoord, vec2(0,0));\r\n float angle = atan(realCoord.y, realCoord.x);\r\n \r\n gl_Position = vec4(angle, realCoord.y, dist, 1);\r\n}";
|
||||
internal const string CollisionTextureFragmentShader = "#version 430 core\r\n\r\nout vec4 Color;\r\n\r\nuniform float range;\r\n\r\nvoid main()\r\n{\r\n float dist = gl_FragCoord.z;\r\n\r\n if(dist > range)\r\n {\r\n discard;\r\n }\r\n dist /= range;\r\n gl_FragDepth = min(dist, gl_FragDepth);\r\n\r\n Color = vec4(dist,0,0,1);\r\n}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="M128.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
#if NET5_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Pack = 16)]
|
||||
public unsafe struct M128:IMemoryType
|
||||
{
|
||||
[FieldOffset(0)] internal Vector4 vec;
|
||||
|
||||
internal M128(Vector4 v)
|
||||
{
|
||||
vec = v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T Read<T>(int index) where T : struct
|
||||
#if NET8_0_OR_GREATER
|
||||
, INumber
|
||||
#else
|
||||
, IConvertible
|
||||
#endif
|
||||
|
||||
{
|
||||
fixed (Vector4* p = &vec)
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
return *(((T*)p) + index);
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string ToString(int sample)
|
||||
{
|
||||
string str = string.Empty;
|
||||
for (int i = 15; i >= 0; i--)
|
||||
{
|
||||
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Write<T>(int index, T value) where T : struct
|
||||
#if NET8_0_OR_GREATER
|
||||
, INumber
|
||||
#else
|
||||
,IConvertible
|
||||
#endif
|
||||
{
|
||||
fixed (Vector4* p = &vec)
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
*(((T*)p) + index) = value;
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<byte>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, byte>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<sbyte>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, sbyte>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<short>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, short>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<ushort>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, ushort>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<int>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, int>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<uint>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, uint>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<long>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, long>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<ulong>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, ulong>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<float>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, float>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator Vector128<double>(M128 m)
|
||||
{
|
||||
return Vector128.As<float, double>(m.vec.AsVector128());
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using StgSharp.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math.HighPrecession
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct M256:IMemoryType
|
||||
{
|
||||
private M128 v0;
|
||||
private M128 v1;
|
||||
|
||||
|
||||
T IMemoryType.Read<T>(int index)
|
||||
{
|
||||
fixed (M128* mptr = &v0)
|
||||
{
|
||||
return *(((T*)mptr) + index);
|
||||
}
|
||||
}
|
||||
|
||||
void IMemoryType.Write<T>(int index, T value)
|
||||
{
|
||||
fixed (M128* mptr = &v0)
|
||||
{
|
||||
*(((T*)mptr) + index) = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
using StgSharp.Data;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public class RandomGenerator
|
||||
{
|
||||
|
||||
|
||||
private readonly byte[] originKey;
|
||||
private byte[] currentKey;
|
||||
private int cycleCount;
|
||||
private SHA512 hash;
|
||||
|
||||
public RandomGenerator():this(DateTime.UtcNow.ToBinary())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RandomGenerator(object source)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
XmlSerializer s = new XmlSerializer(source.GetType());
|
||||
using (StringWriter sw = new StringWriter())
|
||||
{
|
||||
s.Serialize(sw, source);
|
||||
string data = sw.ToString();
|
||||
originKey = Encoding.UTF8.GetBytes(data);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
hash = SHA512.Create();
|
||||
originKey = hash.ComputeHash(originKey);
|
||||
currentKey = originKey;
|
||||
cycleCount = 0;
|
||||
}
|
||||
|
||||
public int TotalGeneratedRandom
|
||||
{
|
||||
get => cycleCount;
|
||||
}
|
||||
|
||||
public unsafe int GenRandomInt()
|
||||
{
|
||||
M128 source = PrivateRand();
|
||||
cycleCount++;
|
||||
|
||||
/*
|
||||
float d0 = MathF.Sin(1 / source.Read<float>(0));
|
||||
float d1 = MathF.Sin(1 / source.Read<float>(1));
|
||||
float d2 = MathF.Sin(1 / source.Read<float>(2));
|
||||
float d3 = MathF.Sin(1 / source.Read<float>(3));
|
||||
|
||||
source.Write<short>(0, *( short*)&d3);
|
||||
source.Write<short>(2, *((short*)&d2+1));
|
||||
source.Write<short>(4, *( short*)&d1);
|
||||
source.Write<short>(6, *((short*)&d0+1));
|
||||
|
||||
/**/
|
||||
|
||||
return source.Read<int>(cycleCount % 4);
|
||||
}
|
||||
|
||||
public float GenRandomSingle()
|
||||
{
|
||||
cycleCount++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
M128 source = PrivateRand();
|
||||
|
||||
uint
|
||||
temp0 = source.Read<uint>(0),
|
||||
temp1 = source.Read<uint>(2);
|
||||
|
||||
if (temp0 * temp1 != 0)
|
||||
{
|
||||
float ret = (temp0 % temp1) * 1.0f / temp1;
|
||||
if (ret < 0.335f)
|
||||
{
|
||||
ret = ret * (ret * -0.7811934f + 1.4489113f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ret * (ret * -0.1158368f + 1.0580600f) + 0.0590584f;
|
||||
}
|
||||
if (ret > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte GenRandomInt8()
|
||||
{
|
||||
cycleCount++;
|
||||
if (cycleCount % 64 == 0)
|
||||
{
|
||||
PrivateRand();
|
||||
}
|
||||
return (byte)(currentKey[ cycleCount % 64 ]);
|
||||
}
|
||||
|
||||
private unsafe M128 PrivateRand()
|
||||
{
|
||||
currentKey = hash.ComputeHash(currentKey);
|
||||
M128 ret;
|
||||
fixed (byte* bptr = currentKey)
|
||||
{
|
||||
switch ((cycleCount % 16) / 4)
|
||||
{
|
||||
case 0:
|
||||
ret= *((M128*)bptr + 0);break;
|
||||
case 1:
|
||||
ret= *((M128*)bptr + 1);break;
|
||||
case 2:
|
||||
ret= *((M128*)bptr + 2);break;
|
||||
case 3:
|
||||
ret= *((M128*)bptr + 3);break;
|
||||
default:
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
//Console.WriteLine(ret.ToString(16));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
currentKey = originKey;
|
||||
cycleCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using StgSharp.Data.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// An independent storage area, used as the only folder type in root folder.
|
||||
/// Contains several <see cref="SSD"/> files reference as virtual disc.
|
||||
/// Data is actually stored in <see cref="SSD"/>s in certain RAID mode.
|
||||
/// </summary>
|
||||
public partial class Area
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="DataHead.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct SSDSegmentHead
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal M128 data;
|
||||
|
||||
[FieldOffset(0)] public int globalID;
|
||||
[FieldOffset(4)] public int nextID;
|
||||
[FieldOffset(8)] public int previousHash;
|
||||
|
||||
|
||||
[FieldOffset(12)] internal byte size;
|
||||
[FieldOffset(13)] public byte selfDefine_1;
|
||||
[FieldOffset(14)] public byte selfDefine_2;
|
||||
[FieldOffset(15)] public byte selfDefine_3;
|
||||
|
||||
|
||||
public int Size
|
||||
{
|
||||
get => ((int)size) + 1;
|
||||
set
|
||||
{
|
||||
if ((value > 256) || (value < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
size = (byte)(value - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16];
|
||||
fixed (Vector4* vptr = &data.vec)
|
||||
{
|
||||
byte* bptr = (byte*)vptr;
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
ret[i] = *bptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="DataSegment.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16)]
|
||||
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
|
||||
{
|
||||
|
||||
[FieldOffset(16)] public fixed byte Data[16 * (StgSharp.ssdSegmentLength - 1)];
|
||||
[FieldOffset(12)] public int DataHash;
|
||||
[FieldOffset(8)] public int PreviousHash;
|
||||
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
|
||||
|
||||
public SSDSegment(int previousHash)
|
||||
{
|
||||
this.PreviousHash = previousHash;
|
||||
}
|
||||
|
||||
public static SSDSegment FromStream(byte[] stream)
|
||||
{
|
||||
if (stream.Length != 16 * StgSharp.ssdSegmentLength)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
SSDSegment ret = new SSDSegment();
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
ret.Head.data = *(M128*)bptr;
|
||||
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
|
||||
{
|
||||
ret.WriteData<M128>(i - 1, *(M128*)(bptr + 16 * i));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return Data[index];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
Data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return Head.globalID; }
|
||||
set { Head.globalID = value; }
|
||||
}
|
||||
|
||||
public short Size => Head.size;
|
||||
|
||||
public void FillRandomBytes(int begin)
|
||||
{
|
||||
if (begin > 255)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = begin; i < 255; i++)
|
||||
{
|
||||
Data[i] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
fixed (byte* aptr = ret)
|
||||
{
|
||||
Vector4* vsptr = (Vector4*)mptr;
|
||||
Vector4* vtptr = (Vector4*)aptr;
|
||||
for (int i = 0; i < 18; i++)
|
||||
{
|
||||
*(vtptr + i) = *(vsptr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetDataHash()
|
||||
{
|
||||
Vector4 v = Vector4.One;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1)
|
||||
{
|
||||
v += (*vptr) * 31;
|
||||
}
|
||||
}
|
||||
M128 m = new M128(v);
|
||||
DataHash = m.vec.GetHashCode();
|
||||
return DataHash;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int ret = 17;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < StgSharp.ssdSegmentLength; i++)
|
||||
{
|
||||
ret = (ret + (*vptr).GetHashCode()) * 31;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe T ReadData<T>(int index) where T : struct
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
return *(tptr + index);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void WriteData<T>(int index, T value) where T : struct
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
*(tptr + index) = value;
|
||||
}
|
||||
}
|
||||
|
||||
int IComparable<int>.CompareTo(int other)
|
||||
{
|
||||
return ID.CompareTo(other);
|
||||
}
|
||||
|
||||
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
|
||||
{
|
||||
return ID.CompareTo(other.ID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="SSD.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public partial class SSD
|
||||
{
|
||||
private SSDrawHead head;
|
||||
|
||||
private Dictionary<string, SSDraw> fileList;
|
||||
|
||||
private FileStream file;
|
||||
|
||||
public SSD()
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
}
|
||||
|
||||
public SSD(FileStream fileStream)
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
file = fileStream;
|
||||
}
|
||||
|
||||
public static SSD FromFile(string fileRoute)
|
||||
{
|
||||
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read)) { };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="SSDVirtualFolder.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public class SSDFolder : ISSDSerializable
|
||||
{
|
||||
internal int _folderID;
|
||||
internal string _name;
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
|
||||
internal SSDFolder()
|
||||
{
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
internal SSDFolder(string name)
|
||||
{
|
||||
if (name == "root")
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Name cannot be root," +
|
||||
"it is preserved for root file indexer.");
|
||||
}
|
||||
if (name == "default")
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Name cannot be default," +
|
||||
"it is preserved for default file id provider.");
|
||||
}
|
||||
_name = name;
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
|
||||
|
||||
//TODO 虚拟文件夹的GetBytes好难写
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="SSDraw.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.ShaderEdit;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Data.FileIO
|
||||
{
|
||||
public class SSDraw
|
||||
{
|
||||
private byte[] data;
|
||||
|
||||
public SSDraw(string name, Stream streamSource)
|
||||
{
|
||||
if ((streamSource == null) || (streamSource.Length == 0))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(streamSource));
|
||||
}
|
||||
Name = name;
|
||||
data = new byte[streamSource.Length];
|
||||
streamSource.Read(data.AsSpan());
|
||||
}
|
||||
|
||||
public SSDrawHead Head { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
||||
public unsafe struct SSDrawHead
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Define.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A class contains a sets of methods to serialize several types
|
||||
/// </summary>
|
||||
public static partial class Serializer
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
|
||||
public interface ISSDSerializable
|
||||
{
|
||||
public SerializableTypeCode SSDTypeCode { get; }
|
||||
|
||||
public byte[] GetBytes();
|
||||
|
||||
internal void FromBytes(byte[] stream);
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode
|
||||
{
|
||||
Unknown = 0,
|
||||
IndexTable = 1,
|
||||
PixelImage = 2,
|
||||
VectorImage = 3,
|
||||
Audio = 4,
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = int.MaxValue,
|
||||
}
|
||||
|
||||
public static partial class Serializer
|
||||
{
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(byte[] stream)where T : ISSDSerializable
|
||||
{
|
||||
T serializableObject = (T)Activator.CreateInstance<T>();
|
||||
serializableObject.FromBytes(stream);
|
||||
return serializableObject;
|
||||
}
|
||||
|
||||
public static string GetNameTail(SerializableTypeCode typeCode)
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case SerializableTypeCode.IndexTable:
|
||||
return "_idt";
|
||||
case SerializableTypeCode.PixelImage:
|
||||
return "_pim";
|
||||
case SerializableTypeCode.VectorImage:
|
||||
return "_vim";
|
||||
case SerializableTypeCode.Audio:
|
||||
return "_wav";
|
||||
case SerializableTypeCode.Shader:
|
||||
return "_gls";
|
||||
case SerializableTypeCode.Text:
|
||||
return "_txt";
|
||||
case SerializableTypeCode.RawData:
|
||||
return "_raw";
|
||||
case SerializableTypeCode.VirtualFolder:
|
||||
return "_fod";
|
||||
default:
|
||||
throw new ArgumentException("Unknown file type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user