From 258679388c1c398aa39e49ded38d7a4b35fcb66a Mon Sep 17 00:00:00 2001 From: GitHub Date: Sun, 10 Jan 2021 11:45:07 +0000 Subject: [PATCH] UPM package version 3.1.0 --- CHANGELOG.md | 21 + CHANGELOG.md.meta | 7 + Core.meta | 8 + .../AllowMultipleAttribute.cs | 0 .../AllowMultipleAttribute.cs.meta | 2 +- .../CheckEntityUtilities.cs | 3 +- .../CheckEntityUtilities.cs.meta | 2 +- .../ComponentBuilder.CheckFields.cs | 0 .../ComponentBuilder.CheckFields.cs.meta | 2 +- .../ComponentBuilder.cs | 0 .../ComponentBuilder.cs.meta | 2 +- DBC.cs => Core/DBC.cs | 0 DBC.cs.meta => Core/DBC.cs.meta | 2 +- ECSException.cs => Core/ECSException.cs | 0 .../ECSException.cs.meta | 2 +- EGID.cs => Core/EGID.cs | 2 +- EGID.cs.meta => Core/EGID.cs.meta | 2 +- EGIDMapper.cs => Core/EGIDMapper.cs | 1 - EGIDMapper.cs.meta => Core/EGIDMapper.cs.meta | 2 +- Core/EnginesGroup.meta | 8 + Core/EnginesGroup/IStepEngine.cs | 25 + Core/EnginesGroup/IStepEngine.cs.meta | 11 + .../EnginesGroup/SortedEnginesGroup.cs | 28 +- .../EnginesGroup/SortedEnginesGroup.cs.meta | 2 +- .../EnginesGroup/UnsortedEnginesGroup.cs | 28 + .../EnginesGroup/UnsortedEnginesGroup.cs.meta | 2 +- ...EnginesRoot.DoubleBufferedEntitiesToAdd.cs | 3 +- ...esRoot.DoubleBufferedEntitiesToAdd.cs.meta | 2 +- .../EnginesRoot.Engines.cs | 106 ++-- .../EnginesRoot.Engines.cs.meta | 2 +- .../EnginesRoot.Entities.cs | 7 +- .../EnginesRoot.Entities.cs.meta | 2 +- .../EnginesRoot.GenericEntityFactory.cs | 18 +- .../EnginesRoot.GenericEntityFactory.cs.meta | 2 +- .../EnginesRoot.GenericEntityFunctions.cs | 29 +- ...EnginesRoot.GenericEntityFunctions.cs.meta | 2 +- .../EnginesRoot.Submission.cs | 129 +++-- .../EnginesRoot.Submission.cs.meta | 2 +- .../EntitiesDB.FindGroups.cs | 0 .../EntitiesDB.FindGroups.cs.meta | 2 +- EntitiesDB.cs => Core/EntitiesDB.cs | 0 EntitiesDB.cs.meta => Core/EntitiesDB.cs.meta | 2 +- .../EntityCollection.cs | 54 +- .../EntityCollection.cs.meta | 2 +- Core/EntityDescriptor.meta | 8 + .../DynamicEntityDescriptor.cs | 0 .../DynamicEntityDescriptor.cs.meta | 2 +- .../ExtendibleEntityDescriptor.cs | 13 + .../ExtendibleEntityDescriptor.cs.meta | 2 +- .../GenericEntityDescriptor.cs | 0 .../GenericEntityDescriptor.cs.meta | 2 +- .../IDynamicEntityDescriptor.cs | 6 + .../IDynamicEntityDescriptor.cs.meta | 11 + Core/EntityDescriptor/IEntityDescriptor.cs | 7 + .../IEntityDescriptor.cs.meta | 11 + .../EntityDescriptorTemplate.cs | 9 - .../EntityDescriptorTemplate.cs.meta | 2 +- EntityFactory.cs => Core/EntityFactory.cs | 0 .../EntityFactory.cs.meta | 2 +- .../EntityGroupNotFoundException.cs | 0 .../EntityGroupNotFoundException.cs.meta | 2 +- EntityInfoView.cs => Core/EntityInfoView.cs | 0 .../EntityInfoView.cs.meta | 2 +- .../EntityInitializer.cs | 7 +- Core/EntityInitializer.cs.meta | 11 + .../EntityNotFoundException.cs | 0 .../EntityNotFoundException.cs.meta | 2 +- Core/EntitySubmissionScheduler.cs | 16 + .../EntitySubmissionScheduler.cs.meta | 2 +- .../EntitySubmitOperation.cs | 0 .../EntitySubmitOperation.cs.meta | 2 +- .../EntityViewUtility.cs | 0 .../EntityViewUtility.cs.meta | 2 +- Filters.meta => Core/Filters.meta | 2 +- .../Filters}/EntitiesDB.GroupFilters.cs | 3 +- .../Filters}/EntitiesDB.GroupFilters.cs.meta | 2 +- {Filters => Core/Filters}/FilterGroup.cs | 0 {Filters => Core/Filters}/FilterGroup.cs.meta | 2 +- {Filters => Core/Filters}/FilteredIndices.cs | 16 +- .../Filters}/FilteredIndices.cs.meta | 2 +- {Filters => Core/Filters}/GroupFilters.cs | 2 +- .../Filters}/GroupFilters.cs.meta | 2 +- GlobalTypeID.cs => Core/GlobalTypeID.cs | 4 +- .../GlobalTypeID.cs.meta | 2 +- Core/Groups.meta | 8 + Core/Groups/ExclusiveBuildGroup.cs | 27 + Core/Groups/ExclusiveBuildGroup.cs.meta | 11 + .../Groups/ExclusiveGroup.cs | 1 - .../Groups/ExclusiveGroup.cs.meta | 2 +- .../Groups/ExclusiveGroupStruct.cs | 25 - .../Groups/ExclusiveGroupStruct.cs.meta | 2 +- .../Groups/GroupCompound.cs | 8 +- .../Groups/GroupCompound.cs.meta | 2 +- .../Groups/NamedExclusiveGroup.cs | 0 .../Groups/NamedExclusiveGroup.cs.meta | 2 +- Hybrid.meta => Core/Hybrid.meta | 2 +- .../Hybrid/IEntityDescriptorHolder.cs | 0 .../Hybrid/IEntityDescriptorHolder.cs.meta | 2 +- .../Hybrid}/IEntityViewComponent.cs | 0 .../Hybrid}/IEntityViewComponent.cs.meta | 2 +- {Hybrid => Core/Hybrid}/IImplementor.cs | 0 {Hybrid => Core/Hybrid}/IImplementor.cs.meta | 2 +- Core/Hybrid/ValueReference.cs | 13 + Core/Hybrid/ValueReference.cs.meta | 11 + .../IComponentBuilder.cs | 0 .../IComponentBuilder.cs.meta | 2 +- .../IDisposingEngine.cs | 0 .../IDisposingEngine.cs.meta | 2 +- IEngine.cs => Core/IEngine.cs | 8 + IEngine.cs.meta => Core/IEngine.cs.meta | 2 +- Core/IEntityComponent.cs | 7 + .../IEntityComponent.cs.meta | 2 +- IEntityFactory.cs => Core/IEntityFactory.cs | 12 +- .../IEntityFactory.cs.meta | 2 +- Core/IEntityFunctions.cs | 34 ++ .../IEntityFunctions.cs.meta | 2 +- IEntityComponent.cs => Core/INeedEGID.cs | 5 - Core/INeedEGID.cs.meta | 11 + .../IQueryingEntitiesEngine.cs | 0 .../IQueryingEntitiesEngine.cs.meta | 2 +- QueryGroups.cs => Core/QueryGroups.cs | 0 .../QueryGroups.cs.meta | 2 +- .../SetEGIDWithoutBoxing.cs | 2 - .../SetEGIDWithoutBoxing.cs.meta | 2 +- Core/SimpleEntitiesSubmissionScheduler.cs | 47 ++ .../SimpleEntitiesSubmissionScheduler.cs.meta | 2 +- Core/SpecialEnumerators.meta | 8 + .../DoubleIterationEnumerator.cs | 546 ++++++++++++++++++ .../DoubleIterationEnumerator.cs.meta | 11 + .../WaitForSubmissionEnumerator.cs | 48 ++ .../WaitForSubmissionEnumerator.cs.meta | 2 +- Streams.meta => Core/Streams.meta | 2 +- {Streams => Core/Streams}/Consumer.cs | 0 {Streams => Core/Streams}/Consumer.cs.meta | 2 +- .../Streams}/EnginesRoot.Streams.cs | 0 .../Streams}/EnginesRoot.Streams.cs.meta | 2 +- .../Streams}/EntitiesDB.Streams.cs | 3 +- .../Streams}/EntitiesDB.Streams.cs.meta | 2 +- {Streams => Core/Streams}/EntitiesStreams.cs | 0 .../Streams}/EntitiesStreams.cs.meta | 2 +- {Streams => Core/Streams}/EntityStream.cs | 0 .../Streams}/EntityStream.cs.meta | 2 +- .../GenericentityStreamConsumerFactory.cs | 0 ...GenericentityStreamConsumerFactory.cs.meta | 2 +- .../Streams}/ThreadSafeNativeEntityStream.cs | 0 .../ThreadSafeNativeEntityStream.cs.meta | 2 +- .../TypeSafeDictionaryFactory.cs | 0 .../TypeSafeDictionaryFactory.cs.meta | 2 +- DataStructures/TypeSafeDictionary.cs | 18 +- DataStructures/Unmanaged/NativeBag.cs | 1 - .../Unmanaged/NativeDynamicArrayCast.cs | 6 +- DataStructures/Unmanaged/SharedNativeInt.cs | 1 - Dispatcher/DispatchOnChange.cs | 4 +- Dispatcher/DispatchOnSet.cs | 25 +- EntityComponentInitializer.cs.meta | 11 - EntitySubmissionScheduler.cs | 21 - Extensions/Svelto/AllGroupsEnumerable.cs | 34 +- .../Svelto/EntityCollectionExtension.cs | 29 +- Extensions/Svelto/GroupsEnumerable.cs | 163 +++--- Extensions/Unity/DOTS/Jobs/DisposeJob.cs | 2 +- Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs | 21 + .../Unity/DOTS/Jobs/IJobifiedEngine.cs.meta | 11 + .../Unity/DOTS/Jobs/JobifiedEnginesGroup.cs | 20 +- .../DOTS/Jobs/SortedJobifiedEnginesGroup.cs | 2 +- .../Unity/DOTS/Jobs/UnityJobExtensions.cs | 26 +- .../Native/EnginesRoot.NativeOperation.cs | 79 +-- .../DOTS/Native/NativeEGIDMultiMapper.cs | 12 +- .../NativeEntityComponentInitializer.cs.meta | 11 - .../Unity/DOTS/Native/NativeEntityFactory.cs | 12 +- ...tializer.cs => NativeEntityInitializer.cs} | 4 +- .../Native/NativeEntityInitializer.cs.meta | 11 + .../Unity/DOTS/Native/NativeEntitySwap.cs | 2 +- .../DOTS/Native/UnityEntityDBExtensions.cs | 6 +- .../Unity/DOTS/UECS/IUECSSubmissionEngine.cs | 19 +- .../DOTS/UECS/SveltoOverUECSEnginesGroup.cs | 28 +- .../UECS/SveltoUECSEntitiesSubmissionGroup.cs | 43 +- .../Unity/EntityDescriptorHolderHelper.cs | 6 +- Extensions/Unity/SveltoGUIHelper.cs | 4 +- .../Unity/UnityEntitiesSubmissionScheduler.cs | 6 +- IEntityFunctions.cs | 32 - README.md | 15 +- Serialization/DefaultVersioningFactory.cs | 2 +- .../EnginesRoot.GenericEntitySerialization.cs | 4 +- .../EntitiesDB.SerializationDescriptorMap.cs | 1 - Serialization/IDeserializationFactory.cs | 2 +- Serialization/IEntitySerialization.cs | 6 +- .../ISerializableComponentBuilder.cs | 2 +- Serialization/SerializableComponentBuilder.cs | 2 +- SimpleEntitiesSubmissionScheduler.cs | 30 - Svelto.ECS.asmdef | 5 +- Svelto.ECS.csproj | 3 +- WaitForSubmissionEnumerator.cs | 64 -- package.json | 7 +- 193 files changed, 1627 insertions(+), 772 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 CHANGELOG.md.meta create mode 100644 Core.meta rename AllowMultipleAttribute.cs => Core/AllowMultipleAttribute.cs (100%) rename AllowMultipleAttribute.cs.meta => Core/AllowMultipleAttribute.cs.meta (83%) rename CheckEntityUtilities.cs => Core/CheckEntityUtilities.cs (97%) rename CheckEntityUtilities.cs.meta => Core/CheckEntityUtilities.cs.meta (83%) rename ComponentBuilder.CheckFields.cs => Core/ComponentBuilder.CheckFields.cs (100%) rename ComponentBuilder.CheckFields.cs.meta => Core/ComponentBuilder.CheckFields.cs.meta (83%) rename ComponentBuilder.cs => Core/ComponentBuilder.cs (100%) rename ComponentBuilder.cs.meta => Core/ComponentBuilder.cs.meta (83%) rename DBC.cs => Core/DBC.cs (100%) rename DBC.cs.meta => Core/DBC.cs.meta (83%) rename ECSException.cs => Core/ECSException.cs (100%) rename ECSException.cs.meta => Core/ECSException.cs.meta (83%) rename EGID.cs => Core/EGID.cs (96%) rename EGID.cs.meta => Core/EGID.cs.meta (83%) rename EGIDMapper.cs => Core/EGIDMapper.cs (98%) rename EGIDMapper.cs.meta => Core/EGIDMapper.cs.meta (83%) create mode 100644 Core/EnginesGroup.meta create mode 100644 Core/EnginesGroup/IStepEngine.cs create mode 100644 Core/EnginesGroup/IStepEngine.cs.meta rename SortedEnginesGroup.cs => Core/EnginesGroup/SortedEnginesGroup.cs (80%) rename SortedEnginesGroup.cs.meta => Core/EnginesGroup/SortedEnginesGroup.cs.meta (83%) rename UnsortedEnginesGroup.cs => Core/EnginesGroup/UnsortedEnginesGroup.cs (50%) rename UnsortedEnginesGroup.cs.meta => Core/EnginesGroup/UnsortedEnginesGroup.cs.meta (83%) rename EnginesRoot.DoubleBufferedEntitiesToAdd.cs => Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs (99%) rename EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta => Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta (83%) rename EnginesRoot.Engines.cs => Core/EnginesRoot.Engines.cs (70%) rename EnginesRoot.Engines.cs.meta => Core/EnginesRoot.Engines.cs.meta (83%) rename EnginesRoot.Entities.cs => Core/EnginesRoot.Entities.cs (98%) rename EnginesRoot.Entities.cs.meta => Core/EnginesRoot.Entities.cs.meta (83%) rename EnginesRoot.GenericEntityFactory.cs => Core/EnginesRoot.GenericEntityFactory.cs (75%) rename EnginesRoot.GenericEntityFactory.cs.meta => Core/EnginesRoot.GenericEntityFactory.cs.meta (83%) rename EnginesRoot.GenericEntityFunctions.cs => Core/EnginesRoot.GenericEntityFunctions.cs (88%) rename EnginesRoot.GenericEntityFunctions.cs.meta => Core/EnginesRoot.GenericEntityFunctions.cs.meta (83%) rename EnginesRoot.Submission.cs => Core/EnginesRoot.Submission.cs (53%) rename EnginesRoot.Submission.cs.meta => Core/EnginesRoot.Submission.cs.meta (83%) rename EntitiesDB.FindGroups.cs => Core/EntitiesDB.FindGroups.cs (100%) rename EntitiesDB.FindGroups.cs.meta => Core/EntitiesDB.FindGroups.cs.meta (83%) rename EntitiesDB.cs => Core/EntitiesDB.cs (100%) rename EntitiesDB.cs.meta => Core/EntitiesDB.cs.meta (83%) rename EntityCollection.cs => Core/EntityCollection.cs (82%) rename EntityCollection.cs.meta => Core/EntityCollection.cs.meta (83%) create mode 100644 Core/EntityDescriptor.meta rename DynamicEntityDescriptor.cs => Core/EntityDescriptor/DynamicEntityDescriptor.cs (100%) rename DynamicEntityDescriptor.cs.meta => Core/EntityDescriptor/DynamicEntityDescriptor.cs.meta (83%) rename ExtendibleEntityDescriptor.cs => Core/EntityDescriptor/ExtendibleEntityDescriptor.cs (77%) rename ExtendibleEntityDescriptor.cs.meta => Core/EntityDescriptor/ExtendibleEntityDescriptor.cs.meta (83%) rename GenericEntityDescriptor.cs => Core/EntityDescriptor/GenericEntityDescriptor.cs (100%) rename GenericEntityDescriptor.cs.meta => Core/EntityDescriptor/GenericEntityDescriptor.cs.meta (83%) create mode 100644 Core/EntityDescriptor/IDynamicEntityDescriptor.cs create mode 100644 Core/EntityDescriptor/IDynamicEntityDescriptor.cs.meta create mode 100644 Core/EntityDescriptor/IEntityDescriptor.cs create mode 100644 Core/EntityDescriptor/IEntityDescriptor.cs.meta rename EntityDescriptorTemplate.cs => Core/EntityDescriptorTemplate.cs (72%) rename EntityDescriptorTemplate.cs.meta => Core/EntityDescriptorTemplate.cs.meta (83%) rename EntityFactory.cs => Core/EntityFactory.cs (100%) rename EntityFactory.cs.meta => Core/EntityFactory.cs.meta (83%) rename EntityGroupNotFoundException.cs => Core/EntityGroupNotFoundException.cs (100%) rename EntityGroupNotFoundException.cs.meta => Core/EntityGroupNotFoundException.cs.meta (83%) rename EntityInfoView.cs => Core/EntityInfoView.cs (100%) rename EntityInfoView.cs.meta => Core/EntityInfoView.cs.meta (83%) rename EntityComponentInitializer.cs => Core/EntityInitializer.cs (90%) create mode 100644 Core/EntityInitializer.cs.meta rename EntityNotFoundException.cs => Core/EntityNotFoundException.cs (100%) rename EntityNotFoundException.cs.meta => Core/EntityNotFoundException.cs.meta (83%) create mode 100644 Core/EntitySubmissionScheduler.cs rename EntitySubmissionScheduler.cs.meta => Core/EntitySubmissionScheduler.cs.meta (83%) rename EntitySubmitOperation.cs => Core/EntitySubmitOperation.cs (100%) rename EntitySubmitOperation.cs.meta => Core/EntitySubmitOperation.cs.meta (83%) rename EntityViewUtility.cs => Core/EntityViewUtility.cs (100%) rename EntityViewUtility.cs.meta => Core/EntityViewUtility.cs.meta (83%) rename Filters.meta => Core/Filters.meta (77%) rename {Filters => Core/Filters}/EntitiesDB.GroupFilters.cs (99%) rename {Filters => Core/Filters}/EntitiesDB.GroupFilters.cs.meta (83%) rename {Filters => Core/Filters}/FilterGroup.cs (100%) rename {Filters => Core/Filters}/FilterGroup.cs.meta (83%) rename {Filters => Core/Filters}/FilteredIndices.cs (53%) rename {Filters => Core/Filters}/FilteredIndices.cs.meta (83%) rename {Filters => Core/Filters}/GroupFilters.cs (98%) rename {Filters => Core/Filters}/GroupFilters.cs.meta (83%) rename GlobalTypeID.cs => Core/GlobalTypeID.cs (90%) rename GlobalTypeID.cs.meta => Core/GlobalTypeID.cs.meta (83%) create mode 100644 Core/Groups.meta create mode 100644 Core/Groups/ExclusiveBuildGroup.cs create mode 100644 Core/Groups/ExclusiveBuildGroup.cs.meta rename ExclusiveGroup.cs => Core/Groups/ExclusiveGroup.cs (99%) rename ExclusiveGroup.cs.meta => Core/Groups/ExclusiveGroup.cs.meta (83%) rename ExclusiveGroupStruct.cs => Core/Groups/ExclusiveGroupStruct.cs (84%) rename ExclusiveGroupStruct.cs.meta => Core/Groups/ExclusiveGroupStruct.cs.meta (83%) rename GroupCompound.cs => Core/Groups/GroupCompound.cs (96%) rename GroupCompound.cs.meta => Core/Groups/GroupCompound.cs.meta (83%) rename NamedExclusiveGroup.cs => Core/Groups/NamedExclusiveGroup.cs (100%) rename NamedExclusiveGroup.cs.meta => Core/Groups/NamedExclusiveGroup.cs.meta (83%) rename Hybrid.meta => Core/Hybrid.meta (77%) rename IEntityDescriptorHolder.cs => Core/Hybrid/IEntityDescriptorHolder.cs (100%) rename IEntityDescriptorHolder.cs.meta => Core/Hybrid/IEntityDescriptorHolder.cs.meta (83%) rename {Hybrid => Core/Hybrid}/IEntityViewComponent.cs (100%) rename {Hybrid => Core/Hybrid}/IEntityViewComponent.cs.meta (83%) rename {Hybrid => Core/Hybrid}/IImplementor.cs (100%) rename {Hybrid => Core/Hybrid}/IImplementor.cs.meta (83%) create mode 100644 Core/Hybrid/ValueReference.cs create mode 100644 Core/Hybrid/ValueReference.cs.meta rename IComponentBuilder.cs => Core/IComponentBuilder.cs (100%) rename IComponentBuilder.cs.meta => Core/IComponentBuilder.cs.meta (83%) rename IDisposingEngine.cs => Core/IDisposingEngine.cs (100%) rename IDisposingEngine.cs.meta => Core/IDisposingEngine.cs.meta (83%) rename IEngine.cs => Core/IEngine.cs (78%) rename IEngine.cs.meta => Core/IEngine.cs.meta (83%) create mode 100644 Core/IEntityComponent.cs rename IEntityComponent.cs.meta => Core/IEntityComponent.cs.meta (83%) rename IEntityFactory.cs => Core/IEntityFactory.cs (83%) rename IEntityFactory.cs.meta => Core/IEntityFactory.cs.meta (83%) create mode 100644 Core/IEntityFunctions.cs rename IEntityFunctions.cs.meta => Core/IEntityFunctions.cs.meta (83%) rename IEntityComponent.cs => Core/INeedEGID.cs (71%) create mode 100644 Core/INeedEGID.cs.meta rename IQueryingEntitiesEngine.cs => Core/IQueryingEntitiesEngine.cs (100%) rename IQueryingEntitiesEngine.cs.meta => Core/IQueryingEntitiesEngine.cs.meta (83%) rename QueryGroups.cs => Core/QueryGroups.cs (100%) rename QueryGroups.cs.meta => Core/QueryGroups.cs.meta (83%) rename SetEGIDWithoutBoxing.cs => Core/SetEGIDWithoutBoxing.cs (96%) rename SetEGIDWithoutBoxing.cs.meta => Core/SetEGIDWithoutBoxing.cs.meta (83%) create mode 100644 Core/SimpleEntitiesSubmissionScheduler.cs rename SimpleEntitiesSubmissionScheduler.cs.meta => Core/SimpleEntitiesSubmissionScheduler.cs.meta (83%) create mode 100644 Core/SpecialEnumerators.meta create mode 100644 Core/SpecialEnumerators/DoubleIterationEnumerator.cs create mode 100644 Core/SpecialEnumerators/DoubleIterationEnumerator.cs.meta create mode 100644 Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs rename WaitForSubmissionEnumerator.cs.meta => Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs.meta (83%) rename Streams.meta => Core/Streams.meta (77%) rename {Streams => Core/Streams}/Consumer.cs (100%) rename {Streams => Core/Streams}/Consumer.cs.meta (83%) rename {Streams => Core/Streams}/EnginesRoot.Streams.cs (100%) rename {Streams => Core/Streams}/EnginesRoot.Streams.cs.meta (83%) rename {Streams => Core/Streams}/EntitiesDB.Streams.cs (90%) rename {Streams => Core/Streams}/EntitiesDB.Streams.cs.meta (83%) rename {Streams => Core/Streams}/EntitiesStreams.cs (100%) rename {Streams => Core/Streams}/EntitiesStreams.cs.meta (83%) rename {Streams => Core/Streams}/EntityStream.cs (100%) rename {Streams => Core/Streams}/EntityStream.cs.meta (83%) rename {Streams => Core/Streams}/GenericentityStreamConsumerFactory.cs (100%) rename {Streams => Core/Streams}/GenericentityStreamConsumerFactory.cs.meta (83%) rename {Streams => Core/Streams}/ThreadSafeNativeEntityStream.cs (100%) rename {Streams => Core/Streams}/ThreadSafeNativeEntityStream.cs.meta (83%) rename TypeSafeDictionaryFactory.cs => Core/TypeSafeDictionaryFactory.cs (100%) rename TypeSafeDictionaryFactory.cs.meta => Core/TypeSafeDictionaryFactory.cs.meta (83%) delete mode 100644 EntityComponentInitializer.cs.meta delete mode 100644 EntitySubmissionScheduler.cs create mode 100644 Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs create mode 100644 Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs.meta delete mode 100644 Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs.meta rename Extensions/Unity/DOTS/Native/{NativeEntityComponentInitializer.cs => NativeEntityInitializer.cs} (77%) create mode 100644 Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs.meta delete mode 100644 IEntityFunctions.cs delete mode 100644 SimpleEntitiesSubmissionScheduler.cs delete mode 100644 WaitForSubmissionEnumerator.cs diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..dd5f969 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# Changelog +All notable changes to this project will be documented in this file. I created this file with Svelto.ECS version 3.1. + +## [0.3.1] + +### Changed + +* rearrange folders structures for clarity +* added DoubleEntitiesEnumerator, as seen in MiniExample 4, to allow a double iteration of the same group skipping already checked tuples +* reengineered the behaviour of WaitForSubmissionEnumerator +* removed redudant ISimpleEntitySubmissionScheduler interface +* renamed BuildGroup in to ExclusiveBuildGroup +* renamed EntityComponentInitializer to EntityInitializer +* Entity Submission now can optionally be time slices (based on number of entities to submit per slice) +* working on the Unity extension Submission Engine, still wip +* added the possibility to hold a reference in a EntityViewComponent. This reference cannot be accesses as an object, but can be converted to the original object in OOP abstract layers +* renamed NativeEntityComponentInitializer to NativeEntityInitializer +* + +### Fixed + diff --git a/CHANGELOG.md.meta b/CHANGELOG.md.meta new file mode 100644 index 0000000..cde4052 --- /dev/null +++ b/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 46f11aabb9f33c4c883a62268c9d8e75 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core.meta b/Core.meta new file mode 100644 index 0000000..814936f --- /dev/null +++ b/Core.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 780543feb41c3e379f62a1cb4012dd73 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AllowMultipleAttribute.cs b/Core/AllowMultipleAttribute.cs similarity index 100% rename from AllowMultipleAttribute.cs rename to Core/AllowMultipleAttribute.cs diff --git a/AllowMultipleAttribute.cs.meta b/Core/AllowMultipleAttribute.cs.meta similarity index 83% rename from AllowMultipleAttribute.cs.meta rename to Core/AllowMultipleAttribute.cs.meta index 638e636..fcffc97 100644 --- a/AllowMultipleAttribute.cs.meta +++ b/Core/AllowMultipleAttribute.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3c9bebf03e59386d84e0a930eccf48fc +guid: 6fb69554705d3885b0bd4cf46e72fa95 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/CheckEntityUtilities.cs b/Core/CheckEntityUtilities.cs similarity index 97% rename from CheckEntityUtilities.cs rename to Core/CheckEntityUtilities.cs index 020b4b2..0016ac8 100644 --- a/CheckEntityUtilities.cs +++ b/Core/CheckEntityUtilities.cs @@ -3,7 +3,6 @@ #endif using System; using System.Collections.Generic; -using System.Diagnostics; using Svelto.DataStructures; namespace Svelto.ECS @@ -72,7 +71,7 @@ namespace Svelto.ECS #if DONT_USE [Conditional("CHECK_ALL")] #endif - void RemoveGroupID(BuildGroup groupID) { _idChecker.Remove(groupID); } + void RemoveGroupID(ExclusiveBuildGroup groupID) { _idChecker.Remove(groupID); } #if DONT_USE [Conditional("CHECK_ALL")] diff --git a/CheckEntityUtilities.cs.meta b/Core/CheckEntityUtilities.cs.meta similarity index 83% rename from CheckEntityUtilities.cs.meta rename to Core/CheckEntityUtilities.cs.meta index 9f23933..f0969c6 100644 --- a/CheckEntityUtilities.cs.meta +++ b/Core/CheckEntityUtilities.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1f68096cd077321494ba5dd6f816076c +guid: 2b103bee96523b9da1a57a2e6c2ddb27 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ComponentBuilder.CheckFields.cs b/Core/ComponentBuilder.CheckFields.cs similarity index 100% rename from ComponentBuilder.CheckFields.cs rename to Core/ComponentBuilder.CheckFields.cs diff --git a/ComponentBuilder.CheckFields.cs.meta b/Core/ComponentBuilder.CheckFields.cs.meta similarity index 83% rename from ComponentBuilder.CheckFields.cs.meta rename to Core/ComponentBuilder.CheckFields.cs.meta index 3eed1a2..2bddeaa 100644 --- a/ComponentBuilder.CheckFields.cs.meta +++ b/Core/ComponentBuilder.CheckFields.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b8801fb2bdee37a6aa48c7ab61badd55 +guid: dd4e9c0e74f3396fad9d053821b3a920 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ComponentBuilder.cs b/Core/ComponentBuilder.cs similarity index 100% rename from ComponentBuilder.cs rename to Core/ComponentBuilder.cs diff --git a/ComponentBuilder.cs.meta b/Core/ComponentBuilder.cs.meta similarity index 83% rename from ComponentBuilder.cs.meta rename to Core/ComponentBuilder.cs.meta index 42001e1..07abe61 100644 --- a/ComponentBuilder.cs.meta +++ b/Core/ComponentBuilder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cf16c7aee929396a99cb63c9d8242a91 +guid: 5a37611df353344e9e4d8f5b09f3e122 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/DBC.cs b/Core/DBC.cs similarity index 100% rename from DBC.cs rename to Core/DBC.cs diff --git a/DBC.cs.meta b/Core/DBC.cs.meta similarity index 83% rename from DBC.cs.meta rename to Core/DBC.cs.meta index 85c52f3..7c1a227 100644 --- a/DBC.cs.meta +++ b/Core/DBC.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3b94ce79abd33ebdb58b4feb589e2ec2 +guid: edf26e91bb743648b20976997c28cdc9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ECSException.cs b/Core/ECSException.cs similarity index 100% rename from ECSException.cs rename to Core/ECSException.cs diff --git a/ECSException.cs.meta b/Core/ECSException.cs.meta similarity index 83% rename from ECSException.cs.meta rename to Core/ECSException.cs.meta index 7d1237d..27c1ffa 100644 --- a/ECSException.cs.meta +++ b/Core/ECSException.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ebf9ad21334336bd87fc11d4ce9edfb2 +guid: 84772ff612c9344a8a46c1ad75879a2f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EGID.cs b/Core/EGID.cs similarity index 96% rename from EGID.cs rename to Core/EGID.cs index e2a0f77..fc50271 100644 --- a/EGID.cs +++ b/Core/EGID.cs @@ -31,7 +31,7 @@ namespace Svelto.ECS _GID = MAKE_GLOBAL_ID(entityID, groupID); } - public EGID(uint entityID, BuildGroup groupID) : this() + public EGID(uint entityID, ExclusiveBuildGroup groupID) : this() { _GID = MAKE_GLOBAL_ID(entityID, groupID.group); } diff --git a/EGID.cs.meta b/Core/EGID.cs.meta similarity index 83% rename from EGID.cs.meta rename to Core/EGID.cs.meta index 31112da..f9c5cdf 100644 --- a/EGID.cs.meta +++ b/Core/EGID.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b45ce870121e36ff9e022e665152b753 +guid: e887cc489753338cafc98950283c76d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EGIDMapper.cs b/Core/EGIDMapper.cs similarity index 98% rename from EGIDMapper.cs rename to Core/EGIDMapper.cs index 3596a9d..bfadf1c 100644 --- a/EGIDMapper.cs +++ b/Core/EGIDMapper.cs @@ -1,7 +1,6 @@ using System; using System.Runtime.CompilerServices; using Svelto.Common; -using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS diff --git a/EGIDMapper.cs.meta b/Core/EGIDMapper.cs.meta similarity index 83% rename from EGIDMapper.cs.meta rename to Core/EGIDMapper.cs.meta index 864e8aa..d65a06a 100644 --- a/EGIDMapper.cs.meta +++ b/Core/EGIDMapper.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f2ad50acf4bd3aff9debb59333681ac8 +guid: 501b2e2d9db632fe9547410a9d30e49b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/EnginesGroup.meta b/Core/EnginesGroup.meta new file mode 100644 index 0000000..4965a53 --- /dev/null +++ b/Core/EnginesGroup.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 283bf9c0ee343a8da006c6f651b6b41a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core/EnginesGroup/IStepEngine.cs b/Core/EnginesGroup/IStepEngine.cs new file mode 100644 index 0000000..bf4c249 --- /dev/null +++ b/Core/EnginesGroup/IStepEngine.cs @@ -0,0 +1,25 @@ +namespace Svelto.ECS +{ + public interface IStepEngine : IEngine + { + void Step(); + + string name { get; } + } + + public interface IStepEngine : IEngine + { + void Step(in T _param); + + string name { get; } + } + + //this must stay IStep Engine as it may be part of a group itself + public interface IStepGroupEngine : IStepEngine + { + } + + public interface IStepGroupEngine : IStepEngine + { + } +} \ No newline at end of file diff --git a/Core/EnginesGroup/IStepEngine.cs.meta b/Core/EnginesGroup/IStepEngine.cs.meta new file mode 100644 index 0000000..3ee581f --- /dev/null +++ b/Core/EnginesGroup/IStepEngine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ee2c4f1f4c543668b06899b70adbdd89 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SortedEnginesGroup.cs b/Core/EnginesGroup/SortedEnginesGroup.cs similarity index 80% rename from SortedEnginesGroup.cs rename to Core/EnginesGroup/SortedEnginesGroup.cs index dc4d7ec..e2d9224 100644 --- a/SortedEnginesGroup.cs +++ b/Core/EnginesGroup/SortedEnginesGroup.cs @@ -3,28 +3,6 @@ using Svelto.Common; namespace Svelto.ECS { - public interface IStepEngine : IEngine - { - void Step(); - - string name { get; } - } - - public interface IStepEngine : IEngine - { - void Step(ref T _param); - - string name { get; } - } - - public interface IStepGroupEngine : IStepEngine - { - } - - public interface IStepGroupEngine : IStepEngine - { - } - public abstract class SortedEnginesGroup : IStepGroupEngine where SequenceOrder : struct, ISequenceOrder where Interface : IStepEngine { @@ -47,7 +25,7 @@ namespace Svelto.ECS } } - public string name => _name; + public string name => _name; readonly string _name; readonly Sequence _instancedSequence; @@ -62,7 +40,7 @@ namespace Svelto.ECS _instancedSequence = new Sequence(engines); } - public void Step(ref Parameter param) + public void Step(in Parameter param) { var sequenceItems = _instancedSequence.items; using (var profiler = new PlatformProfiler(_name)) @@ -70,7 +48,7 @@ namespace Svelto.ECS for (var index = 0; index < sequenceItems.count; index++) { var engine = sequenceItems[index]; - using (profiler.Sample(engine.name)) engine.Step(ref param); + using (profiler.Sample(engine.name)) engine.Step(param); } } } diff --git a/SortedEnginesGroup.cs.meta b/Core/EnginesGroup/SortedEnginesGroup.cs.meta similarity index 83% rename from SortedEnginesGroup.cs.meta rename to Core/EnginesGroup/SortedEnginesGroup.cs.meta index 5c1c011..09bbd93 100644 --- a/SortedEnginesGroup.cs.meta +++ b/Core/EnginesGroup/SortedEnginesGroup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 690435cd81303cf593cf1c5bdf96e70f +guid: 07174f15395d3c0dba8a34b0d485bc22 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/UnsortedEnginesGroup.cs b/Core/EnginesGroup/UnsortedEnginesGroup.cs similarity index 50% rename from UnsortedEnginesGroup.cs rename to Core/EnginesGroup/UnsortedEnginesGroup.cs index 2362f80..c36572a 100644 --- a/UnsortedEnginesGroup.cs +++ b/Core/EnginesGroup/UnsortedEnginesGroup.cs @@ -30,4 +30,32 @@ namespace Svelto.ECS readonly string _name; readonly FasterList _instancedSequence; } + + public abstract class UnsortedEnginesGroup : IStepGroupEngine + where Interface : IStepEngine + { + protected UnsortedEnginesGroup(FasterList engines) + { + _name = "UnsortedEnginesGroup - "+this.GetType().Name; + _instancedSequence = engines; + } + + public void Step(in Parameter param) + { + var sequenceItems = _instancedSequence; + using (var profiler = new PlatformProfiler(_name)) + { + for (var index = 0; index < sequenceItems.count; index++) + { + var engine = sequenceItems[index]; + using (profiler.Sample(engine.name)) engine.Step(param); + } + } + } + + public string name => _name; + + readonly string _name; + readonly FasterList _instancedSequence; + } } \ No newline at end of file diff --git a/UnsortedEnginesGroup.cs.meta b/Core/EnginesGroup/UnsortedEnginesGroup.cs.meta similarity index 83% rename from UnsortedEnginesGroup.cs.meta rename to Core/EnginesGroup/UnsortedEnginesGroup.cs.meta index 9142963..0f395b8 100644 --- a/UnsortedEnginesGroup.cs.meta +++ b/Core/EnginesGroup/UnsortedEnginesGroup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 885e43f2997833bcacd6681fd4744a33 +guid: e211b8eca6013fbe96e90e4eeb954a58 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.DoubleBufferedEntitiesToAdd.cs b/Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs similarity index 99% rename from EnginesRoot.DoubleBufferedEntitiesToAdd.cs rename to Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs index 86322d4..d62f522 100644 --- a/EnginesRoot.DoubleBufferedEntitiesToAdd.cs +++ b/Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs @@ -1,5 +1,4 @@ -using System; -using Svelto.DataStructures; +using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS diff --git a/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta b/Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta similarity index 83% rename from EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta rename to Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta index df1be29..c0b15c1 100644 --- a/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta +++ b/Core/EnginesRoot.DoubleBufferedEntitiesToAdd.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5bf312fc57853c4d8368dcb99141a1e9 +guid: 36851f224e1339e489644c58b97044d9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.Engines.cs b/Core/EnginesRoot.Engines.cs similarity index 70% rename from EnginesRoot.Engines.cs rename to Core/EnginesRoot.Engines.cs index 7b3b388..b7f7e8c 100644 --- a/EnginesRoot.Engines.cs +++ b/Core/EnginesRoot.Engines.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using Svelto.Common; using Svelto.DataStructures; @@ -9,26 +10,38 @@ namespace Svelto.ECS { public sealed partial class EnginesRoot { - public readonly struct EntitiesSubmitter + public struct EntitiesSubmitter { - public EntitiesSubmitter(EnginesRoot enginesRoot) + public EntitiesSubmitter(EnginesRoot enginesRoot) : this() { _weakReference = new Svelto.DataStructures.WeakReference(enginesRoot); } public bool IsUnused => _weakReference.IsValid == false; - public void Invoke() + public IEnumerator Invoke(uint maxNumberOfOperationsPerFrame) { - if (_weakReference.IsValid) - _weakReference.Target.SubmitEntityComponents(); + var entitiesSubmissionScheduler = _weakReference.Target._scheduler; + if (_weakReference.IsValid && entitiesSubmissionScheduler.paused == false) + { + var submitEntityComponents = + _weakReference.Target.SubmitEntityComponents(maxNumberOfOperationsPerFrame); + DBC.ECS.Check.Require(entitiesSubmissionScheduler.isRunning == false + , "A submission started while the previous one was still flushing"); + entitiesSubmissionScheduler.isRunning = true; + while (submitEntityComponents.MoveNext() == true) + yield return null; + + entitiesSubmissionScheduler.isRunning = false; + ++entitiesSubmissionScheduler.iteration; + } } readonly Svelto.DataStructures.WeakReference _weakReference; } - readonly EntitiesSubmissionScheduler _scheduler; - public IEntitiesSubmissionScheduler scheduler => _scheduler; + readonly EntitiesSubmissionScheduler _scheduler; + public EntitiesSubmissionScheduler scheduler => _scheduler; /// /// Engines root contextualize your engines and entities. You don't need to limit yourself to one EngineRoot @@ -40,15 +53,16 @@ namespace Svelto.ECS /// public EnginesRoot(EntitiesSubmissionScheduler entitiesComponentScheduler) { - _entitiesOperations = new ThreadSafeDictionary(); - serializationDescriptorMap = new SerializationDescriptorMap(); - _reactiveEnginesAddRemove = new FasterDictionary>(); - _reactiveEnginesSwap = new FasterDictionary>(); - _reactiveEnginesSubmission = new FasterList(); - _enginesSet = new FasterList(); - _enginesTypeSet = new HashSet(); - _disposableEngines = new FasterList(); - _transientEntitiesOperations = new FasterList(); + _entitiesOperations = new FasterDictionary(); + serializationDescriptorMap = new SerializationDescriptorMap(); + _reactiveEnginesAddRemove = new FasterDictionary>(); + _reactiveEnginesAddRemoveOnDispose = new FasterDictionary>(); + _reactiveEnginesSwap = new FasterDictionary>(); + _reactiveEnginesSubmission = new FasterList(); + _enginesSet = new FasterList(); + _enginesTypeSet = new HashSet(); + _disposableEngines = new FasterList(); + _transientEntitiesOperations = new FasterList(); _groupEntityComponentsDB = new FasterDictionary>(); @@ -104,15 +118,13 @@ namespace Svelto.ECS } } - foreach (FasterDictionary>. - KeyValuePairFast groups in _groupEntityComponentsDB) + foreach (var groups in _groupEntityComponentsDB) { - foreach (FasterDictionary.KeyValuePairFast entityList in groups - .Value) + foreach (var entityList in groups.Value) try { - entityList.Value.ExecuteEnginesRemoveCallbacks(_reactiveEnginesAddRemove, profiler - , new ExclusiveGroupStruct(groups.Key)); + entityList.Value.ExecuteEnginesRemoveCallbacks(_reactiveEnginesAddRemoveOnDispose, profiler + , new ExclusiveGroupStruct(groups.Key)); } catch (Exception e) { @@ -120,18 +132,15 @@ namespace Svelto.ECS } } - foreach (FasterDictionary>. - KeyValuePairFast groups in _groupEntityComponentsDB) + foreach (var groups in _groupEntityComponentsDB) { - foreach (FasterDictionary.KeyValuePairFast entityList in groups - .Value) + foreach (var entityList in groups.Value) entityList.Value.Dispose(); } - foreach (FasterDictionary>. - KeyValuePairFast type in _groupFilters) - foreach (FasterDictionary.KeyValuePairFast group in type.Value) - group.Value.Dispose(); + foreach (var type in _groupFilters) + foreach (var group in type.Value) + group.Value.Dispose(); _groupFilters.Clear(); @@ -148,6 +157,7 @@ namespace Svelto.ECS _enginesTypeSet.Clear(); _reactiveEnginesSwap.Clear(); _reactiveEnginesAddRemove.Clear(); + _reactiveEnginesAddRemoveOnDispose.Clear(); _reactiveEnginesSubmission.Clear(); _entitiesOperations.Clear(); @@ -183,6 +193,9 @@ namespace Svelto.ECS if (engine is IReactOnAddAndRemove viewEngine) CheckReactEngineComponents(viewEngine, _reactiveEnginesAddRemove); + if (engine is IReactOnDispose viewEngineDispose) + CheckReactEngineComponents(viewEngineDispose, _reactiveEnginesAddRemoveOnDispose); + if (engine is IReactOnSwap viewEngineSwap) CheckReactEngineComponents(viewEngineSwap, _reactiveEnginesSwap); @@ -219,12 +232,12 @@ namespace Svelto.ECS { var genericArguments = interf.GetGenericArgumentsEx(); - AddEngine(engine, genericArguments, engines); + AddEngineToList(engine, genericArguments, engines); } } } - static void AddEngine + static void AddEngineToList (T engine, Type[] entityComponentTypes, FasterDictionary> engines) where T : class, IReactEngine { @@ -232,29 +245,24 @@ namespace Svelto.ECS { var type = entityComponentTypes[i]; - AddEngine(engine, engines, type); - } - } + if (engines.TryGetValue(new RefWrapperType(type), out var list) == false) + { + list = new FasterList(); - static void AddEngine(T engine, FasterDictionary> engines, Type type) - where T : class, IReactEngine - { - if (engines.TryGetValue(new RefWrapperType(type), out var list) == false) - { - list = new FasterList(); + engines.Add(new RefWrapperType(type), list); + } - engines.Add(new RefWrapperType(type), list); + list.Add(engine); } - - list.Add(engine); } readonly FasterDictionary> _reactiveEnginesAddRemove; + readonly FasterDictionary> _reactiveEnginesAddRemoveOnDispose; readonly FasterDictionary> _reactiveEnginesSwap; - readonly FasterList _reactiveEnginesSubmission; - readonly FasterList _disposableEngines; - readonly FasterList _enginesSet; - readonly HashSet _enginesTypeSet; - internal bool _isDisposing; + readonly FasterList _reactiveEnginesSubmission; + readonly FasterList _disposableEngines; + readonly FasterList _enginesSet; + readonly HashSet _enginesTypeSet; + internal bool _isDisposing; } } \ No newline at end of file diff --git a/EnginesRoot.Engines.cs.meta b/Core/EnginesRoot.Engines.cs.meta similarity index 83% rename from EnginesRoot.Engines.cs.meta rename to Core/EnginesRoot.Engines.cs.meta index 188770a..b86a6b1 100644 --- a/EnginesRoot.Engines.cs.meta +++ b/Core/EnginesRoot.Engines.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 06751374e9a5391080488d0150900530 +guid: 9e95fbe15f7d39cd8587f07094ece7b2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.Entities.cs b/Core/EnginesRoot.Entities.cs similarity index 98% rename from EnginesRoot.Entities.cs rename to Core/EnginesRoot.Entities.cs index fadbabb..1192ae2 100644 --- a/EnginesRoot.Entities.cs +++ b/Core/EnginesRoot.Entities.cs @@ -29,7 +29,7 @@ namespace Svelto.ECS ///-------------------------------------------- [MethodImpl(MethodImplOptions.AggressiveInlining)] - EntityComponentInitializer BuildEntity + EntityInitializer BuildEntity (EGID entityID, IComponentBuilder[] componentsToBuild, Type descriptorType, IEnumerable implementors = null) { @@ -39,7 +39,7 @@ namespace Svelto.ECS var dic = EntityFactory.BuildGroupedEntities(entityID, _groupedEntityToAdd, componentsToBuild , implementors, descriptorType); - return new EntityComponentInitializer(entityID, dic); + return new EntityInitializer(entityID, dic); } ///-------------------------------------------- @@ -285,8 +285,7 @@ namespace Svelto.ECS { if (_groupEntityComponentsDB.TryGetValue(groupID, out var dictionariesOfEntities)) { - foreach (FasterDictionary.KeyValuePairFast dictionaryOfEntities - in dictionariesOfEntities) + foreach (var dictionaryOfEntities in dictionariesOfEntities) { dictionaryOfEntities.Value.ExecuteEnginesRemoveCallbacks(_reactiveEnginesAddRemove, profiler , new ExclusiveGroupStruct(groupID)); diff --git a/EnginesRoot.Entities.cs.meta b/Core/EnginesRoot.Entities.cs.meta similarity index 83% rename from EnginesRoot.Entities.cs.meta rename to Core/EnginesRoot.Entities.cs.meta index 073c43b..aed09de 100644 --- a/EnginesRoot.Entities.cs.meta +++ b/Core/EnginesRoot.Entities.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4e91e7ae14883825ab74a51da18c18d5 +guid: 285427eb696631de93209efd46376859 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.GenericEntityFactory.cs b/Core/EnginesRoot.GenericEntityFactory.cs similarity index 75% rename from EnginesRoot.GenericEntityFactory.cs rename to Core/EnginesRoot.GenericEntityFactory.cs index e13432b..fc0a80e 100644 --- a/EnginesRoot.GenericEntityFactory.cs +++ b/Core/EnginesRoot.GenericEntityFactory.cs @@ -13,8 +13,8 @@ namespace Svelto.ECS _enginesRoot = new Svelto.DataStructures.WeakReference(weakReference); } - public EntityComponentInitializer BuildEntity - (uint entityID, BuildGroup groupStructId, IEnumerable implementors = null) + public EntityInitializer BuildEntity + (uint entityID, ExclusiveBuildGroup groupStructId, IEnumerable implementors = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId) @@ -22,26 +22,26 @@ namespace Svelto.ECS , TypeCache.type, implementors); } - public EntityComponentInitializer BuildEntity(EGID egid, IEnumerable implementors = null) + public EntityInitializer BuildEntity(EGID egid, IEnumerable implementors = null) where T : IEntityDescriptor, new() { return _enginesRoot.Target.BuildEntity( egid, EntityDescriptorTemplate.descriptor.componentsToBuild, TypeCache.type, implementors); } - public EntityComponentInitializer BuildEntity + public EntityInitializer BuildEntity (EGID egid, T entityDescriptor, IEnumerable implementors) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(egid, entityDescriptor.componentsToBuild, TypeCache.type, implementors); } #if UNITY_NATIVE - public NativeEntityFactory ToNative(string memberName) where T : IEntityDescriptor, new() + public NativeEntityFactory ToNative(string callerName) where T : IEntityDescriptor, new() { - return _enginesRoot.Target.ProvideNativeEntityFactoryQueue(memberName); + return _enginesRoot.Target.ProvideNativeEntityFactoryQueue(callerName); } #endif - public EntityComponentInitializer BuildEntity - (uint entityID, BuildGroup groupStructId, T descriptorEntity, IEnumerable implementors) + public EntityInitializer BuildEntity + (uint entityID, ExclusiveBuildGroup groupStructId, T descriptorEntity, IEnumerable implementors) where T : IEntityDescriptor { return _enginesRoot.Target.BuildEntity(new EGID(entityID, groupStructId) @@ -54,7 +54,7 @@ namespace Svelto.ECS _enginesRoot.Target.Preallocate(groupStructId, size); } - public EntityComponentInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable implementors = null) + public EntityInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable implementors = null) { return _enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors); } diff --git a/EnginesRoot.GenericEntityFactory.cs.meta b/Core/EnginesRoot.GenericEntityFactory.cs.meta similarity index 83% rename from EnginesRoot.GenericEntityFactory.cs.meta rename to Core/EnginesRoot.GenericEntityFactory.cs.meta index 309f694..13e7eb9 100644 --- a/EnginesRoot.GenericEntityFactory.cs.meta +++ b/Core/EnginesRoot.GenericEntityFactory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 44d18988251a391090b6a72a159f32b3 +guid: 3c51c0b5c5723f3bafc17521eff882b1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.GenericEntityFunctions.cs b/Core/EnginesRoot.GenericEntityFunctions.cs similarity index 88% rename from EnginesRoot.GenericEntityFunctions.cs rename to Core/EnginesRoot.GenericEntityFunctions.cs index 8b9a537..801700d 100644 --- a/EnginesRoot.GenericEntityFunctions.cs +++ b/Core/EnginesRoot.GenericEntityFunctions.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using Svelto.Common; using Svelto.DataStructures; using Svelto.ECS.Internal; @@ -20,18 +19,18 @@ namespace Svelto.ECS } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveEntity(uint entityID, BuildGroup groupID) where T : + public void RemoveEntity(uint entityID, ExclusiveBuildGroup groupID, [CallerMemberName] string memberName = "") where T : IEntityDescriptor, new() { - RemoveEntity(new EGID(entityID, groupID)); + RemoveEntity(new EGID(entityID, groupID), memberName); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveEntity(EGID entityEGID) where T : IEntityDescriptor, new() + public void RemoveEntity(EGID entityEGID, [CallerMemberName] string memberName = "") where T : IEntityDescriptor, new() { DBC.ECS.Check.Require(entityEGID.groupID != 0, "invalid group detected"); var descriptorComponentsToBuild = EntityDescriptorTemplate.descriptor.componentsToBuild; - _enginesRoot.Target.CheckRemoveEntityID(entityEGID, TypeCache.type); + _enginesRoot.Target.CheckRemoveEntityID(entityEGID, TypeCache.type, memberName); _enginesRoot.Target.QueueEntitySubmitOperation( new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityEGID, entityEGID, @@ -39,7 +38,7 @@ namespace Svelto.ECS } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void RemoveEntitiesFromGroup(BuildGroup groupID) + public void RemoveEntitiesFromGroup(ExclusiveBuildGroup groupID) { DBC.ECS.Check.Require(groupID != 0, "invalid group detected"); _enginesRoot.Target.RemoveGroupID(groupID); @@ -73,7 +72,7 @@ namespace Svelto.ECS // } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SwapEntitiesInGroup(BuildGroup fromGroupID, BuildGroup toGroupID) + public void SwapEntitiesInGroup(ExclusiveBuildGroup fromGroupID, ExclusiveBuildGroup toGroupID) where T : IEntityDescriptor, new() { if (_enginesRoot.Target._groupEntityComponentsDB.TryGetValue( @@ -98,23 +97,23 @@ namespace Svelto.ECS } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SwapEntityGroup(uint entityID, BuildGroup fromGroupID, - BuildGroup toGroupID) + public void SwapEntityGroup(uint entityID, ExclusiveBuildGroup fromGroupID, + ExclusiveBuildGroup toGroupID) where T : IEntityDescriptor, new() { SwapEntityGroup(new EGID(entityID, fromGroupID), toGroupID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SwapEntityGroup(EGID fromID, BuildGroup toGroupID) + public void SwapEntityGroup(EGID fromID, ExclusiveBuildGroup toGroupID) where T : IEntityDescriptor, new() { SwapEntityGroup(fromID, new EGID(fromID.entityID, (uint) toGroupID)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SwapEntityGroup(EGID fromID, BuildGroup toGroupID - , BuildGroup mustBeFromGroup) + public void SwapEntityGroup(EGID fromID, ExclusiveBuildGroup toGroupID + , ExclusiveBuildGroup mustBeFromGroup) where T : IEntityDescriptor, new() { if (fromID.groupID != mustBeFromGroup) @@ -125,7 +124,7 @@ namespace Svelto.ECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SwapEntityGroup(EGID fromID, EGID toID - , BuildGroup mustBeFromGroup) + , ExclusiveBuildGroup mustBeFromGroup) where T : IEntityDescriptor, new() { if (fromID.groupID != mustBeFromGroup) @@ -196,7 +195,7 @@ namespace Svelto.ECS } else #endif - _entitiesOperations.Set((ulong) entitySubmitOperation.fromID, entitySubmitOperation); + _entitiesOperations[(ulong) entitySubmitOperation.fromID] = entitySubmitOperation; } } } \ No newline at end of file diff --git a/EnginesRoot.GenericEntityFunctions.cs.meta b/Core/EnginesRoot.GenericEntityFunctions.cs.meta similarity index 83% rename from EnginesRoot.GenericEntityFunctions.cs.meta rename to Core/EnginesRoot.GenericEntityFunctions.cs.meta index 4199b70..5effed3 100644 --- a/EnginesRoot.GenericEntityFunctions.cs.meta +++ b/Core/EnginesRoot.GenericEntityFunctions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 682629f22d513d658b85361c143e5a48 +guid: a3e5901720f035a7bd7f9d192cc0a9ed MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EnginesRoot.Submission.cs b/Core/EnginesRoot.Submission.cs similarity index 53% rename from EnginesRoot.Submission.cs rename to Core/EnginesRoot.Submission.cs index 559c800..8c22000 100644 --- a/EnginesRoot.Submission.cs +++ b/Core/EnginesRoot.Submission.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections; using Svelto.Common; using Svelto.DataStructures; using Svelto.ECS.Internal; @@ -9,16 +9,18 @@ namespace Svelto.ECS { readonly FasterList _transientEntitiesOperations; - void SubmitEntityComponents() + IEnumerator SubmitEntityComponents(uint maxNumberOfOperations) { using (var profiler = new PlatformProfiler("Svelto.ECS - Entities Submission")) { int iterations = 0; do { - SingleSubmission(profiler); + var submitEntityComponents = SingleSubmission(profiler, maxNumberOfOperations); + while (submitEntityComponents.MoveNext() == true) + yield return null; } while ((_groupedEntityToAdd.currentEntitiesCreatedPerGroup.count > 0 || - _entitiesOperations.Count > 0) && ++iterations < 5); + _entitiesOperations.count > 0) && ++iterations < 5); #if DEBUG && !PROFILE_SVELTO if (iterations == 5) @@ -32,7 +34,8 @@ namespace Svelto.ECS /// Something to do when I will optimize the callbacks /// /// - void SingleSubmission(in PlatformProfiler profiler) + /// + IEnumerator SingleSubmission(PlatformProfiler profiler, uint maxNumberOfOperations) { #if UNITY_NATIVE NativeOperationSubmission(profiler); @@ -40,8 +43,9 @@ namespace Svelto.ECS ClearChecks(); bool entitiesAreSubmitted = false; + uint numberOfOperations = 0; - if (_entitiesOperations.Count > 0) + if (_entitiesOperations.count > 0) { using (profiler.Sample("Remove and Swap operations")) { @@ -88,6 +92,16 @@ namespace Svelto.ECS throw; } + + ++numberOfOperations; + + if ((uint)numberOfOperations >= (uint)maxNumberOfOperations) + { + yield return null; + + numberOfOperations = 0; + + } } } @@ -102,11 +116,61 @@ namespace Svelto.ECS { try { - AddEntityComponentsToTheDBAndSuitableEngines(profiler); + using (profiler.Sample("Add entities to database")) + { + //each group is indexed by entity view type. for each type there is a dictionary indexed by entityID + foreach (var groupToSubmit in _groupedEntityToAdd.otherEntitiesCreatedPerGroup) + { + var groupID = groupToSubmit.Key; + var groupDB = GetOrCreateGroup(groupID, profiler); + + //add the entityComponents in the group + foreach (var entityComponentsToSubmit in _groupedEntityToAdd.other[groupID]) + { + var type = entityComponentsToSubmit.Key; + var targetTypeSafeDictionary = entityComponentsToSubmit.Value; + var wrapper = new RefWrapperType(type); + + ITypeSafeDictionary dbDic = GetOrCreateTypeSafeDictionary(groupID, groupDB, wrapper, + targetTypeSafeDictionary); + + //Fill the DB with the entity components generate this frame. + dbDic.AddEntitiesFromDictionary(targetTypeSafeDictionary, groupID); + } + } + } + + //then submit everything in the engines, so that the DB is up to date with all the entity components + //created by the entity built + using (profiler.Sample("Add entities to engines")) + { + foreach (var groupToSubmit in _groupedEntityToAdd.otherEntitiesCreatedPerGroup) + { + var groupID = groupToSubmit.Key; + var groupDB = _groupEntityComponentsDB[groupID]; + + foreach (var entityComponentsToSubmit in _groupedEntityToAdd.other[groupID]) + { + var realDic = groupDB[new RefWrapperType(entityComponentsToSubmit.Key)]; + + entityComponentsToSubmit.Value.ExecuteEnginesAddOrSwapCallbacks(_reactiveEnginesAddRemove, realDic, + null, new ExclusiveGroupStruct(groupID), in profiler); + + ++numberOfOperations; + + if (numberOfOperations >= maxNumberOfOperations) + { + yield return null; + + numberOfOperations = 0; + } + } + } + } } finally { - using (profiler.Sample("clear 6operates double buffering")) + using (profiler.Sample("clear double buffering")) { //other can be cleared now, but let's avoid deleting the dictionary every time _groupedEntityToAdd.ClearOther(); @@ -125,54 +189,7 @@ namespace Svelto.ECS } } - void AddEntityComponentsToTheDBAndSuitableEngines(in PlatformProfiler profiler) - { - using (profiler.Sample("Add entities to database")) - { - //each group is indexed by entity view type. for each type there is a dictionary indexed by entityID - foreach (var groupOfEntitiesToSubmit in _groupedEntityToAdd.otherEntitiesCreatedPerGroup) - { - var groupID = groupOfEntitiesToSubmit.Key; - - var groupDB = GetOrCreateGroup(groupID, profiler); - - //add the entityComponents in the group - foreach (var entityComponentsToSubmit in _groupedEntityToAdd.other[groupID]) - { - var type = entityComponentsToSubmit.Key; - var targetTypeSafeDictionary = entityComponentsToSubmit.Value; - var wrapper = new RefWrapperType(type); - - ITypeSafeDictionary dbDic = GetOrCreateTypeSafeDictionary(groupID, groupDB, wrapper, - targetTypeSafeDictionary); - - //Fill the DB with the entity components generate this frame. - dbDic.AddEntitiesFromDictionary(targetTypeSafeDictionary, groupID); - } - } - } - - //then submit everything in the engines, so that the DB is up to date with all the entity components - //created by the entity built - using (profiler.Sample("Add entities to engines")) - { - foreach (var groupToSubmit in _groupedEntityToAdd.otherEntitiesCreatedPerGroup) - { - var groupID = groupToSubmit.Key; - var groupDB = _groupEntityComponentsDB[groupID]; - - foreach (var entityComponentsToSubmit in _groupedEntityToAdd.other[groupID]) - { - var realDic = groupDB[new RefWrapperType(entityComponentsToSubmit.Key)]; - - entityComponentsToSubmit.Value.ExecuteEnginesAddOrSwapCallbacks(_reactiveEnginesAddRemove, realDic, - null, new ExclusiveGroupStruct(groupToSubmit.Key), in profiler); - } - } - } - } - readonly DoubleBufferedEntitiesToAdd _groupedEntityToAdd; - readonly ThreadSafeDictionary _entitiesOperations; + readonly FasterDictionary _entitiesOperations; } } \ No newline at end of file diff --git a/EnginesRoot.Submission.cs.meta b/Core/EnginesRoot.Submission.cs.meta similarity index 83% rename from EnginesRoot.Submission.cs.meta rename to Core/EnginesRoot.Submission.cs.meta index 8969107..a8f168a 100644 --- a/EnginesRoot.Submission.cs.meta +++ b/Core/EnginesRoot.Submission.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 973c984f2c7e39b8a01cbc6fc27a23a4 +guid: d0fa18c41935378096a8a18fef23d90c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntitiesDB.FindGroups.cs b/Core/EntitiesDB.FindGroups.cs similarity index 100% rename from EntitiesDB.FindGroups.cs rename to Core/EntitiesDB.FindGroups.cs diff --git a/EntitiesDB.FindGroups.cs.meta b/Core/EntitiesDB.FindGroups.cs.meta similarity index 83% rename from EntitiesDB.FindGroups.cs.meta rename to Core/EntitiesDB.FindGroups.cs.meta index 3183390..f80c63f 100644 --- a/EntitiesDB.FindGroups.cs.meta +++ b/Core/EntitiesDB.FindGroups.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 11e0317f53f0374d9924cae6235eacdb +guid: 3a9f8fa92212370fb4baed7ca10e1404 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntitiesDB.cs b/Core/EntitiesDB.cs similarity index 100% rename from EntitiesDB.cs rename to Core/EntitiesDB.cs diff --git a/EntitiesDB.cs.meta b/Core/EntitiesDB.cs.meta similarity index 83% rename from EntitiesDB.cs.meta rename to Core/EntitiesDB.cs.meta index 736ac6b..ef1868c 100644 --- a/EntitiesDB.cs.meta +++ b/Core/EntitiesDB.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ed0a1aea8dc43fbd8c620e8c09ac389b +guid: 48c9691c769a30019d3b411353e06df3 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityCollection.cs b/Core/EntityCollection.cs similarity index 82% rename from EntityCollection.cs rename to Core/EntityCollection.cs index c39ed69..803328f 100644 --- a/EntityCollection.cs +++ b/Core/EntityCollection.cs @@ -6,16 +6,17 @@ namespace Svelto.ECS { public readonly ref struct EntityCollection where T : struct, IEntityComponent { - static readonly bool IsUnmanaged = TypeSafeDictionary.IsUnmanaged; - - public EntityCollection(IBuffer buffer, uint count):this() + static readonly bool IsUnmanaged = TypeSafeDictionary.IsUnmanaged; + + public EntityCollection(IBuffer buffer, uint count) : this() { + DBC.ECS.Check.Require(count == 0 || buffer.isValid, "Buffer is found in impossible state"); if (IsUnmanaged) _nativedBuffer = (NB) buffer; else _managedBuffer = (MB) buffer; - - _count = count; + + _count = count; } public uint count => _count; @@ -26,7 +27,8 @@ namespace Svelto.ECS readonly uint _count; } - public readonly ref struct EntityCollection where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent + public readonly ref struct EntityCollection + where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent { internal EntityCollection(in EntityCollection array1, in EntityCollection array2) { @@ -89,14 +91,14 @@ namespace Svelto.ECS readonly EntityCollection _array3; } - public readonly ref struct EntityCollection - where T1 : struct, IEntityComponent - where T2 : struct, IEntityComponent - where T3 : struct, IEntityComponent - where T4 : struct, IEntityComponent + public readonly ref struct EntityCollection where T1 : struct, IEntityComponent + where T2 : struct, IEntityComponent + where T3 : struct, IEntityComponent + where T4 : struct, IEntityComponent { internal EntityCollection - (in EntityCollection array1, in EntityCollection array2, in EntityCollection array3, in EntityCollection array4) + (in EntityCollection array1, in EntityCollection array2, in EntityCollection array3 + , in EntityCollection array4) { _array1 = array1; _array2 = array2; @@ -104,25 +106,25 @@ namespace Svelto.ECS _array4 = array4; } - internal EntityCollection Item1 + internal EntityCollection buffer1 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array1; } - internal EntityCollection Item2 + internal EntityCollection buffer2 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array2; } - internal EntityCollection Item3 + internal EntityCollection buffer3 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array3; } - - internal EntityCollection Item4 + + internal EntityCollection buffer4 { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _array4; @@ -142,7 +144,7 @@ namespace Svelto.ECS public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; public readonly BufferT4 buffer4; - public readonly int count; + public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, BufferT4 bufferT4, uint count) : this() { @@ -159,7 +161,7 @@ namespace Svelto.ECS public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; public readonly BufferT3 buffer3; - public readonly int count; + public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, BufferT3 bufferT3, uint count) : this() { @@ -174,27 +176,27 @@ namespace Svelto.ECS bufferT1 = buffer1; bufferT2 = buffer2; bufferT3 = buffer3; - count = this.count; + count = this.count; } } public readonly struct BT { public readonly BufferT1 buffer; - public readonly int count; + public readonly int count; public BT(BufferT1 bufferT1, uint count) : this() { this.buffer = bufferT1; this.count = (int) count; } - + public void Deconstruct(out BufferT1 bufferT1, out int count) { bufferT1 = buffer; count = this.count; } - + public static implicit operator BufferT1(BT t) => t.buffer; } @@ -202,7 +204,7 @@ namespace Svelto.ECS { public readonly BufferT1 buffer1; public readonly BufferT2 buffer2; - public readonly int count; + public readonly int count; public BT(BufferT1 bufferT1, BufferT2 bufferT2, uint count) : this() { @@ -210,7 +212,7 @@ namespace Svelto.ECS this.buffer2 = bufferT2; this.count = (int) count; } - + public void Deconstruct(out BufferT1 bufferT1, out BufferT2 bufferT2, out int count) { bufferT1 = buffer1; @@ -218,4 +220,4 @@ namespace Svelto.ECS count = this.count; } } -} +} \ No newline at end of file diff --git a/EntityCollection.cs.meta b/Core/EntityCollection.cs.meta similarity index 83% rename from EntityCollection.cs.meta rename to Core/EntityCollection.cs.meta index ea65200..8f12b7b 100644 --- a/EntityCollection.cs.meta +++ b/Core/EntityCollection.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 40f815cf92d2362d8d1b86099231660f +guid: 7c93f6823945390588d566a600f0dfbe MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/EntityDescriptor.meta b/Core/EntityDescriptor.meta new file mode 100644 index 0000000..c71f2df --- /dev/null +++ b/Core/EntityDescriptor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4384643b30cf368c9e63ff9f8d683c1a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/DynamicEntityDescriptor.cs b/Core/EntityDescriptor/DynamicEntityDescriptor.cs similarity index 100% rename from DynamicEntityDescriptor.cs rename to Core/EntityDescriptor/DynamicEntityDescriptor.cs diff --git a/DynamicEntityDescriptor.cs.meta b/Core/EntityDescriptor/DynamicEntityDescriptor.cs.meta similarity index 83% rename from DynamicEntityDescriptor.cs.meta rename to Core/EntityDescriptor/DynamicEntityDescriptor.cs.meta index e978b5d..939702e 100644 --- a/DynamicEntityDescriptor.cs.meta +++ b/Core/EntityDescriptor/DynamicEntityDescriptor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7302cea0b2d33e25a977d5eab9553ffa +guid: fe131b7b45e33280be3e268429559849 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ExtendibleEntityDescriptor.cs b/Core/EntityDescriptor/ExtendibleEntityDescriptor.cs similarity index 77% rename from ExtendibleEntityDescriptor.cs rename to Core/EntityDescriptor/ExtendibleEntityDescriptor.cs index 384823c..6e479f8 100644 --- a/ExtendibleEntityDescriptor.cs +++ b/Core/EntityDescriptor/ExtendibleEntityDescriptor.cs @@ -6,6 +6,19 @@ namespace Svelto.ECS /// /// Inherit from an ExtendibleEntityDescriptor to extend a base entity descriptor that can be used /// to swap and remove specialized entities from abstract engines + /// + /// Usage Example: + /// + /// class SpecialisedDescriptor : ExtendibleEntityDescriptor + /// { + /// public SpecialisedDescriptor() : base (new IComponentBuilder[] + /// { + /// new ComponentBuilder() //add more components to the base descriptor + /// }) + /// { + /// ExtendWith(); //add extra components from descriptors that act as contract + /// } + /// } /// /// public class ExtendibleEntityDescriptor : IDynamicEntityDescriptor where TType : IEntityDescriptor, new() diff --git a/ExtendibleEntityDescriptor.cs.meta b/Core/EntityDescriptor/ExtendibleEntityDescriptor.cs.meta similarity index 83% rename from ExtendibleEntityDescriptor.cs.meta rename to Core/EntityDescriptor/ExtendibleEntityDescriptor.cs.meta index 1815317..e16431f 100644 --- a/ExtendibleEntityDescriptor.cs.meta +++ b/Core/EntityDescriptor/ExtendibleEntityDescriptor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 556422fea1ed3a2da4ffe08d8c57791d +guid: bfe2a66cb78f3fc195d27f316bb5dfbf MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/GenericEntityDescriptor.cs b/Core/EntityDescriptor/GenericEntityDescriptor.cs similarity index 100% rename from GenericEntityDescriptor.cs rename to Core/EntityDescriptor/GenericEntityDescriptor.cs diff --git a/GenericEntityDescriptor.cs.meta b/Core/EntityDescriptor/GenericEntityDescriptor.cs.meta similarity index 83% rename from GenericEntityDescriptor.cs.meta rename to Core/EntityDescriptor/GenericEntityDescriptor.cs.meta index de069d3..b843a12 100644 --- a/GenericEntityDescriptor.cs.meta +++ b/Core/EntityDescriptor/GenericEntityDescriptor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fcc3912821f83f1c89b6cf7a53776f22 +guid: 0ebe5676f01b32709d477f35e66418d6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/EntityDescriptor/IDynamicEntityDescriptor.cs b/Core/EntityDescriptor/IDynamicEntityDescriptor.cs new file mode 100644 index 0000000..f7889de --- /dev/null +++ b/Core/EntityDescriptor/IDynamicEntityDescriptor.cs @@ -0,0 +1,6 @@ +namespace Svelto.ECS +{ + public interface IDynamicEntityDescriptor: IEntityDescriptor + { + } +} \ No newline at end of file diff --git a/Core/EntityDescriptor/IDynamicEntityDescriptor.cs.meta b/Core/EntityDescriptor/IDynamicEntityDescriptor.cs.meta new file mode 100644 index 0000000..eddd7ac --- /dev/null +++ b/Core/EntityDescriptor/IDynamicEntityDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a46883da73f53f8c80de22402a293c6a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core/EntityDescriptor/IEntityDescriptor.cs b/Core/EntityDescriptor/IEntityDescriptor.cs new file mode 100644 index 0000000..45674f2 --- /dev/null +++ b/Core/EntityDescriptor/IEntityDescriptor.cs @@ -0,0 +1,7 @@ +namespace Svelto.ECS +{ + public interface IEntityDescriptor + { + IComponentBuilder[] componentsToBuild { get; } + } +} \ No newline at end of file diff --git a/Core/EntityDescriptor/IEntityDescriptor.cs.meta b/Core/EntityDescriptor/IEntityDescriptor.cs.meta new file mode 100644 index 0000000..99dbc3d --- /dev/null +++ b/Core/EntityDescriptor/IEntityDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9da55a5d6ea337fb438062186eb459e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/EntityDescriptorTemplate.cs b/Core/EntityDescriptorTemplate.cs similarity index 72% rename from EntityDescriptorTemplate.cs rename to Core/EntityDescriptorTemplate.cs index d32b16b..e7b1525 100644 --- a/EntityDescriptorTemplate.cs +++ b/Core/EntityDescriptorTemplate.cs @@ -2,15 +2,6 @@ using System; namespace Svelto.ECS { - public interface IEntityDescriptor - { - IComponentBuilder[] componentsToBuild { get; } - } - - public interface IDynamicEntityDescriptor: IEntityDescriptor - { - } - static class EntityDescriptorTemplate where TType : IEntityDescriptor, new() { static EntityDescriptorTemplate() diff --git a/EntityDescriptorTemplate.cs.meta b/Core/EntityDescriptorTemplate.cs.meta similarity index 83% rename from EntityDescriptorTemplate.cs.meta rename to Core/EntityDescriptorTemplate.cs.meta index 9357145..2ef37fe 100644 --- a/EntityDescriptorTemplate.cs.meta +++ b/Core/EntityDescriptorTemplate.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 92c8c4b47f1b3e09866c630f2a653595 +guid: 275dc525832d3dea9603e34155f4bd31 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityFactory.cs b/Core/EntityFactory.cs similarity index 100% rename from EntityFactory.cs rename to Core/EntityFactory.cs diff --git a/EntityFactory.cs.meta b/Core/EntityFactory.cs.meta similarity index 83% rename from EntityFactory.cs.meta rename to Core/EntityFactory.cs.meta index 7d4420e..705da6c 100644 --- a/EntityFactory.cs.meta +++ b/Core/EntityFactory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ab53ac7587913f74ae704c3b436f435b +guid: e72bb26ae5d3308386aa30e95eea9479 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityGroupNotFoundException.cs b/Core/EntityGroupNotFoundException.cs similarity index 100% rename from EntityGroupNotFoundException.cs rename to Core/EntityGroupNotFoundException.cs diff --git a/EntityGroupNotFoundException.cs.meta b/Core/EntityGroupNotFoundException.cs.meta similarity index 83% rename from EntityGroupNotFoundException.cs.meta rename to Core/EntityGroupNotFoundException.cs.meta index 4a3a02d..1168d44 100644 --- a/EntityGroupNotFoundException.cs.meta +++ b/Core/EntityGroupNotFoundException.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a47fdee155873f1b885a2247f91d17e1 +guid: f5290f4d2cdc30d4bb27969f6f41d052 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityInfoView.cs b/Core/EntityInfoView.cs similarity index 100% rename from EntityInfoView.cs rename to Core/EntityInfoView.cs diff --git a/EntityInfoView.cs.meta b/Core/EntityInfoView.cs.meta similarity index 83% rename from EntityInfoView.cs.meta rename to Core/EntityInfoView.cs.meta index f9f93a6..a3d36ab 100644 --- a/EntityInfoView.cs.meta +++ b/Core/EntityInfoView.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 736fd837eacf3210b80c1c46a3242b6f +guid: 3782e96d12573ef7a4e7cda84492abca MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityComponentInitializer.cs b/Core/EntityInitializer.cs similarity index 90% rename from EntityComponentInitializer.cs rename to Core/EntityInitializer.cs index 72cbad2..dd2b2e3 100644 --- a/EntityComponentInitializer.cs +++ b/Core/EntityInitializer.cs @@ -1,12 +1,11 @@ -using System; -using Svelto.DataStructures; +using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS { - public readonly ref struct EntityComponentInitializer + public readonly ref struct EntityInitializer { - public EntityComponentInitializer(EGID id, FasterDictionary group) + public EntityInitializer(EGID id, FasterDictionary group) { _group = group; _ID = id; diff --git a/Core/EntityInitializer.cs.meta b/Core/EntityInitializer.cs.meta new file mode 100644 index 0000000..d0ae1d3 --- /dev/null +++ b/Core/EntityInitializer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5f91809a80832939d3d4cb8adefd744 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/EntityNotFoundException.cs b/Core/EntityNotFoundException.cs similarity index 100% rename from EntityNotFoundException.cs rename to Core/EntityNotFoundException.cs diff --git a/EntityNotFoundException.cs.meta b/Core/EntityNotFoundException.cs.meta similarity index 83% rename from EntityNotFoundException.cs.meta rename to Core/EntityNotFoundException.cs.meta index d759b90..2184b79 100644 --- a/EntityNotFoundException.cs.meta +++ b/Core/EntityNotFoundException.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 77c06caa7f893965b2fcb96361c01b26 +guid: 03bfc923223536d0bb63c3a3b8e3351b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/EntitySubmissionScheduler.cs b/Core/EntitySubmissionScheduler.cs new file mode 100644 index 0000000..ac24d91 --- /dev/null +++ b/Core/EntitySubmissionScheduler.cs @@ -0,0 +1,16 @@ +using System.Collections; + +namespace Svelto.ECS.Schedulers +{ + public abstract class EntitiesSubmissionScheduler + { + protected internal abstract EnginesRoot.EntitiesSubmitter onTick { set; } + + public abstract void Dispose(); + + public abstract bool paused { get; set; } + public uint iteration { get; protected internal set; } + + internal bool isRunning; + } +} \ No newline at end of file diff --git a/EntitySubmissionScheduler.cs.meta b/Core/EntitySubmissionScheduler.cs.meta similarity index 83% rename from EntitySubmissionScheduler.cs.meta rename to Core/EntitySubmissionScheduler.cs.meta index 6cdbe74..996e6f9 100644 --- a/EntitySubmissionScheduler.cs.meta +++ b/Core/EntitySubmissionScheduler.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 154b8b6eca333188a3a9838eb9702852 +guid: 7b3aa74564f6362ca6e3c22f072cd5ac MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntitySubmitOperation.cs b/Core/EntitySubmitOperation.cs similarity index 100% rename from EntitySubmitOperation.cs rename to Core/EntitySubmitOperation.cs diff --git a/EntitySubmitOperation.cs.meta b/Core/EntitySubmitOperation.cs.meta similarity index 83% rename from EntitySubmitOperation.cs.meta rename to Core/EntitySubmitOperation.cs.meta index 7d139c0..c96e5d3 100644 --- a/EntitySubmitOperation.cs.meta +++ b/Core/EntitySubmitOperation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d2606ff288d53bf79dc8528a1b937a28 +guid: 871a9cbbaa6f3ddaa66006db670e8d62 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/EntityViewUtility.cs b/Core/EntityViewUtility.cs similarity index 100% rename from EntityViewUtility.cs rename to Core/EntityViewUtility.cs diff --git a/EntityViewUtility.cs.meta b/Core/EntityViewUtility.cs.meta similarity index 83% rename from EntityViewUtility.cs.meta rename to Core/EntityViewUtility.cs.meta index 68884c2..7189d57 100644 --- a/EntityViewUtility.cs.meta +++ b/Core/EntityViewUtility.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 96edc607702a36969e4a671478a49319 +guid: 6d5906217c3431e79e8938b026700ba1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Filters.meta b/Core/Filters.meta similarity index 77% rename from Filters.meta rename to Core/Filters.meta index 760b9c8..2fc42d4 100644 --- a/Filters.meta +++ b/Core/Filters.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 661a733f7383361088023fba3ffea29b +guid: 069239a1daad353c88ee1334d8c7b138 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Filters/EntitiesDB.GroupFilters.cs b/Core/Filters/EntitiesDB.GroupFilters.cs similarity index 99% rename from Filters/EntitiesDB.GroupFilters.cs rename to Core/Filters/EntitiesDB.GroupFilters.cs index 77e5684..af599d9 100644 --- a/Filters/EntitiesDB.GroupFilters.cs +++ b/Core/Filters/EntitiesDB.GroupFilters.cs @@ -1,4 +1,3 @@ -using System; using Svelto.DataStructures; namespace Svelto.ECS @@ -99,7 +98,7 @@ namespace Svelto.ECS #endif return ref _filters[TypeRefWrapper.wrapper][groupID].GetFilter(filterId); } - + public bool TryGetFilterForGroup(int filterId, ExclusiveGroupStruct groupID, out FilterGroup groupFilter) where T : struct, IEntityComponent { diff --git a/Filters/EntitiesDB.GroupFilters.cs.meta b/Core/Filters/EntitiesDB.GroupFilters.cs.meta similarity index 83% rename from Filters/EntitiesDB.GroupFilters.cs.meta rename to Core/Filters/EntitiesDB.GroupFilters.cs.meta index deb8ca1..db34c30 100644 --- a/Filters/EntitiesDB.GroupFilters.cs.meta +++ b/Core/Filters/EntitiesDB.GroupFilters.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e2644d7bdd9e3c4d96a07f93a5a28497 +guid: 5a8f3a6e101838a88604fe66d87cf9d6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Filters/FilterGroup.cs b/Core/Filters/FilterGroup.cs similarity index 100% rename from Filters/FilterGroup.cs rename to Core/Filters/FilterGroup.cs diff --git a/Filters/FilterGroup.cs.meta b/Core/Filters/FilterGroup.cs.meta similarity index 83% rename from Filters/FilterGroup.cs.meta rename to Core/Filters/FilterGroup.cs.meta index 7dd88f8..817c3d0 100644 --- a/Filters/FilterGroup.cs.meta +++ b/Core/Filters/FilterGroup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 820d8be7dde53b5b94864955b2a26a67 +guid: 2f13dc2395a2359fa5acac05ebaafc41 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Filters/FilteredIndices.cs b/Core/Filters/FilteredIndices.cs similarity index 53% rename from Filters/FilteredIndices.cs rename to Core/Filters/FilteredIndices.cs index 47697cd..799a8f6 100644 --- a/Filters/FilteredIndices.cs +++ b/Core/Filters/FilteredIndices.cs @@ -8,14 +8,28 @@ namespace Svelto.ECS public FilteredIndices(NativeDynamicArrayCast denseListOfIndicesToEntityComponentArray) { _denseListOfIndicesToEntityComponentArray = denseListOfIndicesToEntityComponentArray; + _count = _denseListOfIndicesToEntityComponentArray.count; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Count() => _denseListOfIndicesToEntityComponentArray.Count(); + public int Count() => _count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public uint Get(uint index) => _denseListOfIndicesToEntityComponentArray[index]; + public uint this[uint index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _denseListOfIndicesToEntityComponentArray[index]; + } + + public uint this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _denseListOfIndicesToEntityComponentArray[index]; + } + readonly NativeDynamicArrayCast _denseListOfIndicesToEntityComponentArray; + readonly int _count; } } \ No newline at end of file diff --git a/Filters/FilteredIndices.cs.meta b/Core/Filters/FilteredIndices.cs.meta similarity index 83% rename from Filters/FilteredIndices.cs.meta rename to Core/Filters/FilteredIndices.cs.meta index aa47509..72905df 100644 --- a/Filters/FilteredIndices.cs.meta +++ b/Core/Filters/FilteredIndices.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8311e83888a9391a821923ab0940cb81 +guid: 8d699c30169d326ba534c80d1ab5c504 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Filters/GroupFilters.cs b/Core/Filters/GroupFilters.cs similarity index 98% rename from Filters/GroupFilters.cs rename to Core/Filters/GroupFilters.cs index 4226a23..99004d8 100644 --- a/Filters/GroupFilters.cs +++ b/Core/Filters/GroupFilters.cs @@ -40,7 +40,7 @@ namespace Svelto.ECS return filters.TryGetValue(filterIndex, out filter); } - public SveltoDictionary>, NativeStrategy + public SveltoDictionary>, NativeStrategy , NativeStrategy>.SveltoDictionaryKeyValueEnumerator GetEnumerator() { return filters.GetEnumerator(); diff --git a/Filters/GroupFilters.cs.meta b/Core/Filters/GroupFilters.cs.meta similarity index 83% rename from Filters/GroupFilters.cs.meta rename to Core/Filters/GroupFilters.cs.meta index afb6a65..41dc438 100644 --- a/Filters/GroupFilters.cs.meta +++ b/Core/Filters/GroupFilters.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 36769f644df630609a3f3c4589bab898 +guid: 7f1fcb3722433ba98f34384a1553a661 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/GlobalTypeID.cs b/Core/GlobalTypeID.cs similarity index 90% rename from GlobalTypeID.cs rename to Core/GlobalTypeID.cs index 78a12c6..8e4cc18 100644 --- a/GlobalTypeID.cs +++ b/Core/GlobalTypeID.cs @@ -16,7 +16,7 @@ namespace Svelto.ECS interface IFiller { - void FillFromByteArray(EntityComponentInitializer init, NativeBag buffer); + void FillFromByteArray(EntityInitializer init, NativeBag buffer); } class Filler : IFiller where T : struct, IEntityComponent @@ -27,7 +27,7 @@ namespace Svelto.ECS } //it's an internal interface - public void FillFromByteArray(EntityComponentInitializer init, NativeBag buffer) + public void FillFromByteArray(EntityInitializer init, NativeBag buffer) { var component = buffer.Dequeue(); diff --git a/GlobalTypeID.cs.meta b/Core/GlobalTypeID.cs.meta similarity index 83% rename from GlobalTypeID.cs.meta rename to Core/GlobalTypeID.cs.meta index 06f8a43..9e9362f 100644 --- a/GlobalTypeID.cs.meta +++ b/Core/GlobalTypeID.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 740c683eaf643b0ea295428cd190c318 +guid: 37971713191c36abbf22e12726eac5b1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/Groups.meta b/Core/Groups.meta new file mode 100644 index 0000000..3cdd03d --- /dev/null +++ b/Core/Groups.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a1919d31796f3c9f954d36b5debf3047 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core/Groups/ExclusiveBuildGroup.cs b/Core/Groups/ExclusiveBuildGroup.cs new file mode 100644 index 0000000..87aca8b --- /dev/null +++ b/Core/Groups/ExclusiveBuildGroup.cs @@ -0,0 +1,27 @@ +namespace Svelto.ECS +{ + public readonly struct ExclusiveBuildGroup + { + internal ExclusiveBuildGroup(ExclusiveGroupStruct group) + { + this.group = group; + } + + public static implicit operator ExclusiveBuildGroup(ExclusiveGroupStruct group) + { + return new ExclusiveBuildGroup(group); + } + + public static implicit operator ExclusiveBuildGroup(ExclusiveGroup group) + { + return new ExclusiveBuildGroup(group); + } + + public static implicit operator uint(ExclusiveBuildGroup groupStruct) + { + return groupStruct.group; + } + + internal ExclusiveGroupStruct @group { get; } + } +} \ No newline at end of file diff --git a/Core/Groups/ExclusiveBuildGroup.cs.meta b/Core/Groups/ExclusiveBuildGroup.cs.meta new file mode 100644 index 0000000..67ace25 --- /dev/null +++ b/Core/Groups/ExclusiveBuildGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 759fccc978ac33eaab89d2076fc6545d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ExclusiveGroup.cs b/Core/Groups/ExclusiveGroup.cs similarity index 99% rename from ExclusiveGroup.cs rename to Core/Groups/ExclusiveGroup.cs index b4fdac3..6f691fa 100644 --- a/ExclusiveGroup.cs +++ b/Core/Groups/ExclusiveGroup.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; #pragma warning disable 660,661 diff --git a/ExclusiveGroup.cs.meta b/Core/Groups/ExclusiveGroup.cs.meta similarity index 83% rename from ExclusiveGroup.cs.meta rename to Core/Groups/ExclusiveGroup.cs.meta index c079243..8019c94 100644 --- a/ExclusiveGroup.cs.meta +++ b/Core/Groups/ExclusiveGroup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 11a6c1ee094c3a9da95234d1387d3403 +guid: cee0b977af8e315ca8cad5b28d2d46dd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ExclusiveGroupStruct.cs b/Core/Groups/ExclusiveGroupStruct.cs similarity index 84% rename from ExclusiveGroupStruct.cs rename to Core/Groups/ExclusiveGroupStruct.cs index 8bb0a9c..30d25e5 100644 --- a/ExclusiveGroupStruct.cs +++ b/Core/Groups/ExclusiveGroupStruct.cs @@ -4,31 +4,6 @@ using System.Runtime.InteropServices; namespace Svelto.ECS { - public readonly struct BuildGroup - { - internal BuildGroup(ExclusiveGroupStruct group) - { - this.group = group; - } - - public static implicit operator BuildGroup(ExclusiveGroupStruct group) - { - return new BuildGroup(group); - } - - public static implicit operator BuildGroup(ExclusiveGroup group) - { - return new BuildGroup(group); - } - - public static implicit operator uint(BuildGroup groupStruct) - { - return groupStruct.group; - } - - internal ExclusiveGroupStruct @group { get; } - } - [StructLayout(LayoutKind.Explicit, Size = 4)] public struct ExclusiveGroupStruct : IEquatable, IComparable, IEqualityComparer diff --git a/ExclusiveGroupStruct.cs.meta b/Core/Groups/ExclusiveGroupStruct.cs.meta similarity index 83% rename from ExclusiveGroupStruct.cs.meta rename to Core/Groups/ExclusiveGroupStruct.cs.meta index 6a5f657..879ff30 100644 --- a/ExclusiveGroupStruct.cs.meta +++ b/Core/Groups/ExclusiveGroupStruct.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 67dde70e73a3374a87d0e9b93385405a +guid: b6cfcea8668c32ef94ce020fb53a4ed2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/GroupCompound.cs b/Core/Groups/GroupCompound.cs similarity index 96% rename from GroupCompound.cs rename to Core/Groups/GroupCompound.cs index 53badc1..25be5bd 100644 --- a/GroupCompound.cs +++ b/Core/Groups/GroupCompound.cs @@ -20,7 +20,7 @@ namespace Svelto.ECS static readonly FasterList _Groups; public static FasterReadOnlyList Groups => new FasterReadOnlyList(_Groups); - public static BuildGroup BuildGroup => new BuildGroup(_Groups[0]); + public static ExclusiveBuildGroup BuildGroup => new ExclusiveBuildGroup(_Groups[0]); static GroupCompound() { @@ -100,7 +100,7 @@ namespace Svelto.ECS public static FasterReadOnlyList Groups => new FasterReadOnlyList(_Groups); - public static BuildGroup BuildGroup => new BuildGroup(_Groups[0]); + public static ExclusiveBuildGroup BuildGroup => new ExclusiveBuildGroup(_Groups[0]); public static void Add(ExclusiveGroupStruct group) { @@ -152,7 +152,7 @@ namespace Svelto.ECS public static FasterReadOnlyList Groups => new FasterReadOnlyList(_Groups); - public static BuildGroup BuildGroup => new BuildGroup(_Groups[0]); + public static ExclusiveBuildGroup BuildGroup => new ExclusiveBuildGroup(_Groups[0]); public static void Add(ExclusiveGroupStruct group) { @@ -200,7 +200,7 @@ namespace Svelto.ECS public static FasterReadOnlyList Groups => new FasterReadOnlyList(_Groups); - public static BuildGroup BuildGroup => new BuildGroup(_Groups[0]); + public static ExclusiveBuildGroup BuildGroup => new ExclusiveBuildGroup(_Groups[0]); static GroupTag() { diff --git a/GroupCompound.cs.meta b/Core/Groups/GroupCompound.cs.meta similarity index 83% rename from GroupCompound.cs.meta rename to Core/Groups/GroupCompound.cs.meta index 0d5fe69..977200b 100644 --- a/GroupCompound.cs.meta +++ b/Core/Groups/GroupCompound.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b4c8e3ece545370bbdd5fb72949c5984 +guid: 9fa284c90e64364a9b9f51059873d380 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/NamedExclusiveGroup.cs b/Core/Groups/NamedExclusiveGroup.cs similarity index 100% rename from NamedExclusiveGroup.cs rename to Core/Groups/NamedExclusiveGroup.cs diff --git a/NamedExclusiveGroup.cs.meta b/Core/Groups/NamedExclusiveGroup.cs.meta similarity index 83% rename from NamedExclusiveGroup.cs.meta rename to Core/Groups/NamedExclusiveGroup.cs.meta index 60c9a37..849b713 100644 --- a/NamedExclusiveGroup.cs.meta +++ b/Core/Groups/NamedExclusiveGroup.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 362902783441376594e2c3b205be9758 +guid: 66873b05950835849a0c2f5a80231aa7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Hybrid.meta b/Core/Hybrid.meta similarity index 77% rename from Hybrid.meta rename to Core/Hybrid.meta index 3d047be..025626c 100644 --- a/Hybrid.meta +++ b/Core/Hybrid.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 452fdabd148532a29a6b4ca381ab3ef0 +guid: 026e29ec3d85325bbc2608d35de19990 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/IEntityDescriptorHolder.cs b/Core/Hybrid/IEntityDescriptorHolder.cs similarity index 100% rename from IEntityDescriptorHolder.cs rename to Core/Hybrid/IEntityDescriptorHolder.cs diff --git a/IEntityDescriptorHolder.cs.meta b/Core/Hybrid/IEntityDescriptorHolder.cs.meta similarity index 83% rename from IEntityDescriptorHolder.cs.meta rename to Core/Hybrid/IEntityDescriptorHolder.cs.meta index cd80315..2157b27 100644 --- a/IEntityDescriptorHolder.cs.meta +++ b/Core/Hybrid/IEntityDescriptorHolder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1636c499352d37f1b9e429f84429f4c0 +guid: 8abbfa8e203e3d70a839bda4ab032eac MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Hybrid/IEntityViewComponent.cs b/Core/Hybrid/IEntityViewComponent.cs similarity index 100% rename from Hybrid/IEntityViewComponent.cs rename to Core/Hybrid/IEntityViewComponent.cs diff --git a/Hybrid/IEntityViewComponent.cs.meta b/Core/Hybrid/IEntityViewComponent.cs.meta similarity index 83% rename from Hybrid/IEntityViewComponent.cs.meta rename to Core/Hybrid/IEntityViewComponent.cs.meta index 611c32c..f114125 100644 --- a/Hybrid/IEntityViewComponent.cs.meta +++ b/Core/Hybrid/IEntityViewComponent.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 98b35f1b576439b68efee7e27c7c3f47 +guid: feb91403dddf3b3c8393879238a18aa0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Hybrid/IImplementor.cs b/Core/Hybrid/IImplementor.cs similarity index 100% rename from Hybrid/IImplementor.cs rename to Core/Hybrid/IImplementor.cs diff --git a/Hybrid/IImplementor.cs.meta b/Core/Hybrid/IImplementor.cs.meta similarity index 83% rename from Hybrid/IImplementor.cs.meta rename to Core/Hybrid/IImplementor.cs.meta index 80c8dc7..4d17f38 100644 --- a/Hybrid/IImplementor.cs.meta +++ b/Core/Hybrid/IImplementor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cdec02434e883087a58ba5af78af7e46 +guid: f9b097f67abc3bceb0dc1fa606d0703d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/Hybrid/ValueReference.cs b/Core/Hybrid/ValueReference.cs new file mode 100644 index 0000000..0a4c802 --- /dev/null +++ b/Core/Hybrid/ValueReference.cs @@ -0,0 +1,13 @@ +using System.Runtime.InteropServices; + +namespace Svelto.ECS.Hybrid +{ + public struct ValueReference where T:class, IImplementor + { + public ValueReference(T obj) { _pointer = GCHandle.Alloc(obj, GCHandleType.Normal); } + + public static explicit operator T(ValueReference t) => (T) t._pointer.Target; + + GCHandle _pointer; + } +} \ No newline at end of file diff --git a/Core/Hybrid/ValueReference.cs.meta b/Core/Hybrid/ValueReference.cs.meta new file mode 100644 index 0000000..212405a --- /dev/null +++ b/Core/Hybrid/ValueReference.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e5aeb1326b38390395ec10ae2feeff78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/IComponentBuilder.cs b/Core/IComponentBuilder.cs similarity index 100% rename from IComponentBuilder.cs rename to Core/IComponentBuilder.cs diff --git a/IComponentBuilder.cs.meta b/Core/IComponentBuilder.cs.meta similarity index 83% rename from IComponentBuilder.cs.meta rename to Core/IComponentBuilder.cs.meta index adcf084..30bde62 100644 --- a/IComponentBuilder.cs.meta +++ b/Core/IComponentBuilder.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2104c9265d383a0fbaf1b7e720fa044f +guid: 9a94799fec633d11bab9086810b18846 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/IDisposingEngine.cs b/Core/IDisposingEngine.cs similarity index 100% rename from IDisposingEngine.cs rename to Core/IDisposingEngine.cs diff --git a/IDisposingEngine.cs.meta b/Core/IDisposingEngine.cs.meta similarity index 83% rename from IDisposingEngine.cs.meta rename to Core/IDisposingEngine.cs.meta index e336309..6b736f0 100644 --- a/IDisposingEngine.cs.meta +++ b/Core/IDisposingEngine.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aff503a030833df49da65ec7cfdce9a4 +guid: d84da7d1e8013ee1a167261cf43428ae MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/IEngine.cs b/Core/IEngine.cs similarity index 78% rename from IEngine.cs rename to Core/IEngine.cs index 5c5c8e9..ec87289 100644 --- a/IEngine.cs +++ b/Core/IEngine.cs @@ -7,6 +7,9 @@ namespace Svelto.ECS.Internal public interface IReactOnAddAndRemove : IReactEngine {} + + public interface IReactOnDispose : IReactEngine + {} public interface IReactOnSwap : IReactEngine {} @@ -23,6 +26,11 @@ namespace Svelto.ECS void Remove(ref T entityComponent, EGID egid); } + public interface IReactOnDispose : IReactOnDispose where T : IEntityComponent + { + void Remove(ref T entityComponent, EGID egid); + } + public interface IReactOnSwap : IReactOnSwap where T : IEntityComponent { void MovedTo(ref T entityComponent, ExclusiveGroupStruct previousGroup, EGID egid); diff --git a/IEngine.cs.meta b/Core/IEngine.cs.meta similarity index 83% rename from IEngine.cs.meta rename to Core/IEngine.cs.meta index 194bedb..2a8162d 100644 --- a/IEngine.cs.meta +++ b/Core/IEngine.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e70e2a9b56f43b48a73f8c1b5629d00d +guid: 00ac1c1daa9c38c2b81a70d81ac309eb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/IEntityComponent.cs b/Core/IEntityComponent.cs new file mode 100644 index 0000000..cf4d06c --- /dev/null +++ b/Core/IEntityComponent.cs @@ -0,0 +1,7 @@ +namespace Svelto.ECS +{ + ///Entity Components MUST implement IEntityComponent + public interface IEntityComponent + { + } +} \ No newline at end of file diff --git a/IEntityComponent.cs.meta b/Core/IEntityComponent.cs.meta similarity index 83% rename from IEntityComponent.cs.meta rename to Core/IEntityComponent.cs.meta index 8788a77..183eaf3 100644 --- a/IEntityComponent.cs.meta +++ b/Core/IEntityComponent.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4652689ed0b73fae9b01d8835918badd +guid: 25bd99235be530aaa1f75f0d01aaa408 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/IEntityFactory.cs b/Core/IEntityFactory.cs similarity index 83% rename from IEntityFactory.cs rename to Core/IEntityFactory.cs index 6220c2b..0a7c180 100644 --- a/IEntityFactory.cs +++ b/Core/IEntityFactory.cs @@ -43,25 +43,25 @@ namespace Svelto.ECS /// /// /// - EntityComponentInitializer BuildEntity(uint entityID, BuildGroup groupStructId, + EntityInitializer BuildEntity(uint entityID, ExclusiveBuildGroup groupStructId, IEnumerable implementors = null) where T : IEntityDescriptor, new(); - EntityComponentInitializer BuildEntity(EGID egid, IEnumerable implementors = null) + EntityInitializer BuildEntity(EGID egid, IEnumerable implementors = null) where T : IEntityDescriptor, new(); - EntityComponentInitializer BuildEntity(uint entityID, BuildGroup groupStructId, + EntityInitializer BuildEntity(uint entityID, ExclusiveBuildGroup groupStructId, T descriptorEntity, IEnumerable implementors = null) where T : IEntityDescriptor; - EntityComponentInitializer BuildEntity(EGID egid, T entityDescriptor, IEnumerable implementors = null) + EntityInitializer BuildEntity(EGID egid, T entityDescriptor, IEnumerable implementors = null) where T : IEntityDescriptor; - EntityComponentInitializer BuildEntity + EntityInitializer BuildEntity (EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable implementors = null); #if UNITY_NATIVE - NativeEntityFactory ToNative(string memberName) where T : IEntityDescriptor, new(); + NativeEntityFactory ToNative(string callerName) where T : IEntityDescriptor, new(); #endif } } \ No newline at end of file diff --git a/IEntityFactory.cs.meta b/Core/IEntityFactory.cs.meta similarity index 83% rename from IEntityFactory.cs.meta rename to Core/IEntityFactory.cs.meta index 40902ca..b4a748a 100644 --- a/IEntityFactory.cs.meta +++ b/Core/IEntityFactory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b7809361e18139e88669f7be7b7b6ac5 +guid: ef29364e36bf3219a3dea4ea31e8374a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/IEntityFunctions.cs b/Core/IEntityFunctions.cs new file mode 100644 index 0000000..1dd15bc --- /dev/null +++ b/Core/IEntityFunctions.cs @@ -0,0 +1,34 @@ +using System.Runtime.CompilerServices; + +namespace Svelto.ECS +{ + public interface IEntityFunctions + { + //being entity ID globally not unique, the group must be specified when + //an entity is removed. Not specifying the group will attempt to remove + //the entity from the special standard group. + void RemoveEntity(uint entityID, ExclusiveBuildGroup groupID, [CallerMemberName] string memberName = "") where T : IEntityDescriptor, new(); + void RemoveEntity(EGID entityegid, [CallerMemberName] string memberName = "") where T : IEntityDescriptor, new(); + + void RemoveEntitiesFromGroup(ExclusiveBuildGroup groupID); + + void SwapEntitiesInGroup(ExclusiveBuildGroup fromGroupID, ExclusiveBuildGroup toGroupID) where T : IEntityDescriptor, new(); + + void SwapEntityGroup(uint entityID, ExclusiveBuildGroup fromGroupID, ExclusiveBuildGroup toGroupID) + where T : IEntityDescriptor, new(); + + void SwapEntityGroup(EGID fromID, ExclusiveBuildGroup toGroupID) where T : IEntityDescriptor, new(); + + void SwapEntityGroup(EGID fromID, ExclusiveBuildGroup toGroupID, ExclusiveBuildGroup mustBeFromGroup) + where T : IEntityDescriptor, new(); + + void SwapEntityGroup(EGID fromID, EGID toId) where T : IEntityDescriptor, new(); + + void SwapEntityGroup(EGID fromID, EGID toId, ExclusiveBuildGroup mustBeFromGroup) + where T : IEntityDescriptor, new(); +#if UNITY_NATIVE + NativeEntityRemove ToNativeRemove(string memberName) where T : IEntityDescriptor, new(); + NativeEntitySwap ToNativeSwap(string memberName) where T : IEntityDescriptor, new(); +#endif + } +} \ No newline at end of file diff --git a/IEntityFunctions.cs.meta b/Core/IEntityFunctions.cs.meta similarity index 83% rename from IEntityFunctions.cs.meta rename to Core/IEntityFunctions.cs.meta index c91bcb2..c59ee13 100644 --- a/IEntityFunctions.cs.meta +++ b/Core/IEntityFunctions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6cc2546ce1453840a6b4e66e61409318 +guid: 4d3bccdb6e8d30a69c18039b2d859e34 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/IEntityComponent.cs b/Core/INeedEGID.cs similarity index 71% rename from IEntityComponent.cs rename to Core/INeedEGID.cs index d5269f7..1812438 100644 --- a/IEntityComponent.cs +++ b/Core/INeedEGID.cs @@ -1,10 +1,5 @@ namespace Svelto.ECS { - ///Entity Components MUST implement IEntityComponent - public interface IEntityComponent - { - } - /// /// use INeedEGID on an IEntityComponent only if you need the EGID. consider using EGIDComponent instead /// diff --git a/Core/INeedEGID.cs.meta b/Core/INeedEGID.cs.meta new file mode 100644 index 0000000..3dc145f --- /dev/null +++ b/Core/INeedEGID.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58afbcdd89a8352e989d57ed7c7c54ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/IQueryingEntitiesEngine.cs b/Core/IQueryingEntitiesEngine.cs similarity index 100% rename from IQueryingEntitiesEngine.cs rename to Core/IQueryingEntitiesEngine.cs diff --git a/IQueryingEntitiesEngine.cs.meta b/Core/IQueryingEntitiesEngine.cs.meta similarity index 83% rename from IQueryingEntitiesEngine.cs.meta rename to Core/IQueryingEntitiesEngine.cs.meta index aadfe7f..c68d0a0 100644 --- a/IQueryingEntitiesEngine.cs.meta +++ b/Core/IQueryingEntitiesEngine.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b93cd3a636bf38509b3de3039ce76fdb +guid: 939e4e90b2f73bf4b7acc815acf6a808 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/QueryGroups.cs b/Core/QueryGroups.cs similarity index 100% rename from QueryGroups.cs rename to Core/QueryGroups.cs diff --git a/QueryGroups.cs.meta b/Core/QueryGroups.cs.meta similarity index 83% rename from QueryGroups.cs.meta rename to Core/QueryGroups.cs.meta index 050c2e2..d5911b4 100644 --- a/QueryGroups.cs.meta +++ b/Core/QueryGroups.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a23c1bfaf8dd3e8082b63b0aa9974351 +guid: e3063c92835c3dcfb72ee2221375b2c0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/SetEGIDWithoutBoxing.cs b/Core/SetEGIDWithoutBoxing.cs similarity index 96% rename from SetEGIDWithoutBoxing.cs rename to Core/SetEGIDWithoutBoxing.cs index bc81645..d5af6e1 100644 --- a/SetEGIDWithoutBoxing.cs +++ b/Core/SetEGIDWithoutBoxing.cs @@ -1,5 +1,3 @@ -using System.Runtime.CompilerServices; - namespace Svelto.ECS.Internal { delegate void SetEGIDWithoutBoxingActionCast(ref T target, EGID egid) where T : struct, IEntityComponent; diff --git a/SetEGIDWithoutBoxing.cs.meta b/Core/SetEGIDWithoutBoxing.cs.meta similarity index 83% rename from SetEGIDWithoutBoxing.cs.meta rename to Core/SetEGIDWithoutBoxing.cs.meta index 5530359..340103d 100644 --- a/SetEGIDWithoutBoxing.cs.meta +++ b/Core/SetEGIDWithoutBoxing.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 49b9484bd0a43721bbb45a6676d44987 +guid: 57376a4b1fa43468830e99c6fe73a89e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/SimpleEntitiesSubmissionScheduler.cs b/Core/SimpleEntitiesSubmissionScheduler.cs new file mode 100644 index 0000000..d1c27bd --- /dev/null +++ b/Core/SimpleEntitiesSubmissionScheduler.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections; + +namespace Svelto.ECS.Schedulers +{ + public sealed class SimpleEntitiesSubmissionScheduler : EntitiesSubmissionScheduler + { + public SimpleEntitiesSubmissionScheduler(uint maxNumberOfOperationsPerFrame = UInt32.MaxValue) + { + _maxNumberOfOperationsPerFrame = maxNumberOfOperationsPerFrame; + } + + public IEnumerator SubmitEntitiesAsync() + { + if (paused == false) + { + var submitEntities = _onTick.Invoke(_maxNumberOfOperationsPerFrame); + + while (submitEntities.MoveNext()) + yield return null; + } + } + + public void SubmitEntities() + { + var enumerator = SubmitEntitiesAsync(); + + while (enumerator.MoveNext()); + } + + public override bool paused { get; set; } + public override void Dispose() { } + + protected internal override EnginesRoot.EntitiesSubmitter onTick + { + set + { + DBC.ECS.Check.Require(_onTick.IsUnused, "a scheduler can be exclusively used by one enginesRoot only"); + + _onTick = value; + } + } + + EnginesRoot.EntitiesSubmitter _onTick; + readonly uint _maxNumberOfOperationsPerFrame; + } +} \ No newline at end of file diff --git a/SimpleEntitiesSubmissionScheduler.cs.meta b/Core/SimpleEntitiesSubmissionScheduler.cs.meta similarity index 83% rename from SimpleEntitiesSubmissionScheduler.cs.meta rename to Core/SimpleEntitiesSubmissionScheduler.cs.meta index cc27f5f..547d930 100644 --- a/SimpleEntitiesSubmissionScheduler.cs.meta +++ b/Core/SimpleEntitiesSubmissionScheduler.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 442baaf96b073bcda1728f7be4985308 +guid: c27c68f088b73bd699ae41d0b2b696dd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Core/SpecialEnumerators.meta b/Core/SpecialEnumerators.meta new file mode 100644 index 0000000..e8314ad --- /dev/null +++ b/Core/SpecialEnumerators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e6f24a1d39e93180a75badcd7770342e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core/SpecialEnumerators/DoubleIterationEnumerator.cs b/Core/SpecialEnumerators/DoubleIterationEnumerator.cs new file mode 100644 index 0000000..18afdab --- /dev/null +++ b/Core/SpecialEnumerators/DoubleIterationEnumerator.cs @@ -0,0 +1,546 @@ +using System; + +namespace Svelto.ECS +{ + public readonly ref struct DoubleEntitiesEnumerator where T1 : struct, IEntityComponent + { + public DoubleEntitiesEnumerator(GroupsEnumerable groupsEnumerable) { _groupsEnumerable = groupsEnumerable; } + + public EntityGroupsIterator GetEnumerator() { return new EntityGroupsIterator(_groupsEnumerable); } + + readonly GroupsEnumerable _groupsEnumerable; + + public ref struct EntityGroupsIterator + { + public EntityGroupsIterator(GroupsEnumerable groupsEnumerable) : this() + { + _groupsEnumerableA = groupsEnumerable.GetEnumerator(); + _groupsEnumerableA.MoveNext(); + _groupsEnumerableB = _groupsEnumerableA; + _indexA = 0; + _indexB = 0; + } + + public bool MoveNext() + { + //once GroupEnumerables complete, they reset. If they reset and moveNext doesn't happen, they are invalid + while (_groupsEnumerableA.isValid) + { + var (buffersA, _) = _groupsEnumerableA.Current; + var (buffersB, _) = _groupsEnumerableB.Current; + + //current index A must iterate as long as is less than the current A group count + while (_indexA < buffersA.count) + { + //current index B must iterate as long as is less than the current B group count + if (++_indexB < buffersB.count) + { + return true; + } + + //if B iteration is over, move to the next group + if (_groupsEnumerableB.MoveNext() == false) + { + //if there is no valid next groups, we reset B and we need to move to the next A element + _groupsEnumerableB = _groupsEnumerableA; + (buffersB, _) = _groupsEnumerableB.Current; + ++_indexA; //next A element + _indexB = _indexA; + } + else + //otherwise the current A will be checked against the new B group. IndexB must be reset + //to work on the new group + { + _indexB = -1; + } + } + + //the current group A iteration is done, so we move to the next A group + if (_groupsEnumerableA.MoveNext() == true) + { + //there is a new group, we reset the iteration + _indexA = 0; + _indexB = 0; + _groupsEnumerableB = _groupsEnumerableA; + } + else + return false; + } + + return false; + } + + public void Reset() { throw new Exception(); } + + public ValueRef Current + { + get + { + var valueRef = new ValueRef(_groupsEnumerableA.Current, _indexA, _groupsEnumerableB.Current + , _indexB); + return valueRef; + } + } + + public void Dispose() { } + + GroupsEnumerable.GroupsIterator _groupsEnumerableA; + GroupsEnumerable.GroupsIterator _groupsEnumerableB; + int _indexA; + int _indexB; + } + + public ref struct ValueRef + { + public readonly GroupsEnumerable.RefCurrent _current; + public readonly int _indexA; + public readonly GroupsEnumerable.RefCurrent _refCurrent; + public readonly int _indexB; + + public ValueRef + (GroupsEnumerable.RefCurrent current, int indexA, GroupsEnumerable.RefCurrent refCurrent + , int indexB) + { + _current = current; + _indexA = indexA; + _refCurrent = refCurrent; + _indexB = indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out EntityCollection refCurrent, out int indexB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out ExclusiveGroupStruct groupA + , out EntityCollection refCurrent, out int indexB, out ExclusiveGroupStruct groupB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + groupA = _current._group; + groupB = _refCurrent._group; + } + } + } + + public readonly ref struct DoubleIterationEnumerator where T1 : struct, IEntityComponent + where T2 : struct, IEntityComponent + { + public DoubleIterationEnumerator(GroupsEnumerable groupsEnumerable) + { + _groupsEnumerable = groupsEnumerable; + } + + public EntityGroupsIterator GetEnumerator() { return new EntityGroupsIterator(_groupsEnumerable); } + + readonly GroupsEnumerable _groupsEnumerable; + + public ref struct EntityGroupsIterator + { + public EntityGroupsIterator(GroupsEnumerable groupsEnumerable) : this() + { + _groupsEnumerableA = groupsEnumerable.GetEnumerator(); + _groupsEnumerableA.MoveNext(); + _groupsEnumerableB = _groupsEnumerableA; + _indexA = 0; + _indexB = 0; + } + + public bool MoveNext() + { + //once GroupEnumerables complete, they reset. If they reset and moveNext doesn't happen, they are invalid + while (_groupsEnumerableA.isValid) + { + var (buffersA, _) = _groupsEnumerableA.Current; + var (buffersB, _) = _groupsEnumerableB.Current; + + //current index A must iterate as long as is less than the current A group count + while (_indexA < buffersA.count) + { + //current index B must iterate as long as is less than the current B group count + if (++_indexB < buffersB.count) + { + return true; + } + + //if B iteration is over, move to the next group + if (_groupsEnumerableB.MoveNext() == false) + { + //if there is no valid next groups, we reset B and we need to move to the next A element + _groupsEnumerableB = _groupsEnumerableA; + (buffersB, _) = _groupsEnumerableB.Current; + ++_indexA; //next A element + _indexB = _indexA; + } + else + //otherwise the current A will be checked against the new B group. IndexB must be reset + //to work on the new group + { + _indexB = -1; + } + } + + //the current group A iteration is done, so we move to the next A group + if (_groupsEnumerableA.MoveNext() == true) + { + //there is a new group, we reset the iteration + _indexA = 0; + _indexB = 0; + _groupsEnumerableB = _groupsEnumerableA; + } + else + return false; + } + + return false; + } + + public void Reset() { throw new Exception(); } + + public ValueRef Current + { + get + { + var valueRef = new ValueRef(_groupsEnumerableA.Current, _indexA, _groupsEnumerableB.Current + , _indexB); + return valueRef; + } + } + + public void Dispose() { } + + GroupsEnumerable.GroupsIterator _groupsEnumerableA; + GroupsEnumerable.GroupsIterator _groupsEnumerableB; + int _indexA; + int _indexB; + } + + public ref struct ValueRef + { + public readonly GroupsEnumerable.RefCurrent _current; + public readonly int _indexA; + public readonly GroupsEnumerable.RefCurrent _refCurrent; + public readonly int _indexB; + + public ValueRef + (GroupsEnumerable.RefCurrent current, int indexA, GroupsEnumerable.RefCurrent refCurrent + , int indexB) + { + _current = current; + _indexA = indexA; + _refCurrent = refCurrent; + _indexB = indexB; + } + + public void Deconstruct(out EntityCollection buffers, out int indexA, + out EntityCollection refCurrent, out int indexB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out ExclusiveGroupStruct groupA + , out EntityCollection refCurrent, out int indexB, out ExclusiveGroupStruct groupB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + groupA = _current._group; + groupB = _refCurrent._group; + } + } + } + + /// + /// Special Enumerator to iterate a group of entities against themselves with complexity n*(n+1)/2 (skips already tested couples) + /// + /// + /// + /// + public readonly ref struct DoubleEntitiesEnumerator where T1 : struct, IEntityComponent + where T2 : struct, IEntityComponent + where T3 : struct, IEntityComponent + { + public DoubleEntitiesEnumerator(GroupsEnumerable groupsEnumerable) + { + _groupsEnumerable = groupsEnumerable; + } + + public EntityGroupsIterator GetEnumerator() { return new EntityGroupsIterator(_groupsEnumerable); } + + readonly GroupsEnumerable _groupsEnumerable; + + public ref struct EntityGroupsIterator + { + public EntityGroupsIterator(GroupsEnumerable groupsEnumerable) : this() + { + _groupsEnumerableA = groupsEnumerable.GetEnumerator(); + _groupsEnumerableA.MoveNext(); + _groupsEnumerableB = _groupsEnumerableA; + _indexA = 0; + _indexB = 0; + } + + public bool MoveNext() + { + //once GroupEnumerables complete, they reset. If they reset and moveNext doesn't happen, they are invalid + while (_groupsEnumerableA.isValid) + { + var (buffersA, _) = _groupsEnumerableA.Current; + var (buffersB, _) = _groupsEnumerableB.Current; + + //current index A must iterate as long as is less than the current A group count + while (_indexA < buffersA.count) + { + //current index B must iterate as long as is less than the current B group count + if (++_indexB < buffersB.count) + { + return true; + } + + //if B iteration is over, move to the next group + if (_groupsEnumerableB.MoveNext() == false) + { + //if there is no valid next groups, we reset B and we need to move to the next A element + _groupsEnumerableB = _groupsEnumerableA; + (buffersB, _) = _groupsEnumerableB.Current; + ++_indexA; //next A element + _indexB = _indexA; + } + else + //otherwise the current A will be checked against the new B group. IndexB must be reset + //to work on the new group + { + _indexB = -1; + } + } + + //the current group A iteration is done, so we move to the next A group + if (_groupsEnumerableA.MoveNext() == true) + { + //there is a new group, we reset the iteration + _indexA = 0; + _indexB = 0; + _groupsEnumerableB = _groupsEnumerableA; + } + else + return false; + } + + return false; + } + + public void Reset() { throw new Exception(); } + + public ValueRef Current + { + get + { + var valueRef = new ValueRef(_groupsEnumerableA.Current, _indexA, _groupsEnumerableB.Current + , _indexB); + return valueRef; + } + } + + public void Dispose() { } + + GroupsEnumerable.GroupsIterator _groupsEnumerableA; + GroupsEnumerable.GroupsIterator _groupsEnumerableB; + int _indexA; + int _indexB; + } + + public ref struct ValueRef + { + public readonly GroupsEnumerable.RefCurrent _current; + public readonly int _indexA; + public readonly GroupsEnumerable.RefCurrent _refCurrent; + public readonly int _indexB; + + public ValueRef + (GroupsEnumerable.RefCurrent current, int indexA + , GroupsEnumerable.RefCurrent refCurrent, int indexB) + { + _current = current; + _indexA = indexA; + _refCurrent = refCurrent; + _indexB = indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out EntityCollection refCurrent + , out int indexB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out ExclusiveGroupStruct groupA + , out EntityCollection refCurrent, out int indexB, out ExclusiveGroupStruct groupB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + groupA = _current._group; + groupB = _refCurrent._group; + } + } + } + + /// + /// Special Enumerator to iterate a group of entities against themselves with complexity n*(n+1)/2 (skips already tested couples) + /// + /// + /// + /// + /// + public readonly ref struct DoubleEntitiesEnumerator where T1 : struct, IEntityComponent + where T2 : struct, IEntityComponent + where T3 : struct, IEntityComponent + where T4 : struct, IEntityComponent + { + public DoubleEntitiesEnumerator(GroupsEnumerable groupsEnumerable) + { + _groupsEnumerable = groupsEnumerable; + } + + public EntityGroupsIterator GetEnumerator() { return new EntityGroupsIterator(_groupsEnumerable); } + + readonly GroupsEnumerable _groupsEnumerable; + + public ref struct EntityGroupsIterator + { + public EntityGroupsIterator(GroupsEnumerable groupsEnumerable) : this() + { + _groupsEnumerableA = groupsEnumerable.GetEnumerator(); + _groupsEnumerableA.MoveNext(); + _groupsEnumerableB = _groupsEnumerableA; + _indexA = 0; + _indexB = 0; + } + + public bool MoveNext() + { + //once GroupEnumerables complete, they reset. If they reset and moveNext doesn't happen, they are invalid + while (_groupsEnumerableA.isValid) + { + var (buffersA, _) = _groupsEnumerableA.Current; + var (buffersB, _) = _groupsEnumerableB.Current; + + //current index A must iterate as long as is less than the current A group count + while (_indexA < buffersA.count) + { + //current index B must iterate as long as is less than the current B group count + if (++_indexB < buffersB.count) + { + return true; + } + + //if B iteration is over, move to the next group + if (_groupsEnumerableB.MoveNext() == false) + { + //if there is no valid next groups, we reset B and we need to move to the next A element + _groupsEnumerableB = _groupsEnumerableA; + (buffersB, _) = _groupsEnumerableB.Current; + ++_indexA; //next A element + _indexB = _indexA; + } + else + //otherwise the current A will be checked against the new B group. IndexB must be reset + //to work on the new group + { + _indexB = -1; + } + } + + //the current group A iteration is done, so we move to the next A group + if (_groupsEnumerableA.MoveNext() == true) + { + //there is a new group, we reset the iteration + _indexA = 0; + _indexB = 0; + _groupsEnumerableB = _groupsEnumerableA; + } + else + return false; + } + + return false; + } + + public void Reset() { throw new Exception(); } + + public ValueRef Current + { + get + { + var valueRef = new ValueRef(_groupsEnumerableA.Current, _indexA, _groupsEnumerableB.Current + , _indexB); + return valueRef; + } + } + + public void Dispose() { } + + GroupsEnumerable.GroupsIterator _groupsEnumerableA; + GroupsEnumerable.GroupsIterator _groupsEnumerableB; + int _indexA; + int _indexB; + } + + public ref struct ValueRef + { + public readonly GroupsEnumerable.RefCurrent _current; + public readonly int _indexA; + public readonly GroupsEnumerable.RefCurrent _refCurrent; + public readonly int _indexB; + + public ValueRef + (GroupsEnumerable.RefCurrent current, int indexA + , GroupsEnumerable.RefCurrent refCurrent, int indexB) + { + _current = current; + _indexA = indexA; + _refCurrent = refCurrent; + _indexB = indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out EntityCollection refCurrent + , out int indexB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + } + + public void Deconstruct + (out EntityCollection buffers, out int indexA, out ExclusiveGroupStruct groupA + , out EntityCollection refCurrent, out int indexB, out ExclusiveGroupStruct groupB) + { + buffers = _current._buffers; + indexA = _indexA; + refCurrent = _refCurrent._buffers; + indexB = _indexB; + groupA = _current._group; + groupB = _refCurrent._group; + } + } + } +} \ No newline at end of file diff --git a/Core/SpecialEnumerators/DoubleIterationEnumerator.cs.meta b/Core/SpecialEnumerators/DoubleIterationEnumerator.cs.meta new file mode 100644 index 0000000..96212bc --- /dev/null +++ b/Core/SpecialEnumerators/DoubleIterationEnumerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51c7d2db61da3a69846c30fa9dd12a5b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs b/Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs new file mode 100644 index 0000000..6222a78 --- /dev/null +++ b/Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using Svelto.ECS.Schedulers; + +namespace Svelto.ECS +{ + /// + /// Enumerator that yields until the next Entities Submission + /// + public struct WaitForSubmissionEnumerator : IEnumerator + { + public WaitForSubmissionEnumerator(EntitiesSubmissionScheduler scheduler):this() + { + _scheduler = scheduler; + } + + public bool MoveNext() + { + switch (_state) + { + case 0: + _iteration = _scheduler.iteration; + _state = 1; + return true; + case 1: + if (_iteration != _scheduler.iteration) + { + _state = 0; + return false; + } + return true; + } + + throw new Exception("something is wrong"); + } + + void IEnumerator.Reset() + { + throw new NotImplementedException(); + } + + public object Current { get; } + + readonly EntitiesSubmissionScheduler _scheduler; + uint _state; + uint _iteration; + } +} \ No newline at end of file diff --git a/WaitForSubmissionEnumerator.cs.meta b/Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs.meta similarity index 83% rename from WaitForSubmissionEnumerator.cs.meta rename to Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs.meta index 4a59cc9..fcbe481 100644 --- a/WaitForSubmissionEnumerator.cs.meta +++ b/Core/SpecialEnumerators/WaitForSubmissionEnumerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fa37064da3c933b392ace056a680d170 +guid: 0e686787bf1539d0bfdf6ab5dcc5faaa MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams.meta b/Core/Streams.meta similarity index 77% rename from Streams.meta rename to Core/Streams.meta index d3f18fb..1db7cdf 100644 --- a/Streams.meta +++ b/Core/Streams.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 949ebb1ddf5136ea8894e09bba93aade +guid: 238674459e283d7e9c16339d03882e46 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Streams/Consumer.cs b/Core/Streams/Consumer.cs similarity index 100% rename from Streams/Consumer.cs rename to Core/Streams/Consumer.cs diff --git a/Streams/Consumer.cs.meta b/Core/Streams/Consumer.cs.meta similarity index 83% rename from Streams/Consumer.cs.meta rename to Core/Streams/Consumer.cs.meta index 8fdf7d4..662cc00 100644 --- a/Streams/Consumer.cs.meta +++ b/Core/Streams/Consumer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e90417a44ee539088f95c95c60cc14a2 +guid: 1fcf98964379339eb1e8116e7a47e355 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/EnginesRoot.Streams.cs b/Core/Streams/EnginesRoot.Streams.cs similarity index 100% rename from Streams/EnginesRoot.Streams.cs rename to Core/Streams/EnginesRoot.Streams.cs diff --git a/Streams/EnginesRoot.Streams.cs.meta b/Core/Streams/EnginesRoot.Streams.cs.meta similarity index 83% rename from Streams/EnginesRoot.Streams.cs.meta rename to Core/Streams/EnginesRoot.Streams.cs.meta index 4cbb36c..f697c51 100644 --- a/Streams/EnginesRoot.Streams.cs.meta +++ b/Core/Streams/EnginesRoot.Streams.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 811b766279f630978d8b8b8d9f9ab37e +guid: ab223c7c5d03362fb7eb0e2793d9beec MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/EntitiesDB.Streams.cs b/Core/Streams/EntitiesDB.Streams.cs similarity index 90% rename from Streams/EntitiesDB.Streams.cs rename to Core/Streams/EntitiesDB.Streams.cs index 6b2f4c1..d5d47f2 100644 --- a/Streams/EntitiesDB.Streams.cs +++ b/Core/Streams/EntitiesDB.Streams.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Svelto.ECS { diff --git a/Streams/EntitiesDB.Streams.cs.meta b/Core/Streams/EntitiesDB.Streams.cs.meta similarity index 83% rename from Streams/EntitiesDB.Streams.cs.meta rename to Core/Streams/EntitiesDB.Streams.cs.meta index aa49f73..9893783 100644 --- a/Streams/EntitiesDB.Streams.cs.meta +++ b/Core/Streams/EntitiesDB.Streams.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0f2d5c7623463601bed8b9f8d25c210a +guid: c5dd44aac0643358901edec2dc65d746 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/EntitiesStreams.cs b/Core/Streams/EntitiesStreams.cs similarity index 100% rename from Streams/EntitiesStreams.cs rename to Core/Streams/EntitiesStreams.cs diff --git a/Streams/EntitiesStreams.cs.meta b/Core/Streams/EntitiesStreams.cs.meta similarity index 83% rename from Streams/EntitiesStreams.cs.meta rename to Core/Streams/EntitiesStreams.cs.meta index 38efc7d..07e5eac 100644 --- a/Streams/EntitiesStreams.cs.meta +++ b/Core/Streams/EntitiesStreams.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0969c421a99f328582f902b595a6fdfc +guid: da06e4698d013d49a3a1e465e425d520 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/EntityStream.cs b/Core/Streams/EntityStream.cs similarity index 100% rename from Streams/EntityStream.cs rename to Core/Streams/EntityStream.cs diff --git a/Streams/EntityStream.cs.meta b/Core/Streams/EntityStream.cs.meta similarity index 83% rename from Streams/EntityStream.cs.meta rename to Core/Streams/EntityStream.cs.meta index d97f58d..2618809 100644 --- a/Streams/EntityStream.cs.meta +++ b/Core/Streams/EntityStream.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b6c9debed17b35ad97a6d6fd05c1e674 +guid: 9a6bcabd4d4d3b3b888d55c3dd6682b2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/GenericentityStreamConsumerFactory.cs b/Core/Streams/GenericentityStreamConsumerFactory.cs similarity index 100% rename from Streams/GenericentityStreamConsumerFactory.cs rename to Core/Streams/GenericentityStreamConsumerFactory.cs diff --git a/Streams/GenericentityStreamConsumerFactory.cs.meta b/Core/Streams/GenericentityStreamConsumerFactory.cs.meta similarity index 83% rename from Streams/GenericentityStreamConsumerFactory.cs.meta rename to Core/Streams/GenericentityStreamConsumerFactory.cs.meta index 4f07489..8a7180f 100644 --- a/Streams/GenericentityStreamConsumerFactory.cs.meta +++ b/Core/Streams/GenericentityStreamConsumerFactory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e59b74ad5c7433aabb1af5306b8990c5 +guid: 0df676e7378b3ddaba343a50fac2b6c4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Streams/ThreadSafeNativeEntityStream.cs b/Core/Streams/ThreadSafeNativeEntityStream.cs similarity index 100% rename from Streams/ThreadSafeNativeEntityStream.cs rename to Core/Streams/ThreadSafeNativeEntityStream.cs diff --git a/Streams/ThreadSafeNativeEntityStream.cs.meta b/Core/Streams/ThreadSafeNativeEntityStream.cs.meta similarity index 83% rename from Streams/ThreadSafeNativeEntityStream.cs.meta rename to Core/Streams/ThreadSafeNativeEntityStream.cs.meta index bba3586..36c7422 100644 --- a/Streams/ThreadSafeNativeEntityStream.cs.meta +++ b/Core/Streams/ThreadSafeNativeEntityStream.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 88e3ed2a84aa3618b082b42ef9c1c582 +guid: a0c49b065ae330f083a88e1b042a108a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/TypeSafeDictionaryFactory.cs b/Core/TypeSafeDictionaryFactory.cs similarity index 100% rename from TypeSafeDictionaryFactory.cs rename to Core/TypeSafeDictionaryFactory.cs diff --git a/TypeSafeDictionaryFactory.cs.meta b/Core/TypeSafeDictionaryFactory.cs.meta similarity index 83% rename from TypeSafeDictionaryFactory.cs.meta rename to Core/TypeSafeDictionaryFactory.cs.meta index b0cf072..ae803ad 100644 --- a/TypeSafeDictionaryFactory.cs.meta +++ b/Core/TypeSafeDictionaryFactory.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 04c8b41c23ff37e8a4c2d032f5aaf21e +guid: 4887cf3dc121377db4f46ea9d4750e8b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/DataStructures/TypeSafeDictionary.cs b/DataStructures/TypeSafeDictionary.cs index c74f124..e3c3710 100644 --- a/DataStructures/TypeSafeDictionary.cs +++ b/DataStructures/TypeSafeDictionary.cs @@ -15,21 +15,21 @@ namespace Svelto.ECS.Internal internal static readonly bool IsUnmanaged = _type.IsUnmanagedEx() && (typeof(IEntityViewComponent).IsAssignableFrom(_type) == false); - SveltoDictionary>, ManagedStrategy, + SveltoDictionary>, ManagedStrategy, ManagedStrategy> implMgd; //used directly by native methods - internal SveltoDictionary>, NativeStrategy, + internal SveltoDictionary>, NativeStrategy, NativeStrategy> implUnmgd; public TypeSafeDictionary(uint size) { if (IsUnmanaged) - implUnmgd = new SveltoDictionary>, + implUnmgd = new SveltoDictionary>, NativeStrategy, NativeStrategy>(size); else { - implMgd = new SveltoDictionary>, + implMgd = new SveltoDictionary>, ManagedStrategy, ManagedStrategy>(size); } } @@ -106,8 +106,9 @@ namespace Svelto.ECS.Internal //this can be optimized, should pass all the entities and not restart the process for each one foreach (var value in implUnmgd) - ExecuteEnginesAddOrSwapCallbacksOnSingleEntity(entityComponentEnginesDB, ref typeSafeDictionary[value.Key] - , fromGroup, in profiler, new EGID(value.Key, toGroup)); + ExecuteEnginesAddOrSwapCallbacksOnSingleEntity(entityComponentEnginesDB + , ref typeSafeDictionary[value.Key], fromGroup + , in profiler, new EGID(value.Key, toGroup)); } else { @@ -115,8 +116,9 @@ namespace Svelto.ECS.Internal //this can be optimized, should pass all the entities and not restart the process for each one foreach (var value in implMgd) - ExecuteEnginesAddOrSwapCallbacksOnSingleEntity(entityComponentEnginesDB, ref typeSafeDictionary[value.Key] - , fromGroup, in profiler, new EGID(value.Key, toGroup)); + ExecuteEnginesAddOrSwapCallbacksOnSingleEntity(entityComponentEnginesDB + , ref typeSafeDictionary[value.Key], fromGroup + , in profiler, new EGID(value.Key, toGroup)); } } diff --git a/DataStructures/Unmanaged/NativeBag.cs b/DataStructures/Unmanaged/NativeBag.cs index 96e89c6..cb2ac97 100644 --- a/DataStructures/Unmanaged/NativeBag.cs +++ b/DataStructures/Unmanaged/NativeBag.cs @@ -9,7 +9,6 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; -using System.Threading; using Svelto.Common; namespace Svelto.ECS.DataStructures diff --git a/DataStructures/Unmanaged/NativeDynamicArrayCast.cs b/DataStructures/Unmanaged/NativeDynamicArrayCast.cs index a34078b..3c45777 100644 --- a/DataStructures/Unmanaged/NativeDynamicArrayCast.cs +++ b/DataStructures/Unmanaged/NativeDynamicArrayCast.cs @@ -9,7 +9,11 @@ namespace Svelto.ECS.DataStructures [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => _array.Count(); - public int count => _array.Count(); + public int count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _array.Count(); + } public ref T this[int index] { diff --git a/DataStructures/Unmanaged/SharedNativeInt.cs b/DataStructures/Unmanaged/SharedNativeInt.cs index e180084..6810c79 100644 --- a/DataStructures/Unmanaged/SharedNativeInt.cs +++ b/DataStructures/Unmanaged/SharedNativeInt.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using System.Threading; using Svelto.Common; diff --git a/Dispatcher/DispatchOnChange.cs b/Dispatcher/DispatchOnChange.cs index c2a40aa..b7ae294 100644 --- a/Dispatcher/DispatchOnChange.cs +++ b/Dispatcher/DispatchOnChange.cs @@ -8,7 +8,9 @@ namespace Svelto.ECS { _value = initialValue; } - + + public DispatchOnChange(EGID senderID, Action callback) : base(senderID, callback) {} + public new T value { set diff --git a/Dispatcher/DispatchOnSet.cs b/Dispatcher/DispatchOnSet.cs index 8334d2e..37c6e43 100644 --- a/Dispatcher/DispatchOnSet.cs +++ b/Dispatcher/DispatchOnSet.cs @@ -4,11 +4,12 @@ namespace Svelto.ECS { public class DispatchOnSet { - public DispatchOnSet(EGID senderID) - { - _senderID = senderID; + public DispatchOnSet(EGID senderID, Action callback):this(senderID) + { + NotifyOnValueSet(callback); } - + public DispatchOnSet(EGID senderID) { _senderID = senderID; } + public T value { set @@ -19,29 +20,29 @@ namespace Svelto.ECS _subscriber(_senderID, value); } } - + public void NotifyOnValueSet(Action action) { #if DEBUG && !PROFILE_SVELTO - DBC.ECS.Check.Require(_subscriber == null, $"{this.GetType().Name}: listener already registered"); + DBC.ECS.Check.Require(_subscriber == null, $"{this.GetType().Name}: listener already registered"); #endif _subscriber = action; - _paused = false; + _paused = false; } public void StopNotify() { _subscriber = null; - _paused = true; + _paused = true; } - public void PauseNotify() { _paused = true; } + public void PauseNotify() { _paused = true; } public void ResumeNotify() { _paused = false; } - protected T _value; - readonly EGID _senderID; + protected T _value; + readonly EGID _senderID; Action _subscriber; bool _paused; } -} +} \ No newline at end of file diff --git a/EntityComponentInitializer.cs.meta b/EntityComponentInitializer.cs.meta deleted file mode 100644 index 619a26e..0000000 --- a/EntityComponentInitializer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 005da4cbd47736e1bc2fb1676cb30190 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/EntitySubmissionScheduler.cs b/EntitySubmissionScheduler.cs deleted file mode 100644 index d5af356..0000000 --- a/EntitySubmissionScheduler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Svelto.ECS.Schedulers -{ - public interface IEntitiesSubmissionScheduler: IDisposable - { - bool paused { get; set; } - } - - public abstract class EntitiesSubmissionScheduler: IEntitiesSubmissionScheduler - { - protected internal abstract EnginesRoot.EntitiesSubmitter onTick { set; } - public abstract void Dispose(); - public abstract bool paused { get; set; } - } - - public abstract class ISimpleEntitiesSubmissionScheduler: EntitiesSubmissionScheduler - { - public abstract void SubmitEntities(); - } -} \ No newline at end of file diff --git a/Extensions/Svelto/AllGroupsEnumerable.cs b/Extensions/Svelto/AllGroupsEnumerable.cs index eb746df..54673e3 100644 --- a/Extensions/Svelto/AllGroupsEnumerable.cs +++ b/Extensions/Svelto/AllGroupsEnumerable.cs @@ -19,15 +19,12 @@ namespace Svelto.ECS public void Deconstruct(out EntityCollection collection, out ExclusiveGroupStruct group) { collection = this.collection; - group = this.@group; + group = this.@group; } } - - public AllGroupsEnumerable(EntitiesDB db) - { - _db = db; - } - + + public AllGroupsEnumerable(EntitiesDB db) { _db = db; } + public ref struct GroupsIterator { public GroupsIterator(EntitiesDB db) : this() @@ -40,13 +37,14 @@ namespace Svelto.ECS //attention, the while is necessary to skip empty groups while (_db.MoveNext() == true) { - FasterDictionary.KeyValuePairFast group = _db.Current; + var group = _db.Current; ITypeSafeDictionary typeSafeDictionary = @group.Value as ITypeSafeDictionary; - - if (typeSafeDictionary.count == 0) continue; + + if (typeSafeDictionary.count == 0) + continue; _array.collection = new EntityCollection(typeSafeDictionary.GetValues(out var count), count); - _array.@group = new ExclusiveGroupStruct(group.Key); + _array.@group = new ExclusiveGroupStruct(group.Key); return true; } @@ -56,15 +54,15 @@ namespace Svelto.ECS public GroupCollection Current => _array; - FasterDictionary.FasterDictionaryKeyValueEnumerator _db; + SveltoDictionary>, ManagedStrategy, + ManagedStrategy>.SveltoDictionaryKeyValueEnumerator _db; + GroupCollection _array; } - public GroupsIterator GetEnumerator() - { - return new GroupsIterator(_db); - } + public GroupsIterator GetEnumerator() { return new GroupsIterator(_db); } - readonly EntitiesDB _db; + readonly EntitiesDB _db; } -} +} \ No newline at end of file diff --git a/Extensions/Svelto/EntityCollectionExtension.cs b/Extensions/Svelto/EntityCollectionExtension.cs index b9b4153..a4d5029 100644 --- a/Extensions/Svelto/EntityCollectionExtension.cs +++ b/Extensions/Svelto/EntityCollectionExtension.cs @@ -1,4 +1,3 @@ -using System; using System.Runtime.CompilerServices; using Svelto.DataStructures; using Svelto.ECS.Hybrid; @@ -46,10 +45,10 @@ namespace Svelto.ECS where T3 : unmanaged, IEntityComponent where T4 : unmanaged, IEntityComponent { - buffer1 = ec.Item1._nativedBuffer; - buffer2 = ec.Item2._nativedBuffer; - buffer3 = ec.Item3._nativedBuffer; - buffer4 = ec.Item4._nativedBuffer; + buffer1 = ec.buffer1._nativedBuffer; + buffer2 = ec.buffer2._nativedBuffer; + buffer3 = ec.buffer3._nativedBuffer; + buffer4 = ec.buffer4._nativedBuffer; count = (int) ec.count; } @@ -188,10 +187,10 @@ namespace Svelto.ECS where T3 : unmanaged, IEntityComponent where T4 : struct, IEntityViewComponent { - buffer1 = ec.Item1._nativedBuffer; - buffer2 = ec.Item2._nativedBuffer; - buffer3 = ec.Item3._nativedBuffer; - buffer4 = ec.Item4._managedBuffer; + buffer1 = ec.buffer1._nativedBuffer; + buffer2 = ec.buffer2._nativedBuffer; + buffer3 = ec.buffer3._nativedBuffer; + buffer4 = ec.buffer4._managedBuffer; count = (int) ec.count; } } @@ -229,8 +228,8 @@ namespace Svelto.ECS where T3 : unmanaged, IEntityComponent where T4 : unmanaged, IEntityComponent { - return new BT, NB, NB, NB>(ec.Item1._nativedBuffer, ec.Item2._nativedBuffer - , ec.Item3._nativedBuffer, ec.Item4._nativedBuffer, ec.count); + return new BT, NB, NB, NB>(ec.buffer1._nativedBuffer, ec.buffer2._nativedBuffer + , ec.buffer3._nativedBuffer, ec.buffer4._nativedBuffer, ec.count); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -241,10 +240,10 @@ namespace Svelto.ECS where T3 : struct, IEntityViewComponent where T4 : struct, IEntityViewComponent { - buffer1 = ec.Item1._nativedBuffer; - buffer2 = ec.Item2._nativedBuffer; - buffer3 = ec.Item3._managedBuffer; - buffer4 = ec.Item4._managedBuffer; + buffer1 = ec.buffer1._nativedBuffer; + buffer2 = ec.buffer2._nativedBuffer; + buffer3 = ec.buffer3._managedBuffer; + buffer4 = ec.buffer4._managedBuffer; count = (int) ec.count; } } diff --git a/Extensions/Svelto/GroupsEnumerable.cs b/Extensions/Svelto/GroupsEnumerable.cs index 465ed8a..b1b9559 100644 --- a/Extensions/Svelto/GroupsEnumerable.cs +++ b/Extensions/Svelto/GroupsEnumerable.cs @@ -17,9 +17,6 @@ namespace Svelto.ECS where T3 : struct, IEntityComponent where T4 : struct, IEntityComponent { - readonly EntitiesDB _db; - readonly LocalFasterReadOnlyList _groups; - public GroupsEnumerable(EntitiesDB db, in LocalFasterReadOnlyList groups) { _db = db; @@ -52,7 +49,8 @@ namespace Svelto.ECS var array = entityCollection1; var array2 = entityCollection2; - _buffers = new EntityCollection(array.buffer1, array.buffer2, array.buffer3, array2); + _buffers = new EntityCollection(array.buffer1, array.buffer2, array.buffer3 + , array2); break; } @@ -66,7 +64,8 @@ namespace Svelto.ECS public void Reset() { _indexGroup = -1; } - public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public bool isValid => _indexGroup != -1; readonly LocalFasterReadOnlyList _groups; @@ -76,44 +75,36 @@ namespace Svelto.ECS } public GroupsIterator GetEnumerator() { return new GroupsIterator(_db, _groups); } - } - public ref struct RefCurrent where T1 : struct, IEntityComponent - where T2 : struct, IEntityComponent - where T3 : struct, IEntityComponent - where T4 : struct, IEntityComponent - { - public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) - { - _buffers = buffers; - _group = group; - } + readonly EntitiesDB _db; + readonly LocalFasterReadOnlyList _groups; - public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + public ref struct RefCurrent { - buffers = _buffers; - group = _group; - } + public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) + { + _buffers = buffers; + _group = group; + } - public readonly EntityCollection _buffers; - public readonly ExclusiveGroupStruct _group; + public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + { + buffers = _buffers; + group = _group; + } + + public readonly EntityCollection _buffers; + public readonly ExclusiveGroupStruct _group; + } } - /// - /// ToDo source gen could return the implementation of IBuffer directly, but cannot be done manually - /// - /// - /// - /// public readonly ref struct GroupsEnumerable where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent where T3 : struct, IEntityComponent { - readonly EntitiesDB _db; - readonly LocalFasterReadOnlyList _groups; - public GroupsEnumerable(EntitiesDB db, in LocalFasterReadOnlyList groups) { + DBC.ECS.Check.Require(groups.count > 0, "can't initialise a query without valid groups"); _db = db; _groups = groups; } @@ -150,7 +141,8 @@ namespace Svelto.ECS public void Reset() { _indexGroup = -1; } - public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public bool isValid => _indexGroup != -1; readonly LocalFasterReadOnlyList _groups; @@ -160,26 +152,27 @@ namespace Svelto.ECS } public GroupsIterator GetEnumerator() { return new GroupsIterator(_db, _groups); } - } - public ref struct RefCurrent where T1 : struct, IEntityComponent - where T2 : struct, IEntityComponent - where T3 : struct, IEntityComponent - { - public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) - { - _buffers = buffers; - _group = group; - } + readonly EntitiesDB _db; + readonly LocalFasterReadOnlyList _groups; - public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + public ref struct RefCurrent { - buffers = _buffers; - group = _group; - } + public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) + { + _buffers = buffers; + _group = group; + } + + public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + { + buffers = _buffers; + group = _group; + } - public readonly EntityCollection _buffers; - public readonly ExclusiveGroupStruct _group; + public readonly EntityCollection _buffers; + public readonly ExclusiveGroupStruct _group; + } } public readonly ref struct GroupsEnumerable @@ -223,7 +216,8 @@ namespace Svelto.ECS public void Reset() { _indexGroup = -1; } - public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public RefCurrent Current => new RefCurrent(_buffers, _groups[_indexGroup]); + public bool isValid => _indexGroup != -1; readonly EntitiesDB _db; readonly LocalFasterReadOnlyList _groups; @@ -236,24 +230,24 @@ namespace Svelto.ECS readonly EntitiesDB _db; readonly LocalFasterReadOnlyList _groups; - } - public ref struct RefCurrent where T1 : struct, IEntityComponent where T2 : struct, IEntityComponent - { - public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) + public ref struct RefCurrent { - _buffers = buffers; - _group = group; - } + public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) + { + _buffers = buffers; + _group = group; + } - public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) - { - buffers = _buffers; - group = _group; - } + public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + { + buffers = _buffers; + group = _group; + } - public readonly EntityCollection _buffers; - public readonly ExclusiveGroupStruct _group; + public readonly EntityCollection _buffers; + public readonly ExclusiveGroupStruct _group; + } } public readonly ref struct GroupsEnumerable where T1 : struct, IEntityComponent @@ -285,13 +279,19 @@ namespace Svelto.ECS _buffer = entityCollection; break; } + + var moveNext = _indexGroup < _groups.count; - return _indexGroup < _groups.count; + if (moveNext == false) + Reset(); + + return moveNext; } public void Reset() { _indexGroup = -1; } - public RefCurrent Current => new RefCurrent(_buffer, _groups[_indexGroup]); + public RefCurrent Current => new RefCurrent(_buffer, _groups[_indexGroup]); + public bool isValid => _indexGroup != -1; readonly EntitiesDB _db; readonly LocalFasterReadOnlyList _groups; @@ -304,23 +304,28 @@ namespace Svelto.ECS readonly EntitiesDB _db; readonly LocalFasterReadOnlyList _groups; - } - public ref struct RefCurrent where T1 : struct, IEntityComponent - { - public RefCurrent(in EntityCollection buffers, ExclusiveGroupStruct group) + public readonly ref struct RefCurrent { - _buffers = buffers; - _group = group; - } + public RefCurrent(in EntityCollection buffers, in ExclusiveGroupStruct group) + { + _buffers = buffers; + _group = group; + } - public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) - { - buffers = _buffers; - group = _group; - } + public void Deconstruct(out EntityCollection buffers, out ExclusiveGroupStruct group) + { + buffers = _buffers; + group = _group; + } + + public void Deconstruct(out EntityCollection buffers) + { + buffers = _buffers; + } - public readonly EntityCollection _buffers; - public readonly ExclusiveGroupStruct _group; + public readonly EntityCollection _buffers; + public readonly ExclusiveGroupStruct _group; + } } } \ No newline at end of file diff --git a/Extensions/Unity/DOTS/Jobs/DisposeJob.cs b/Extensions/Unity/DOTS/Jobs/DisposeJob.cs index 670241d..2ccc059 100644 --- a/Extensions/Unity/DOTS/Jobs/DisposeJob.cs +++ b/Extensions/Unity/DOTS/Jobs/DisposeJob.cs @@ -1,4 +1,4 @@ -#if UNITY_2019_2_OR_NEWER +#if UNITY_JOBS using System; using Unity.Jobs; diff --git a/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs b/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs new file mode 100644 index 0000000..ab091a9 --- /dev/null +++ b/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs @@ -0,0 +1,21 @@ +#if UNITY_JOBS +using Unity.Jobs; + +namespace Svelto.ECS.Extensions.Unity +{ + public interface IJobifiedEngine : IEngine + { + JobHandle Execute(JobHandle inputDeps, ref T _param); + + string name { get; } + } + + public interface IJobifiedEngine : IEngine + { + JobHandle Execute(JobHandle inputDeps); + + string name { get; } + } +} + +#endif \ No newline at end of file diff --git a/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs.meta b/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs.meta new file mode 100644 index 0000000..13a7b65 --- /dev/null +++ b/Extensions/Unity/DOTS/Jobs/IJobifiedEngine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dcadc16a6f0a357090970f072ad797a3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Extensions/Unity/DOTS/Jobs/JobifiedEnginesGroup.cs b/Extensions/Unity/DOTS/Jobs/JobifiedEnginesGroup.cs index 2a5eb10..148d10e 100644 --- a/Extensions/Unity/DOTS/Jobs/JobifiedEnginesGroup.cs +++ b/Extensions/Unity/DOTS/Jobs/JobifiedEnginesGroup.cs @@ -1,24 +1,10 @@ -#if UNITY_2019_2_OR_NEWER +#if UNITY_JOBS using Svelto.Common; using Svelto.DataStructures; using Unity.Jobs; namespace Svelto.ECS.Extensions.Unity { - public interface IJobifiedEngine : IEngine - { - JobHandle Execute(JobHandle inputDeps); - - string name { get; } - } - - public interface IJobifiedEngine : IEngine - { - JobHandle Execute(JobHandle inputDeps, ref T _param); - - string name { get; } - } - public interface IJobifiedGroupEngine : IJobifiedEngine { } /// @@ -58,7 +44,7 @@ namespace Svelto.ECS.Extensions.Unity return combinedHandles; } - protected internal void Add(Interface engine) + public void Add(Interface engine) { _engines.Add(engine); } @@ -66,7 +52,7 @@ namespace Svelto.ECS.Extensions.Unity public string name => _name; protected readonly FasterList _engines; - readonly string _name; + readonly string _name; } public abstract class JobifiedEnginesGroup: IJobifiedGroupEngine where Interface : class, IJobifiedEngine diff --git a/Extensions/Unity/DOTS/Jobs/SortedJobifiedEnginesGroup.cs b/Extensions/Unity/DOTS/Jobs/SortedJobifiedEnginesGroup.cs index f0c7546..7693866 100644 --- a/Extensions/Unity/DOTS/Jobs/SortedJobifiedEnginesGroup.cs +++ b/Extensions/Unity/DOTS/Jobs/SortedJobifiedEnginesGroup.cs @@ -1,4 +1,4 @@ -#if UNITY_2019_1_OR_NEWER +#if UNITY_JOBS using Svelto.DataStructures; using Unity.Jobs; using Svelto.Common; diff --git a/Extensions/Unity/DOTS/Jobs/UnityJobExtensions.cs b/Extensions/Unity/DOTS/Jobs/UnityJobExtensions.cs index 7d0df74..312c703 100644 --- a/Extensions/Unity/DOTS/Jobs/UnityJobExtensions.cs +++ b/Extensions/Unity/DOTS/Jobs/UnityJobExtensions.cs @@ -1,34 +1,10 @@ -#if UNITY_NATIVE +#if UNITY_JOBS using System; using Svelto.ECS.Extensions.Unity; using Unity.Jobs; namespace Svelto.ECS { -#if UNITY_JOBS - public static class UnityJobExtensions - { - public static JobHandle ScheduleParallel - (this JOB job, uint iterations, JobHandle inputDeps) where JOB: struct, IJobParallelForBatch - { - if (iterations == 0) - return inputDeps; - - var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations); - return job.ScheduleBatch((int)iterations, innerloopBatchCount, inputDeps); - } - - public static JobHandle ScheduleParallel - (this JOB job, int iterations, JobHandle inputDeps) where JOB: struct, IJobParallelForBatch - { - if (iterations <= 0) - return inputDeps; - - var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations); - return job.ScheduleBatch((int)iterations, innerloopBatchCount, inputDeps); - } - } -#endif public static class UnityJobExtensions2 { public static JobHandle ScheduleDispose diff --git a/Extensions/Unity/DOTS/Native/EnginesRoot.NativeOperation.cs b/Extensions/Unity/DOTS/Native/EnginesRoot.NativeOperation.cs index 0302254..136129c 100644 --- a/Extensions/Unity/DOTS/Native/EnginesRoot.NativeOperation.cs +++ b/Extensions/Unity/DOTS/Native/EnginesRoot.NativeOperation.cs @@ -9,30 +9,28 @@ namespace Svelto.ECS public partial class EnginesRoot { //todo: I very likely don't need to create one for each native entity factory, the same can be reused - readonly AtomicNativeBags _addOperationQueue = - new AtomicNativeBags(Common.Allocator.Persistent); + readonly AtomicNativeBags _addOperationQueue = new AtomicNativeBags(Common.Allocator.Persistent); - readonly AtomicNativeBags _removeOperationQueue = - new AtomicNativeBags(Common.Allocator.Persistent); + readonly AtomicNativeBags _removeOperationQueue = new AtomicNativeBags(Common.Allocator.Persistent); - readonly AtomicNativeBags _swapOperationQueue = - new AtomicNativeBags(Common.Allocator.Persistent); + readonly AtomicNativeBags _swapOperationQueue = new AtomicNativeBags(Common.Allocator.Persistent); NativeEntityRemove ProvideNativeEntityRemoveQueue(string memberName) where T : IEntityDescriptor, new() { //todo: remove operation array and store entity descriptor hash in the return value //todo I maybe able to provide a _nativeSwap.SwapEntity - _nativeRemoveOperations.Add( - new NativeOperationRemove(EntityDescriptorTemplate.descriptor.componentsToBuild, TypeCache.type, memberName)); + _nativeRemoveOperations.Add(new NativeOperationRemove( + EntityDescriptorTemplate.descriptor.componentsToBuild, TypeCache.type + , memberName)); return new NativeEntityRemove(_removeOperationQueue, _nativeRemoveOperations.count - 1); } - + NativeEntitySwap ProvideNativeEntitySwapQueue(string memberName) where T : IEntityDescriptor, new() { //todo: remove operation array and store entity descriptor hash in the return value - _nativeSwapOperations.Add( - new NativeOperationSwap(EntityDescriptorTemplate.descriptor.componentsToBuild, TypeCache.type, memberName)); + _nativeSwapOperations.Add(new NativeOperationSwap(EntityDescriptorTemplate.descriptor.componentsToBuild + , TypeCache.type, memberName)); return new NativeEntitySwap(_swapOperationQueue, _nativeSwapOperations.count - 1); } @@ -50,35 +48,41 @@ namespace Svelto.ECS { using (profiler.Sample("Native Remove/Swap Operations")) { - for (int i = 0; i < _removeOperationQueue.count; i++) + var removeBuffersCount = _removeOperationQueue.count; + for (int i = 0; i < removeBuffersCount; i++) { ref var buffer = ref _removeOperationQueue.GetBuffer(i); while (buffer.IsEmpty() == false) { - var componentsIndex = buffer.Dequeue(); - var entityEGID = buffer.Dequeue(); - var nativeRemoveOperation = _nativeRemoveOperations[componentsIndex]; - CheckRemoveEntityID(entityEGID, nativeRemoveOperation.entityDescriptorType); + var componentsIndex = buffer.Dequeue(); + var entityEGID = buffer.Dequeue(); + NativeOperationRemove nativeRemoveOperation = _nativeRemoveOperations[componentsIndex]; + CheckRemoveEntityID(entityEGID, nativeRemoveOperation.entityDescriptorType + , nativeRemoveOperation.caller); QueueEntitySubmitOperation(new EntitySubmitOperation( EntitySubmitOperationType.Remove, entityEGID, entityEGID , nativeRemoveOperation.components)); } } - for (int i = 0; i < _swapOperationQueue.count; i++) + var swapBuffersCount = _swapOperationQueue.count; + for (int i = 0; i < swapBuffersCount; i++) { ref var buffer = ref _swapOperationQueue.GetBuffer(i); while (buffer.IsEmpty() == false) { - var componentsIndex = buffer.Dequeue(); + var componentsIndex = buffer.Dequeue(); var entityEGID = buffer.Dequeue(); - + var componentBuilders = _nativeSwapOperations[componentsIndex].components; - CheckRemoveEntityID(entityEGID.@from, _nativeSwapOperations[componentsIndex].entityDescriptorType, _nativeSwapOperations[componentsIndex].caller ); - CheckAddEntityID(entityEGID.to, _nativeSwapOperations[componentsIndex].entityDescriptorType, _nativeSwapOperations[componentsIndex].caller); + CheckRemoveEntityID(entityEGID.@from + , _nativeSwapOperations[componentsIndex].entityDescriptorType + , _nativeSwapOperations[componentsIndex].caller); + CheckAddEntityID(entityEGID.to, _nativeSwapOperations[componentsIndex].entityDescriptorType + , _nativeSwapOperations[componentsIndex].caller); QueueEntitySubmitOperation(new EntitySubmitOperation( EntitySubmitOperationType.Swap, entityEGID.@from, entityEGID.to @@ -86,21 +90,22 @@ namespace Svelto.ECS } } } - + using (profiler.Sample("Native Add Operations")) { - for (int i = 0; i < _addOperationQueue.count; i++) + var addBuffersCount = _addOperationQueue.count; + for (int i = 0; i < addBuffersCount; i++) { ref var buffer = ref _addOperationQueue.GetBuffer(i); - + while (buffer.IsEmpty() == false) { var componentsIndex = buffer.Dequeue(); var egid = buffer.Dequeue(); var componentCounts = buffer.Dequeue(); - - EntityComponentInitializer init = - BuildEntity(egid, _nativeAddOperations[componentsIndex].components, _nativeAddOperations[componentsIndex].entityDescriptorType); + + var init = BuildEntity(egid, _nativeAddOperations[componentsIndex].components + , _nativeAddOperations[componentsIndex].entityDescriptorType); //only called if Init is called on the initialized (there is something to init) while (componentCounts > 0) @@ -146,22 +151,23 @@ namespace Svelto.ECS readonly struct NativeOperationBuild { internal readonly IComponentBuilder[] components; - internal readonly Type entityDescriptorType; + internal readonly Type entityDescriptorType; public NativeOperationBuild(IComponentBuilder[] descriptorComponentsToBuild, Type entityDescriptorType) { this.entityDescriptorType = entityDescriptorType; - components = descriptorComponentsToBuild; + components = descriptorComponentsToBuild; } } readonly struct NativeOperationRemove { internal readonly IComponentBuilder[] components; - internal readonly Type entityDescriptorType; - internal readonly string caller; - - public NativeOperationRemove(IComponentBuilder[] descriptorComponentsToRemove, Type entityDescriptorType, string caller) + internal readonly Type entityDescriptorType; + internal readonly string caller; + + public NativeOperationRemove + (IComponentBuilder[] descriptorComponentsToRemove, Type entityDescriptorType, string caller) { this.caller = caller; components = descriptorComponentsToRemove; @@ -172,10 +178,11 @@ namespace Svelto.ECS readonly struct NativeOperationSwap { internal readonly IComponentBuilder[] components; - internal readonly Type entityDescriptorType; - internal readonly string caller; + internal readonly Type entityDescriptorType; + internal readonly string caller; - public NativeOperationSwap(IComponentBuilder[] descriptorComponentsToSwap, Type entityDescriptorType, string caller) + public NativeOperationSwap + (IComponentBuilder[] descriptorComponentsToSwap, Type entityDescriptorType, string caller) { this.caller = caller; components = descriptorComponentsToSwap; diff --git a/Extensions/Unity/DOTS/Native/NativeEGIDMultiMapper.cs b/Extensions/Unity/DOTS/Native/NativeEGIDMultiMapper.cs index cac1afd..1a5af5e 100644 --- a/Extensions/Unity/DOTS/Native/NativeEGIDMultiMapper.cs +++ b/Extensions/Unity/DOTS/Native/NativeEGIDMultiMapper.cs @@ -7,24 +7,24 @@ namespace Svelto.ECS public struct NativeEGIDMultiMapper:IDisposable where T : unmanaged, IEntityComponent { SveltoDictionary>, + NativeStrategy>, NativeStrategy, NativeStrategy>, - NativeStrategy>, + NativeStrategy>, NativeStrategy>, + NativeStrategy>, NativeStrategy, NativeStrategy>>, NativeStrategy> _dic; public NativeEGIDMultiMapper (SveltoDictionary>, + NativeStrategy>, NativeStrategy, NativeStrategy>, - NativeStrategy>, + NativeStrategy>, NativeStrategy>, + NativeStrategy>, NativeStrategy, NativeStrategy>>, NativeStrategy> dictionary) diff --git a/Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs.meta b/Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs.meta deleted file mode 100644 index e287740..0000000 --- a/Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d63198265758388c8d03afb9fa128938 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Extensions/Unity/DOTS/Native/NativeEntityFactory.cs b/Extensions/Unity/DOTS/Native/NativeEntityFactory.cs index 7351b16..dc83142 100644 --- a/Extensions/Unity/DOTS/Native/NativeEntityFactory.cs +++ b/Extensions/Unity/DOTS/Native/NativeEntityFactory.cs @@ -14,19 +14,19 @@ namespace Svelto.ECS _addOperationQueue = addOperationQueue; } - public NativeEntityComponentInitializer BuildEntity - (uint eindex, BuildGroup BuildGroup, int threadIndex) + public NativeEntityInitializer BuildEntity + (uint eindex, ExclusiveBuildGroup exclusiveBuildGroup, int threadIndex) { NativeBag unsafeBuffer = _addOperationQueue.GetBuffer(threadIndex + 1); unsafeBuffer.Enqueue(_index); - unsafeBuffer.Enqueue(new EGID(eindex, BuildGroup)); + unsafeBuffer.Enqueue(new EGID(eindex, exclusiveBuildGroup)); unsafeBuffer.ReserveEnqueue(out var index) = 0; - return new NativeEntityComponentInitializer(unsafeBuffer, index); + return new NativeEntityInitializer(unsafeBuffer, index); } - public NativeEntityComponentInitializer BuildEntity(EGID egid, int threadIndex) + public NativeEntityInitializer BuildEntity(EGID egid, int threadIndex) { NativeBag unsafeBuffer = _addOperationQueue.GetBuffer(threadIndex + 1); @@ -34,7 +34,7 @@ namespace Svelto.ECS unsafeBuffer.Enqueue(new EGID(egid.entityID, egid.groupID)); unsafeBuffer.ReserveEnqueue(out var index) = 0; - return new NativeEntityComponentInitializer(unsafeBuffer, index); + return new NativeEntityInitializer(unsafeBuffer, index); } } } diff --git a/Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs b/Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs similarity index 77% rename from Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs rename to Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs index 1d988b6..dbd0225 100644 --- a/Extensions/Unity/DOTS/Native/NativeEntityComponentInitializer.cs +++ b/Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs @@ -2,12 +2,12 @@ using Svelto.ECS.DataStructures; namespace Svelto.ECS { - public readonly ref struct NativeEntityComponentInitializer + public readonly ref struct NativeEntityInitializer { readonly NativeBag _unsafeBuffer; readonly UnsafeArrayIndex _index; - public NativeEntityComponentInitializer(in NativeBag unsafeBuffer, UnsafeArrayIndex index) + public NativeEntityInitializer(in NativeBag unsafeBuffer, UnsafeArrayIndex index) { _unsafeBuffer = unsafeBuffer; _index = index; diff --git a/Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs.meta b/Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs.meta new file mode 100644 index 0000000..c6fa4b1 --- /dev/null +++ b/Extensions/Unity/DOTS/Native/NativeEntityInitializer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a06b3feb4a338168b106bea67dd09b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Extensions/Unity/DOTS/Native/NativeEntitySwap.cs b/Extensions/Unity/DOTS/Native/NativeEntitySwap.cs index 53de378..a60d1ac 100644 --- a/Extensions/Unity/DOTS/Native/NativeEntitySwap.cs +++ b/Extensions/Unity/DOTS/Native/NativeEntitySwap.cs @@ -22,7 +22,7 @@ namespace Svelto.ECS } - public void SwapEntity(EGID from, BuildGroup to, int threadIndex) + public void SwapEntity(EGID from, ExclusiveBuildGroup to, int threadIndex) { var simpleNativeBag = _swapQueue.GetBuffer(threadIndex); simpleNativeBag.Enqueue(_indexSwap); diff --git a/Extensions/Unity/DOTS/Native/UnityEntityDBExtensions.cs b/Extensions/Unity/DOTS/Native/UnityEntityDBExtensions.cs index 4917887..41fefe7 100644 --- a/Extensions/Unity/DOTS/Native/UnityEntityDBExtensions.cs +++ b/Extensions/Unity/DOTS/Native/UnityEntityDBExtensions.cs @@ -48,12 +48,12 @@ namespace Svelto.ECS { var dictionary = new SveltoDictionary>, + NativeStrategy>, NativeStrategy, NativeStrategy>, - NativeStrategy>, + NativeStrategy>, NativeStrategy>, + NativeStrategy>, NativeStrategy, NativeStrategy>>, NativeStrategy> diff --git a/Extensions/Unity/DOTS/UECS/IUECSSubmissionEngine.cs b/Extensions/Unity/DOTS/UECS/IUECSSubmissionEngine.cs index b86f9db..9e7e4bb 100644 --- a/Extensions/Unity/DOTS/UECS/IUECSSubmissionEngine.cs +++ b/Extensions/Unity/DOTS/UECS/IUECSSubmissionEngine.cs @@ -1,12 +1,25 @@ #if UNITY_ECS +using Svelto.Common; using Unity.Entities; +using Unity.Jobs; namespace Svelto.ECS.Extensions.Unity { - public interface IUECSSubmissionEngine : IJobifiedEngine + public abstract class SubmissionEngine : SystemBase, IJobifiedEngine { - EntityCommandBuffer ECB { get; set;} - EntityManager EM { get; set;} + public JobHandle Execute(JobHandle inputDeps) + { + Dependency = JobHandle.CombineDependencies(Dependency, inputDeps); + + OnUpdate(); + + return Dependency; + } + + public EntityCommandBuffer ECB { get; internal set; } + protected EntityManager EM => this.EntityManager; + + public string name => TypeToString.Name(this); } } #endif \ No newline at end of file diff --git a/Extensions/Unity/DOTS/UECS/SveltoOverUECSEnginesGroup.cs b/Extensions/Unity/DOTS/UECS/SveltoOverUECSEnginesGroup.cs index 309fc74..f4e7013 100644 --- a/Extensions/Unity/DOTS/UECS/SveltoOverUECSEnginesGroup.cs +++ b/Extensions/Unity/DOTS/UECS/SveltoOverUECSEnginesGroup.cs @@ -6,19 +6,35 @@ using Unity.Jobs; namespace Svelto.ECS.Extensions.Unity { + /// + /// This is a high level class to abstract the complexity of creating a Svelto ECS application that interacts + /// with UECS. However this is designed to make it work almost out of the box, but it should be eventually + /// substituted by project customized code. + /// This is a JobifiedEngine and as such it expect to be ticked. Normally it must be executed in a + /// SortedEnginesGroup as step that happens after the Svelto jobified engines run. The flow should be: + /// Svelto Engines Run + /// This Engine runs, which causeS: + /// Jobs to be completed (it's a sync point) + /// Synchronizations engines to be executed (Svelto to UECS) + /// Submission of Entities to be executed + /// Svelto Add/Remove callbacks to be called + /// ISubmissionEngines to be executed + /// UECS engines to executed + /// Synchronizations engines to be executed (UECS To Svelto) + /// [Sequenced(nameof(JobifiedSveltoEngines.SveltoOverUECS))] public class SveltoOverUECSEnginesGroup: IJobifiedEngine { public SveltoOverUECSEnginesGroup(EnginesRoot enginesRoot) { - DBC.ECS.Check.Require(enginesRoot.scheduler is ISimpleEntitiesSubmissionScheduler, "The Engines root must use a EntitiesSubmissionScheduler scheduler implementation"); + DBC.ECS.Check.Require(enginesRoot.scheduler is SimpleEntitiesSubmissionScheduler, "The Engines root must use a EntitiesSubmissionScheduler scheduler implementation"); - CreateUnityECSWorldForSvelto(enginesRoot.scheduler as ISimpleEntitiesSubmissionScheduler, enginesRoot); + CreateUnityECSWorldForSvelto(enginesRoot.scheduler as SimpleEntitiesSubmissionScheduler, enginesRoot); } public World world { get; private set; } - void CreateUnityECSWorldForSvelto(ISimpleEntitiesSubmissionScheduler scheduler, EnginesRoot enginesRoot) + void CreateUnityECSWorldForSvelto(SimpleEntitiesSubmissionScheduler scheduler, EnginesRoot enginesRoot) { world = new World("Svelto<>UECS world"); @@ -29,7 +45,6 @@ namespace Svelto.ECS.Extensions.Unity //This is the UECS group that takes care of all the UECS systems that creates entities //it also submits Svelto entities _sveltoUecsEntitiesSubmissionGroup = new SveltoUECSEntitiesSubmissionGroup(scheduler, world); - enginesRoot.AddEngine(_sveltoUecsEntitiesSubmissionGroup); //This is the group that handles the UECS sync systems that copy the svelto entities values to UECS entities _syncSveltoToUecsGroup = new SyncSveltoToUECSGroup(); enginesRoot.AddEngine(_syncSveltoToUecsGroup); @@ -45,7 +60,7 @@ namespace Svelto.ECS.Extensions.Unity public JobHandle Execute(JobHandle inputDeps) { //this is a sync point, there won't be pending jobs after this - _sveltoUecsEntitiesSubmissionGroup.Execute(inputDeps); + _sveltoUecsEntitiesSubmissionGroup.SubmitEntities(inputDeps); //Mixed explicit job dependency and internal automatic ECS dependency system //Write in to UECS entities so the UECS dependencies react on the components touched @@ -59,7 +74,7 @@ namespace Svelto.ECS.Extensions.Unity return _syncUecsToSveltoGroup.Execute(handle); } - public void AddUECSSubmissionEngine(IUECSSubmissionEngine spawnUnityEntityOnSveltoEntityEngine) + public void AddUECSSubmissionEngine(SubmissionEngine spawnUnityEntityOnSveltoEntityEngine) { _sveltoUecsEntitiesSubmissionGroup.Add(spawnUnityEntityOnSveltoEntityEngine); _enginesRoot.AddEngine(spawnUnityEntityOnSveltoEntityEngine); @@ -94,7 +109,6 @@ namespace Svelto.ECS.Extensions.Unity SyncSveltoToUECSGroup _syncSveltoToUecsGroup; SyncUECSToSveltoGroup _syncUecsToSveltoGroup; EnginesRoot _enginesRoot; - } } #endif \ No newline at end of file diff --git a/Extensions/Unity/DOTS/UECS/SveltoUECSEntitiesSubmissionGroup.cs b/Extensions/Unity/DOTS/UECS/SveltoUECSEntitiesSubmissionGroup.cs index ca835d6..1f0a8d3 100644 --- a/Extensions/Unity/DOTS/UECS/SveltoUECSEntitiesSubmissionGroup.cs +++ b/Extensions/Unity/DOTS/UECS/SveltoUECSEntitiesSubmissionGroup.cs @@ -1,4 +1,7 @@ #if UNITY_ECS +using System.Collections; +using Svelto.Common; +using Svelto.DataStructures; using Svelto.ECS.Schedulers; using Unity.Entities; using Unity.Jobs; @@ -15,22 +18,21 @@ namespace Svelto.ECS.Extensions.Unity /// solve external dependencies. External dependencies are tracked, but only linked to the UECS components operations /// With Dependency I cannot guarantee that an external container is used before previous jobs working on it are completed /// - public class SveltoUECSEntitiesSubmissionGroup : JobifiedEnginesGroup + public sealed class SveltoUECSEntitiesSubmissionGroup { - public SveltoUECSEntitiesSubmissionGroup - (ISimpleEntitiesSubmissionScheduler submissionScheduler, World UECSWorld) + public SveltoUECSEntitiesSubmissionGroup(SimpleEntitiesSubmissionScheduler submissionScheduler, World UECSWorld) { _submissionScheduler = submissionScheduler; _ECBSystem = UECSWorld.CreateSystem(); + _engines = new FasterList(); } - public new void Execute(JobHandle jobHandle) + public void SubmitEntities(JobHandle jobHandle) { - //Sync Point as we must be sure that jobs that create/swap/remove entities are done - jobHandle.Complete(); - if (_submissionScheduler.paused) return; + + jobHandle.Complete(); //prepare the entity command buffer to be used by the registered engines var entityCommandBuffer = _ECBSystem.CreateCommandBuffer(); @@ -38,21 +40,40 @@ namespace Svelto.ECS.Extensions.Unity foreach (var system in _engines) { system.ECB = entityCommandBuffer; - system.EM = _ECBSystem.EntityManager; } //Submit Svelto Entities, calls Add/Remove/MoveTo that can be used by the IUECSSubmissionEngines _submissionScheduler.SubmitEntities(); - //execute submission engines and complete jobs - base.Execute(default).Complete(); + //execute submission engines and complete jobs because of this I don't need to do _ECBSystem.AddJobHandleForProducer(Dependency); + using (var profiler = new PlatformProfiler("SveltoUECSEntitiesSubmissionGroup")) + { + for (var index = 0; index < _engines.count; index++) + { + ref var engine = ref _engines[index]; + using (profiler.Sample(engine.name)) + { + jobHandle = engine.Execute(jobHandle); + } + } + } + + //Sync Point as we must be sure that jobs that create/swap/remove entities are done + jobHandle.Complete(); //flush command buffer _ECBSystem.Update(); } + + public void Add(SubmissionEngine engine) + { + _ECBSystem.World.AddSystem(engine); + _engines.Add(engine); + } - readonly ISimpleEntitiesSubmissionScheduler _submissionScheduler; + readonly SimpleEntitiesSubmissionScheduler _submissionScheduler; readonly SubmissionEntitiesCommandBufferSystem _ECBSystem; + readonly FasterList _engines; [DisableAutoCreation] class SubmissionEntitiesCommandBufferSystem : EntityCommandBufferSystem { } diff --git a/Extensions/Unity/EntityDescriptorHolderHelper.cs b/Extensions/Unity/EntityDescriptorHolderHelper.cs index 609c845..087d755 100644 --- a/Extensions/Unity/EntityDescriptorHolderHelper.cs +++ b/Extensions/Unity/EntityDescriptorHolderHelper.cs @@ -1,4 +1,4 @@ -#if UNITY_ECS +#if UNITY_5 || UNITY_5_3_OR_NEWER using Svelto.ECS.Hybrid; using UnityEngine; @@ -6,7 +6,7 @@ namespace Svelto.ECS.Extensions.Unity { public static class EntityDescriptorHolderHelper { - public static EntityComponentInitializer CreateEntity(this Transform contextHolder, EGID ID, + public static EntityInitializer CreateEntity(this Transform contextHolder, EGID ID, IEntityFactory factory, out T holder) where T : MonoBehaviour, IEntityDescriptorHolder { @@ -16,7 +16,7 @@ namespace Svelto.ECS.Extensions.Unity return factory.BuildEntity(ID, holder.GetDescriptor(), implementors); } - public static EntityComponentInitializer Create(this Transform contextHolder, EGID ID, + public static EntityInitializer Create(this Transform contextHolder, EGID ID, IEntityFactory factory) where T : MonoBehaviour, IEntityDescriptorHolder { diff --git a/Extensions/Unity/SveltoGUIHelper.cs b/Extensions/Unity/SveltoGUIHelper.cs index e24303b..b639404 100644 --- a/Extensions/Unity/SveltoGUIHelper.cs +++ b/Extensions/Unity/SveltoGUIHelper.cs @@ -86,7 +86,7 @@ namespace Svelto.ECS.Extensions.Unity return s; } - public static EntityComponentInitializer Create(EGID ID, Transform contextHolder, IEntityFactory factory, + public static EntityInitializer Create(EGID ID, Transform contextHolder, IEntityFactory factory, out T holder, bool searchImplementorsInChildren = false) where T : MonoBehaviour, IEntityDescriptorHolder { @@ -100,7 +100,7 @@ namespace Svelto.ECS.Extensions.Unity return factory.BuildEntity(ID, holder.GetDescriptor(), implementors); } - public static EntityComponentInitializer Create(EGID ID, Transform contextHolder, + public static EntityInitializer Create(EGID ID, Transform contextHolder, IEntityFactory factory, bool searchImplementorsInChildren = false) where T : MonoBehaviour, IEntityDescriptorHolder { diff --git a/Extensions/Unity/UnityEntitiesSubmissionScheduler.cs b/Extensions/Unity/UnityEntitiesSubmissionScheduler.cs index f58a5b3..d33078c 100644 --- a/Extensions/Unity/UnityEntitiesSubmissionScheduler.cs +++ b/Extensions/Unity/UnityEntitiesSubmissionScheduler.cs @@ -1,4 +1,5 @@ #if UNITY_5 || UNITY_5_3_OR_NEWER +using System; using Object = UnityEngine.Object; using System.Collections; using UnityEngine; @@ -57,7 +58,10 @@ namespace Svelto.ECS.Schedulers.Unity void SubmitEntities() { if (paused == false) - _onTick.Invoke(); + { + var enumerator = _onTick.Invoke(UInt32.MaxValue); + while (enumerator.MoveNext()) ; + } } protected internal override EnginesRoot.EntitiesSubmitter onTick diff --git a/IEntityFunctions.cs b/IEntityFunctions.cs deleted file mode 100644 index cee25a4..0000000 --- a/IEntityFunctions.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Svelto.ECS -{ - public interface IEntityFunctions - { - //being entity ID globally not unique, the group must be specified when - //an entity is removed. Not specifying the group will attempt to remove - //the entity from the special standard group. - void RemoveEntity(uint entityID, BuildGroup groupID) where T : IEntityDescriptor, new(); - void RemoveEntity(EGID entityegid) where T : IEntityDescriptor, new(); - - void RemoveEntitiesFromGroup(BuildGroup groupID); - - void SwapEntitiesInGroup(BuildGroup fromGroupID, BuildGroup toGroupID) where T : IEntityDescriptor, new(); - - void SwapEntityGroup(uint entityID, BuildGroup fromGroupID, BuildGroup toGroupID) - where T : IEntityDescriptor, new(); - - void SwapEntityGroup(EGID fromID, BuildGroup toGroupID) where T : IEntityDescriptor, new(); - - void SwapEntityGroup(EGID fromID, BuildGroup toGroupID, BuildGroup mustBeFromGroup) - where T : IEntityDescriptor, new(); - - void SwapEntityGroup(EGID fromID, EGID toId) where T : IEntityDescriptor, new(); - - void SwapEntityGroup(EGID fromID, EGID toId, BuildGroup mustBeFromGroup) - where T : IEntityDescriptor, new(); -#if UNITY_NATIVE - NativeEntityRemove ToNativeRemove(string memberName) where T : IEntityDescriptor, new(); - NativeEntitySwap ToNativeSwap(string memberName) where T : IEntityDescriptor, new(); -#endif - } -} \ No newline at end of file diff --git a/README.md b/README.md index 2529d16..c7bdef4 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,15 @@ Real ECS framework for c\#. Enables to write encapsulated, decoupled, maintainab Svelto.ECS wasn't born just from the needs of a large team, but also as result of years of reasoning behind software engineering applied to game development. Svelto.ECS hasn't been written just to develop faster code, it has been designed to help develop better code. Performance gains is just one of the benefits in using Svelto.ECS, as ECS in general is a great way to write cache-friendly code. Svelto.ECS has been developed with the idea of ECS being a paradigm and not just a pattern, letting the user shift completely away from Object Oriented Programming with consequent improvements of the code design and code maintainability. Svelto.ECS is the result of years of iteration of the ECS paradigm applied to real game development with the intent to be as fool proof as possible. ## How to clone the repository: -The folders Svelto.ECS, Svelto.Tasks and Svelto.Common, where present, are submodules pointing to the relative repositories. If you find them empty, you need to update them through the submodule command. Check some instructions here: https://github.com/sebas77/Svelto.ECS.Vanilla.Example/wiki +The folders Svelto.ECS and Svelto.Common, where present, are submodules pointing to the relative repositories. If you find them empty, you need to update them through the submodule command. Check some instructions here: https://github.com/sebas77/Svelto.ECS.Vanilla.Example/wiki ## Svelto is now distributed as Unity Package too [![openupm](https://img.shields.io/npm/v/com.sebaslab.svelto.ecs?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.sebaslab.svelto.ecs/) -read this article for more information:http://www.sebaslab.com/distributing-svelto-through-openupm/ +read this article for more information: http://www.sebaslab.com/distributing-svelto-through-openupm/ or just install the package that comes from the link https://package-installer.glitch.me/v1/installer/OpenUPM/com.sebaslab.svelto.ecs?registry=https%3A%2F%2Fpackage.openupm.com + +**Note on the System.Runtime.CompilerServices.Unsafe.dll dependency and the bit of a mess that Unity Package Depenendency System is:** + +Unity Package System has a big deficency when it comes to dll dependency solving: two packages cannot point to the same dependency from different sources. Since Unity Collection remove the Unsafe.dll dependency officially (I can't understand this move at all), I had to distribute my own package. This means that if you want to use Svelto from UPM, you will need Svelto unsafe dll to be the only unsafe dll in the project. Otherwise you just download the source code and solve dependencies manually. ## Official Examples @@ -26,7 +30,7 @@ read this article for more information:http://www.sebaslab.com/distributing-svel **Framework articles:** -* [Svelto ECS 3.0 is finally here (article in progress)] +* [Svelto ECS 3.0 is finally here](https://www.sebaslab.com/whats-new-in-svelto-ecs-3-0/) \(re-introducing svelto\) * [Introducing Svelto ECS 2.9](http://www.sebaslab.com/introducing-svelto-ecs-2-9/) \(shows what's changed since 2.8\) * [Introducing Svelto ECS 2.8](http://www.sebaslab.com/introducing-svelto-ecs-2-8/) \(shows what's changed since 2.7\) * [Svelto.ECS 2.7: what’s new and best practices](http://www.sebaslab.com/svelto-2-7-whats-new-and-best-practices/) \(shows what's changed since 2.5\) @@ -44,6 +48,7 @@ read this article for more information:http://www.sebaslab.com/distributing-svel * [The truth behind Inversion of Control – Part IV – Dependency Inversion Principle](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-iv-dependency-inversion-principle/) * [The truth behind Inversion of Control – Part V – Entity Component System design to achieve true Inversion of Flow Control](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-v-drifting-away-from-ioc-containers/) * [The Quest for Maintainable Code and The Path to ECS](http://www.sebaslab.com/the-quest-for-maintainable-code-and-the-path-to-ecs/) +* [OOP abstraction layer in an ECS-centric application](https://www.sebaslab.com/oop-abstraction-layer-in-a-ecs-centric-application/) **Practical articles** @@ -60,10 +65,6 @@ read this article for more information:http://www.sebaslab.com/distributing-svel Note: I included the IoC articles just to show how I shifted over the years from using an IoC container to use an ECS framework and the rationale behind its adoption. -**The perfect companion for Svelto.ECS is Svelto.Tasks to run the logic of the Systems even on other threads!** - -* [https://github.com/sebas77/Svelto.Tasks](https://github.com/sebas77/Svelto.Tasks) - ## Users Generated Content \(I removed all the outdated articles, so this is a call for new ones!\) * [A Beginner’s Guide to Svelto.ECS (3.0) with Unity by Jiheh Ritterling](https://jiheh.medium.com/a-beginners-guide-to-svelto-ecs-3-0-with-unity-e9dbc88a2145) diff --git a/Serialization/DefaultVersioningFactory.cs b/Serialization/DefaultVersioningFactory.cs index 2e3dfa4..917b52f 100644 --- a/Serialization/DefaultVersioningFactory.cs +++ b/Serialization/DefaultVersioningFactory.cs @@ -14,7 +14,7 @@ namespace Svelto.ECS.Serialization _implementors = implementors; } - public EntityComponentInitializer BuildDeserializedEntity + public EntityInitializer BuildDeserializedEntity (EGID egid, ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor , int serializationType, IEntitySerialization entitySerialization, IEntityFactory factory , bool enginesRootIsDeserializationOnly) diff --git a/Serialization/EnginesRoot.GenericEntitySerialization.cs b/Serialization/EnginesRoot.GenericEntitySerialization.cs index 98d856f..b2a873d 100644 --- a/Serialization/EnginesRoot.GenericEntitySerialization.cs +++ b/Serialization/EnginesRoot.GenericEntitySerialization.cs @@ -33,7 +33,7 @@ namespace Svelto.ECS } } - public EntityComponentInitializer DeserializeNewEntity + public EntityInitializer DeserializeNewEntity (EGID egid, ISerializationData serializationData, int serializationType) { //todo: SerializableEntityHeader may be needed to be customizable @@ -67,7 +67,7 @@ namespace Svelto.ECS public void DeserializeEntityComponents (ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor - , ref EntityComponentInitializer initializer, int serializationType) + , ref EntityInitializer initializer, int serializationType) { foreach (var serializableEntityBuilder in entityDescriptor.entitiesToSerialize) { diff --git a/Serialization/EntitiesDB.SerializationDescriptorMap.cs b/Serialization/EntitiesDB.SerializationDescriptorMap.cs index e301625..3e14cdb 100644 --- a/Serialization/EntitiesDB.SerializationDescriptorMap.cs +++ b/Serialization/EntitiesDB.SerializationDescriptorMap.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using Svelto.Common; using Svelto.ECS.Serialization; diff --git a/Serialization/IDeserializationFactory.cs b/Serialization/IDeserializationFactory.cs index b35226e..b741b24 100644 --- a/Serialization/IDeserializationFactory.cs +++ b/Serialization/IDeserializationFactory.cs @@ -2,7 +2,7 @@ namespace Svelto.ECS.Serialization { public interface IDeserializationFactory { - EntityComponentInitializer BuildDeserializedEntity + EntityInitializer BuildDeserializedEntity (EGID egid, ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor , int serializationType, IEntitySerialization entitySerialization, IEntityFactory factory , bool enginesRootIsDeserializationOnly); diff --git a/Serialization/IEntitySerialization.cs b/Serialization/IEntitySerialization.cs index 2ff055d..686a52c 100644 --- a/Serialization/IEntitySerialization.cs +++ b/Serialization/IEntitySerialization.cs @@ -29,7 +29,7 @@ namespace Svelto.ECS.Serialization void DeserializeEntity(EGID egid, ISerializationData serializationData, int serializationType); /// - /// Deserialize a serializationData and copy directly to an previously created EntityComponentInitializer + /// Deserialize a serializationData and copy directly to an previously created EntityInitializer /// /// /// @@ -37,7 +37,7 @@ namespace Svelto.ECS.Serialization /// void DeserializeEntityComponents(ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor, - ref EntityComponentInitializer initializer, int serializationType); + ref EntityInitializer initializer, int serializationType); /// /// Contrary to the other Deserialize methods that assume that the entity exists, this method is used to deserialise @@ -47,7 +47,7 @@ namespace Svelto.ECS.Serialization /// /// /// - EntityComponentInitializer DeserializeNewEntity(EGID egid, ISerializationData serializationData, + EntityInitializer DeserializeNewEntity(EGID egid, ISerializationData serializationData, int serializationType); /// diff --git a/Serialization/ISerializableComponentBuilder.cs b/Serialization/ISerializableComponentBuilder.cs index 2b1e906..a3729a0 100644 --- a/Serialization/ISerializableComponentBuilder.cs +++ b/Serialization/ISerializableComponentBuilder.cs @@ -10,7 +10,7 @@ namespace Svelto.ECS.Serialization void Deserialize(uint id, ITypeSafeDictionary dictionary, ISerializationData serializationData , int serializationType); - void Deserialize(ISerializationData serializationData, in EntityComponentInitializer initializer + void Deserialize(ISerializationData serializationData, in EntityInitializer initializer , int serializationType); } } \ No newline at end of file diff --git a/Serialization/SerializableComponentBuilder.cs b/Serialization/SerializableComponentBuilder.cs index d3ba176..6fbdecf 100644 --- a/Serialization/SerializableComponentBuilder.cs +++ b/Serialization/SerializableComponentBuilder.cs @@ -55,7 +55,7 @@ namespace Svelto.ECS.Serialization } public void Deserialize - (ISerializationData serializationData, in EntityComponentInitializer initializer + (ISerializationData serializationData, in EntityInitializer initializer , int serializationType) { IComponentSerializer componentSerializer = _serializers[(int) serializationType]; diff --git a/SimpleEntitiesSubmissionScheduler.cs b/SimpleEntitiesSubmissionScheduler.cs deleted file mode 100644 index 512a49f..0000000 --- a/SimpleEntitiesSubmissionScheduler.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Svelto.ECS.Schedulers; - -namespace Svelto.ECS.Schedulers -{ - //This scheduler shouldn't be used in production and it's meant to be used for Unit Tests only - public sealed class SimpleEntitiesSubmissionScheduler : ISimpleEntitiesSubmissionScheduler - { - public override void SubmitEntities() - { - if (paused == false) - _onTick.Invoke(); - } - - protected internal override EnginesRoot.EntitiesSubmitter onTick - { - set - { - DBC.ECS.Check.Require(_onTick.IsUnused , "a scheduler can be exclusively used by one enginesRoot only"); - - _onTick = value; - } - } - - public override bool paused { get; set; } - - public override void Dispose() { } - - EnginesRoot.EntitiesSubmitter _onTick; - } -} \ No newline at end of file diff --git a/Svelto.ECS.asmdef b/Svelto.ECS.asmdef index 6ccb718..b836337 100644 --- a/Svelto.ECS.asmdef +++ b/Svelto.ECS.asmdef @@ -1,5 +1,6 @@ { "name": "Svelto.ECS", + "rootNamespace": "", "references": [ "Unity.Entities", "Unity.Collections", @@ -48,8 +49,8 @@ "define": "UNITY_NATIVE" }, { - "name": "com.unity.jobs", - "expression": "", + "name": "Unity", + "expression": "2019.3.0", "define": "UNITY_JOBS" } ], diff --git a/Svelto.ECS.csproj b/Svelto.ECS.csproj index 1e77aca..d480b8a 100644 --- a/Svelto.ECS.csproj +++ b/Svelto.ECS.csproj @@ -15,8 +15,7 @@ true - - + diff --git a/WaitForSubmissionEnumerator.cs b/WaitForSubmissionEnumerator.cs deleted file mode 100644 index acf4816..0000000 --- a/WaitForSubmissionEnumerator.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections; - -namespace Svelto.ECS -{ - public class WaitForSubmissionEnumerator : IEnumerator - { - class SubmissionEntityDescriptor : GenericEntityDescriptor - { - internal static readonly ExclusiveGroup SubmissionGroup = new ExclusiveGroup(); - } - - readonly IEntityFactory _entityFactory; - readonly EntitiesDB _entitiesDB; - readonly IEntityFunctions _entityFunctions; - - int _state; - - public WaitForSubmissionEnumerator(IEntityFunctions entityFunctions, IEntityFactory entityFactory, - EntitiesDB entitiesDb) - { - _entityFactory = entityFactory; - _entityFunctions = entityFunctions; - _entitiesDB = entitiesDb; - } - - public bool MoveNext() - { - switch (_state) - { - case 0: - _counter = _COUNTER++; - _entityFactory.BuildEntity(new EGID((uint) _counter, - SubmissionEntityDescriptor.SubmissionGroup)); - _state = 1; - return true; - case 1: - if (_entitiesDB.Exists(new EGID((uint) _counter, - SubmissionEntityDescriptor.SubmissionGroup)) == false) - return true; - - _entityFunctions.RemoveEntity(new EGID((uint) _counter, - SubmissionEntityDescriptor.SubmissionGroup)); - _state = 0; - return false; - } - - throw new Exception("something is wrong"); - } - - void IEnumerator.Reset() - { - throw new NotImplementedException(); - } - - public object Current { get; } - - struct SubmissionSignalStruct : IEntityComponent - {} - - int _counter; - static int _COUNTER; - } -} \ No newline at end of file diff --git a/package.json b/package.json index ece32d7..58d61f5 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,13 @@ "category": "Svelto", "description": "Svelto ECS C# Lightweight Data Oriented Entity Component System Framework", "dependencies": { - "com.sebaslab.svelto.common": "3.0.2" + "com.sebaslab.svelto.common": "3.1.0" }, "keywords": [ "svelto" ], "name": "com.sebaslab.svelto.ecs", - "version": "3.0.3", - "type": "framework" + "version": "3.1.0", + "type": "library", + "unity": "2019.3" } \ No newline at end of file