From 5781a5d280a328c1d1dec186d5a7ce62e64e80bb Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Thu, 1 Jul 2021 21:03:48 +0100 Subject: [PATCH] Caching bounds for primary colliders instead of regenerating every frame --- ShipCombatCore/ShipCombatCore.csproj | 2 +- .../Simulation/Behaviours/SphereColliderPrimary.cs | 8 +++++++- SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ShipCombatCore/ShipCombatCore.csproj b/ShipCombatCore/ShipCombatCore.csproj index 33b6284..5eea68a 100644 --- a/ShipCombatCore/ShipCombatCore.csproj +++ b/ShipCombatCore/ShipCombatCore.csproj @@ -6,7 +6,7 @@ netstandard2.1 Martin Evans - 23.0.0 + 24.0.0 diff --git a/ShipCombatCore/Simulation/Behaviours/SphereColliderPrimary.cs b/ShipCombatCore/Simulation/Behaviours/SphereColliderPrimary.cs index aa1726f..4ddad46 100644 --- a/ShipCombatCore/Simulation/Behaviours/SphereColliderPrimary.cs +++ b/ShipCombatCore/Simulation/Behaviours/SphereColliderPrimary.cs @@ -30,7 +30,7 @@ public class SphereColliderPrimary private readonly HashSet _queryResults = new(); - public BoundingBox Bounds => new(new BoundingSphere(Position, Radius)); + public BoundingBox Bounds { get; private set; } public override void Initialise(INamedDataProvider? initialisationData) { @@ -40,6 +40,11 @@ public override void Initialise(INamedDataProvider? initialisationData) _secondaryManager = Owner.Scene!.GetManager(); } + protected void InitialiseBounds() + { + Bounds = new(new BoundingSphere(Position, Radius)); + } + public override void CreateProperties(Entity.ConstructionContext context) { _radius = context.CreateProperty(PropertyNames.SphereRadius); @@ -95,6 +100,7 @@ public override void Add(SphereColliderPrimary behaviour) { base.Add(behaviour); + behaviour.InitialiseBounds(); var min = ToBucket(behaviour.Bounds.Min); var max = ToBucket(behaviour.Bounds.Max); diff --git a/SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj b/SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj index 36973e7..2562a4a 100644 --- a/SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj +++ b/SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj @@ -4,7 +4,7 @@ enable Exe net5.0 - 23.0.0 + 24.0.0