private void OnEntityAdded(EntityChangeData changeData) { bool include = false; foreach (var includeitem in IncludeDBTypeIndexFilter) { //debug var someentity = changeData.Entity.Manager.GetFirstEntityWithDataBlob(includeitem); var db = someentity.GetDataBlob <BaseDataBlob>(includeitem); //end debug if (changeData.Entity.HasDataBlob(includeitem)) { include = true; } else { include = false; break; } } if (include && _ownerDB.OwnedEntities.ContainsKey(changeData.Entity.Guid)) //note: this will miss a lot of new entittes, since this code gets called before ownership is set on a new entity. it will get caught when a datablob is set though. { ListningToEntites.Add(changeData.Entity); EntityChanges.Enqueue(changeData); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Pulsar4X.ECSLib.EntityChangeListnerDB"/> class. /// </summary> /// <param name="factionEntity">will listen for any entites added or removed that are owned by this entity</param> public EntityChangeListner(EntityManager manager, Entity factionEntity, List <int> datablobFilter) : base(manager) { ListenForFaction = factionEntity; _ownerDB = ListenForFaction.GetDataBlob <FactionOwnerDB>(); IncludeDBTypeIndexFilter = datablobFilter; bool include = false; foreach (var entityitem in manager.GetEntitiesByFaction(ListenForFaction.Guid)) { foreach (var item in IncludeDBTypeIndexFilter) { if (entityitem.HasDataBlob(item)) { include = true; } else { include = false; break; } } if (include) { ListningToEntites.Add(entityitem); } } }
private void OnEntityRemoved(EntityChangeData changeData) { if (ListningToEntites.Contains(changeData.Entity)) { ListningToEntites.Add(changeData.Entity); EntityChanges.Enqueue(changeData); } }
private void OnDBRemoved(EntityChangeData changeData) { if (ListningToEntites.Contains(changeData.Entity)) { if (IncludeDBTypeIndexFilter.Contains(EntityManager.DataBlobTypes[changeData.Datablob.GetType()])) { ListningToEntites.Remove(changeData.Entity); } EntityChanges.Enqueue(changeData); } }
private void OnDBAdded(EntityChangeData changeData) { if (ListningToEntites.Contains(changeData.Entity)) { ListningToEntites.Add(changeData.Entity); EntityChanges.Enqueue(changeData); } else { if (IncludeDBTypeIndexFilter.Contains(EntityManager.DataBlobTypes[changeData.Datablob.GetType()])) { bool include = false; foreach (var includeitem in IncludeDBTypeIndexFilter) { if (!changeData.Entity.HasDataBlob(includeitem)) { include = false; break; } else { include = true; } } if (include && _ownerDB.OwnedEntities.ContainsKey(changeData.Entity.Guid)) { ListningToEntites.Add(changeData.Entity); EntityChangeData addedChange = new EntityChangeData() { ChangeType = EntityChangeData.EntityChangeType.EntityAdded, Entity = changeData.Entity }; EntityChanges.Enqueue(addedChange); //EntityChanges.Enqueue(changeData); } } } }
/// <summary> /// Initializes a new instance of the <see cref="T:Pulsar4X.ECSLib.EntityChangeListnerDB"/> class. /// </summary> /// <param name="factionEntity">will listen for any entites added or removed that are owned by this entity</param> internal EntityChangeListner(EntityManager manager, Entity factionEntity, List <int> datablobFilter) : base(manager) { ListenForFaction = factionEntity; _ownerDB = ListenForFaction.GetDataBlob <FactionOwnerDB>(); IncludeDBTypeIndexFilter = datablobFilter; if (!IncludeDBTypeIndexFilter.Contains(EntityManager.DataBlobTypes[typeof(OwnedDB)])) { IncludeDBTypeIndexFilter.Add(EntityManager.DataBlobTypes[typeof(OwnedDB)]); } bool include = false; foreach (var entityitem in manager.GetAllEntitiesWithDataBlob <OwnedDB>()) //TODO: this could maybe be made more efficent if GetAllEntiesWithDatablobs(mask) had some use instructions. { if (entityitem.GetDataBlob <OwnedDB>().OwnedByFaction == ListenForFaction) { foreach (var item in IncludeDBTypeIndexFilter) { if (entityitem.HasDataBlob(item)) { include = true; } else { include = false; break; } } } if (include) { ListningToEntites.Add(entityitem); } } }