コード例 #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);
 }
コード例 #2
0
 public IFlyweightGraphicComponent AddComponent(ElementTag tagEntity, IFlyweightGraphicComponent com)
 {
     flyweightComSynchronizer.Add((owner, inp) => {
         owner._AddComponent(tagEntity, inp);
     }, com);
     return(com);
 }
コード例 #3
0
ファイル: GraphicEntity.cs プロジェクト: GreyArmor/d3dlab
 internal GraphicEntity(ElementTag tag, IComponentManager manager, IEntityManager emanager, EntityOrderContainer order)
 {
     this.order    = order;
     this.manager  = manager;
     this.emanager = emanager;
     Tag           = tag;
 }
コード例 #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);
        }
コード例 #5
0
 public IEnumerable <IGraphicComponent> GetComponents(ElementTag tagEntity)
 {
     if (!components.ContainsKey(tagEntity))
     {
         return(new IGraphicComponent[0]);
     }
     return(components[tagEntity].Values.ToArray());
 }
コード例 #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));
 }
コード例 #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);
     }
 }
コード例 #8
0
ファイル: GraphicEntity.cs プロジェクト: GreyArmor/d3dlab
 public int Get <TSys>(ElementTag tag)
     where TSys : IGraphicSystem
 {
     if (!componentOrderIndex.ContainsKey(tag))
     {
         return(int.MaxValue);
     }
     return(componentOrderIndex[tag][typeof(TSys)]);
 }
コード例 #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);
 }
コード例 #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);
        }
コード例 #11
0
 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);
 }
コード例 #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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: GraphicEntity.cs プロジェクト: GreyArmor/d3dlab
        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);
        }
コード例 #15
0
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 protected GraphicComponent()
 {
     Tag = new ElementTag(Guid.NewGuid().ToString());
 }
コード例 #21
0
 GraphicEntity _CreateEntity(ElementTag tag)
 {
     return(new GraphicEntity(tag, this, this, orderContainer));
 }
コード例 #22
0
 public bool IsExisted(ElementTag tag)
 {
     return(entities.ContainsKey(tag));
 }
コード例 #23
0
 public GraphicEntity GetEntity(ElementTag tag)
 {
     return(new GraphicEntity(tag, this, this, orderContainer));
 }
コード例 #24
0
 public T GetComponent <T>(ElementTag tagEntity) where T : IGraphicComponent
 {
     if (!entities[tagEntity].TryGetValue(typeof(T), out var comTag))
     {
         return(default);
コード例 #25
0
 public IEnumerable <T> GetComponents <T>(ElementTag tagEntity) where T : IGraphicComponent
 {
     return(components[tagEntity].Values.OfType <T>());
 }
コード例 #26
0
 public bool Has <T>(ElementTag tag) where T : IGraphicComponent
 {
     return(components[tag].Any(x => x.Value is T));
 }
コード例 #27
0
 public IComponentManager AddComponent <T>(ElementTag tagEntity, T com) where T : IGraphicComponent
 {
     return(AddComponent(tagEntity, com, out _));
 }
コード例 #28
0
 public bool Has(ElementTag tag, params Type[] types)
 {
     return(types.All(type => entityHas[tag].Contains(type)));
 }
コード例 #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())));
 }
コード例 #30
0
 public void RemoveComponent(ElementTag tagEntity, IFlyweightGraphicComponent com)
 {
     flyweightComSynchronizer.Add((owner, inp) => {
         owner._RemoveComponent(tagEntity, inp);
     }, com);
 }