Browse Source

DispatchOnChange and DispatchOnSet must hold only value types

fix QueryGroupedEntityViews
tags/Rel2b2
sebas77 6 years ago
parent
commit
d6fe686096
3 changed files with 10 additions and 18 deletions
  1. +2
    -4
      Svelto.ECS/Dispatcher/DispatchOnChange.cs
  2. +3
    -3
      Svelto.ECS/Dispatcher/DispatchOnSet.cs
  3. +5
    -11
      Svelto.ECS/EntityViewsDB.cs

+ 2
- 4
Svelto.ECS/Dispatcher/DispatchOnChange.cs View File

@@ -2,14 +2,12 @@ using System.Collections.Generic;

namespace Svelto.ECS
{
public class DispatchOnChange<T> : DispatchOnSet<T>
public class DispatchOnChange<T> : DispatchOnSet<T> where T:struct
{
public DispatchOnChange(int senderID) : base(senderID)
{ }

public DispatchOnChange()
{
}
public DispatchOnChange() {}

public new T value
{


+ 3
- 3
Svelto.ECS/Dispatcher/DispatchOnSet.cs View File

@@ -2,7 +2,7 @@ using Svelto.WeakEvents;

namespace Svelto.ECS
{
public class DispatchOnSet<T>
public class DispatchOnSet<T> where T:struct
{
public DispatchOnSet(int senderID)
{
@@ -42,8 +42,8 @@ namespace Svelto.ECS
}

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

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

+ 5
- 11
Svelto.ECS/EntityViewsDB.cs View File

@@ -31,12 +31,12 @@ namespace Svelto.ECS.Internal

public FasterReadOnlyList<T> QueryGroupedEntityViews<T>(int @group) where T:EntityView, new()
{
Dictionary<Type, ITypeSafeList> entityViews;
Dictionary<Type, ITypeSafeList> entitiesInGroupPerType;

if (_groupEntityViewsDB.TryGetValue(group, out entityViews) == false)
if (_groupEntityViewsDB.TryGetValue(group, out entitiesInGroupPerType) == false)
return RetrieveEmptyEntityViewList<T>();
return new FasterReadOnlyList<T>(entityViews as FasterList<T>);
return new FasterReadOnlyList<T>((FasterList<T>) entitiesInGroupPerType[typeof(T)]);
}

public T[] QueryEntityViewsAsArray<T>(out int count) where T : IEntityView
@@ -49,9 +49,7 @@ namespace Svelto.ECS.Internal
if (_entityViewsDB.TryGetValue(type, out entityViews) == false)
return RetrieveEmptyEntityViewArray<T>();
var castedEntityViews = (FasterList<T>)entityViews;

return FasterList < T > .NoVirt.ToArrayFast(castedEntityViews, out count);
return FasterList<T>.NoVirt.ToArrayFast((FasterList<T>)entityViews, out count);
}
public T[] QueryGroupedEntityViewsAsArray<T>(int @group, out int count) where T : IEntityView
@@ -64,11 +62,7 @@ namespace Svelto.ECS.Internal
if (_groupEntityViewsDB.TryGetValue(group, out entityViews) == false)
return RetrieveEmptyEntityViewArray<T>();
var castedEntityViews = (FasterList<T>)entityViews[type];

count = castedEntityViews.Count;

return FasterList<T>.NoVirt.ToArrayFast(castedEntityViews, out count);
return FasterList<T>.NoVirt.ToArrayFast((FasterList<T>)entityViews[type], out count);
}

public ReadOnlyDictionary<int, T> QueryIndexableEntityViews<T>() where T:IEntityView


Loading…
Cancel
Save