Browse Source

add Exists<T>(egid), Fetch<T> and Has<T>

add support for engines with EntityView, EntityStruct and EntityViewStruct
tags/Rel25a
sebas77 6 years ago
parent
commit
550c21851c
6 changed files with 24 additions and 98 deletions
  1. +14
    -4
      Svelto.ECS/EntityViewsDB.cs
  2. +5
    -3
      Svelto.ECS/IEntityViewsDB.cs
  3. +4
    -4
      Svelto.ECS/MultiEntitiesEngine.cs
  4. +0
    -43
      Svelto.ECS/MultiEntityEngine.cs
  5. +0
    -43
      Svelto.ECS/MultiEntityStructsEngine.cs
  6. +1
    -1
      Svelto.ECS/SingleEntityEngine.cs

+ 14
- 4
Svelto.ECS/EntityViewsDB.cs View File

@@ -60,7 +60,7 @@ namespace Svelto.ECS.Internal
return entityView;
}

public bool EntityExists<T>(EGID entityGID) where T : IEntityData
public bool Exists<T>(EGID entityGID) where T : IEntityData
{
var type = typeof(T);

@@ -83,13 +83,23 @@ namespace Svelto.ECS.Internal

return false;
}
public bool TryQueryEntityView<T>(EGID entityegid, out T entityView) where T : class, IEntityData

public void Fetch<T>(out T entity) where T : IEntityData
{
entity = QueryEntities<T>()[0];
}

public bool Has<T>() where T : IEntityData
{
return QueryEntities<T>().Count > 0;
}

public bool TryQueryEntityView<T>(EGID entityegid, out T entityView) where T : IEntityData
{
return TryQueryEntityViewInGroup(entityegid, out entityView);
}

bool TryQueryEntityViewInGroup<T>(EGID entityGID, out T entityView) where T:class, IEntityData
bool TryQueryEntityViewInGroup<T>(EGID entityGID, out T entityView) where T:IEntityData
{
var type = typeof(T);



+ 5
- 3
Svelto.ECS/IEntityViewsDB.cs View File

@@ -13,9 +13,11 @@ namespace Svelto.ECS
T[] QueryEntitiesCacheFriendly<T>(int group, out int count) where T : struct, IEntityData;

//to use with EntityViews
bool TryQueryEntityView<T>(EGID ID, out T entityView) where T : class, IEntityData;
T QueryEntityView<T>(EGID entityGID) where T : class, IEntityData;
bool TryQueryEntityView<T>(EGID egid, out T entityView) where T : IEntityData;
T QueryEntityView<T>(EGID egid) where T : class, IEntityData;
bool EntityExists<T>(EGID ID) where T : IEntityData;
bool Exists<T>(EGID egid) where T : IEntityData;
void Fetch<T>(out T entity) where T:IEntityData;
bool Has<T>() where T:IEntityData;
}
}

+ 4
- 4
Svelto.ECS/MultiEntitiesEngine.cs View File

@@ -1,7 +1,7 @@
namespace Svelto.ECS
{
public abstract class MultiEntitiesEngine<T, U> : SingleEntitiesEngine<T>, IHandleEntityStructEngine<U>
where U : struct, IEntityData where T : struct, IEntityData
public abstract class MultiEntitiesEngine<T, U> : SingleEntityEngine<T>, IHandleEntityStructEngine<U>
where U : IEntityData where T : IEntityData
{
public void AddInternal(ref U entityView)
{ Add(ref entityView); }
@@ -13,7 +13,7 @@ namespace Svelto.ECS
}
public abstract class MultiEntitiesEngine<T, U, V> : MultiEntitiesEngine<T, U>, IHandleEntityStructEngine<V>
where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData
where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref V entityView)
{ Add(ref entityView); }
@@ -30,7 +30,7 @@ namespace Svelto.ECS
/// already too many responsabilities.
/// </summary>
public abstract class MultiEntitiesEngine<T, U, V, W> : MultiEntitiesEngine<T, U, V>, IHandleEntityStructEngine<W>
where W : struct, IEntityData where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData
where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref W entityView)
{ Add(ref entityView); }


+ 0
- 43
Svelto.ECS/MultiEntityEngine.cs View File

@@ -1,43 +0,0 @@
namespace Svelto.ECS
{
public abstract class MultiEntityStructsEngine<T, U> : SingleEntityStructEngine<T>, IHandleEntityStructEngine<U>
where U : struct, IEntityData where T : struct, IEntityData
{
public void AddInternal(ref U entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref U entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref U entityView);
protected abstract void Remove(ref U entityView);
}
public abstract class MultiEntityStructsEngine<T, U, V> : MultiEntityViewsEngine<T, U>, IHandleEntityStructEngine<V>
where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData
{
public void AddInternal(ref V entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref V entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref V entityView);
protected abstract void Remove(ref V entityView);
}

/// <summary>
/// Please do not add more MultiEntityViewsEngine
/// if you use more than 4 nodes, your engine has
/// already too many responsabilities.
/// </summary>
public abstract class MultiEntityStructsEngine<T, U, V, W> : MultiEntityViewsEngine<T, U, V>, IHandleEntityStructEngine<W>
where W : struct, IEntityData where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData
{
public void AddInternal(ref W entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref W entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref W entityView);
protected abstract void Remove(ref W entityView);
}
}

+ 0
- 43
Svelto.ECS/MultiEntityStructsEngine.cs View File

@@ -1,43 +0,0 @@
namespace Svelto.ECS
{
public abstract class MultiEntityStructsEngine<T, U> : SingleEntityViewEngine<T>, IHandleEntityStructEngine<U>
where U : IEntityData where T : IEntityData
{
public void AddInternal(ref U entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref U entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref U entityView);
protected abstract void Remove(ref U entityView);
}
public abstract class MultiEntityStructsEngine<T, U, V> : MultiEntityViewsEngine<T, U>, IHandleEntityStructEngine<V>
where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref V entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref V entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref V entityView);
protected abstract void Remove(ref V entityView);
}

/// <summary>
/// Please do not add more MultiEntityViewsEngine
/// if you use more than 4 nodes, your engine has
/// already too many responsabilities.
/// </summary>
public abstract class MultiEntityStructsEngine<T, U, V, W> : MultiEntityViewsEngine<T, U, V>, IHandleEntityStructEngine<W>
where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref W entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref W entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref W entityView);
protected abstract void Remove(ref W entityView);
}
}

Svelto.ECS/SingleEntitiesEngine.cs → Svelto.ECS/SingleEntityEngine.cs View File

@@ -1,6 +1,6 @@
namespace Svelto.ECS
{
public abstract class SingleEntitiesEngine<T> : IHandleEntityStructEngine<T> where T : struct, IEntityData
public abstract class SingleEntityEngine<T> : IHandleEntityStructEngine<T> where T : IEntityData
{
public void AddInternal(ref T entityView)
{ Add(ref entityView); }

Loading…
Cancel
Save