daily update on 20240514 by nitload youmu

This commit is contained in:
YoumuLiu
2024-05-14 15:41:22 +08:00
parent a3506c96a3
commit 2e57126ab7
75 changed files with 3572 additions and 198 deletions
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
+4
View File
@@ -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
;
+12
View File
@@ -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
}
}
+156
View File
@@ -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")]
+29 -3
View File
@@ -33,20 +33,40 @@ namespace StgSharp
VertexArray vao;
ElementBuffer ebo;
internal TimeSpanProvider spanProvider;
internal static vec3d DefaultRotation(TimeSpanProvider provider, out float rotation)
{
rotation = 0.1f;
float angle = provider.CurrentSpan * 0.1f;
return new vec3d(
0.01f * Scaler.Cos(angle),
- 0.01f * Scaler.Sin(angle),
0
);
}
protected override void Init()
{
spanProvider = new TimeSpanProvider(1 / 60.00f, TimeSpanProvider.DefaultProvider);
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
for (int i = 0; i < 10; i++)
{
float ai =Scaler.Abs(i - 5.0f);
for (int t = 0; t < 10; t++)
{
float at = Scaler.Abs(t - 5.0f);
ParticleOnPlain p = new ParticleOnPlain(buffer);
((IInstancing<ParticleOnPlain>)p).Coord = new vec3d(
(-5 + i) * 0.2f + 0.1f, (-5 + t) * 0.2f + 0.1f, 0);
((IInstancing<ParticleOnPlain>)p).Scale = Scaler.MinOf(i,t) * 0.2f;
((IInstancing<ParticleOnPlain>)p).Motion = GeometryMotion.DefaultMotion;
((IInstancing<ParticleOnPlain>)p).Scale =
Scaler.MinOf(ai, at) * 0.4f + 0.1f;
((IInstancing<ParticleOnPlain>)p).Motion = new GeometryMotion(
true,spanProvider,
DefaultRotation)
;
}
}
@@ -83,7 +103,7 @@ namespace StgSharp
ebo.SetValue(0, rec.Indices, BufferUsage.STATIC_DRAW);
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float),0);
vbo.WriteVectorData(1, buffer.CoordSpan,BufferUsage.STATIC_DRAW);
vbo.WriteVectorData(1, buffer.CoordSpan,BufferUsage.STREAM_DRAW);
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float), 3 * sizeof(float));
@@ -111,10 +131,16 @@ namespace StgSharp
protected override void Main(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
{
buffer.UpdateAllParticles();
GL.ClearColor(0.6f,0.1f,0.3f,1);
GL.Clear(MaskBufferBit.COLOR | MaskBufferBit.DEPTH);
vao.Bind(0);
vbo.Bind(1);
vbo.WriteVectorData(1, buffer.CoordSpan, BufferUsage.STREAM_DRAW);
s.Use();
NativeCamera.SetAllUniforms();
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[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("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/56459deec57aa5078d6bb5991dbf32f29c06e826/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/a3506c96a3f6c7df608c22594ca2eaec41efa511/*"}}