Exemple #1
0
 public bool HasFlag(ComponentFlag flag)
 {
     if (flag.GetHashCode() == 0)
     {
         return(false);
     }
     return((this.SystemLowFlag & flag.SystemLowFlag) == flag.SystemLowFlag && (this.SystemHighFlag & flag.SystemHighFlag) == flag.SystemHighFlag && (this.PlayerLowFlag & flag.PlayerLowFlag) == flag.PlayerLowFlag && (this.PlayerHighFlag & flag.PlayerHighFlag) == flag.PlayerHighFlag);
 }
Exemple #2
0
 public Entity(ComponentCallBack componentCallBack, GetComponentFunc getFunc)
 {
     _id                      = Utils.GetEntityId();
     ChildList                = new List <Entity>();
     _allComponenArray        = new NormalComponent[ComponentIds.COMPONENT_MAX_COUNT];
     _changeComponentCallBack = componentCallBack;
     _getComponentFunc        = getFunc;
     _currentFlag             = new ComponentFlag();
 }
Exemple #3
0
        public void DataDrivenMethod(Entity entity, NormalComponent com)
        {
            if (entity == null)
            {
                return;
            }
            int             sharedId        = com.SharedId;
            SharedComponent sharedComponent = null;

            if (sharedId > 0)
            {
                sharedComponent = _sharedComponentDic[sharedId];
            }
            int count = _systemReactiveDic.Count;

            for (int i = 0; i < count; i++)
            {
                ReactiveSystemDto dto = _systemReactiveDic[i];
                ComponentFlag     executeCondition        = dto.CurrentSystem.ExecuteCondition;
                ComponentFlag     reactiveCondition       = dto.CurrentSystem.ReactiveCondition;
                ComponentFlag     reactiveIgnoreCondition = dto.CurrentSystem.ReactiveIgnoreCondition;
                if (!reactiveCondition.HasFlag(com.OperatorId))
                {
                    continue;
                }
                if (sharedId > 0)
                {
                    foreach (Entity setEntity in sharedComponent.SharedEntityHashSet)
                    {
                        if (setEntity.GetComponentFlag().HasFlag(reactiveIgnoreCondition))
                        {
                            continue;
                        }
                        if (setEntity.GetComponentFlag().HasFlag(executeCondition))
                        {
                            dto.EntityHashSet.Add(setEntity);
                        }
                    }
                }
                else
                {
                    if (entity.GetComponentFlag().HasFlag(reactiveIgnoreCondition))
                    {
                        continue;
                    }
                    if (entity.GetComponentFlag().HasFlag(executeCondition))
                    {
                        dto.EntityHashSet.Add(entity);
                    }
                }
            }
        }
Exemple #4
0
 public Group(params Int64[] array)
 {
     _componentFlag = new ComponentFlag();
     if (array != null)
     {
         for (int i = 0; i < array.Length; i++)
         {
             ComponentFlag.SetFlag(array[i]);
         }
     }
     _hashCode      = _componentFlag.GetHashCode();
     _entityHashSet = new HashSet <Entity>();
 }
Exemple #5
0
        public Group MatchGetGroup(ComponentFlag flag)
        {
            foreach (Group item in _matchGroupHashSet)
            {
                if (item.GetHashCode() == flag.GetHashCode())
                {
                    return(item);
                }
            }

            Group group = new Group(flag);

            _matchGroupHashSet.Add(group);
            return(group);
        }
Exemple #6
0
        public ComponentFlag GetFlag(params Int64[] args)
        {
            ComponentFlag flag = new ComponentFlag();

            if (args != null)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (!flag.HasFlag(args[i]))
                    {
                        flag.SetFlag(args[i]);
                    }
                }
            }
            return(flag);
        }
Exemple #7
0
        public static ComponentFlag operator &(ComponentFlag cf1, ComponentFlag cf2)
        {
            object o1 = cf1;
            object o2 = cf2;

            if (o1 == null || o2 == null)
            {
                throw new Exception("Object is Null");
            }
            ComponentFlag temp = new ComponentFlag();

            temp.SystemLowFlag  = cf1.SystemLowFlag & cf2.SystemLowFlag;
            temp.SystemHighFlag = cf1.SystemHighFlag & cf2.SystemHighFlag;
            temp.PlayerLowFlag  = cf1.PlayerLowFlag & cf2.PlayerLowFlag;
            temp.PlayerHighFlag = cf1.PlayerHighFlag & cf2.PlayerHighFlag;
            return(temp);
        }
Exemple #8
0
        public Group MatchGetGroup(params Int64[] componentIds)
        {
            if (componentIds == null)
            {
                throw new Exception("ComponentIds is null");
            }
            ComponentFlag flag = new ComponentFlag();

            for (int i = 0; i < componentIds.Length; i++)
            {
                if (flag.HasFlag(componentIds[i]))
                {
                    continue;
                }
                flag.SetFlag(componentIds[i]);
            }
            return(MatchGetGroup(flag));
        }
Exemple #9
0
 public bool HasComponent(Int32 flag)
 {
     return(ComponentFlag.HasFlag(flag));
 }
Exemple #10
0
 public Group(ComponentFlag flag)
 {
     _componentFlag = flag;
     _hashCode      = _componentFlag.GetHashCode();
     _entityHashSet = new HashSet <Entity>();
 }