daily update on 20240514 by nitload youmu
This commit is contained in:
@@ -42,12 +42,16 @@ namespace StgSharp.Math
|
||||
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
|
||||
;
|
||||
|
||||
|
||||
@@ -54,10 +54,18 @@ namespace StgSharp.Data
|
||||
|
||||
[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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +88,15 @@ namespace StgSharp.Data
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,17 @@ namespace StgSharp.Data
|
||||
internal abstract void BuildFromByteStream(byte[] stream);
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode:byte
|
||||
public enum SerializableTypeCode
|
||||
{
|
||||
IndexTable = 1,
|
||||
PixelImage = 2,
|
||||
VectorImage = 3,
|
||||
Audio = 4,
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = 8,
|
||||
Unknown = 0,
|
||||
IndexTable = 1,
|
||||
PixelImage = 2,
|
||||
VectorImage = 3,
|
||||
Audio = 4,
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = 8,
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
movement = motionDelegate;
|
||||
}
|
||||
sourceIsStatic = false;
|
||||
}
|
||||
|
||||
public bool IsIncrement
|
||||
@@ -71,12 +72,15 @@ namespace StgSharp.Geometries
|
||||
public unsafe void RunMotion(ref vec3d coord, ref float rotation)
|
||||
{
|
||||
float rot = 0;
|
||||
|
||||
vec3d vec;
|
||||
if (sourceIsStatic)
|
||||
{
|
||||
|
||||
vec = ((delegate*<TimeSpanProvider, out float, vec3d>)handle)(time, out rot);
|
||||
}
|
||||
else
|
||||
{
|
||||
vec = movement(time, out rot);
|
||||
}
|
||||
vec3d vec = ((delegate*<TimeSpanProvider, out float, vec3d>)handle)(time, out rot);
|
||||
|
||||
if (isIncrementMode)
|
||||
{
|
||||
@@ -89,6 +93,5 @@ namespace StgSharp.Geometries
|
||||
rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}//------------------------------- End of Class -------------------------------
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
(vec3d coord , float rotation) =(Coord, Rotation);
|
||||
Motion.RunMotion(ref coord, ref rotation);
|
||||
(Rotation, Coord) = (rotation, coord);
|
||||
(Coord,Rotation) = (coord, rotation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
@@ -43,7 +44,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainInstancingBuffer<T> : IDisposable where T : IInstancing<T>
|
||||
public class PlainInstancingBuffer<T> : IDisposable,IEnumerable<T> where T : IInstancing<T>
|
||||
{
|
||||
|
||||
private CoordinatePlain globalCorrdinnate;
|
||||
@@ -158,7 +159,7 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
foreach (var particle in instanceList)
|
||||
{
|
||||
|
||||
particle.Move();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,5 +189,21 @@ namespace StgSharp.Geometries
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
foreach (var item in instanceList)
|
||||
{
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
foreach (var item in instanceList)
|
||||
{
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Stg
|
||||
{
|
||||
public class CollisionTexture : glRenderStream
|
||||
{
|
||||
string vertexShader = "";
|
||||
|
||||
string fragmentShader = "";
|
||||
|
||||
public CollisionTexture(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] InputPortsName =>
|
||||
[
|
||||
"InstanceBufferList",
|
||||
];
|
||||
|
||||
protected override string[] OutputPortsName =>
|
||||
[
|
||||
""
|
||||
];
|
||||
|
||||
protected override void Deinit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Main(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void ProcessInput()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+56459deec57aa5078d6bb5991dbf32f29c06e826")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a3506c96a3f6c7df608c22594ca2eaec41efa511")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user