Daily update on 20250414-003153 by Nitload Youmu. Additional Message : Tech Issue: due to forbidden of multi-inheritance in C#, full ranslate fron EXPRESS to C# code is impossible, the EXPRESS interpreter in StgSharp will become a dialect

Add: A group of classes imported from lib https://github.com/ixmilia/step under MIT license, representing all STEP AP203 geometry objects
Change: many change to classes from https://github.com/ixmilia/step to link data interfaces to those in StgSharp
Freeze: implementation to StgSharp EXPRESS interpreter about collextion operation and element define grammer

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-04-14 00:31:54 +08:00
parent 2692495dc8
commit 9457309c5a
69 changed files with 3318 additions and 117 deletions
+37 -66
View File
@@ -32,42 +32,34 @@ using StgSharp.HighPerformance;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Serialization;
namespace StgSharp.Data
{
public class RandomGenerator
public unsafe class RandomGenerator
{
private byte[] currentKey;
private readonly byte[] originKey;
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 );
}
ArgumentNullException.ThrowIfNull( source );
XmlSerializer s = new XmlSerializer( source.GetType() );
using( StringWriter sw = new StringWriter() )
{
s.Serialize( sw, source );
string data = sw.ToString();
originKey = Encoding.Unicode.GetBytes( data );
}
catch( Exception ) {
throw;
currentKey = [0,0,0,0];
fixed( byte* o = originKey, c = currentKey ) {
*( int* )c = UnsafeCompute.CityHashSimplify( ( char* )o, 0, originKey.Length / 2 );
}
hash = SHA512.Create();
originKey = hash.ComputeHash( originKey );
currentKey = originKey;
cycleCount = 0;
}
@@ -78,53 +70,45 @@ namespace StgSharp.Data
public unsafe int GenRandomInt()
{
M128 source = PrivateRand();
uint 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 );
M64 m = new M64();
m.Write<uint>( 0, source );
m.Write<uint>( 1, source );
return ( m << ( cycleCount % 32 ) ).Read<int>( 1 );
}
public byte GenRandomInt8()
{
cycleCount++;
if( cycleCount % 64 == 0 ) {
if( cycleCount % 4 == 0 ) {
PrivateRand();
}
return currentKey[ cycleCount % 64 ];
return currentKey[ cycleCount % 4 ];
}
public float GenRandomSingle()
{
cycleCount++;
while( true ) {
M128 source = PrivateRand();
while( true )
{
uint
temp0 = source.Read<uint>( 0 ),
temp1 = source.Read<uint>( 2 );
temp0 = PrivateRand(),
temp1 = PrivateRand();
if( temp0 * temp1 != 0 ) {
if( temp0 * temp1 != 0 )
{
float ret = ( ( temp0 % temp1 ) * 1.0f ) / temp1;
if( ret < 0.335f ) {
if( ret < 0.335f )
{
ret = ret * ( ( ret * ( -0.7811934f ) ) + 1.4489113f );
} else {
} else
{
ret = ( ret * ( ( ret * ( -0.1158368f ) ) + 1.0580600f ) ) + 0.0590584f;
}
if( ret > 1 ) {
if( ret > 1 )
{
continue;
}
return ret;
@@ -138,27 +122,14 @@ namespace StgSharp.Data
cycleCount = 0;
}
private unsafe M128 PrivateRand()
private unsafe uint 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();
}
uint ret;
fixed( byte* bptr = currentKey )
{
*( int* )bptr = UnsafeCompute.CityHashSimplify(
( char* )bptr, currentKey.Length / 2 );
ret = *( uint* )bptr;
}
//Console.WriteLine(ret.ToString(16));
+1 -5
View File
@@ -65,11 +65,7 @@ namespace StgSharp.Geometries
public Vec3 Coord
{
get => coord;
set
{
coord = value;
coordVec.W = 1;
}
set { coord = value; }
}
}
+111
View File
@@ -0,0 +1,111 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M64.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.Drawing;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.HighPerformance
{
[StructLayout( LayoutKind.Explicit, Pack = 8 )]
public unsafe struct M64 : IRegisterType
{
[FieldOffset( 0 )] private fixed byte buffer[ 8 ];
[FieldOffset( 0 )] private ulong value;
public M64()
{
Unsafe.SkipInit( out this );
value = 0;
}
public ref T AsRef<T>() where T: struct,INumber<T>
{
return ref Unsafe.As<byte, T>( ref buffer[ 0 ] );
}
public override bool Equals( object obj )
{
return obj is M64 m64 && this == m64;
}
public override int GetHashCode()
{
return value.GetHashCode();
}
public T Read<T>( int index ) where T: struct, INumber<T>
{
return Unsafe.As<byte, T>( ref buffer[ index * sizeof( T ) ] );
}
public void Write<T>( int index, T value ) where T: struct, INumber<T>
{
Unsafe.As<byte, T>( ref buffer[ index * sizeof( T ) ] ) = value;
}
public static bool operator !=( M64 left, M64 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static M64 operator <<( M64 m, int shift )
{
return new M64
{
value = m.value << shift
};
}
public static bool operator ==( M64 left, M64 right )
{
return left.value == right.value;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static M64 operator >>( M64 m, int shift )
{
return new M64
{
value = m.value >> shift
};
}
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+148b0fed4a1abaaeaa3a28e7c7b088590805ebef")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2692495dc8460e1f60a2d073f162c5f526e1ba1b")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[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/148b0fed4a1abaaeaa3a28e7c7b088590805ebef/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/2692495dc8460e1f60a2d073f162c5f526e1ba1b/*"}}