Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServiceEventContainer.cs 1.3KB

Svelto.ECS 2.9 changes (random order of importance): New Serialization framework more thorough disposing of the EnginesRoot an EnginesRoot reference should never be held, unless it’s a weak reference. The code changed to stick to this rule IReactOnAddAndRemove callbacks are now guaranteed to be called after all the entity structs generated by the same entity have been added and before any is removed. both functions pass the EGID of the analysing entity by parameter now, so that the entity struct won’t need to implement INeedEGID for this sole purpose. The IReactOnSwap MovedFrom method has been removed, it is now redundant. Entities built or removed during the IReactOnAddAndRemove callbacks are now added and removed immediately and not on the next submission like used to happen. This avoid some awkward checks that were previously needed inside engines. EntityStreams can get (optionally) the EGID of the entity published, so that the EntityStruct won’t need an INeedEGID for this sole purpose. Groups are not trimmed anymore when they are emptied to avoid allocations. Removed a bunch of run-time allocations that weren’t supposed to happen in Release and/or when the Profile define is used in editor (for debugging reasons Svelto.ECS may need to use strings at run-time, but Svelto.ECS is allocation zero in Release and when the Profile keyword is used) A improved the DynamicEntityDescriptor and ExtendibleEntityDescriptor code and more notably, introduced the new method ExtendedWith<> to facilitate the writing of modular and reusable entity descriptors. Several minor code design improvements/optimisations
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Svelto.ServiceLayer.Experimental
  4. {
  5. public abstract class ServiceEventContainer : IServiceEventContainer
  6. {
  7. public void Dispose()
  8. {
  9. foreach (var listener in _listeners)
  10. {
  11. listener.Dispose();
  12. }
  13. _listeners.Clear();
  14. }
  15. protected ServiceEventContainer()
  16. {
  17. //call all the AddRelation in the implementation if you wish
  18. }
  19. public void ListenTo<TListener, TDelegate>(TDelegate callBack)
  20. where TListener : class, IServiceEventListener<TDelegate> where TDelegate : Delegate
  21. {
  22. var concreteType = _registeredTypes[typeof(TListener)];
  23. var listener = (TListener)Activator.CreateInstance(concreteType);
  24. listener.SetCallback(callBack);
  25. _listeners.Add(listener);
  26. }
  27. protected void AddRelation<TInterface, TConcrete>() where TInterface : IServiceEventListenerBase
  28. where TConcrete : TInterface
  29. {
  30. _registeredTypes.Add(typeof(TInterface), typeof(TConcrete));
  31. }
  32. readonly List<IServiceEventListenerBase> _listeners = new List<IServiceEventListenerBase>();
  33. readonly Dictionary<Type, Type> _registeredTypes = new Dictionary<Type, Type>();
  34. }
  35. }