fix bug where priorities were not cleared at end of frame

pull/5/head
Evan Hemsley 2019-12-29 19:43:05 -08:00
parent 6f00191258
commit 3ef34d37ae
4 changed files with 26 additions and 4 deletions

View File

@ -124,6 +124,14 @@ namespace Encompass
Lookup<TComponent>().Clear();
}
public virtual void ClearAllPriorities()
{
foreach (var store in Stores.Values)
{
store.ClearPriorities();
}
}
public virtual void ClearAll()
{
ComponentBitSet.Clear();

View File

@ -11,6 +11,7 @@ namespace Encompass
public abstract bool Remove(int entity, int priority);
public abstract void ForceRemove(int entity);
public abstract void Clear();
public abstract void ClearPriorities();
}
internal class TypedComponentStore<TComponent> : TypedComponentStore where TComponent : struct, IComponent
@ -73,6 +74,11 @@ namespace Encompass
priorities.Clear();
}
public override void ClearPriorities()
{
priorities.Clear();
}
public IEnumerable<(TComponent, int)> All()
{
foreach (var kvp in store)

View File

@ -55,6 +55,8 @@ namespace Encompass
internal void WriteComponents()
{
existingComponentStore.UpdateUsing(replayStore);
existingComponentStore.ClearAllPriorities();
upToDateComponentStore.ClearAllPriorities();
immediateComponentStore.ClearAll();
replayStore.ClearAll();
}

View File

@ -98,7 +98,6 @@ namespace Tests
}
[Reads(typeof(MockComponent))]
[WritesImmediate(typeof(MockComponent))]
[Writes(typeof(MockComponent))]
class OverwriteEngine : Engine
{
@ -106,12 +105,11 @@ namespace Tests
{
foreach (var (mockComponent, entity) in ReadComponentsIncludingEntity<MockComponent>())
{
SetComponent(entity, new MockComponent { myInt = 420 });
SetComponent(entity, new MockComponent { myInt = mockComponent.myInt + 1 });
}
}
}
[ReadsImmediate(typeof(MockComponent))]
[Reads(typeof(MockComponent))]
class ReadMockComponentEngine : Engine
{
@ -129,12 +127,20 @@ namespace Tests
worldBuilder.AddEngine(new ReadMockComponentEngine());
var entity = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new MockComponent { });
worldBuilder.SetComponent(entity, new MockComponent { myInt = 420 });
var world = worldBuilder.Build();
world.Update(0.01);
Assert.That(gottenMockComponent.myInt, Is.EqualTo(420));
world.Update(0.01);
Assert.That(gottenMockComponent.myInt, Is.EqualTo(421));
world.Update(0.01);
Assert.That(gottenMockComponent.myInt, Is.EqualTo(422));
}
[Reads(typeof(MockComponent))]