Weiß ich nicht, ist Monate her...

This commit is contained in:
Simon Lübeß
2023-05-30 16:54:57 +02:00
parent 5855b13873
commit 6a59deb9e2
20 changed files with 1021 additions and 234 deletions
-44
View File
@@ -1,44 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using GlitchyEngine.Math;
namespace GlitchyEngine;
public class CSharpTesting
{
public float MyPublicFloatVar = 5.0f;
public CSharpTesting()
{
Console.WriteLine("Hallo von C#!");
DoSomething();
Console.WriteLine(Sample());
Vector3 a = new Vector3(1, 2, 3);
Vector3 b = new Vector3(3, 2, 1);
Vector3 result;
//Vector3.Add_Internal(a, b, out result);
//Console.WriteLine(result);
}
[DllImport ("__Internal", EntryPoint="DoSomething")]
static extern void DoSomething();
[MethodImpl(MethodImplOptions.InternalCall)]
static extern string Sample();
public void PrintFloatVar()
{
Console.WriteLine("MyPublicFloatVar = {0:F}", MyPublicFloatVar);
}
private float IncrementFloatVar(float value)
{
MyPublicFloatVar += value;
return MyPublicFloatVar;
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
namespace GlitchyEngine.Editor;
//public sealed class RangeAttribute : Attribute
//{
// public float Min { get; set; }
// public float Max { get; set; }
// public RangeAttribute(float min, float max)
// {
// Min = min;
// Max = max;
// }
//}
@@ -0,0 +1,11 @@
using System;
namespace GlitchyEngine.Editor;
public sealed class ShowInEditorAttribute : Attribute
{
public string DisplayName { get; set; } = null;
public ShowInEditorAttribute()
{}
}
+155
View File
@@ -0,0 +1,155 @@
using System;
using System.Runtime.CompilerServices;
namespace GlitchyEngine.Math;
public struct Vector4
{
//public static readonly Vector3 Zero = new(0.0f, 0.0f, 0.0f);
//public static readonly Vector3 UnitX = new(1.0f, 0.0f, 0.0f);
//public static readonly Vector3 UnitY = new(0.0f, 1.0f, 0.0f);
//public static readonly Vector3 UnitZ = new(0.0f, 0.0f, 1.0f);
//public static readonly Vector3 One = new(0.0f, 0.0f, 0.0f);
//public static readonly Vector3 Forward = new(0.0f, 0.0f, 1.0f);
//public static readonly Vector3 Backward = new(0.0f, 0.0f, -1.0f);
//public static readonly Vector3 Left = new(-1.0f, 0.0f, 0.0f);
//public static readonly Vector3 Right = new(1.0f, 0.0f, 0.0f);
//public static readonly Vector3 Up = new(0.0f, 1.0f, 0.0f);
//public static readonly Vector3 Down = new(0.0f, -1.0f, 0.0f);
public const int ComponentCount = 4;
public float X, Y, Z, W;
public Vector4()
{
X = Y = Z = W = 0.0f;
}
public Vector4(float x, float y, float z, float w)
{
X = x;
Y = y;
Z = z;
W = w;
}
public Vector4(Vector2 xy, Vector2 zw)
{
X = xy.X;
Y = xy.Y;
Z = zw.X;
W = zw.Y;
}
public Vector4(Vector3 xyz, float w)
{
X = xyz.X;
Y = xyz.Y;
Z = xyz.Z;
W = w;
}
public float this[int index]
{
get
{
switch (index)
{
case 0: return X;
case 1: return Y;
case 2: return Z;
case 3: return W;
default: throw new IndexOutOfRangeException();
}
}
set
{
switch (index)
{
case 0:
X = value;
break;
case 1:
Y = value;
break;
case 2:
Z = value;
break;
case 3:
W = value;
break;
default: throw new IndexOutOfRangeException();
}
}
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator +(in Vector3 a, in Vector3 b) => new(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator +(float a, in Vector3 b) => new(a + b.X, a + b.Y, a + b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator +(in Vector3 a, float b) => new(a.X + b, a.Y + b, a.Z + b);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator +(in Vector3 a) => a;
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator -(in Vector3 a, in Vector3 b) => new(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator -(float a, in Vector3 b) => new(a - b.X, a - b.Y, a - b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator -(in Vector3 a, float b) => new(a.X - b, a.Y - b, a.Z - b);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator -(in Vector3 a) => new Vector3(-a.X, -a.Y, -a.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator *(in Vector3 a, in Vector3 b) => new(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator *(float a, in Vector3 b) => new(a * b.X, a * b.Y, a * b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator *(in Vector3 a, float b) => new(a.X * b, a.Y * b, a.Z * b);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator /(in Vector3 a, in Vector3 b) => new(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator /(float a, in Vector3 b) => new(a / b.X, a / b.Y, a / b.Z);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static Vector3 operator /(in Vector3 a, float b) => new(a.X / b, a.Y / b, a.Z / b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Vector4 a, Vector4 b)
{
float diffX = a.X - b.X;
float diffY = a.Y - b.Y;
float diffZ = a.Z - b.Z;
float diffW = a.W - b.W;
return diffX * diffX + diffY * diffY + diffZ * diffZ + diffW * diffW < 0.00001f;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Vector4 a, Vector4 b)
{
return !(a == b);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = X.GetHashCode();
hashCode = (hashCode * 397) ^ Y.GetHashCode();
hashCode = (hashCode * 397) ^ Z.GetHashCode();
hashCode = (hashCode * 397) ^ Z.GetHashCode();
return hashCode;
}
}
public override string ToString()
{
return $"X:{X}, Y:{Y}, Z:{Z}, W:{W}";
}
}
-59
View File
@@ -1,59 +0,0 @@
using System;
using GlitchyEngine.Math;
namespace GlitchyEngine;
class MyTestEntity : Entity
{
RigidBody2D _rigidBody;
/// <summary>
/// Called after the script component was created. (The entity might not be fully created yet)
/// </summary>
void OnCreate()
{
Log.Info($"Create! {UUID}");
_rigidBody ??= GetComponent<RigidBody2D>() ?? AddComponent<RigidBody2D>();
}
/// <summary>
/// Called every frame.
/// </summary>
/// <param name="deltaTime"></param>
void OnUpdate(float deltaTime)
{
Vector2 force = Vector2.Zero;
if (Input.IsKeyPressed(Key.A))
{
force.X -= 1000 * deltaTime;
}
if (Input.IsKeyPressed(Key.D))
{
force.X += 1000 * deltaTime;
}
if (Input.IsKeyPressing(Key.Space))
{
force.Y += 2000;
}
_rigidBody.ApplyForceToCenter(force);
//if (Input.IsMouseButtonReleasing(MouseButton.MiddleButton))
//{
// Log.Info("Ouha!");
// Physics2D.Gravity *= new Vector2(1, -1);
//}
}
/// <summary>
/// Called before the component is being destroyed.
/// </summary>
void OnDestroy()
{
Log.Trace("Destroy");
}
}
+3 -2
View File
@@ -48,15 +48,16 @@
<Compile Include="Components\Transform.cs" />
<Compile Include="Core\EngineObject.cs" />
<Compile Include="Core\UUID.cs" />
<Compile Include="CSharpTesting.cs" />
<Compile Include="Editor\RangeAttribute.cs" />
<Compile Include="Editor\ShowInEditorAttribute.cs" />
<Compile Include="Entity.cs" />
<Compile Include="Input.cs" />
<Compile Include="Key.cs" />
<Compile Include="Log.cs" />
<Compile Include="Math\Vector2.cs" />
<Compile Include="Math\Vector4.cs" />
<Compile Include="Math\Vector3.cs" />
<Compile Include="MouseButton.cs" />
<Compile Include="MyTestEntity.cs" />
<Compile Include="Physics2D.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptGlue.cs" />