Skip to content

Commit

Permalink
Caching bounds for primary colliders instead of regenerating every frame
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed Jul 1, 2021
1 parent 6ba5f79 commit 5781a5d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ShipCombatCore/ShipCombatCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>Martin Evans</Authors>
<Product />
<Version>23.0.0</Version>
<Version>24.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SphereColliderPrimary

private readonly HashSet<SphereColliderPrimary> _queryResults = new();

public BoundingBox Bounds => new(new BoundingSphere(Position, Radius));
public BoundingBox Bounds { get; private set; }

public override void Initialise(INamedDataProvider? initialisationData)
{
Expand All @@ -40,6 +40,11 @@ public override void Initialise(INamedDataProvider? initialisationData)
_secondaryManager = Owner.Scene!.GetManager<SphereColliderSecondary.Manager>();
}

protected void InitialiseBounds()
{
Bounds = new(new BoundingSphere(Position, Radius));
}

public override void CreateProperties(Entity.ConstructionContext context)
{
_radius = context.CreateProperty(PropertyNames.SphereRadius);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion SpaceShipCombatSimulator/SpaceShipCombatSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Version>23.0.0</Version>
<Version>24.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 5781a5d

Please sign in to comment.