public void TrySetDirtyShouldReturnFalseAfterFirstCall() { var dirtyTracker = new EntityDirtyTracker(); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeTrue(); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeFalse(); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeFalse(); }
public void TestResetSingleComponent() { var dirtyTracker = new EntityDirtyTracker(); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeTrue(); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeFalse(); dirtyTracker.Reset(ComponentMap <ISimpleComponent> .Accessor); dirtyTracker.TrySetDirty(ComponentMap <ISimpleComponent> .Accessor).ShouldBeTrue(); }
/// <summary> /// Returns the writeable component of type <typeparamref name="TWrite" /> for the next tick. /// </summary> /// <exception cref="ComponentAccessException"> /// Thrown if the component does not exist on the entity or has already been /// accessed during this tick. /// </exception> /// <typeparam name="TWrite">The interface type of the component you wish to write too.</typeparam> /// <returns>The writeable component of type <typeparamref name="TWrite" />.</returns> public TWrite Modify <TWrite>() where TWrite : class, IWriteableComponent { var accessor = WriteableComponentMap <TWrite> .Accessor; ComponentContainer c; if (!_components.TryGetValue(accessor, out c)) { throw new ComponentAccessException(Id, typeof(TWrite), ComponentAccessException.Reasons.ComponentDoesNotExist); } if (!_dirtyTracker.TrySetDirty(accessor)) { throw new ComponentAccessException(Id, typeof(TWrite), ComponentAccessException.Reasons.ComponentAlreadyAccessed); } _eventDispatcher.Post(new EntityComponentModified(Id, accessor)); return((TWrite)_components[accessor].Next); }