Browse Source

update svelto ECS 2.8

tags/2.8
sebas77 5 years ago
parent
commit
d873c114b8
12 changed files with 99 additions and 164 deletions
  1. +1
    -1
      Svelto.Common
  2. +2
    -3
      Svelto.ECS.Components/Components/ExtensionMethods.cs
  3. +69
    -0
      Svelto.ECS.Components/Components/ExtensionMethodsUECS.cs
  4. +0
    -106
      Svelto.ECS/DataStructures/GroupsList.cs
  5. +2
    -2
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  6. +7
    -28
      Svelto.ECS/Dispatcher/DispatchOnSet.cs
  7. +1
    -1
      Svelto.ECS/EnginesRoot.Entities.cs
  8. +5
    -7
      Svelto.ECS/ExecuteOnEntitiesDB.cs
  9. +8
    -7
      Svelto.ECS/Extensions/Unity/SveltoGUIHelper.cs
  10. +2
    -2
      Svelto.ECS/GenericentityStreamConsumerFactory.cs
  11. +1
    -6
      Svelto.ECS/IEntitiesDB.cs
  12. +1
    -1
      Svelto.ECS/IReactOnSwap.cs

+ 1
- 1
Svelto.Common

@@ -1 +1 @@
Subproject commit b43c9866240e40da0caacdf0f717b37d6e5a6cf0
Subproject commit 09e2b8967e24eb94c701ceb8f4907e45afb64d6d

+ 2
- 3
Svelto.ECS.Components/Components/ExtensionMethods.cs View File

@@ -92,10 +92,9 @@ public static partial class ExtensionMethods
float wz = rotation.w * z;

