add mono c# (using dotnet9.0 from https://github.com/dotnet/runtime), add ECS (entt), add some c# code, add fastNoise

This commit is contained in:
2025-12-08 23:38:22 +08:00
parent 39378bf23c
commit 3ffb4cc449
341 changed files with 11747 additions and 262 deletions

View File

@ -0,0 +1,75 @@
using System.Runtime.InteropServices;
namespace Prism
{
[StructLayout(LayoutKind.Explicit)]
public struct Mat4
{
[FieldOffset( 0)] public float D00;
[FieldOffset( 4)] public float D10;
[FieldOffset( 8)] public float D20;
[FieldOffset(12)] public float D30;
[FieldOffset(16)] public float D01;
[FieldOffset(20)] public float D11;
[FieldOffset(24)] public float D21;
[FieldOffset(28)] public float D31;
[FieldOffset(32)] public float D02;
[FieldOffset(36)] public float D12;
[FieldOffset(40)] public float D22;
[FieldOffset(44)] public float D32;
[FieldOffset(48)] public float D03;
[FieldOffset(52)] public float D13;
[FieldOffset(56)] public float D23;
[FieldOffset(60)] public float D33;
public Mat4(float value)
{
D00 = value; D10 = 0.0f; D20 = 0.0f; D30 = 0.0f;
D01 = 0.0f; D11 = value; D21 = 0.0f; D31 = 0.0f;
D02 = 0.0f; D12 = 0.0f; D22 = value; D32 = 0.0f;
D03 = 0.0f; D13 = 0.0f; D23 = 0.0f; D33 = value;
}
public Vec3 Translation
{
get { return new Vec3(D03, D13, D23); }
set { D03 = value.X; D13 = value.Y; D23 = value.Z; }
}
public static Mat4 Translate(Vec3 translation)
{
Mat4 result = new Mat4(1.0f);
result.D03 = translation.X;
result.D13 = translation.Y;
result.D23 = translation.Z;
return result;
}
public static Mat4 Scale(Vec3 scale)
{
Mat4 result = new Mat4(1.0f);
result.D00 = scale.X;
result.D11 = scale.Y;
result.D22 = scale.Z;
return result;
}
public static Mat4 Scale(float scale)
{
Mat4 result = new Mat4(1.0f);
result.D00 = scale;
result.D11 = scale;
result.D22 = scale;
return result;
}
public void DebugPrint()
{
Console.WriteLine("{0:0.00} {1:0.00} {2:0.00} {3:0.00}", D00, D10, D20, D30);
Console.WriteLine("{0:0.00} {1:0.00} {2:0.00} {3:0.00}", D01, D11, D21, D31);
Console.WriteLine("{0:0.00} {1:0.00} {2:0.00} {3:0.00}", D02, D12, D22, D32);
Console.WriteLine("{0:0.00} {1:0.00} {2:0.00} {3:0.00}", D03, D13, D23, D33);
}
}
}

View File

@ -0,0 +1,16 @@
using System.Runtime.CompilerServices;
namespace Prism
{
public static class Noise
{
public static float PerlinNoise(float x, float y)
{
return PerlinNoise_Native(x, y);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float PerlinNoise_Native(float x, float y);
}
}

View File

@ -0,0 +1,22 @@
using System.Runtime.InteropServices;
namespace Prism
{
[StructLayout(LayoutKind.Sequential)]
public struct Vec2
{
public float X;
public float Y;
public Vec2(float scalar)
{
X = Y = scalar;
}
public Vec2(float x, float y)
{
X = x;
Y = y;
}
}
}

View File

@ -0,0 +1,26 @@
using System.Runtime.InteropServices;
namespace Prism
{
[StructLayout(LayoutKind.Explicit)]
public struct Vec3
{
[FieldOffset(0)] public float X;
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
public Vec3(float scalar)
{
X = Y = Z = scalar;
}
public Vec3(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
}
}

View File

@ -0,0 +1,69 @@
using System.Runtime.InteropServices;
namespace Prism
{
[StructLayout(LayoutKind.Explicit)]
public struct Vec4
{
[FieldOffset(0)] public float X;
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
[FieldOffset(12)] public float W;
public Vec4(float scalar)
{
X = Y = Z = W =scalar;
}
public Vec4(float x, float y, float z, float w)
{
X = x;
Y = y;
Z = z;
W = w;
}
public static Vec4 operator+(Vec4 left, Vec4 right)
{
return new Vec4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
}
public static Vec4 operator-(Vec4 left, Vec4 right)
{
return new Vec4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
}
public static Vec4 operator*(Vec4 left, Vec4 right)
{
return new Vec4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W);
}
public static Vec4 operator *(Vec4 left, float scalar)
{
return new Vec4(left.X * scalar, left.Y * scalar, left.Z * scalar, left.W * scalar);
}
public static Vec4 operator *(float scalar, Vec4 right)
{
return new Vec4(scalar * right.X, scalar * right.Y, scalar * right.Z, scalar * right.W);
}
public static Vec4 operator/(Vec4 left, Vec4 right)
{
return new Vec4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W);
}
public static Vec4 operator /(Vec4 left, float scalar)
{
return new Vec4(left.X / scalar, left.Y / scalar, left.Z / scalar, left.W / scalar);
}
public static Vec4 Lerp(Vec4 a, Vec4 b, float t)
{
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
return (1.0f - t) * a + t * b;
}
}
}