void _AddComponent(ElementTag tagEntity, IGraphicComponent com) { com.EntityTag = tagEntity; components[tagEntity].Add(com.Tag, com); entityHas[tagEntity].Add(com.GetType()); notify.NotifyChange(com); }
public IFlyweightGraphicComponent AddComponent(ElementTag tagEntity, IFlyweightGraphicComponent com) { flyweightComSynchronizer.Add((owner, inp) => { owner._AddComponent(tagEntity, inp); }, com); return(com); }
internal GraphicEntity(ElementTag tag, IComponentManager manager, IEntityManager emanager, EntityOrderContainer order) { this.order = order; this.manager = manager; this.emanager = emanager; Tag = tag; }
void _RemoveComponent(ElementTag tagEntity, IGraphicComponent com) { var removed = components[tagEntity].Remove(com.Tag); removed = entityHas[tagEntity].Remove(com.GetType()); com.Dispose(); notify.NotifyChange(com); }
public IEnumerable <IGraphicComponent> GetComponents(ElementTag tagEntity) { if (!components.ContainsKey(tagEntity)) { return(new IGraphicComponent[0]); } return(components[tagEntity].Values.ToArray()); }
public GraphicEntity GetEntity(ElementTag tag) { if (!entities.Contains(tag)) { return(GraphicEntity.Empty()); //throw new Exception($"There is no {tag} "); } return(new GraphicEntity(tag, this, this, orderContainer)); }
public void RemoveComponents <T>(ElementTag tagEntity) where T : IGraphicComponent { foreach (var com in GetComponents <T>(tagEntity).ToList()) { comSynchronizer.Add((owner, c) => { owner._RemoveComponent(tagEntity, c); }, com); } }
public int Get <TSys>(ElementTag tag) where TSys : IGraphicSystem { if (!componentOrderIndex.ContainsKey(tag)) { return(int.MaxValue); } return(componentOrderIndex[tag][typeof(TSys)]); }
void _RemoveComponent(ElementTag tagEntity, IFlyweightGraphicComponent com) { if (!flyweightComponents[com].Remove(tagEntity)) { //no data to remove - dispose comp com.Dispose(); } entityHas[tagEntity].Remove(com.GetType()); notify.NotifyChange(com); }
public T GetOrCreateComponent <T>(ElementTag tagEntity, T newone) where T : IGraphicComponent { var any = GetComponents <T>(tagEntity); if (any.Any()) { return(any.Single()); } AddComponent(tagEntity, newone); return(newone); }
public void RemoveComponent <T>(ElementTag tagEntity) where T : IGraphicComponent { if (typeof(T) == typeof(IGraphicComponent)) { throw new NotSupportedException("IGraphicComponent is incorrect type, must be the certain component type."); } comSynchronizer.Add <T>((owner, c) => { var com = GetComponent <T>(tagEntity); return(owner._RemoveComponent(tagEntity, com)); }, default); }
public GraphicEntity CreateEntity(ElementTag tag) { var en = _CreateEntity(tag); entitySynchronizer.Add((owner, input) => { owner.entities.Add(tag); owner.notify.NotifyChange(input); owner.components.Add(input.Tag, new Dictionary <ElementTag, IGraphicComponent>()); entityHas.Add(input.Tag, new HashSet <Type>()); }, en); return(en); }
public GraphicEntity CreateEntity(ElementTag tag) { var en = _CreateEntity(tag); entitySynchronizer.Add((owner, input) => { // owner.entities.Add(tag); this.entities.Add(input.Tag, new Dictionary <Type, ElementTag>()); owner.notify.NotifyAdd(input); // owner.components.Add(input.Tag, new Dictionary<Type, IGraphicComponent>()); return(true); }, en); return(en); }
public EntityOrderContainer RegisterOrder <TSys>(ElementTag tag) { OrderSystemContainer ordering; if (!componentOrderIndex.TryGetValue(tag, out ordering)) { ordering = new OrderSystemContainer(); componentOrderIndex.Add(tag, ordering); } var t = typeof(TSys); ordering.Add(t, IncrementSystemOrderIndex(t)); return(this); }
public IComponentManager AddComponent <T>(ElementTag tagEntity, T com, out Task awaiter) where T : IGraphicComponent { if (typeof(T) == typeof(IGraphicComponent)) { throw new NotSupportedException("IGraphicComponent is incorrect type, must be the certain component type."); } if (components.ContainsKey(com.Tag)) { throw new NotSupportedException($"Component {typeof(T)} '{com.Tag}' is already belong to other Entity."); } awaiter = comSynchronizer.Add((owner, inp) => owner._AddComponent(tagEntity, inp), com); return(this); }
void _AddComponent(ElementTag tagEntity, IFlyweightGraphicComponent com) { if (flyweightComponents.ContainsKey(com)) { flyweightComponents[com].Add(tagEntity); } else { flyweightComponents.Add(com, new HashSet <ElementTag> { tagEntity }); } entityHas[tagEntity].Add(com.GetType()); notify.NotifyChange(com); }
public void UpdateComponents <T>(ElementTag tagEntity, T com) where T : IGraphicComponent { comSynchronizer.Add((owner, inp) => { var any = GetComponents <T>(tagEntity); if (any.Any()) { var old = any.Single(); var removed = components[tagEntity].Remove(old.Tag); old.Dispose(); } com.EntityTag = tagEntity; components[tagEntity].Add(com.Tag, com); notify.NotifyChange(com); }, com); }
public void RemoveEntity(ElementTag elementTag) { entitySynchronizer.Add((owner, input) => { if (owner.entities.Contains(elementTag)) { var entity = _CreateEntity(elementTag); foreach (var component in owner.GetComponents(entity.Tag)) { owner._RemoveComponent(entity.Tag, component); } owner.entities.Remove(entity.Tag); owner.components.Remove(entity.Tag); entityHas.Remove(entity.Tag); notify.NotifyChange(entity); } }, null); }
public void RemoveEntity(ElementTag elementTag) { entitySynchronizer.Add((owner, input) => { if (owner.entities.ContainsKey(elementTag)) { var entity = _CreateEntity(elementTag); notify.NotifyRemove(entity); foreach (var component in owner.GetComponents(entity.Tag)) { owner._RemoveComponent(entity.Tag, component); } owner.entities.Remove(entity.Tag); owner.components.Remove(entity.Tag); //this.entities.Remove(entity.Tag); //notify.NotifyChange(entity); } return(true); }, default); }
protected GraphicComponent() { Tag = new ElementTag(Guid.NewGuid().ToString()); }
GraphicEntity _CreateEntity(ElementTag tag) { return(new GraphicEntity(tag, this, this, orderContainer)); }
public bool IsExisted(ElementTag tag) { return(entities.ContainsKey(tag)); }
public GraphicEntity GetEntity(ElementTag tag) { return(new GraphicEntity(tag, this, this, orderContainer)); }
public T GetComponent <T>(ElementTag tagEntity) where T : IGraphicComponent { if (!entities[tagEntity].TryGetValue(typeof(T), out var comTag)) { return(default);
public IEnumerable <T> GetComponents <T>(ElementTag tagEntity) where T : IGraphicComponent { return(components[tagEntity].Values.OfType <T>()); }
public bool Has <T>(ElementTag tag) where T : IGraphicComponent { return(components[tag].Any(x => x.Value is T)); }
public IComponentManager AddComponent <T>(ElementTag tagEntity, T com) where T : IGraphicComponent { return(AddComponent(tagEntity, com, out _)); }
public bool Has(ElementTag tag, params Type[] types) { return(types.All(type => entityHas[tag].Contains(type))); }
public IEnumerable <IGraphicComponent> GetComponents(ElementTag tag, params Type[] types) { //TODO: temporary decision return(components[tag].Values.Where(x => types.Any(t => t == x.GetType()))); }
public void RemoveComponent(ElementTag tagEntity, IFlyweightGraphicComponent com) { flyweightComSynchronizer.Add((owner, inp) => { owner._RemoveComponent(tagEntity, inp); }, com); }