Browse Source

Add ExclusiveGroups comments

DispatchOnChange and DispatchOnSet must receive an EGID (sorry)
Rename GenericEntityDescriptorHolder to UnityEntityDescriptorHolder
tags/Rel25b
sebas77 6 years ago
parent
commit
cdb56f6f53
5 changed files with 50 additions and 10 deletions
  1. +3
    -0
      Svelto.ECS/Dispatcher/DispatchOnChange.cs
  2. +13
    -9
      Svelto.ECS/Dispatcher/DispatchOnSet.cs
  3. +6
    -1
      Svelto.ECS/EGID.cs
  4. +14
    -0
      Svelto.ECS/ExclusiveGroups.cs
  5. +14
    -0
      Svelto.ECS/Extensions/Unity/UnityEntityDescriptorHolder.cs

+ 3
- 0
Svelto.ECS/Dispatcher/DispatchOnChange.cs View File

@@ -6,6 +6,9 @@ namespace Svelto.ECS
{
public DispatchOnChange(int senderID) : base(senderID)
{ }
public DispatchOnChange(EGID senderID) : base(senderID)
{ }

public DispatchOnChange() {}



+ 13
- 9
Svelto.ECS/Dispatcher/DispatchOnSet.cs View File

@@ -4,16 +4,20 @@ namespace Svelto.ECS
{
public class DispatchOnSet<T> where T:struct
{
public DispatchOnSet(int senderID)
public DispatchOnSet(int senderID):this()
{
_senderID = new EGID(senderID, ExclusiveGroup.StandardEntitiesGroup);
}
public DispatchOnSet(EGID senderID):this()
{
_senderID = senderID;
_subscribers = new WeakEvent<int, T>();
}
public DispatchOnSet()
{
_senderID = -1;
_subscribers = new WeakEvent<int, T>();
_senderID = new EGID();
_subscribers = new WeakEvent<EGID, T>();
}

public T value
@@ -30,20 +34,20 @@ namespace Svelto.ECS
return _value;
}
}
public void NotifyOnValueSet(System.Action<int, T> action)
public void NotifyOnValueSet(System.Action<EGID, T> action)
{
_subscribers += action;
}

public void StopNotify(System.Action<int, T> action)
public void StopNotify(System.Action<EGID, T> action)
{
_subscribers -= action;
}

protected T _value;
readonly int _senderID;
readonly EGID _senderID;

WeakEvent<int, T> _subscribers;
WeakEvent<EGID, T> _subscribers;
}
}

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

@@ -33,7 +33,12 @@ namespace Svelto.ECS

static long MAKE_GLOBAL_ID(int entityId, int groupId)
{
return (long)groupId << 32 | (((long)(uint)entityId) & 0xFFFFFFFF);
return (long)groupId << 32 | ((long)(uint)entityId & 0xFFFFFFFF);
}
public static implicit operator int(EGID id)
{
return id.entityID;
}
}
}

+ 14
- 0
Svelto.ECS/ExclusiveGroups.cs View File

@@ -1,5 +1,16 @@
namespace Svelto.ECS
{
/// <summary>
/// Exclusive Groups guarantee that the GroupID is unique.
///
/// The best way to use it is like:
///
/// public static class MyExclusiveGroups //(can be as many as you want)
/// {
/// public static MyExclusiveGroup1 = new ExclusiveGroup();
/// }
/// </summary>
public class ExclusiveGroup
{
internal const int StandardEntitiesGroup = int.MaxValue;
@@ -10,6 +21,9 @@
_globalId += 1;
}

/// <summary>
/// Use this constructor to reserve N groups
/// </summary>
public ExclusiveGroup(int range)
{
_id = _globalId;


+ 14
- 0
Svelto.ECS/Extensions/Unity/UnityEntityDescriptorHolder.cs View File

@@ -0,0 +1,14 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
namespace Svelto.ECS
{
public class UnityEntityDescriptorHolder<T>:
UnityEngine.MonoBehaviour , IEntityDescriptorHolder
where T: IEntityDescriptor, new()
{
public IEntityBuilder[] GetEntitiesToBuild()
{
return EntityDescriptorTemplate<T>.descriptor.entitiesToBuild;
}
}
}
#endif

Loading…
Cancel
Save