mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Wer weiß, was ich alles so gemacht hatte...
- Fixed crash caused by early ScriptEngine shutdown
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace GlitchyEngine.Math;
|
||||
|
||||
@@ -50,4 +51,67 @@ public struct Vector2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator +(in Vector2 a, in Vector2 b) => new(a.X + b.X, a.Y + b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator +(float a, in Vector2 b) => new(a + b.X, a + b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator +(in Vector2 a, float b) => new(a.X + b, a.Y + b);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator +(in Vector2 a) => a;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator -(in Vector2 a, in Vector2 b) => new(a.X - b.X, a.Y - b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator -(float a, in Vector2 b) => new(a - b.X, a - b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator -(in Vector2 a, float b) => new(a.X - b, a.Y - b);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator -(in Vector2 a) => new Vector2(-a.X, -a.Y);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator *(in Vector2 a, in Vector2 b) => new(a.X * b.X, a.Y * b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator *(float a, in Vector2 b) => new(a * b.X, a * b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator *(in Vector2 a, float b) => new(a.X * b, a.Y * b);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator /(in Vector2 a, in Vector2 b) => new(a.X / b.X, a.Y / b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator /(float a, in Vector2 b) => new(a / b.X, a / b.Y);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector2 operator /(in Vector2 a, float b) => new(a.X / b, a.Y / b);
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Vector2 a, Vector2 b)
|
||||
{
|
||||
float diffX = a.X - b.X;
|
||||
float diffY = a.Y - b.Y;
|
||||
|
||||
return diffX * diffX + diffY * diffY < 0.00001f;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Vector2 a, Vector2 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = X.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Y.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"X:{X}, Y:{Y}";
|
||||
}
|
||||
}
|
||||
+24
-32
@@ -13,48 +13,40 @@ class MyTestEntity : Entity
|
||||
void OnCreate()
|
||||
{
|
||||
Log.Info($"Create! {UUID}");
|
||||
|
||||
//_rigidBody = GetComponent<RigidBody2D>();
|
||||
RemoveComponent<RigidBody2D>();
|
||||
|
||||
_rigidBody ??= GetComponent<RigidBody2D>() ?? AddComponent<RigidBody2D>();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Called after the entity was created completely.
|
||||
///// </summary>
|
||||
//void OnInstantiate()
|
||||
//{
|
||||
// Log.Warning($"Instantiated!");
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame.
|
||||
/// </summary>
|
||||
/// <param name="deltaTime"></param>
|
||||
void OnUpdate(float deltaTime)
|
||||
{
|
||||
//Vector2 force = Vector2.Zero;
|
||||
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.LeftButton))
|
||||
if (Input.IsKeyPressed(Key.A))
|
||||
{
|
||||
Log.Info("Ouha!");
|
||||
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>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Allows changing the properties of the 2D physics simulation in the current scene.
|
||||
/// </summary>
|
||||
public static class Physics2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the gravity of the current scene.
|
||||
/// </summary>
|
||||
public static Vector2 Gravity
|
||||
{
|
||||
get
|
||||
{
|
||||
ScriptGlue.Physics2D_GetGravity(out Vector2 gravity);
|
||||
return gravity;
|
||||
}
|
||||
set => ScriptGlue.Physics2D_SetGravity(in value);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -43,4 +43,14 @@ internal static class ScriptGlue
|
||||
|
||||
#endregion RigidBody2D
|
||||
|
||||
#region Physics2D
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void Physics2D_GetGravity(out Vector2 gravity);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void Physics2D_SetGravity(in Vector2 gravity);
|
||||
|
||||
#endregion Physics2D
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user