fix type indices not matching in world transfer
parent
227e3421cd
commit
cd1df0550e
22
src/World.cs
22
src/World.cs
|
@ -5,8 +5,8 @@ namespace MoonTools.ECS
|
|||
{
|
||||
public class World
|
||||
{
|
||||
internal readonly TypeIndices ComponentTypeIndices = new TypeIndices();
|
||||
internal readonly TypeIndices RelationTypeIndices = new TypeIndices();
|
||||
internal readonly static TypeIndices ComponentTypeIndices = new TypeIndices();
|
||||
internal readonly static TypeIndices RelationTypeIndices = new TypeIndices();
|
||||
internal readonly EntityStorage EntityStorage = new EntityStorage();
|
||||
internal readonly ComponentDepot ComponentDepot;
|
||||
internal readonly MessageDepot MessageDepot = new MessageDepot();
|
||||
|
@ -163,14 +163,14 @@ namespace MoonTools.ECS
|
|||
other.Destroy(entity);
|
||||
}
|
||||
|
||||
// create entities and set their components
|
||||
// create entities
|
||||
foreach (var entity in filter.Entities)
|
||||
{
|
||||
TransferEntity(other, entity);
|
||||
var otherWorldEntity = other.CreateEntity(GetTag(entity));
|
||||
WorldToTransferID.Add(entity.ID, otherWorldEntity.ID);
|
||||
}
|
||||
|
||||
// set relations
|
||||
// FIXME: something is going wrong here, the transfer back isn't working
|
||||
// set relations before components so filters don't freak out
|
||||
foreach (var entity in filter.Entities)
|
||||
{
|
||||
var otherWorldEntityA = WorldToTransferID[entity.ID];
|
||||
|
@ -194,19 +194,17 @@ namespace MoonTools.ECS
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe int TransferEntity(World other, Entity entity)
|
||||
// set components
|
||||
foreach (var entity in filter.Entities)
|
||||
{
|
||||
var otherWorldEntity = other.CreateEntity(GetTag(entity));
|
||||
WorldToTransferID.Add(entity.ID, otherWorldEntity.ID);
|
||||
var otherWorldEntity = WorldToTransferID[entity.ID];
|
||||
|
||||
foreach (var componentTypeIndex in EntityStorage.ComponentTypeIndices(entity.ID))
|
||||
{
|
||||
other.Set(otherWorldEntity, componentTypeIndex, ComponentDepot.UntypedGet(entity.ID, componentTypeIndex));
|
||||
}
|
||||
|
||||
return otherWorldEntity.ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue