Skip to content
Permalink
Browse files

[Physics] Replace ColliderShapes' TrackingCollection

  • Loading branch information
Eideren committed May 24, 2019
1 parent 755810d commit 494b235316e61c2a2b43ea0baed5c69a09bc2743
Showing with 41 additions and 6 deletions.
  1. +41 −6 sources/engine/Xenko.Physics/Engine/PhysicsComponent.cs
@@ -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 };
@@ -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.
@@ -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.
You can’t perform that action at this time.