pruning empty entities
							parent
							
								
									4d67b4ddf7
								
							
						
					
					
						commit
						f24ee21de0
					
				|  | @ -1,5 +1,6 @@ | |||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using MoonTools.FastCollections; | ||||
| 
 | ||||
| namespace Encompass | ||||
| { | ||||
|  | @ -262,5 +263,10 @@ namespace Encompass | |||
|                 drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool UpToDateEntityIsEmpty(int entityID) | ||||
|         { | ||||
|             return upToDateComponentStore.EntityBitArray(entityID).AllFalse(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -202,6 +202,14 @@ namespace Encompass | |||
|             return entityManager.EntityExists(entity.ID); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns true if an Entity with the specified ID exists. | ||||
|         /// </summary> | ||||
|         protected bool EntityExists(int entityID) | ||||
|         { | ||||
|             return entityManager.EntityExists(entityID); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns an Entity containing the specified Component type. | ||||
|         /// </summary> | ||||
|  |  | |||
|  | @ -76,5 +76,17 @@ namespace Encompass | |||
| 
 | ||||
|             entitiesMarkedForDestroy.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         // NOTE: this is very suboptimal | ||||
|         public void PruneEmptyEntities() | ||||
|         { | ||||
|             foreach (var id in EntityIDs) | ||||
|             { | ||||
|                 if (componentManager.UpToDateEntityIsEmpty(id)) | ||||
|                 { | ||||
|                     MarkForDestroy(id); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -59,6 +59,7 @@ namespace Encompass | |||
|             } | ||||
| 
 | ||||
|             messageManager.ClearMessages(); | ||||
|             entityManager.PruneEmptyEntities(); | ||||
|             entityManager.DestroyMarkedEntities(enginesInOrder); | ||||
| 
 | ||||
|             componentManager.RemoveMarkedComponents(); | ||||
|  |  | |||
|  | @ -1387,6 +1387,37 @@ namespace Tests | |||
|             getComponentResult.Should().Be(new MockComponentB(5)); | ||||
|         } | ||||
| 
 | ||||
|         static bool entityExistsResult; | ||||
| 
 | ||||
|         class EntityExistsEngine : Engine | ||||
|         { | ||||
|             private int _id; | ||||
| 
 | ||||
|             public EntityExistsEngine(int id) | ||||
|             { | ||||
|                 _id = id; | ||||
|             } | ||||
| 
 | ||||
|             public override void Update(double dt) | ||||
|             { | ||||
|                 entityExistsResult = EntityExists(_id); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         [Test] | ||||
|         public void PruneEmptyEntities() | ||||
|         { | ||||
|             var worldBuilder = new WorldBuilder(); | ||||
|             var entity = worldBuilder.CreateEntity(); | ||||
|             var id = entity.ID; | ||||
| 
 | ||||
|             var world = worldBuilder.Build(); | ||||
| 
 | ||||
|             world.Update(0.01); | ||||
| 
 | ||||
|             entityExistsResult.Should().BeFalse(); | ||||
|         } | ||||
| 
 | ||||
|         public class QueryTests | ||||
|         { | ||||
|             struct MockComponentB : IComponent { } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue