tightening up replay behavior

pull/5/head
Evan Hemsley 2019-12-29 19:08:32 -08:00
parent 4d47a60125
commit 6f00191258
4 changed files with 29 additions and 11 deletions

View File

@ -23,6 +23,14 @@ namespace Encompass
}
}
public override void Set<TComponent>(int entityID, TComponent component)
{
base.Set(entityID, component);
var replayer = _replayers[typeof(TComponent)];
_currentReplayers.Add(replayer);
replayer.UnMarkRemoval(entityID);
}
public override bool Set<TComponent>(int entityID, TComponent component, int priority)
{
var result = base.Set(entityID, component, priority);

View File

@ -57,7 +57,7 @@ namespace Encompass
return Lookup<TComponent>().Get(entityID);
}
public void Set<TComponent>(int entityID, TComponent component) where TComponent : struct, IComponent
public virtual void Set<TComponent>(int entityID, TComponent component) where TComponent : struct, IComponent
{
Lookup<TComponent>().Set(entityID, component);
ComponentBitSet.Set<TComponent>(entityID);
@ -86,6 +86,7 @@ namespace Encompass
public void ForceRemove<TComponent>(int entityID) where TComponent : struct, IComponent
{
Lookup<TComponent>().ForceRemove(entityID);
ComponentBitSet.RemoveComponent<TComponent>(entityID);
}
public virtual void Remove(int entityID)

View File

@ -8,7 +8,8 @@ namespace Encompass
private readonly DrawLayerManager drawLayerManager;
private readonly ComponentStore existingComponentStore;
private readonly ComponentDeltaStore immediateComponentStore;
private readonly ComponentStore immediateComponentStore;
private readonly ComponentDeltaStore replayStore;
private ComponentStore upToDateComponentStore;
public Dictionary<Type, int> TypeToIndex { get; }
@ -22,7 +23,8 @@ namespace Encompass
{
this.drawLayerManager = drawLayerManager;
existingComponentStore = new ComponentStore(typeToIndex);
immediateComponentStore = new ComponentDeltaStore(typeToIndex);
immediateComponentStore = new ComponentStore(typeToIndex);
replayStore = new ComponentDeltaStore(typeToIndex);
upToDateComponentStore = new ComponentStore(typeToIndex);
TypeToIndex = typeToIndex;
}
@ -31,6 +33,7 @@ namespace Encompass
{
existingComponentStore.RegisterComponentType<TComponent>();
immediateComponentStore.RegisterComponentType<TComponent>();
replayStore.RegisterComponentType<TComponent>();
upToDateComponentStore.RegisterComponentType<TComponent>();
}
@ -51,20 +54,16 @@ namespace Encompass
internal void WriteComponents()
{
SetExistingComponentStore(upToDateComponentStore);
upToDateComponentStore.UpdateUsing(immediateComponentStore);
existingComponentStore.UpdateUsing(replayStore);
immediateComponentStore.ClearAll();
}
internal void AddExistingComponent<TComponent>(int entityID, TComponent component) where TComponent : struct, IComponent
{
upToDateComponentStore.Set(entityID, component);
replayStore.ClearAll();
}
internal bool AddImmediateComponent<TComponent>(int entityID, TComponent component, int priority) where TComponent : struct, IComponent
{
if (immediateComponentStore.Set(entityID, component, priority))
{
replayStore.Set(entityID, component);
upToDateComponentStore.Set(entityID, component);
return true;
}
@ -74,7 +73,12 @@ namespace Encompass
public bool UpdateComponent<TComponent>(int entityID, TComponent component, int priority) where TComponent : struct, IComponent
{
return upToDateComponentStore.Set(entityID, component, priority);
var result = upToDateComponentStore.Set(entityID, component, priority);
if (result)
{
replayStore.Set(entityID, component);
}
return result;
}
// existing or immediate reads
@ -215,6 +219,7 @@ namespace Encompass
{
existingComponentStore.Remove(entityID);
immediateComponentStore.Remove(entityID);
replayStore.Remove(entityID);
upToDateComponentStore.Remove(entityID);
drawLayerManager.UnRegisterEntityWithLayer(entityID);
}
@ -226,6 +231,7 @@ namespace Encompass
{
if (immediateComponentStore.Remove<TComponent>(entityID, priority))
{
replayStore.Remove<TComponent>(entityID, priority);
upToDateComponentStore.Remove<TComponent>(entityID, priority);
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
return true;
@ -237,6 +243,7 @@ namespace Encompass
{
if (upToDateComponentStore.Remove<TComponent>(entityID, priority))
{
replayStore.Remove<TComponent>(entityID, priority);
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
}
}

View File

@ -75,6 +75,7 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
world.Update(0.01);
}
[Test]
@ -258,6 +259,7 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
world.Update(0.01);
Assert.AreEqual(mockComponent, gottenMockComponent);