diff --git a/documentation/NEXT_RELEASENOTES.txt b/documentation/NEXT_RELEASENOTES.txt index e3ad3b4..b304ef2 100644 --- a/documentation/NEXT_RELEASENOTES.txt +++ b/documentation/NEXT_RELEASENOTES.txt @@ -1,6 +1,11 @@ ## Breaking changes - Entity.Set, EntitySetSameAs and EntitySetSameAsWorld will now reenable the component if it was disabled +- renamed World.SubscribeComponentAdded to World.SubscribeEntityComponentAdded +- renamed World.SubscribeComponentChanged to World.SubscribeEntityComponentChanged +- renamed World.SubscribeComponentRemoved to World.SubscribeEntityComponentRemoved +- renamed World.SubscribeComponentEnabled to World.SubscribeEntityComponentEnabled +- renamed World.SubscribeComponentDisabled to World.SubscribeEntityComponentDisabled ## New features diff --git a/source/DefaultEcs.Extension/Hierarchy/HierarchyLevelSetter.cs b/source/DefaultEcs.Extension/Hierarchy/HierarchyLevelSetter.cs index 6c5113c..026b060 100644 --- a/source/DefaultEcs.Extension/Hierarchy/HierarchyLevelSetter.cs +++ b/source/DefaultEcs.Extension/Hierarchy/HierarchyLevelSetter.cs @@ -16,9 +16,9 @@ private HierarchyLevelSetter(World world) { _map = world.GetEntities().AsMultiMap(); - _addedSubscription = world.SubscribeComponentAdded(OnAdded); - _changedSubscription = world.SubscribeComponentChanged(OnChanged); - _removedSubscription = world.SubscribeComponentRemoved(OnRemoved); + _addedSubscription = world.SubscribeEntityComponentAdded(OnAdded); + _changedSubscription = world.SubscribeEntityComponentChanged(OnChanged); + _removedSubscription = world.SubscribeEntityComponentRemoved(OnRemoved); using EntitySet entities = world.GetEntities().With().AsSet(); diff --git a/source/DefaultEcs.Test/Command/EntityCommandRecorderTest.cs b/source/DefaultEcs.Test/Command/EntityCommandRecorderTest.cs index d6d19ab..8e7d7d6 100644 --- a/source/DefaultEcs.Test/Command/EntityCommandRecorderTest.cs +++ b/source/DefaultEcs.Test/Command/EntityCommandRecorderTest.cs @@ -374,7 +374,7 @@ public void NotifyChanged_Should_change_component_on_recorded_entity() Entity entity = world.CreateEntity(); entity.Set(true); - using IDisposable changed = world.SubscribeComponentChanged((in Entity e, in bool _, in bool _) => result = e); + using IDisposable changed = world.SubscribeEntityComponentChanged((in Entity e, in bool _, in bool _) => result = e); recorder.Record(entity).NotifyChanged(); @@ -390,7 +390,7 @@ public void NotifyChanged_Should_change_component_on_created_entity() using EntityCommandRecorder recorder = new(1024); using World world = new(); - using IDisposable changed = world.SubscribeComponentChanged((in Entity e, in bool _, in bool _) => result = e); + using IDisposable changed = world.SubscribeEntityComponentChanged((in Entity e, in bool _, in bool _) => result = e); EntityRecord record = recorder.Record(world).CreateEntity(); record.Set(true); diff --git a/source/DefaultEcs.Test/WorldTest.cs b/source/DefaultEcs.Test/WorldTest.cs index b3115e5..a18a440 100644 --- a/source/DefaultEcs.Test/WorldTest.cs +++ b/source/DefaultEcs.Test/WorldTest.cs @@ -525,56 +525,56 @@ public void SubscribeEntityDisposed_Should_call_handler_When_world_disposed() } [Fact] - public void SubscribeComponentAdded_Should_throw_When_action_is_null() + public void SubscribeEntityComponentAdded_Should_throw_When_action_is_null() { using World world = new(); Check - .ThatCode(() => world.SubscribeComponentAdded(null)) + .ThatCode(() => world.SubscribeEntityComponentAdded(null)) .Throws() .WithProperty(e => e.ParamName, "action"); } [Fact] - public void SubscribeComponentChanged_Should_throw_When_action_is_null() + public void SubscribeEntityComponentChanged_Should_throw_When_action_is_null() { using World world = new(); Check - .ThatCode(() => world.SubscribeComponentChanged(null)) + .ThatCode(() => world.SubscribeEntityComponentChanged(null)) .Throws() .WithProperty(e => e.ParamName, "action"); } [Fact] - public void SubscribeComponentRemoved_Should_throw_When_action_is_null() + public void SubscribeEntityComponentRemoved_Should_throw_When_action_is_null() { using World world = new(); Check - .ThatCode(() => world.SubscribeComponentRemoved(null)) + .ThatCode(() => world.SubscribeEntityComponentRemoved(null)) .Throws() .WithProperty(e => e.ParamName, "action"); } [Fact] - public void SubscribeComponentEnabled_Should_throw_When_action_is_null() + public void SubscribeEntityComponentEnabled_Should_throw_When_action_is_null() { using World world = new(); Check - .ThatCode(() => world.SubscribeComponentEnabled(null)) + .ThatCode(() => world.SubscribeEntityComponentEnabled(null)) .Throws() .WithProperty(e => e.ParamName, "action"); } [Fact] - public void SubscribeComponentDisabled_Should_throw_When_action_is_null() + public void SubscribeEntityComponentDisabled_Should_throw_When_action_is_null() { using World world = new(); Check - .ThatCode(() => world.SubscribeComponentDisabled(null)) + .ThatCode(() => world.SubscribeEntityComponentDisabled(null)) .Throws() .WithProperty(e => e.ParamName, "action"); } @@ -613,12 +613,12 @@ public void SubscribeWorldComponentRemoved_Should_throw_When_action_is_null() } [Fact] - public void SubscribeComponentAdded_Should_call_handler_When_component_added() + public void SubscribeEntityComponentAdded_Should_call_handler_When_component_added() { using World world = new(); Entity entity = world.CreateEntity(); bool called = false; - using IDisposable subscription = world.SubscribeComponentAdded((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentAdded((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -630,25 +630,25 @@ public void SubscribeComponentAdded_Should_call_handler_When_component_added() } [Fact] - public void SubscribeComponentAdded_Should_not_throw_When_removing_component() + public void SubscribeEntityComponentAdded_Should_not_throw_When_removing_component() { using World world = new(); Entity entity = world.CreateEntity(); - using IDisposable subscription1 = world.SubscribeComponentChanged((in Entity _, in bool _, in bool _) => { }); - using IDisposable subscription2 = world.SubscribeComponentAdded((in Entity e, in bool _) => e.Remove()); + using IDisposable subscription1 = world.SubscribeEntityComponentChanged((in Entity _, in bool _, in bool _) => { }); + using IDisposable subscription2 = world.SubscribeEntityComponentAdded((in Entity e, in bool _) => e.Remove()); Check.ThatCode(() => entity.Set(true)).DoesNotThrow(); } [Fact] - public void SubscribeComponentEnabled_Should_call_handler_When_component_enabled() + public void SubscribeEntityComponentEnabled_Should_call_handler_When_component_enabled() { using World world = new(); Entity entity = world.CreateEntity(); entity.Set(true); entity.Disable(); bool called = false; - using IDisposable subscription = world.SubscribeComponentEnabled((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentEnabled((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -660,13 +660,13 @@ public void SubscribeComponentEnabled_Should_call_handler_When_component_enabled } [Fact] - public void SubscribeComponentDisabled_Should_call_handler_When_component_disabled() + public void SubscribeEntityComponentDisabled_Should_call_handler_When_component_disabled() { using World world = new(); Entity entity = world.CreateEntity(); entity.Set(true); bool called = false; - using IDisposable subscription = world.SubscribeComponentDisabled((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentDisabled((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -678,12 +678,12 @@ public void SubscribeComponentDisabled_Should_call_handler_When_component_disabl } [Fact] - public void SubscribeComponentRemoved_Should_call_handler_When_component_removed() + public void SubscribeEntityComponentRemoved_Should_call_handler_When_component_removed() { using World world = new(); Entity entity = world.CreateEntity(); bool called = false; - using IDisposable subscription = world.SubscribeComponentRemoved((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentRemoved((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -696,13 +696,13 @@ public void SubscribeComponentRemoved_Should_call_handler_When_component_removed } [Fact] - public void SubscribeComponentRemoved_Should_call_handler_When_entity_disposed() + public void SubscribeEntityComponentRemoved_Should_call_handler_When_entity_disposed() { using World world = new(); Entity entity = world.CreateEntity(); entity.Set(true); bool called = false; - using IDisposable subscription = world.SubscribeComponentRemoved((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentRemoved((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -714,13 +714,13 @@ public void SubscribeComponentRemoved_Should_call_handler_When_entity_disposed() } [Fact] - public void SubscribeComponentRemoved_Should_call_handler_When_world_disposed() + public void SubscribeEntityComponentRemoved_Should_call_handler_When_world_disposed() { World world = new(); Entity entity = world.CreateEntity(); entity.Set(true); bool called = false; - using IDisposable subscription = world.SubscribeComponentRemoved((in Entity e, in bool v) => + using IDisposable subscription = world.SubscribeEntityComponentRemoved((in Entity e, in bool v) => { Check.That(e).IsEqualTo(entity); Check.That(v).IsTrue(); @@ -732,13 +732,13 @@ public void SubscribeComponentRemoved_Should_call_handler_When_world_disposed() } [Fact] - public void SubscribeComponentChanged_Should_call_handler_When_component_changed() + public void SubscribeEntityComponentChanged_Should_call_handler_When_component_changed() { using World world = new(); Entity entity = world.CreateEntity(); entity.Set(false); bool called = false; - using IDisposable subscription = world.SubscribeComponentChanged((in Entity e, in bool ov, in bool nv) => + using IDisposable subscription = world.SubscribeEntityComponentChanged((in Entity e, in bool ov, in bool nv) => { Check.That(e).IsEqualTo(entity); Check.That(ov).IsFalse(); @@ -751,43 +751,43 @@ public void SubscribeComponentChanged_Should_call_handler_When_component_changed } [Fact] - public void SubscribeComponent_Should_do_nothing_When_entity_disposed_without_component() + public void SubscribeEntityComponent_Should_do_nothing_When_entity_disposed_without_component() { using World world = new(); Entity entity = world.CreateEntity(); - using IDisposable added = world.SubscribeComponentAdded((in Entity _, in bool _) => throw new Exception()); - using IDisposable changed = world.SubscribeComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()); - using IDisposable removed = world.SubscribeComponentRemoved((in Entity _, in bool _) => throw new Exception()); - using IDisposable enabled = world.SubscribeComponentEnabled((in Entity _, in bool _) => throw new Exception()); - using IDisposable disabled = world.SubscribeComponentDisabled((in Entity _, in bool _) => throw new Exception()); + using IDisposable added = world.SubscribeEntityComponentAdded((in Entity _, in bool _) => throw new Exception()); + using IDisposable changed = world.SubscribeEntityComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()); + using IDisposable removed = world.SubscribeEntityComponentRemoved((in Entity _, in bool _) => throw new Exception()); + using IDisposable enabled = world.SubscribeEntityComponentEnabled((in Entity _, in bool _) => throw new Exception()); + using IDisposable disabled = world.SubscribeEntityComponentDisabled((in Entity _, in bool _) => throw new Exception()); Check.ThatCode(entity.Dispose).DoesNotThrow(); } [Fact] - public void SubscribeComponent_Should_do_nothing_When_world_disposed_without_component() + public void SubscribeEntityComponent_Should_do_nothing_When_world_disposed_without_component() { World world = new(); Entity entity = world.CreateEntity(); - using IDisposable added = world.SubscribeComponentAdded((in Entity _, in bool _) => throw new Exception()); - using IDisposable changed = world.SubscribeComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()); - using IDisposable removed = world.SubscribeComponentRemoved((in Entity _, in bool _) => throw new Exception()); - using IDisposable enabled = world.SubscribeComponentEnabled((in Entity _, in bool _) => throw new Exception()); - using IDisposable disabled = world.SubscribeComponentDisabled((in Entity _, in bool _) => throw new Exception()); + using IDisposable added = world.SubscribeEntityComponentAdded((in Entity _, in bool _) => throw new Exception()); + using IDisposable changed = world.SubscribeEntityComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()); + using IDisposable removed = world.SubscribeEntityComponentRemoved((in Entity _, in bool _) => throw new Exception()); + using IDisposable enabled = world.SubscribeEntityComponentEnabled((in Entity _, in bool _) => throw new Exception()); + using IDisposable disabled = world.SubscribeEntityComponentDisabled((in Entity _, in bool _) => throw new Exception()); Check.ThatCode(world.Dispose).DoesNotThrow(); } [Fact] - public void SubscribeComponent_Should_do_nothing_When_subscription_disposed() + public void SubscribeEntityComponent_Should_do_nothing_When_subscription_disposed() { using World world = new(); Entity entity = world.CreateEntity(); - world.SubscribeComponentAdded((in Entity _, in bool _) => throw new Exception()).Dispose(); - world.SubscribeComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()).Dispose(); - world.SubscribeComponentRemoved((in Entity _, in bool _) => throw new Exception()).Dispose(); - world.SubscribeComponentEnabled((in Entity _, in bool _) => throw new Exception()).Dispose(); - world.SubscribeComponentDisabled((in Entity _, in bool _) => throw new Exception()).Dispose(); + world.SubscribeEntityComponentAdded((in Entity _, in bool _) => throw new Exception()).Dispose(); + world.SubscribeEntityComponentChanged((in Entity _, in bool _, in bool _) => throw new Exception()).Dispose(); + world.SubscribeEntityComponentRemoved((in Entity _, in bool _) => throw new Exception()).Dispose(); + world.SubscribeEntityComponentEnabled((in Entity _, in bool _) => throw new Exception()).Dispose(); + world.SubscribeEntityComponentDisabled((in Entity _, in bool _) => throw new Exception()).Dispose(); Check.ThatCode(() => entity.Set(true)).DoesNotThrow(); } @@ -891,7 +891,7 @@ public void TrimExcess_Should_fit_storage_of_component() Entity entity = world.CreateEntity(); entity.Set(42); entity.Dispose(); - world.SubscribeComponentChanged((in Entity _, in int __, in int ___) => { }); + world.SubscribeEntityComponentChanged((in Entity _, in int __, in int ___) => { }); world.TrimExcess(); diff --git a/source/DefaultEcs/Delegates.Entity.cs b/source/DefaultEcs/Delegates.Entity.cs new file mode 100644 index 0000000..4b23f74 --- /dev/null +++ b/source/DefaultEcs/Delegates.Entity.cs @@ -0,0 +1,79 @@ +namespace DefaultEcs +{ + /// + /// Represents the method that will called when an is created. + /// + /// The created . + public delegate void EntityCreatedHandler(in Entity entity); + + /// + /// Represents the method that will called when an is enabled. + /// + /// The enabled . + public delegate void EntityEnabledHandler(in Entity entity); + + /// + /// Represents the method that will called when an is disabled. + /// + /// The disabled . + public delegate void EntityDisabledHandler(in Entity entity); + + /// + /// Represents the method that will called when an is disposed. + /// + /// The disposed . + public delegate void EntityDisposedHandler(in Entity entity); + + /// + /// Represents the method that will called when a component of type is added on an . + /// + /// The type of the component added. + /// The on which the component was added. + /// The value of the component. + public delegate void EntityComponentAddedHandler(in Entity entity, in T value); + + /// + /// Represents the method that will called when a component of type is changed on an . + /// + /// The type of the component removed. + /// The on which the component was changed. + /// The previous value of the component. + /// The new value of the component. + public delegate void EntityComponentChangedHandler(in Entity entity, in T oldValue, in T newValue); + + /// + /// Represents the method that will called when a component of type is removed from an . + /// + /// The type of the component removed. + /// The on which the component was removed. + /// The value of the component. + public delegate void EntityComponentRemovedHandler(in Entity entity, in T value); + + /// + /// Represents the method that will called when a component of type is enabled on an . + /// + /// The type of the component enabled. + /// The on which the component was enabled. + /// The value of the component. + public delegate void EntityComponentEnabledHandler(in Entity entity, in T value); + + /// + /// Represents the method that will called when a component of type is disabled on an . + /// + /// The type of the component disabled. + /// The on which the component was disabled. + /// The value of the component. + public delegate void EntityComponentDisabledHandler(in Entity entity, in T value); + + /// + /// Represents the method that will called when an is added to a container. + /// + /// The added . + public delegate void EntityAddedHandler(in Entity entity); + + /// + /// Represents the method that will called when an is removed from a container. + /// + /// The removed . + public delegate void EntityRemovedHandler(in Entity entity); +} diff --git a/source/DefaultEcs/Delegates.World.cs b/source/DefaultEcs/Delegates.World.cs new file mode 100644 index 0000000..b666622 --- /dev/null +++ b/source/DefaultEcs/Delegates.World.cs @@ -0,0 +1,33 @@ +namespace DefaultEcs +{ + /// + /// Represents the method that will called when a is created. + /// + /// The dusposed . + public delegate void WorldDisposedHandler(World world); + + /// + /// Represents the method that will called when a component of type is added on a . + /// + /// The type of the component added. + /// The on which the component was added. + /// The value of the component. + public delegate void WorldComponentAddedHandler(World world, in T value); + + /// + /// Represents the method that will called when a component of type is changed on a . + /// + /// The type of the component removed. + /// The on which the component was changed. + /// The previous value of the component. + /// The new value of the component. + public delegate void WorldComponentChangedHandler(World world, in T oldValue, in T newValue); + + /// + /// Represents the method that will called when a component of type is removed from a . + /// + /// The type of the component removed. + /// The on which the component was removed. + /// The value of the component. + public delegate void WorldComponentRemovedHandler(World world, in T value); +} diff --git a/source/DefaultEcs/Delegates.cs b/source/DefaultEcs/Delegates.cs index 4793c2c..60c32c1 100644 --- a/source/DefaultEcs/Delegates.cs +++ b/source/DefaultEcs/Delegates.cs @@ -7,102 +7,6 @@ /// The parameter of the method that this delegate encapsulates. public delegate void MessageHandler(in T message); - /// - /// Represents the method that will called when a is created. - /// - /// The dusposed . - public delegate void WorldDisposedHandler(World world); - - /// - /// Represents the method that will called when an is created. - /// - /// The created . - public delegate void EntityCreatedHandler(in Entity entity); - - /// - /// Represents the method that will called when an is enabled. - /// - /// The enabled . - public delegate void EntityEnabledHandler(in Entity entity); - - /// - /// Represents the method that will called when an is disabled. - /// - /// The disabled . - public delegate void EntityDisabledHandler(in Entity entity); - - /// - /// Represents the method that will called when an is disposed. - /// - /// The disposed . - public delegate void EntityDisposedHandler(in Entity entity); - - /// - /// Represents the method that will called when a component of type is added on an . - /// - /// The type of the component added. - /// The on which the component was added. - /// The value of the component. - public delegate void ComponentAddedHandler(in Entity entity, in T value); - - /// - /// Represents the method that will called when a component of type is changed on an . - /// - /// The type of the component removed. - /// The on which the component was changed. - /// The previous value of the component. - /// The new value of the component. - public delegate void ComponentChangedHandler(in Entity entity, in T oldValue, in T newValue); - - /// - /// Represents the method that will called when a component of type is removed from an . - /// - /// The type of the component removed. - /// The on which the component was removed. - /// The value of the component. - public delegate void ComponentRemovedHandler(in Entity entity, in T value); - - /// - /// Represents the method that will called when a component of type is added on a . - /// - /// The type of the component added. - /// The on which the component was added. - /// The value of the component. - public delegate void WorldComponentAddedHandler(World world, in T value); - - /// - /// Represents the method that will called when a component of type is changed on a . - /// - /// The type of the component removed. - /// The on which the component was changed. - /// The previous value of the component. - /// The new value of the component. - public delegate void WorldComponentChangedHandler(World world, in T oldValue, in T newValue); - - /// - /// Represents the method that will called when a component of type is removed from a . - /// - /// The type of the component removed. - /// The on which the component was removed. - /// The value of the component. - public delegate void WorldComponentRemovedHandler(World world, in T value); - - /// - /// Represents the method that will called when a component of type is enabled on an . - /// - /// The type of the component enabled. - /// The on which the component was enabled. - /// The value of the component. - public delegate void ComponentEnabledHandler(in Entity entity, in T value); - - /// - /// Represents the method that will called when a component of type is disabled on an . - /// - /// The type of the component disabled. - /// The on which the component was disabled. - /// The value of the component. - public delegate void ComponentDisabledHandler(in Entity entity, in T value); - /// /// Represents the method that defines a set of criteria and determines whether the specified component meets those criteria. /// @@ -110,16 +14,4 @@ /// The component value. /// true if the component meets the criteria; otherwise, false. public delegate bool ComponentPredicate(in T value); - - /// - /// Represents the method that will called when an is added to a container. - /// - /// The added . - public delegate void EntityAddedHandler(in Entity entity); - - /// - /// Represents the method that will called when an is removed from a container. - /// - /// The removed . - public delegate void EntityRemovedHandler(in Entity entity); } diff --git a/source/DefaultEcs/Entity.cs b/source/DefaultEcs/Entity.cs index 6f9a725..fd4691c 100644 --- a/source/DefaultEcs/Entity.cs +++ b/source/DefaultEcs/Entity.cs @@ -86,16 +86,13 @@ private void InnerSet(bool isNew) if (isNew) { components[ComponentManager.Flag] = true; - Publisher.Publish(WorldId, new ComponentAddedMessage(EntityId, components)); - } - else if (components[ComponentManager.Flag]) - { - Publisher.Publish(WorldId, new ComponentChangedMessage(EntityId, components)); + Publisher.Publish(WorldId, new EntityComponentAddedMessage(EntityId, components)); } else { - components[ComponentManager.Flag] = true; - Publisher.Publish(WorldId, new ComponentEnabledMessage(EntityId, components)); + Publisher.Publish(WorldId, new EntityComponentChangedMessage(EntityId, components)); + + Enable(); } if (ComponentManager.GetPrevious(WorldId) is ComponentPool previousPool && Has()) @@ -170,7 +167,7 @@ public void Enable() if (!components[ComponentManager.Flag]) { components[ComponentManager.Flag] = true; - Publisher.Publish(WorldId, new ComponentEnabledMessage(EntityId, components)); + Publisher.Publish(WorldId, new EntityComponentEnabledMessage(EntityId, components)); } } } @@ -190,7 +187,7 @@ public void Disable() if (components[ComponentManager.Flag]) { components[ComponentManager.Flag] = false; - Publisher.Publish(WorldId, new ComponentDisabledMessage(EntityId, components)); + Publisher.Publish(WorldId, new EntityComponentDisabledMessage(EntityId, components)); } } @@ -266,7 +263,7 @@ public void Remove() { ref ComponentEnum components = ref Components; components[ComponentManager.Flag] = false; - Publisher.Publish(WorldId, new ComponentRemovedMessage(EntityId, components)); + Publisher.Publish(WorldId, new EntityComponentRemovedMessage(EntityId, components)); ComponentManager.GetPrevious(WorldId)?.Remove(EntityId); } } @@ -283,8 +280,12 @@ public void NotifyChanged() ThrowIf(WorldId == 0, "Entity was not created from a World"); ThrowIf(!Has(), $"Entity does not have a component of type {nameof(T)}"); - Publisher.Publish(WorldId, new ComponentChangedMessage(EntityId, Components)); - ComponentManager.GetPrevious(WorldId)?.Set(EntityId, Get()); + Publisher.Publish(WorldId, new EntityComponentChangedMessage(EntityId, Components)); + + if (ComponentManager.GetPrevious(WorldId) is ComponentPool previousPool && Has()) + { + previousPool.Set(EntityId, Get()); + } } /// diff --git a/source/DefaultEcs/EntityMap.cs b/source/DefaultEcs/EntityMap.cs index 77df17d..f77cd18 100644 --- a/source/DefaultEcs/EntityMap.cs +++ b/source/DefaultEcs/EntityMap.cs @@ -142,7 +142,7 @@ internal EntityMap( _worldMaxCapacity = world.MaxCapacity == int.MaxValue ? int.MaxValue : (world.MaxCapacity + 1); EntityContainerWatcher container = new(this, filter, predicate); _subscriptions = Enumerable - .Repeat(world.Subscribe>(On), 1) + .Repeat(world.Subscribe>(On), 1) .Concat(subscriptions.Select(s => s(container, world))) .Merge(); _previousComponents = ComponentManager.GetOrCreatePrevious(_worldId); @@ -168,7 +168,7 @@ internal EntityMap( #region Callbacks - private void On(in ComponentChangedMessage message) + private void On(in EntityComponentChangedMessage message) { if (message.EntityId < _entityIds.Length && _entityIds[message.EntityId] && _entities.Remove(_previousComponents.Get(message.EntityId))) { diff --git a/source/DefaultEcs/EntityMultiMap.cs b/source/DefaultEcs/EntityMultiMap.cs index 2c9a415..4e1ea86 100644 --- a/source/DefaultEcs/EntityMultiMap.cs +++ b/source/DefaultEcs/EntityMultiMap.cs @@ -249,7 +249,7 @@ internal EntityMultiMap( _worldMaxCapacity = world.MaxCapacity == int.MaxValue ? int.MaxValue : (world.MaxCapacity + 1); EntityContainerWatcher container = new(this, filter, predicate); _subscriptions = Enumerable - .Repeat(world.Subscribe>(On), 1) + .Repeat(world.Subscribe>(On), 1) .Concat(subscriptions.Select(s => s(container, world))) .Merge(); _components = ComponentManager.GetOrCreate(_worldId); @@ -281,7 +281,7 @@ internal EntityMultiMap( #region Callbacks - private void On(in ComponentChangedMessage message) + private void On(in EntityComponentChangedMessage message) { if (message.EntityId < _mapping.Length) { diff --git a/source/DefaultEcs/EntityQueryBuilder.cs b/source/DefaultEcs/EntityQueryBuilder.cs index 1160280..38c61fb 100644 --- a/source/DefaultEcs/EntityQueryBuilder.cs +++ b/source/DefaultEcs/EntityQueryBuilder.cs @@ -59,10 +59,10 @@ private EitherBuilder OrWith() if (!_builder._withEitherFilter[flag]) { _builder._withEitherFilter[flag] = true; - _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); + _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); } } @@ -78,10 +78,10 @@ private EitherBuilder OrWithout() if (!_builder._withoutEitherFilter[flag]) { _builder._withoutEitherFilter[flag] = true; - _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); + _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedRemove)); } } @@ -93,8 +93,8 @@ private EitherBuilder OrWhenAdded() if (!_builder._whenAddedFilter[ComponentManager.Flag]) { _builder._whenAddedFilter[ComponentManager.Flag] = true; - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } return OrWith(); @@ -107,7 +107,7 @@ private EitherBuilder OrWhenChanged() _builder._whenChangedFilter[ComponentManager.Flag] = true; if (!_builder._predicateFilter[ComponentManager.Flag]) { - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } } @@ -119,8 +119,8 @@ private EitherBuilder OrWhenRemoved() if (!_builder._whenRemovedFilter[ComponentManager.Flag]) { _builder._whenRemovedFilter[ComponentManager.Flag] = true; - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _builder._subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } return OrWithout(); @@ -386,10 +386,10 @@ public EntityQueryBuilder With() if (!_withFilter[ComponentManager.Flag]) { _withFilter[ComponentManager.Flag] = true; - _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); - _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); + _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); + _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); } return this; @@ -410,7 +410,7 @@ public EntityQueryBuilder With(ComponentPredicate predicate) _predicateFilter[ComponentManager.Flag] = true; if (!_whenChangedFilter[ComponentManager.Flag]) { - _subscriptions.Add((s, w) => w.Subscribe>(s.AddOrRemove)); + _subscriptions.Add((s, w) => w.Subscribe>(s.AddOrRemove)); } } @@ -429,10 +429,10 @@ public EntityQueryBuilder Without() if (!_withoutFilter[ComponentManager.Flag]) { _withoutFilter[ComponentManager.Flag] = true; - _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); - _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); + _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _nonReactSubscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); + _subscriptions.Add((s, w) => w.Subscribe>(s.Remove)); } return this; @@ -448,8 +448,8 @@ public EntityQueryBuilder WhenAdded() if (!_whenAddedFilter[ComponentManager.Flag]) { _whenAddedFilter[ComponentManager.Flag] = true; - _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } return With(); @@ -467,7 +467,7 @@ public EntityQueryBuilder WhenChanged() _whenChangedFilter[ComponentManager.Flag] = true; if (!_predicateFilter[ComponentManager.Flag]) { - _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } } @@ -484,8 +484,8 @@ public EntityQueryBuilder WhenRemoved() if (!_whenRemovedFilter[ComponentManager.Flag]) { _whenRemovedFilter[ComponentManager.Flag] = true; - _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); - _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); + _subscriptions.Add((s, w) => w.Subscribe>(s.CheckedAdd)); } return Without(); diff --git a/source/DefaultEcs/EntitySortedSet.cs b/source/DefaultEcs/EntitySortedSet.cs index fa1697d..975a6c5 100644 --- a/source/DefaultEcs/EntitySortedSet.cs +++ b/source/DefaultEcs/EntitySortedSet.cs @@ -58,7 +58,7 @@ internal EntitySortedSet( _worldMaxCapacity = world.MaxCapacity == int.MaxValue ? int.MaxValue : (world.MaxCapacity + 1); EntityContainerWatcher container = new(this, filter, predicate); _subscriptions = Enumerable - .Repeat(world.Subscribe>(On), 1) + .Repeat(world.Subscribe>(On), 1) .Concat(subscriptions.Select(s => s(container, world))) .Merge(); comparer ??= Comparer.Default; @@ -86,7 +86,7 @@ internal EntitySortedSet( #region Callbacks - private void On(in ComponentChangedMessage message) + private void On(in EntityComponentChangedMessage message) { if (message.EntityId < _mapping.Length && _mapping[message.EntityId] != -1) { diff --git a/source/DefaultEcs/Internal/EntityContainerWatcher.cs b/source/DefaultEcs/Internal/EntityContainerWatcher.cs index c3e0309..f537734 100644 --- a/source/DefaultEcs/Internal/EntityContainerWatcher.cs +++ b/source/DefaultEcs/Internal/EntityContainerWatcher.cs @@ -30,7 +30,7 @@ public EntityContainerWatcher(DefaultEcs.IEntityContainer container, Predicate _container.Add(message.EntityId); - public void AddOrRemove(in ComponentChangedMessage message) + public void AddOrRemove(in EntityComponentChangedMessage message) { if (_filter(message.Components)) { @@ -61,7 +61,7 @@ public void CheckedAdd(in EntityDisabledMessage message) } } - public void CheckedAdd(in ComponentAddedMessage message) + public void CheckedAdd(in EntityComponentAddedMessage message) { if (_filter(message.Components) && _predicate(message.EntityId)) { @@ -69,7 +69,7 @@ public void CheckedAdd(in ComponentAddedMessage message) } } - public void CheckedAdd(in ComponentChangedMessage message) + public void CheckedAdd(in EntityComponentChangedMessage message) { if (_filter(message.Components) && _predicate(message.EntityId)) { @@ -77,7 +77,7 @@ public void CheckedAdd(in ComponentChangedMessage message) } } - public void CheckedAdd(in ComponentRemovedMessage message) + public void CheckedAdd(in EntityComponentRemovedMessage message) { if (_filter(message.Components) && _predicate(message.EntityId)) { @@ -85,7 +85,7 @@ public void CheckedAdd(in ComponentRemovedMessage message) } } - public void CheckedAdd(in ComponentEnabledMessage message) + public void CheckedAdd(in EntityComponentEnabledMessage message) { if (_filter(message.Components) && _predicate(message.EntityId)) { @@ -93,7 +93,7 @@ public void CheckedAdd(in ComponentEnabledMessage message) } } - public void CheckedAdd(in ComponentDisabledMessage message) + public void CheckedAdd(in EntityComponentDisabledMessage message) { if (_filter(message.Components) && _predicate(message.EntityId)) { @@ -107,15 +107,15 @@ public void CheckedAdd(in ComponentDisabledMessage message) public void Remove(in EntityDisabledMessage message) => _container.Remove(message.EntityId); - public void Remove(in ComponentAddedMessage message) => _container.Remove(message.EntityId); + public void Remove(in EntityComponentAddedMessage message) => _container.Remove(message.EntityId); - public void Remove(in ComponentRemovedMessage message) => _container.Remove(message.EntityId); + public void Remove(in EntityComponentRemovedMessage message) => _container.Remove(message.EntityId); - public void Remove(in ComponentEnabledMessage message) => _container.Remove(message.EntityId); + public void Remove(in EntityComponentEnabledMessage message) => _container.Remove(message.EntityId); - public void Remove(in ComponentDisabledMessage message) => _container.Remove(message.EntityId); + public void Remove(in EntityComponentDisabledMessage message) => _container.Remove(message.EntityId); - public void CheckedRemove(in ComponentAddedMessage message) + public void CheckedRemove(in EntityComponentAddedMessage message) { if (!_filter(message.Components)) { @@ -123,7 +123,7 @@ public void CheckedRemove(in ComponentAddedMessage message) } } - public void CheckedRemove(in ComponentRemovedMessage message) + public void CheckedRemove(in EntityComponentRemovedMessage message) { if (!_filter(message.Components)) { @@ -131,7 +131,7 @@ public void CheckedRemove(in ComponentRemovedMessage message) } } - public void CheckedRemove(in ComponentEnabledMessage message) + public void CheckedRemove(in EntityComponentEnabledMessage message) { if (!_filter(message.Components)) { @@ -139,7 +139,7 @@ public void CheckedRemove(in ComponentEnabledMessage message) } } - public void CheckedRemove(in ComponentDisabledMessage message) + public void CheckedRemove(in EntityComponentDisabledMessage message) { if (!_filter(message.Components)) { diff --git a/source/DefaultEcs/Internal/Messages/ComponentAddedMessage.cs b/source/DefaultEcs/Internal/Messages/ComponentAddedMessage.cs deleted file mode 100644 index 48fb480..0000000 --- a/source/DefaultEcs/Internal/Messages/ComponentAddedMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct ComponentAddedMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/ComponentChangedMessage.cs b/source/DefaultEcs/Internal/Messages/ComponentChangedMessage.cs deleted file mode 100644 index 01b7d3b..0000000 --- a/source/DefaultEcs/Internal/Messages/ComponentChangedMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct ComponentChangedMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/ComponentDisabledMessage.cs b/source/DefaultEcs/Internal/Messages/ComponentDisabledMessage.cs deleted file mode 100644 index 594d91e..0000000 --- a/source/DefaultEcs/Internal/Messages/ComponentDisabledMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct ComponentDisabledMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/ComponentEnabledMessage.cs b/source/DefaultEcs/Internal/Messages/ComponentEnabledMessage.cs deleted file mode 100644 index cf8f42d..0000000 --- a/source/DefaultEcs/Internal/Messages/ComponentEnabledMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct ComponentEnabledMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/ComponentRemovedMessage.cs b/source/DefaultEcs/Internal/Messages/ComponentRemovedMessage.cs deleted file mode 100644 index 6a7c0ab..0000000 --- a/source/DefaultEcs/Internal/Messages/ComponentRemovedMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct ComponentRemovedMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityCreatedMessage .cs b/source/DefaultEcs/Internal/Messages/EntityCreatedMessage .cs deleted file mode 100644 index 780ce34..0000000 --- a/source/DefaultEcs/Internal/Messages/EntityCreatedMessage .cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct EntityCreatedMessage( - int EntityId); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityDisabledMessage.cs b/source/DefaultEcs/Internal/Messages/EntityDisabledMessage.cs deleted file mode 100644 index 438b649..0000000 --- a/source/DefaultEcs/Internal/Messages/EntityDisabledMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct EntityDisabledMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityDisposedMessage.cs b/source/DefaultEcs/Internal/Messages/EntityDisposedMessage.cs deleted file mode 100644 index efa31e0..0000000 --- a/source/DefaultEcs/Internal/Messages/EntityDisposedMessage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct EntityDisposedMessage( - int EntityId); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityDisposingMessage.cs b/source/DefaultEcs/Internal/Messages/EntityDisposingMessage.cs deleted file mode 100644 index 0e29db0..0000000 --- a/source/DefaultEcs/Internal/Messages/EntityDisposingMessage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct EntityDisposingMessage( - int EntityId); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityEnabledMessage.cs b/source/DefaultEcs/Internal/Messages/EntityEnabledMessage.cs deleted file mode 100644 index 74f660d..0000000 --- a/source/DefaultEcs/Internal/Messages/EntityEnabledMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct EntityEnabledMessage( - int EntityId, - ComponentEnum Components); -} diff --git a/source/DefaultEcs/Internal/Messages/EntityMessages.cs b/source/DefaultEcs/Internal/Messages/EntityMessages.cs new file mode 100644 index 0000000..a2c1b37 --- /dev/null +++ b/source/DefaultEcs/Internal/Messages/EntityMessages.cs @@ -0,0 +1,39 @@ +namespace DefaultEcs.Internal.Messages +{ + internal readonly record struct EntityCreatedMessage( + int EntityId); + + internal readonly record struct EntityEnabledMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityDisabledMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityDisposingMessage( + int EntityId); + + internal readonly record struct EntityDisposedMessage( + int EntityId); + + internal readonly record struct EntityComponentAddedMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityComponentChangedMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityComponentRemovedMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityComponentEnabledMessage( + int EntityId, + ComponentEnum Components); + + internal readonly record struct EntityComponentDisabledMessage( + int EntityId, + ComponentEnum Components); +} diff --git a/source/DefaultEcs/Internal/Messages/WorldComponentAddedMessage.cs b/source/DefaultEcs/Internal/Messages/WorldComponentAddedMessage.cs deleted file mode 100644 index 21964c2..0000000 --- a/source/DefaultEcs/Internal/Messages/WorldComponentAddedMessage.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct WorldComponentAddedMessage; -} diff --git a/source/DefaultEcs/Internal/Messages/WorldComponentChangedMessage.cs b/source/DefaultEcs/Internal/Messages/WorldComponentChangedMessage.cs deleted file mode 100644 index 2a4d000..0000000 --- a/source/DefaultEcs/Internal/Messages/WorldComponentChangedMessage.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct WorldComponentChangedMessage; -} diff --git a/source/DefaultEcs/Internal/Messages/WorldComponentRemovedMessage.cs b/source/DefaultEcs/Internal/Messages/WorldComponentRemovedMessage.cs deleted file mode 100644 index 67eb0be..0000000 --- a/source/DefaultEcs/Internal/Messages/WorldComponentRemovedMessage.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct WorldComponentRemovedMessage; -} diff --git a/source/DefaultEcs/Internal/Messages/WorldDisposedMessage.cs b/source/DefaultEcs/Internal/Messages/WorldDisposedMessage.cs deleted file mode 100644 index 5c49b54..0000000 --- a/source/DefaultEcs/Internal/Messages/WorldDisposedMessage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace DefaultEcs.Internal.Messages -{ - internal readonly record struct WorldDisposedMessage( - int WorldId); -} diff --git a/source/DefaultEcs/Internal/Messages/WorldMessages.cs b/source/DefaultEcs/Internal/Messages/WorldMessages.cs new file mode 100644 index 0000000..336c632 --- /dev/null +++ b/source/DefaultEcs/Internal/Messages/WorldMessages.cs @@ -0,0 +1,11 @@ +namespace DefaultEcs.Internal.Messages +{ + internal readonly record struct WorldComponentAddedMessage; + + internal readonly record struct WorldComponentChangedMessage; + + internal readonly record struct WorldComponentRemovedMessage; + + internal readonly record struct WorldDisposedMessage( + int WorldId); +} diff --git a/source/DefaultEcs/Resource/AResourceManager.cs b/source/DefaultEcs/Resource/AResourceManager.cs index 04a9013..3f66e83 100644 --- a/source/DefaultEcs/Resource/AResourceManager.cs +++ b/source/DefaultEcs/Resource/AResourceManager.cs @@ -274,12 +274,12 @@ public IDisposable Manage(World world) { IEnumerable GetSubscriptions(World w) { - yield return w.SubscribeComponentAdded>(OnAdded); - yield return w.SubscribeComponentChanged>(OnChanged); - yield return w.SubscribeComponentRemoved>(OnRemoved); - yield return w.SubscribeComponentAdded>(OnAdded); - yield return w.SubscribeComponentChanged>(OnChanged); - yield return w.SubscribeComponentRemoved>(OnRemoved); + yield return w.SubscribeEntityComponentAdded>(OnAdded); + yield return w.SubscribeEntityComponentChanged>(OnChanged); + yield return w.SubscribeEntityComponentRemoved>(OnRemoved); + yield return w.SubscribeEntityComponentAdded>(OnAdded); + yield return w.SubscribeEntityComponentChanged>(OnChanged); + yield return w.SubscribeEntityComponentRemoved>(OnRemoved); } world.ThrowIfNull(); diff --git a/source/DefaultEcs/World.cs b/source/DefaultEcs/World.cs index b246ae1..2ed3142 100644 --- a/source/DefaultEcs/World.cs +++ b/source/DefaultEcs/World.cs @@ -530,52 +530,52 @@ IEnumerable GetSubscriptions(EntityDisposedHandler a) } /// - /// Subscribes a on the current to be called when a component of type is added. + /// Subscribes a on the current to be called when a component of type is added. /// /// The type of the component. - /// The to be called. + /// The to be called. /// An object used to unsubscribe. /// is null. - public IDisposable SubscribeComponentAdded(ComponentAddedHandler action) + public IDisposable SubscribeEntityComponentAdded(EntityComponentAddedHandler action) { action.ThrowIfNull(); - return Subscribe((in ComponentAddedMessage message) => action( + return Subscribe((in EntityComponentAddedMessage message) => action( new Entity(WorldId, message.EntityId), ComponentManager.Get(WorldId).Get(message.EntityId))); } /// - /// Subscribes a on the current to be called when a component of type is changed. + /// Subscribes a on the current to be called when a component of type is changed. /// /// The type of the component. - /// The to be called. + /// The to be called. /// An object used to unsubscribe. /// is null. - public IDisposable SubscribeComponentChanged(ComponentChangedHandler action) + public IDisposable SubscribeEntityComponentChanged(EntityComponentChangedHandler action) { action.ThrowIfNull(); ComponentManager.GetOrCreatePrevious(WorldId); - return Subscribe((in ComponentChangedMessage message) => action( + return Subscribe((in EntityComponentChangedMessage message) => action( new Entity(WorldId, message.EntityId), ComponentManager.GetPrevious(WorldId).Get(message.EntityId), ComponentManager.Get(WorldId).Get(message.EntityId))); } /// - /// Subscribes an on the current to be called when a component of type is removed. + /// Subscribes an on the current to be called when a component of type is removed. /// /// The type of the component. - /// The to be called. + /// The to be called. /// An object used to unsubscribe. /// is null. - public IDisposable SubscribeComponentRemoved(ComponentRemovedHandler action) + public IDisposable SubscribeEntityComponentRemoved(EntityComponentRemovedHandler action) { - IEnumerable GetSubscriptions(ComponentRemovedHandler a) + IEnumerable GetSubscriptions(EntityComponentRemovedHandler a) { - yield return Subscribe((in ComponentRemovedMessage message) => a( + yield return Subscribe((in EntityComponentRemovedMessage message) => a( new Entity(WorldId, message.EntityId), ComponentManager.GetPrevious(WorldId).Get(message.EntityId))); yield return Subscribe((in EntityDisposingMessage message) => @@ -607,33 +607,33 @@ IEnumerable GetSubscriptions(ComponentRemovedHandler a) } /// - /// Subscribes a on the current to be called when a component of type is enabled. + /// Subscribes a on the current to be called when a component of type is enabled. /// /// The type of the component. - /// The to be called. + /// The to be called. /// An object used to unsubscribe. /// is null. - public IDisposable SubscribeComponentEnabled(ComponentEnabledHandler action) + public IDisposable SubscribeEntityComponentEnabled(EntityComponentEnabledHandler action) { action.ThrowIfNull(); - return Subscribe((in ComponentEnabledMessage message) => action( + return Subscribe((in EntityComponentEnabledMessage message) => action( new Entity(WorldId, message.EntityId), ComponentManager.Get(WorldId).Get(message.EntityId))); } /// - /// Subscribes a on the current to be called when a component of type is disabled. + /// Subscribes a on the current to be called when a component of type is disabled. /// /// The type of the component. - /// The to be called. + /// The to be called. /// An object used to unsubscribe. /// is null. - public IDisposable SubscribeComponentDisabled(ComponentDisabledHandler action) + public IDisposable SubscribeEntityComponentDisabled(EntityComponentDisabledHandler action) { action.ThrowIfNull(); - return Subscribe((in ComponentDisabledMessage message) => action( + return Subscribe((in EntityComponentDisabledMessage message) => action( new Entity(WorldId, message.EntityId), ComponentManager.Get(WorldId).Get(message.EntityId))); }