Kind of prevent creating invalid colliders sometimes

This commit is contained in:
Simon Lübeß
2024-04-15 12:35:56 +02:00
parent d1fc33cb6d
commit bb7bc41e62
3 changed files with 21 additions and 5 deletions
@@ -640,8 +640,9 @@ namespace GlitchyEngine.World
public float Restitution = 0.0f; public float Restitution = 0.0f;
public float RestitutionThreshold = 0.5f; public float RestitutionThreshold = 0.5f;
public float2[8] Vertices = .(); // initialize with a well formed shape
public int8 VertexCount = 3; public float2[8] Vertices = .(.(-0.5f, -0.5f), .(0.5f, -0.5f), .(0.5f, 0.5f), .(-0.5f, 0.5f),);
public int8 VertexCount = 4;
private int _runtimeFixture = 0; private int _runtimeFixture = 0;
+13
View File
@@ -103,6 +103,19 @@ namespace GlitchyEngine.World
return component; return component;
} }
public T* AddComponent<T>(in T value) where T: struct, new, ICopyComponent<T>
{
Log.EngineLogger.AssertDebug(!HasComponent<T>(), scope $"Entity already has component.");
T* component = _scene._ecsWorld.AssignComponent<T>(_entity, value);
T.Copy(&value, component);
_scene.[Friend]OnComponentAdded(this, typeof(T), component);
return component;
}
public T* GetComponent<T>() where T: struct, new public T* GetComponent<T>() where T: struct, new
{ {
Log.EngineLogger.AssertDebug(HasComponent<T>(), "Entity doesn't have component!"); Log.EngineLogger.AssertDebug(HasComponent<T>(), "Entity doesn't have component!");
+4 -2
View File
@@ -240,12 +240,14 @@ namespace GlitchyEngine.World
if (!target.TryGetComponent<TComponent>(out targetComponent)) if (!target.TryGetComponent<TComponent>(out targetComponent))
{ {
targetComponent = target.AddComponent<TComponent>(); targetComponent = target.AddComponent<TComponent>(*sourceComponent);
} }
else
{
TComponent.Copy(sourceComponent, targetComponent); TComponent.Copy(sourceComponent, targetComponent);
} }
} }
}
/** /**
* Starts the scene. * Starts the scene.