From efe517abeac6d8be86f1c6dbc5aa323cde642a60 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Tue, 4 Oct 2022 09:34:23 -0700 Subject: [PATCH] x) Implement SizeOf x) And clamp and PerlinToContinent x) Optimize loaded scripts as Release --- Utilities.Interop.cs | 2 +- math/fn.cs | 39 +++++++++++++++++++++++++++++++++++++++ scr/Script.cs | 7 ++----- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Utilities.Interop.cs b/Utilities.Interop.cs index de5d43b..2c88928 100644 --- a/Utilities.Interop.cs +++ b/Utilities.Interop.cs @@ -144,7 +144,7 @@ namespace lib [MethodImpl( MethodImplOptions.AggressiveInlining )] public static int SizeOf() { - throw new NotImplementedException(); + return System.Runtime.InteropServices.Marshal.SizeOf(typeof( T )); } public static unsafe void* Write( void* pDest, ref T data ) where T : struct diff --git a/math/fn.cs b/math/fn.cs index c895e2f..7d587ec 100644 --- a/math/fn.cs +++ b/math/fn.cs @@ -32,6 +32,45 @@ namespace math static public class fn { + + static public float Clamp( float v, float min, float max ) + { + return v < min ? min : v > max ? max : v; + } + + //Tracked these down in Desmos + static public float s_a = 0.0f; + static public float s_b = 0.155f; + static public float s_c = 1.03f; + static public float s_d = 6.13f; + static public float s_f = -10.2f; + static public float s_g = 4.06f; + + static public float Quintic( float v ) + { + var vv = v * v; + var vvv = vv * v; + var vvvv = vvv * v; + var vvvvv= vvvv * v; + + var res = s_a + s_b*v + s_c*vv + s_d*vvv + s_f*vvvv + s_g * vvvvv; + + return res; + } + + static public float s_p = 0.37f; + static public float s_o = 0.15f; + static public float s_m = 2.11f; + static public float s_n = -0.57f; + + static public float PerlinToContinent( float h ) + { + var res = Quintic( s_m * h + s_n ) * s_o + s_p; + + return res; + } + + static public float SmoothStepCos( float v ) { var dV = (double)v; diff --git a/scr/Script.cs b/scr/Script.cs index 1412b03..cf8ec5f 100644 --- a/scr/Script.cs +++ b/scr/Script.cs @@ -196,8 +196,6 @@ public static class scr { var fullpath = Path.GetFullPath( filename ); - //string text = System.IO.File.ReadAllText( fullpath ); - var stream = File.OpenRead( fullpath ); var sourceText = SourceText.From( stream ); @@ -221,8 +219,6 @@ public static class scr SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText( sourceText, options, uniquePath ); - //SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(sourceText, options, uniquePath, encoding: System.Text.Encoding.UTF8); - var memRef = new MemoryRefResolver(); @@ -266,13 +262,14 @@ public static class scr { var memRef = new MemoryRefResolver(); + // @@@@ TODO :: Config release / debug CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, syntaxTrees: syntaxTrees, references: RefCache.References, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, sourceReferenceResolver: memRef, - optimizationLevel: OptimizationLevel.Debug, + optimizationLevel: OptimizationLevel.Release, platform: platform, specificDiagnosticOptions: new Dictionary {