From 1279dc0a66cb36d788d9dd0c8b9ef4be854bc25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Thu, 28 Mar 2024 22:40:53 +0100 Subject: [PATCH] Implemented Copy for physics components --- .../src/World/Components/Components.bf | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/GlitchyEngine/src/World/Components/Components.bf b/GlitchyEngine/src/World/Components/Components.bf index fb1aae7..08f2bc1 100644 --- a/GlitchyEngine/src/World/Components/Components.bf +++ b/GlitchyEngine/src/World/Components/Components.bf @@ -344,7 +344,7 @@ namespace GlitchyEngine.World public SceneLight SceneLight; } - struct Rigidbody2DComponent : IDisposableComponent + struct Rigidbody2DComponent : IDisposableComponent, ICopyComponent { public enum BodyType { @@ -384,6 +384,13 @@ namespace GlitchyEngine.World [Inline] set mut => _runtimeBody = (int)(void*)value; } + + public static void Copy(Self* source, Self* target) + { + target._bodyType = source._bodyType; + target._fixedRotation = source._fixedRotation; + target._gravityScale = source._gravityScale; + } public BodyType BodyType { @@ -552,7 +559,7 @@ namespace GlitchyEngine.World } }*/ - struct BoxCollider2DComponent + struct BoxCollider2DComponent : ICopyComponent { public float2 Offset = .(0.0f, 0.0f); public float2 Size = .(0.5f, 0.5f); @@ -575,9 +582,18 @@ namespace GlitchyEngine.World [Inline] internal ref b2Vec2 b2Offset mut => ref *(Box2D.b2Vec2*)(void*)&Offset; + + public static void Copy(Self* source, Self* target) + { + target.Offset = source.Offset; + target.Density = source.Density; + target.Friction = source.Friction; + target.Restitution = source.Restitution; + target.RestitutionThreshold = source.RestitutionThreshold; + } } - struct CircleCollider2DComponent + struct CircleCollider2DComponent : ICopyComponent { public float2 Offset = .(0.0f, 0.0f); @@ -601,10 +617,20 @@ namespace GlitchyEngine.World [Inline] internal ref b2Vec2 b2Offset mut => ref *(Box2D.b2Vec2*)(void*)&Offset; + + public static void Copy(Self* source, Self* target) + { + target.Offset = source.Offset; + target.Radius = source.Radius; + target.Density = source.Density; + target.Friction = source.Friction; + target.Restitution = source.Restitution; + target.RestitutionThreshold = source.RestitutionThreshold; + } } // Todo: This component is rather large (> 1 Cache line) - struct PolygonCollider2DComponent + struct PolygonCollider2DComponent : ICopyComponent { public float2 Offset = .(0.0f, 0.0f); @@ -629,6 +655,16 @@ namespace GlitchyEngine.World [Inline] internal ref b2Vec2 b2Offset mut => ref *(Box2D.b2Vec2*)(void*)&Offset; + + public static void Copy(Self* source, Self* target) + { + target.Offset = source.Offset; + target.Density = source.Density; + target.Friction = source.Friction; + target.Restitution = source.Restitution; + target.Vertices = source.Vertices; + target.VertexCount = source.VertexCount; + } } struct ScriptComponent : IDisposableComponent