fix type indices not matching in world transfer
							parent
							
								
									227e3421cd
								
							
						
					
					
						commit
						cd1df0550e
					
				
							
								
								
									
										30
									
								
								src/World.cs
								
								
								
								
							
							
						
						
									
										30
									
								
								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) | ||||
| 		{ | ||||
| 			var otherWorldEntity = other.CreateEntity(GetTag(entity)); | ||||
| 			WorldToTransferID.Add(entity.ID, otherWorldEntity.ID); | ||||
| 
 | ||||
| 			foreach (var componentTypeIndex in EntityStorage.ComponentTypeIndices(entity.ID)) | ||||
| 			// set components | ||||
| 			foreach (var entity in filter.Entities) | ||||
| 			{ | ||||
| 				other.Set(otherWorldEntity, componentTypeIndex, ComponentDepot.UntypedGet(entity.ID, componentTypeIndex)); | ||||
| 			} | ||||
| 				var otherWorldEntity = WorldToTransferID[entity.ID]; | ||||
| 
 | ||||
| 			return otherWorldEntity.ID; | ||||
| 				foreach (var componentTypeIndex in EntityStorage.ComponentTypeIndices(entity.ID)) | ||||
| 				{ | ||||
| 					other.Set(otherWorldEntity, componentTypeIndex, ComponentDepot.UntypedGet(entity.ID, componentTypeIndex)); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue