Skip to content

Commit

Permalink
fix modified entity not moved out before moving into new storage
Browse files Browse the repository at this point in the history
  • Loading branch information
sicusa committed Apr 27, 2024
1 parent f069b27 commit efb6a95
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Sia/Entities/Hosts/StorageEntityHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,24 @@ public virtual EntityRef Add<TComponent>(in StorageSlot slot, in TComponent init
{
var host = GetSiblingHost<HList<TComponent, TEntity>>();
ref var entity = ref Storage.GetRef(slot);
var newEntity = host.MoveIn(HList.Cons(entity.Head, HList.Cons(initial, entity.Tail)));
var newData = HList.Cons(entity.Head, HList.Cons(initial, entity.Tail));
MoveOut(slot);
return newEntity;
return host.MoveIn(newData);
}

#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type

private unsafe struct EntityMover(
StorageEntityHost<TEntity, TStorage> host, Identity id, EntityRef* result)
StorageEntityHost<TEntity, TStorage> host, StorageSlot slot, Identity id, EntityRef* result)
: IGenericHandler<IHList>
{
public readonly void Handle<TNewEntity>(in TNewEntity entity)
where TNewEntity : IHList
{
var siblingHost = host.GetSiblingHost<TNewEntity>();
*result = siblingHost.MoveIn(HList.Cons(id, entity));
var newData = HList.Cons(id, entity);
host.MoveOut(slot);
*result = siblingHost.MoveIn(newData);
}
}

Expand All @@ -91,19 +93,17 @@ public virtual unsafe EntityRef AddMany<TList>(in StorageSlot slot, in TList lis
{
ref var entity = ref Storage.GetRef(slot);
EntityRef result;
var mover = new EntityMover(this, entity.Head, &result);
var mover = new EntityMover(this, slot, entity.Head, &result);
list.Concat(entity.Tail, mover);
MoveOut(slot);
return result;
}

public virtual unsafe EntityRef Remove<TComponent>(in StorageSlot slot)
{
ref var entity = ref Storage.GetRef(slot);
EntityRef result;
var mover = new EntityMover(this, entity.Head, &result);
var mover = new EntityMover(this, slot, entity.Head, &result);
entity.Tail.Remove(TypeProxy<TComponent>.Default, mover);
MoveOut(slot);
return result;
}

Expand Down

0 comments on commit efb6a95

Please sign in to comment.