Skip to content

Commit

Permalink
[Physics] Replace ColliderShapes' TrackingCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Eideren committed May 24, 2019
1 parent 755810d commit 494b235
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions sources/engine/Xenko.Physics/Engine/PhysicsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ protected PhysicsComponent()
{
CanScaleShape = true;

ColliderShapes = new TrackingCollection<IInlineColliderShapeDesc>();
ColliderShapes.CollectionChanged += (sender, args) =>
{
ColliderShapeChanged = true;
};
ColliderShapes = new ColliderShapeCollection(this);

NewPairChannel = new Channel<Collision> { Preference = ChannelPreference.PreferSender };
PairEndedChannel = new Channel<Collision> { Preference = ChannelPreference.PreferSender };
Expand All @@ -61,7 +57,7 @@ protected PhysicsComponent()
[DataMember(200)]
[Category]
[MemberCollection(NotNullItems = true)]
public TrackingCollection<IInlineColliderShapeDesc> ColliderShapes { get; }
public ColliderShapeCollection ColliderShapes { get; }

/// <summary>
/// Gets or sets the collision group.
Expand Down Expand Up @@ -816,5 +812,44 @@ public bool IsIgnoringCollisionWith(PhysicsComponent other)
{
return ! NativeCollisionObject.CheckCollideWith(other.NativeCollisionObject);
}

[DataContract]
public class ColliderShapeCollection : FastCollection<IInlineColliderShapeDesc>
{
PhysicsComponent component;

public ColliderShapeCollection(PhysicsComponent componentParam)
{
component = componentParam;
}

/// <inheritdoc/>
protected override void InsertItem(int index, IInlineColliderShapeDesc item)
{
base.InsertItem(index, item);
component.ColliderShapeChanged = true;
}

/// <inheritdoc/>
protected override void RemoveItem(int index)
{
base.RemoveItem(index);
component.ColliderShapeChanged = true;
}

/// <inheritdoc/>
protected override void ClearItems()
{
base.ClearItems();
component.ColliderShapeChanged = true;
}

/// <inheritdoc/>
protected override void SetItem(int index, IInlineColliderShapeDesc item)
{
base.SetItem(index, item);
component.ColliderShapeChanged = true;
}
}
}
}

0 comments on commit 494b235

Please sign in to comment.