return new ECSVector3((1F - (yy + zz)) * point.x + (xy - wz) * point.y + (xz + wy) * point.z,
(xy + wz) * point.x + (1F - (xx + zz)) * point.y + (yz - wx) * point.z,
(xz - wy) * point.x + (yz + wx) * point.y + (1F - (xx + yy)) * point.z);
(xy + wz) * point.x + (1F - (xx + zz)) * point.y + (yz - wx) * point.z,
(xz - wy) * point.x + (yz + wx) * point.y + (1F - (xx + yy)) * point.z);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Swap(ref this ECSVector3 vector, ref ECSVector3 vectorS)
{


+ 69
- 0
Svelto.ECS.Components/Components/ExtensionMethodsUECS.cs View File

@@ -0,0 +1,69 @@
#if UNITY_MATHEMATICS
using Svelto.ECS.Components;
using Unity.Mathematics;

public static partial class ExtensionMethods
{
public static float3 ToFloat3(in this ECSVector3 vector)
{
return new float3(vector.x, vector.y, vector.z);
}
public static quaternion ToQuaternion(in this ECSVector4 vector)
{
return new quaternion(vector.x, vector.y, vector.z, vector.w);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Mul(ref this float3 vector1, float value)
{
vector1.x *= value;
vector1.y *= value;
vector1.z *= value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Div(ref this float3 vector1, float value)
{
vector1.x /= value;
vector1.y /= value;
vector1.z /= value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ProjectOnPlane(ref this float3 vector, in float3 planeNormal)
{
var num1 = math.dot(planeNormal,planeNormal);
if ((double) num1 < (double) Mathf.Epsilon)
return;
var num2 = math.dot(vector,planeNormal) / num1;
vector.x -= planeNormal.x * num2;
vector.y -= planeNormal.y * num2;
vector.z -= planeNormal.z * num2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Normalize(ref this float3 x)
{
x.Mul(math.rsqrt(math.dot(x,x)));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void NormalizeSafe(ref this float3 x)
{
var len = math.dot(x,x);
x = len > math.FLT_MIN_NORMAL ? x * math.rsqrt(len) : float3.zero;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Add(ref this float3 a, in float3 b)
{
a.x += b.x;
a.y += b.y;
a.z += b.z;
}

}

#endif

+ 0
- 106
Svelto.ECS/DataStructures/GroupsList.cs View File

@@ -1,106 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using Svelto.DataStructures;

namespace Svelto.ECS.Internal
{
class GroupList<T>
{
public int Count => _list.Count;

public GroupList()
{
_list = new FasterList<T>();
}

public ref T this[uint index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _list[index];
}

public GroupListEnumerator<T> GetEnumerator()
{
return new GroupListEnumerator<T>(_list.ToArrayFast(), _list.Count);
}

public T GetOrAdd<TC>(uint location) where TC:class, T, new()
{
if (location >= _list.Count || this[location] == null)
{
var item = new TC();
_list.Add(location, item);
return item;
}

return this[location];
}
public void Clear() { _list.Clear(); }
public void FastClear() { _list.ResetCountToAvoidGC(); }
public bool TryGetValue(uint index, out T value)
{
if (default(T) == null)
{
if (index < _list.Count && this[index] != null)
{
value = this[index];
return true;
}

value = default(T);
return false;
}
else
{
if (index < _list.Count)
{
value = this[index];
return true;
}

value = default(T);
return false;
}
}
public void Add(uint location, T value) { _list.Add(location, value); }

readonly FasterList<T> _list;
}
public struct GroupListEnumerator<T>
{
public ref readonly T Current => ref _buffer[_counter -1];
public uint index => _counter - 1;

public GroupListEnumerator(T[] buffer, int size)
{
_size = size;
_counter = 0;
_buffer = buffer;
}

public bool MoveNext()
{
if (default(T) == null)
{
while (_counter < _size)
{
if (_buffer[_counter] == null)
_counter++;
else
break;
}
}

return _counter++ < _size;
}

readonly T[] _buffer;
uint _counter;
readonly int _size;
}
}

+ 2
- 2
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -38,7 +38,7 @@ namespace Svelto.ECS.Internal
static readonly string _typeName = _type.Name;
static readonly bool HasEgid = typeof(INeedEGID).IsAssignableFrom(_type);
public TypeSafeDictionary(uint size) : base((uint) size) { }
public TypeSafeDictionary(uint size) : base(size) { }
public TypeSafeDictionary() {}
public void AddEntitiesFromDictionary(ITypeSafeDictionary entitiesToSubmit, uint groupId)
@@ -203,7 +203,7 @@ namespace Svelto.ECS.Internal
try
{
using (profiler.Sample(entityViewsEngines[i], _typeName))
(entityViewsEngines[i] as IReactOnSwap<TValue>).MovedFrom(ref entity, previousGroup.Value);
(entityViewsEngines[i] as IReactOnSwap<TValue>).MovedFrom(ref entity);
}
catch (Exception e)
{


+ 7
- 28
Svelto.ECS/Dispatcher/DispatchOnSet.cs View File

@@ -18,10 +18,9 @@ namespace Svelto.ECS
{
_value = value;

_subscribers.Invoke(_senderID, value);
if(_paused == false)
_subscribers.Invoke(_senderID, value);
}

get => _value;
}
public void NotifyOnValueSet(Action<EGID, T> action)
@@ -34,33 +33,13 @@ namespace Svelto.ECS
_subscribers -= action;
}

public void PauseNotify() { _paused = true; }
public void ResumeNotify() { _paused = false; }

protected T _value;
internal EGID _senderID;
readonly EGID _senderID;

WeakEvent<EGID, T> _subscribers;
}

public static class DispatchExtensions
{
public static DispatchOnSet<T> Setup<T>(DispatchOnSet<T> dispatcher, EGID entity) where T : struct
{
if (dispatcher == null)
dispatcher = new DispatchOnSet<T>(entity);
else
dispatcher._senderID = entity;

return dispatcher;
}
public static DispatchOnChange<T> Setup<T>(DispatchOnChange<T> dispatcher, EGID entity)
where T : struct, IEquatable<T>
{
if (dispatcher == null)
dispatcher = new DispatchOnChange<T>(entity);
else
dispatcher._senderID = entity;
return dispatcher;
}
bool _paused;
}
}

+ 1
- 1
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -57,7 +57,7 @@ namespace Svelto.ECS
///
public IEntityStreamConsumerFactory GenerateConsumerFactory()
{
return new GenericEntityStreamConsumerFactory(new DataStructures.WeakReference<EnginesRoot>(this));
return new GenericentityStreamConsumerFactory(new DataStructures.WeakReference<EnginesRoot>(this));
}

public IEntityFactory GenerateEntityFactory()


+ 5
- 7
Svelto.ECS/ExecuteOnEntitiesDB.cs View File

@@ -5,7 +5,7 @@ namespace Svelto.ECS.Internal
partial class EntitiesDB
{
public void ExecuteOnAllEntities<T>(Action<T[], ExclusiveGroup.ExclusiveGroupStruct, uint, IEntitiesDB> action)
where T : struct, IEntityStruct
where T : struct, IEntityStruct
{
var type = typeof(T);

@@ -13,11 +13,10 @@ namespace Svelto.ECS.Internal
{
foreach (var pair in dic)
{
var entities =
(pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);
var entities = (pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);

if (innerCount > 0)
action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this);
if (innerCount > 0)
action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this);
}
}
}
@@ -32,8 +31,7 @@ namespace Svelto.ECS.Internal
{
foreach (var pair in dic)
{
var entities =
(pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);
var entities = (pair.Value as TypeSafeDictionary<T>).GetValuesArray(out var innerCount);

if (innerCount > 0)
action(entities, new ExclusiveGroup.ExclusiveGroupStruct(pair.Key), innerCount, this, value);


+ 8
- 7
Svelto.ECS/Extensions/Unity/SveltoGUIHelper.cs View File

@@ -5,10 +5,9 @@ namespace Svelto.ECS.Unity
{
public static class SveltoGUIHelper
{
public static T CreateFromPrefab<T>(uint startIndex, Transform contextHolder, IEntityFactory factory, ExclusiveGroup group) where T : MonoBehaviour, IEntityDescriptorHolder
public static T CreateFromPrefab<T>(ref uint startIndex, Transform contextHolder, IEntityFactory factory, ExclusiveGroup group) where T : MonoBehaviour, IEntityDescriptorHolder
{
var holder = Create<T>(new EGID(startIndex++, group), contextHolder, factory);
var childs = contextHolder.GetComponentsInChildren<IEntityDescriptorHolder>(true);
foreach (var child in childs)
@@ -16,7 +15,7 @@ namespace Svelto.ECS.Unity
if (child.GetType() != typeof(T))
{
var childImplementors = (child as MonoBehaviour).GetComponents<IImplementor>();
InternalBuildAll(startIndex, child, factory, group, childImplementors);
startIndex = InternalBuildAll(startIndex, child, factory, group, childImplementors);
}
}
@@ -43,13 +42,13 @@ namespace Svelto.ECS.Unity
{
var implementors = holder.GetComponents<IImplementor>();

InternalBuildAll(startIndex, holder, factory, group, implementors);
startIndex = InternalBuildAll(startIndex, holder, factory, group, implementors);
}

return startIndex;
}
static void InternalBuildAll(uint startIndex, IEntityDescriptorHolder descriptorHolder, IEntityFactory factory, ExclusiveGroup group, IImplementor[] implementors)
static uint InternalBuildAll(uint startIndex, IEntityDescriptorHolder descriptorHolder, IEntityFactory factory, ExclusiveGroup group, IImplementor[] implementors)
{
ExclusiveGroup.ExclusiveGroupStruct realGroup = group;
@@ -62,10 +61,12 @@ namespace Svelto.ECS.Unity
egid = new EGID(startIndex++, realGroup);
else
egid = new EGID(holderId, realGroup);
var init = factory.BuildEntity(egid, descriptorHolder.GetDescriptor(), implementors);
init.Init(new EntityHierarchyStruct(group));
init.Init(new EntityHierarchyStruct(group));
return startIndex;
}
}
}

+ 2
- 2
Svelto.ECS/GenericentityStreamConsumerFactory.cs View File

@@ -1,8 +1,8 @@
namespace Svelto.ECS
{
class GenericEntityStreamConsumerFactory : IEntityStreamConsumerFactory
class GenericentityStreamConsumerFactory : IEntityStreamConsumerFactory
{
public GenericEntityStreamConsumerFactory(DataStructures.WeakReference<EnginesRoot> weakReference)
public GenericentityStreamConsumerFactory(DataStructures.WeakReference<EnginesRoot> weakReference)
{
_enginesRoot = weakReference;
}


+ 1
- 6
Svelto.ECS/IEntitiesDB.cs View File

@@ -14,7 +14,6 @@ namespace Svelto.ECS
/// <typeparam name="T"></typeparam>
/// <returns></returns>
bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : struct, IEntityStruct;

bool TryQueryEntitiesAndIndex
<T>(uint id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index, out T[] array)
where T : struct, IEntityStruct;
@@ -29,7 +28,6 @@ namespace Svelto.ECS
/// <typeparam name="T"></typeparam>
/// <returns></returns>
T[] QueryEntitiesAndIndex<T>(EGID entityGid, out uint index) where T : struct, IEntityStruct;

T[] QueryEntitiesAndIndex<T>(uint id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index)
where T : struct, IEntityStruct;

@@ -49,7 +47,6 @@ namespace Svelto.ECS
/// <typeparam name="T"></typeparam>
/// <returns></returns>
ref T QueryEntity<T>(EGID entityGid) where T : struct, IEntityStruct;

ref T QueryEntity<T>(uint id, ExclusiveGroup.ExclusiveGroupStruct group) where T : struct, IEntityStruct;

/// <summary>
@@ -62,13 +59,11 @@ namespace Svelto.ECS
/// <returns></returns>
T[] QueryEntities<T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct, out uint count)
where T : struct, IEntityStruct;

(T1[], T2[]) QueryEntities<T1, T2>(ExclusiveGroup.ExclusiveGroupStruct groupStruct, out uint count)
where T1 : struct, IEntityStruct where T2 : struct, IEntityStruct;

(T1[], T2[], T3[]) QueryEntities<T1, T2, T3>(ExclusiveGroup.ExclusiveGroupStruct groupStruct, out uint count)
where T1 : struct, IEntityStruct where T2 : struct, IEntityStruct where T3 : struct, IEntityStruct;
EntityCollection<T> QueryEntities<T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct)
where T : struct, IEntityStruct;



+ 1
- 1
Svelto.ECS/IReactOnSwap.cs View File

@@ -5,6 +5,6 @@ namespace Svelto.ECS
public interface IReactOnSwap<T> : IReactOnSwap where T : IEntityStruct
{
void MovedTo(ref T entityView, ExclusiveGroup.ExclusiveGroupStruct previousGroup);
void MovedFrom(ref T entityView, ExclusiveGroup.ExclusiveGroupStruct previousGroupValue);
void MovedFrom(ref T entityView);
}
}

Loading…
Cancel
Save