Mirror of Svelto.ECS because we're a fan of it
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

EnginesRoot.GenericEntityFactory.cs 4.1KB

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
4 anos atrás
1 ano atrás
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
4 anos atrás
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
4 anos atrás
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
4 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using Svelto.Common;
  5. namespace Svelto.ECS
  6. {
  7. public partial class EnginesRoot
  8. {
  9. class GenericEntityFactory : IEntityFactory, IEntitySerializationFactory
  10. {
  11. public GenericEntityFactory(EnginesRoot weakReference)
  12. {
  13. _enginesRoot = new Svelto.DataStructures.WeakReference<EnginesRoot>(weakReference);
  14. }
  15. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  16. public EntityInitializer BuildEntity<T>
  17. (uint entityID, ExclusiveBuildGroup groupStructId, IEnumerable<object> implementors = null
  18. , [CallerMemberName] string caller = null) where T : IEntityDescriptor, new()
  19. {
  20. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId)
  21. , EntityDescriptorTemplate<T>.realDescriptor.componentsToBuild
  22. , TypeCache<T>.type, implementors, caller);
  23. }
  24. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  25. public EntityInitializer BuildEntity<T>
  26. (EGID egid, IEnumerable<object> implementors = null
  27. , [CallerMemberName] string caller = null) where T : IEntityDescriptor, new()
  28. {
  29. return _enginesRoot.Target.BuildEntity(egid, EntityDescriptorTemplate<T>.realDescriptor.componentsToBuild
  30. , TypeCache<T>.type, implementors, caller);
  31. }
  32. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  33. public EntityInitializer BuildEntity<T>
  34. (EGID egid, T entityDescriptor, IEnumerable<object> implementors
  35. , [CallerMemberName] string caller = null) where T : IEntityDescriptor
  36. {
  37. return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.componentsToBuild, TypeCache<T>.type
  38. , implementors, caller);
  39. }
  40. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  41. public EntityInitializer BuildEntity<T>
  42. (uint entityID, ExclusiveBuildGroup groupStructId, T descriptorEntity, IEnumerable<object> implementors
  43. , [CallerMemberName] string caller = null) where T : IEntityDescriptor
  44. {
  45. return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId)
  46. , descriptorEntity.componentsToBuild, TypeCache<T>.type
  47. , implementors, caller);
  48. }
  49. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  50. public EntityInitializer BuildEntity
  51. (EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable<object> implementors = null
  52. , [CallerMemberName] string caller = null)
  53. {
  54. return _enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors, caller);
  55. }
  56. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  57. public void PreallocateEntitySpace<T>(ExclusiveGroupStruct groupStructId, uint numberOfEntities)
  58. where T : IEntityDescriptor, new()
  59. {
  60. _enginesRoot.Target.Preallocate(groupStructId, numberOfEntities
  61. , EntityDescriptorTemplate<T>.realDescriptor.componentsToBuild);
  62. }
  63. #if UNITY_NATIVE
  64. public Native.NativeEntityFactory ToNative<T>
  65. ([CallerMemberName] string caller = null)
  66. where T : IEntityDescriptor, new()
  67. {
  68. return _enginesRoot.Target.ProvideNativeEntityFactoryQueue<T>(caller);
  69. }
  70. #endif
  71. //NOTE: enginesRoot is a weakreference ONLY because GenericEntityStreamConsumerFactory can be injected inside
  72. //engines of other enginesRoot
  73. readonly Svelto.DataStructures.WeakReference<EnginesRoot> _enginesRoot;
  74. }
  75. }
  76. }