Skip to content

Commit

Permalink
Update to svelto 3.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiano Mandala committed Jul 14, 2024
1 parent 2d3cfe2 commit 259d1fe
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 682 deletions.
11 changes: 9 additions & 2 deletions com.sebaslab.svelto.ecs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# Svelto.ECS Changelog
All notable changes to this project will be documented in this file. Changes are listed in random order of importance.

## [3.5.2] - 07-2024

* Minor serialization code improvements
* Remove legacy filters once for all
* breaking change: GetOrCreate*Filter, Create*Filter, Get*Filter don't return by ref anymore to fix reported bug
* references are now updated at the end of the submission frame so they are accessible inside callbacks

## [3.5.1] - 01-2024

* Remove UnityEntitySubmissionScheduler, it was never needed, the user can use the standard EntitySubmissionScheduler and tick it manually
* Dropped the idea to specialise EntitiesSubmissionScheduler. In hindsight it was never necessary.
* Added better support for range exclusive groups, now they are correctly registered in the group hash map
* Removed announg Group compound/tag {type} is not sealed warning
* Removed annoying Group compound/tag {type} is not sealed warning
* Merged Cuyi's workaround to be able to query compound groups in abstract engine. Never had the time to implement a better solution
* It is now possible again to add an entity multiple times inside a filter (it will be overriden)
* Fixed issue https://github.com/sebas77/Svelto.ECS/issues/123
* Fixed issue https://github.com/sebas77/Svelto.ECS/issues/122
* Fixed issue https://github.com/sebas77/Svelto.ECS/issues/121
* AddEngine now adds engines contained in a GroupEngine to the EnginesGroup optionally~~~~
* AddEngine now adds engines contained in a GroupEngine to the EnginesGroup optionally

## [3.5.0] - 09-2023

Expand Down
13 changes: 1 addition & 12 deletions com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public EnginesRoot(EntitiesSubmissionScheduler entitiesComponentScheduler)
new FasterDictionary<ComponentID, FasterDictionary<ExclusiveGroupStruct, ITypeSafeDictionary>>();
_groupedEntityToAdd = new DoubleBufferedEntitiesToAdd();
_entityStreams = EntitiesStreams.Create();
#if SVELTO_LEGACY_FILTERS
_groupFilters =
new FasterDictionary<ComponentID, FasterDictionary<ExclusiveGroupStruct, LegacyGroupFilters>>();
#endif

_entityLocator.InitEntityReferenceMap();
_entitiesDB = new EntitiesDB(this, _entityLocator);

Expand Down Expand Up @@ -296,14 +293,6 @@ void Dispose(bool disposing)
foreach (var entityList in groups.value)
entityList.value.Dispose();

#if SVELTO_LEGACY_FILTERS
foreach (var type in _groupFilters)
foreach (var group in type.value)
group.value.Dispose();

_groupFilters.Clear();
#endif

DisposeFilters();

#if UNITY_NATIVE
Expand Down
5 changes: 0 additions & 5 deletions com.sebaslab.svelto.ecs/Core/EnginesRoot.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ internal readonly FasterDictionary<ExclusiveGroupStruct, FasterDictionary<Compon
// <EntityComponentType <groupID <entityID, EntityComponent>>>
internal readonly FasterDictionary<ComponentID, FasterDictionary<ExclusiveGroupStruct, ITypeSafeDictionary>>
_groupsPerEntity;
#if SVELTO_LEGACY_FILTERS
//The filters stored for each component and group
internal readonly FasterDictionary<ComponentID, FasterDictionary<ExclusiveGroupStruct, LegacyGroupFilters>>
_groupFilters;
#endif

readonly EntitiesDB _entitiesDB;

