Exemple #1
0
 void _AddComponent(ElementTag tagEntity, IGraphicComponent com)
 {
     com.EntityTag = tagEntity;
     components[tagEntity].Add(com.Tag, com);
     entityHas[tagEntity].Add(com.GetType());
     notify.NotifyChange(com);
 }
Exemple #2
0
 public IFlyweightGraphicComponent AddComponent(ElementTag tagEntity, IFlyweightGraphicComponent com)
 {
     flyweightComSynchronizer.Add((owner, inp) => {
         owner._AddComponent(tagEntity, inp);
     }, com);
     return(com);
 }
Exemple #3
0
 internal GraphicEntity(ElementTag tag, IComponentManager manager, IEntityManager emanager, EntityOrderContainer order)
 {
     this.order    = order;
     this.manager  = manager;
     this.emanager = emanager;
     Tag           = tag;
 }
Exemple #4
0
        void _RemoveComponent(ElementTag tagEntity, IGraphicComponent com)
        {
            var removed = components[tagEntity].Remove(com.Tag);

            removed = entityHas[tagEntity].Remove(com.GetType());
            com.Dispose();
            notify.NotifyChange(com);
        }
Exemple #5
0
 public IEnumerable <IGraphicComponent> GetComponents(ElementTag tagEntity)
 {
     if (!components.ContainsKey(tagEntity))
     {
         return(new IGraphicComponent[0]);
     }
     return(components[tagEntity].Values.ToArray());
 }
Exemple #6
0
 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));
 }
Exemple #7
0
 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);
     }
 }
Exemple #8
0
 public int Get <TSys>(ElementTag tag)
     where TSys : IGraphicSystem
 {
     if (!componentOrderIndex.ContainsKey(tag))
     {
         return(int.MaxValue);
     }
     return(componentOrderIndex[tag][typeof(TSys)]);
 }
Exemple #9
0
 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);
 }
Exemple #10
0
        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);
 }
Exemple #12
0
        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);
        }
Exemple #14
0
        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);
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        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);
        }
Exemple #20
0
 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);
Exemple #25
0
 public IEnumerable <T> GetComponents <T>(ElementTag tagEntity) where T : IGraphicComponent
 {
     return(components[tagEntity].Values.OfType <T>());
 }
Exemple #26
0
 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 _));
 }
Exemple #28
0
 public bool Has(ElementTag tag, params Type[] types)
 {
     return(types.All(type => entityHas[tag].Contains(type)));
 }
Exemple #29
0
 public IEnumerable <IGraphicComponent> GetComponents(ElementTag tag, params Type[] types)
 {
     //TODO: temporary decision
     return(components[tag].Values.Where(x => types.Any(t => t == x.GetType())));
 }
Exemple #30
0
 public void RemoveComponent(ElementTag tagEntity, IFlyweightGraphicComponent com)
 {
     flyweightComSynchronizer.Add((owner, inp) => {
         owner._RemoveComponent(tagEntity, inp);
     }, com);
 }