Browse Source

Query an not existing entity by index should always throw an exception

Exclusive groups can allocate a specific range now
tags/Rel25b
sebas77 5 years ago
parent
commit
9e91fa4f21
8 changed files with 52 additions and 16 deletions
  1. +3
    -0
      .gitmodules
  2. +1
    -1
      Svelto.Common
  3. +10
    -2
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  4. +24
    -8
      Svelto.ECS/EntitiesDB.cs
  5. +1
    -1
      Svelto.ECS/EntityViewUtility.cs
  6. +9
    -2
      Svelto.ECS/ExclusiveGroups.cs
  7. +2
    -0
      Svelto.ECS/IEntitiesDB.cs
  8. +2
    -2
      Svelto.ECS/StaticEntityDescriptorInfo.cs

+ 3
- 0
.gitmodules View File

@@ -0,0 +1,3 @@
[submodule "Svelto.Common"]
path = Svelto.Common
url = https://github.com/sebas77/Svelto.Common.git

+ 1
- 1
Svelto.Common

@@ -1 +1 @@
Subproject commit a1f5f55c8b28f66ed033fa02c425dfa16c3c30e6
Subproject commit 5b756d57920c83a8e31dad9eedee8b629c6cb245

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

@@ -115,22 +115,30 @@ namespace Svelto.ECS.Internal
return new TypeSafeDictionary<TValue>();
}
public void ExecuteOnEntityView<W>(int entityGidEntityId, ref W value, ActionRef<TValue, W> action)
public bool ExecuteOnEntityView<W>(int entityGidEntityId, ref W value, ActionRef<TValue, W> action)
{
uint findIndex;
if (FindIndex(entityGidEntityId, out findIndex))
{
action(ref _values[findIndex], ref value);

return true;
}

return false;
}
public void ExecuteOnEntityView(int entityGidEntityId, ActionRef<TValue> action)
public bool ExecuteOnEntityView(int entityGidEntityId, ActionRef<TValue> action)
{
uint findIndex;
if (FindIndex(entityGidEntityId, out findIndex))
{
action(ref _values[findIndex]);
return true;
}

return false;
}
public uint FindElementIndex(int entityGidEntityId)


+ 24
- 8
Svelto.ECS/EntitiesDB.cs View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using Svelto.DataStructures;
using Svelto.Utilities;

@@ -75,11 +74,20 @@ namespace Svelto.ECS.Internal
return QueryEntities<T>(entityGID.groupID, out count);
}

public bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct
{
if ((array = QueryEntitiesAndIndex<T>(entityGid, out index)) != null)
return true;
return false;
}

public T QueryEntityView<T>(EGID entityGID) where T : class, IEntityStruct
{
T entityView;

TryQueryEntityViewInGroup(entityGID, out entityView);
if (TryQueryEntityViewInGroup(entityGID, out entityView) == false)
throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID));

return entityView;
}
@@ -87,19 +95,27 @@ namespace Svelto.ECS.Internal
public void ExecuteOnEntity<T, W>(EGID entityGID, ref W value, ActionRef<T, W> action) where T : IEntityStruct
{
TypeSafeDictionary<T> casted;
if (!FindSafeDictionary(entityGID, out casted)) return;
if (FindSafeDictionary(entityGID, out casted))
{
if (casted != null)
if (casted.ExecuteOnEntityView(entityGID.entityID, ref value, action) == true)
return;
}

if (casted != null)
casted.ExecuteOnEntityView(entityGID.entityID, ref value, action);
throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID));
}
public void ExecuteOnEntity<T>(EGID entityGID, ActionRef<T> action) where T : IEntityStruct
{
TypeSafeDictionary<T> casted;
if (!FindSafeDictionary(entityGID, out casted)) return;
if (FindSafeDictionary(entityGID, out casted))
{
if (casted != null)
if (casted.ExecuteOnEntityView(entityGID.entityID, action) == true)
return;
}

if (casted != null)
casted.ExecuteOnEntityView(entityGID.entityID, action);
throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID));
}

public void ExecuteOnEntity<T>(int id, ActionRef<T> action) where T : IEntityStruct


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

@@ -52,7 +52,7 @@ static class EntityViewUtility
#if DEBUG && !PROFILER
else
{
Utility.Console.LogError(NULL_IMPLEMENTOR_ERROR.FastConcat("Type ", entityDescriptorName, " entityView ", entityBuilder.GetEntityType().ToString()));
Utility.Console.Log(NULL_IMPLEMENTOR_ERROR.FastConcat("Type ", entityDescriptorName, " entityView ", entityBuilder.GetEntityType().ToString()));
}
#endif
}


+ 9
- 2
Svelto.ECS/ExclusiveGroups.cs View File

@@ -6,7 +6,14 @@

public ExclusiveGroup()
{
_id = _globalId++;
_id = _globalId;
_globalId += 1;
}

public ExclusiveGroup(int range)
{
_id = _globalId;
_globalId += range;
}
public static explicit operator int(ExclusiveGroup group) // explicit byte to digit conversion operator
@@ -15,6 +22,6 @@
}

readonly int _id;
static int _globalId;
static int _globalId;
}
}

+ 2
- 0
Svelto.ECS/IEntitiesDB.cs View File

@@ -33,7 +33,9 @@ namespace Svelto.ECS
//to use with EntityViews, EntityStructs and EntityViewStructs
T[] QueryEntities<T>(out int count) where T : IEntityStruct;
T[] QueryEntities<T>(int group, out int count) where T : IEntityStruct;
T[] QueryEntitiesAndIndex<T>(EGID entityGid, out uint index) where T : IEntityStruct;
bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct;

//to use with EntityViews, EntityStructs and EntityViewStructs
void ExecuteOnEntity<T, W>(EGID egid, ref W value, ActionRef<T, W> action) where T : IEntityStruct;


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

@@ -23,7 +23,7 @@ namespace Svelto.ECS
public static readonly StaticEntityDescriptorInfo<TType> descriptor = new StaticEntityDescriptorInfo<TType>(new TType());
}

public struct DynamicEntityDescriptorInfo<TType> where TType : IEntityDescriptor, new()
public struct DynamicEntityDescriptorInfo<TType>:IEntityDescriptor where TType : IEntityDescriptor, new()
{
public DynamicEntityDescriptorInfo(FasterList<IEntityBuilder> extraEntityViews) : this()
{
@@ -42,7 +42,7 @@ namespace Svelto.ECS
public IEntityBuilder[] entitiesToBuild { get; private set; }
}

public struct StaticEntityDescriptorInfo<TType> where TType : IEntityDescriptor
public struct StaticEntityDescriptorInfo<TType>: IEntityDescriptor where TType : IEntityDescriptor
{
internal StaticEntityDescriptorInfo(TType descriptor) : this()
{


Loading…
Cancel
Save