Expand Down
21 changes: 11 additions & 10 deletions com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ static void RemoveEntities(FasterDictionary<ExclusiveGroupStruct, FasterDictiona
{
using (var sampler = new PlatformProfiler("remove Entities"))
{
using (sampler.Sample("Remove Entity References"))
{
var count = entitiesRemoved.count;
for (int i = 0; i < count; i++)
{
enginesRoot._entityLocator.RemoveEntityReference(entitiesRemoved[i]);
}
}

using (sampler.Sample("Execute remove callbacks and remove entities"))
using (sampler.Sample("Execute obsolete remove callbacks"))
{
foreach (var entitiesToRemove in removeOperations)
{
Expand Down Expand Up @@ -157,6 +148,16 @@ static void RemoveEntities(FasterDictionary<ExclusiveGroupStruct, FasterDictiona
}
}
}

//doing this at the end to be able to use EGID.ToEntityReference inside callbacks
using (sampler.Sample("Remove Entity References"))
{
var count = entitiesRemoved.count;
for (int i = 0; i < count; i++)
{
enginesRoot._entityLocator.RemoveEntityReference(entitiesRemoved[i]);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Runtime.CompilerServices;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Svelto.Common;
using Svelto.DataStructures;
using Svelto.DataStructures.Native;
using Svelto.ECS.Reference;

namespace Svelto.ECS
{
// The EntityLocatorMap provides a bidirectional map to help locate entities without using an EGID which might
// The EntityReferenceMap provides a bidirectional map to help locate entities without using an EGID which might
// change at runtime. The Entity Locator map uses a reusable unique identifier struct called EntityLocator to
// find the last known EGID from last entity submission.
public partial class EnginesRoot
Expand Down
1 change: 1 addition & 0 deletions com.sebaslab.svelto.ecs/Core/EntitySubmissionScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected internal EnginesRoot.EntitiesSubmitter onTick

public void Dispose() { }

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public void SubmitEntities()
{
try
Expand Down
3 changes: 1 addition & 2 deletions com.sebaslab.svelto.ecs/Core/EntityViewUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ internal static void SetEntityViewComponentImplementors<T>(this IComponentBuilde
}

//efficient way to collect the fields of every EntityComponentType
var setters = FasterList<KeyValuePair<Type, FastInvokeActionCast<T>>>.NoVirt.ToArrayFast(
entityComponentBlazingFastReflection, out var count);
var setters = entityComponentBlazingFastReflection.ToArrayFast(out var count);

for (var i = 0; i < count; i++)
{
Expand Down
49 changes: 24 additions & 25 deletions com.sebaslab.svelto.ecs/Core/Filters/EntitiesDB.Filters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ internal SveltoFilters(SharedSveltoDictionaryNative<CombinedFilterComponentID, E
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetOrCreatePersistentFilter<T>(int filterID, FilterContextID filterContextId)
public EntityFilterCollection GetOrCreatePersistentFilter<T>(int filterID, FilterContextID filterContextId)
where T : struct, _IInternalEntityComponent
{
return ref GetOrCreatePersistentFilter<T>(new CombinedFilterID(filterID, filterContextId));
return GetOrCreatePersistentFilter<T>(new CombinedFilterID(filterID, filterContextId));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetOrCreatePersistentFilter<T>(CombinedFilterID filterID) where T : struct, _IInternalEntityComponent
public EntityFilterCollection GetOrCreatePersistentFilter<T>(CombinedFilterID filterID) where T : struct, _IInternalEntityComponent
{
var componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(filterID);

if (_persistentEntityFilters.TryFindIndex(componentAndFilterID, out var index) == true)
return ref _persistentEntityFilters.GetDirectValueByRef(index);
return _persistentEntityFilters.GetDirectValueByRef(index);

_persistentEntityFilters.Add(componentAndFilterID, new EntityFilterCollection(filterID));

Expand All @@ -92,7 +92,7 @@ public ref EntityFilterCollection GetOrCreatePersistentFilter<T>(CombinedFilterI
array.Add(lastIndex);
}

return ref _persistentEntityFilters.GetDirectValueByRef((uint)lastIndex);
return _persistentEntityFilters.GetDirectValueByRef((uint)lastIndex);
}

/// <summary>
Expand All @@ -107,7 +107,7 @@ public ref EntityFilterCollection GetOrCreatePersistentFilter<T>(CombinedFilterI
[Unity.Burst.BurstDiscard] //not burst compatible because of ComponentTypeID<T>.id and GetOrAdd callback;
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection CreatePersistentFilter<T>(CombinedFilterID filterID)
public EntityFilterCollection CreatePersistentFilter<T>(CombinedFilterID filterID)
where T : struct, _IInternalEntityComponent
{
var componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(filterID);
Expand All @@ -123,7 +123,7 @@ public ref EntityFilterCollection CreatePersistentFilter<T>(CombinedFilterID fil

_indicesOfPersistentFiltersUsedByThisComponent.GetOrAdd(ComponentTypeID<T>.id, _builder).Add(lastIndex);

return ref _persistentEntityFilters.GetDirectValueByRef((uint)lastIndex);
return _persistentEntityFilters.GetDirectValueByRef((uint)lastIndex);
}

static NativeDynamicArrayCast<int> Builder()
Expand All @@ -132,20 +132,20 @@ static NativeDynamicArrayCast<int> Builder()
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetPersistentFilter<T>(int filterID, FilterContextID filterContextId)
public EntityFilterCollection GetPersistentFilter<T>(int filterID, FilterContextID filterContextId)
where T : struct, _IInternalEntityComponent
{
return ref GetPersistentFilter<T>(new CombinedFilterID(filterID, filterContextId));
return GetPersistentFilter<T>(new CombinedFilterID(filterID, filterContextId));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetPersistentFilter<T>(CombinedFilterID filterID)
public EntityFilterCollection GetPersistentFilter<T>(CombinedFilterID filterID)
where T : struct, _IInternalEntityComponent
{
var componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(filterID);

if (_persistentEntityFilters.TryFindIndex(componentAndFilterID, out var index) == true)
return ref _persistentEntityFilters.GetDirectValueByRef(index);
return _persistentEntityFilters.GetDirectValueByRef(index);

throw new ECSException("filter not found");
}
Expand Down Expand Up @@ -220,34 +220,34 @@ public bool TryGetPersistentFilters<T>(FilterContextID filterContextId,
/// <typeparam name="T"></typeparam>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetOrCreateTransientFilter<T>(CombinedFilterID combinedFilterID, bool trackFilter = false)
public EntityFilterCollection GetOrCreateTransientFilter<T>(CombinedFilterID combinedFilterID, bool trackFilter = false)
where T : struct, _IInternalEntityComponent
{
var componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(combinedFilterID);

if (_transientEntityFilters.TryFindIndex(componentAndFilterID, out var index))
return ref _transientEntityFilters.GetDirectValueByRef(index);
return _transientEntityFilters.GetDirectValueByRef(index);

return ref InternalCreateTransientFilter<T>(combinedFilterID, componentAndFilterID, trackFilter);
return InternalCreateTransientFilter<T>(combinedFilterID, componentAndFilterID, trackFilter);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetOrCreateTransientFilter<T>(int filterID, FilterContextID filterContextId)
public EntityFilterCollection GetOrCreateTransientFilter<T>(int filterID, FilterContextID filterContextId)
where T : struct, _IInternalEntityComponent
{
return ref GetOrCreateTransientFilter<T>(new CombinedFilterID(filterID, filterContextId));
return GetOrCreateTransientFilter<T>(new CombinedFilterID(filterID, filterContextId));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection CreateTransientFilter<T>(CombinedFilterID combinedFilterID, bool trackFilter = false)
public EntityFilterCollection CreateTransientFilter<T>(CombinedFilterID combinedFilterID, bool trackFilter = false)
where T : struct, _IInternalEntityComponent
{
CombinedFilterComponentID componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(combinedFilterID);
#if DEBUG && !PROFILE_SVELTO
if (_transientEntityFilters.TryFindIndex(componentAndFilterID, out _))
throw new ECSException($"filter already exists {TypeCache<T>.name}");
#endif
return ref InternalCreateTransientFilter<T>(combinedFilterID, componentAndFilterID, trackFilter);
return InternalCreateTransientFilter<T>(combinedFilterID, componentAndFilterID, trackFilter);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -267,14 +267,14 @@ public bool TryGetTransientFilter<T>(CombinedFilterID filterID, out EntityFilter
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityFilterCollection GetTransientFilter<T>(CombinedFilterID filterID)
public EntityFilterCollection GetTransientFilter<T>(CombinedFilterID filterID)
where T : struct, _IInternalEntityComponent
{
var componentAndFilterID = Internal_FilterHelper.CombineFilterIDWithComponentID<T>(filterID);

if (_transientEntityFilters.TryFindIndex(componentAndFilterID, out var index))
{
return ref _transientEntityFilters.GetDirectValueByRef(index);
return _transientEntityFilters.GetDirectValueByRef(index);
}

throw new ECSException($"no filters associated with the type {TypeCache<T>.name}");
Expand Down Expand Up @@ -326,7 +326,7 @@ public bool TryGetTransientFilters<T>(FilterContextID filterContextId, out Entit
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
ref EntityFilterCollection InternalCreateTransientFilter<T>(CombinedFilterID filterID, CombinedFilterComponentID componentAndFilterID,
EntityFilterCollection InternalCreateTransientFilter<T>(CombinedFilterID filterID, CombinedFilterComponentID componentAndFilterID,
bool trackFilter)
where T : struct, _IInternalEntityComponent
{
Expand All @@ -336,12 +336,11 @@ ref EntityFilterCollection InternalCreateTransientFilter<T>(CombinedFilterID fil

if (trackFilter)
{
var typeRef = ComponentTypeID<T>.id;
var lastIndex = _transientEntityFilters.count - 1;
_indicesOfTransientFiltersUsedByThisComponent.GetOrAdd(ComponentTypeID<T>.id, _builder).Add(lastIndex);
}

return ref _transientEntityFilters.GetDirectValueByRef((uint)(_transientEntityFilters.count - 1));
return _transientEntityFilters.GetDirectValueByRef((uint)(_transientEntityFilters.count - 1));
}

public struct EntityFilterCollectionsEnumerator
Expand Down Expand Up @@ -371,10 +370,10 @@ public bool MoveNext()
return false;
}

public ref EntityFilterCollection Current
public EntityFilterCollection Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _sharedSveltoDictionaryNative.GetDirectValueByRef((uint)_currentIndex - 1);
get => _sharedSveltoDictionaryNative.GetDirectValueByRef((uint)_currentIndex - 1);
}

readonly NativeDynamicArrayCast<int> _getDirectValueByRef;
Expand Down
Loading

0 comments on commit 259d1fe

Please sign in to comment.