private void InitFunction2SystemTypeDict()
    {
        function2SystemTypeDict = new Dictionary <ECSDefine.SystemFunctionType, List <ECSDefine.SystemType> >();
        Dictionary <ECSDefine.SystemType, ECSDefine.SystemFunctionType> .Enumerator enumerator = ECSInstanceDefine.SystemType2Function.GetEnumerator();
        while (enumerator.MoveNext())
        {
            ECSDefine.SystemFunctionType systemFunctionType = enumerator.Current.Value;
            ECSDefine.SystemType         systemType         = enumerator.Current.Key;

            List <ECSDefine.SystemType> systemTypeList;
            if (!function2SystemTypeDict.TryGetValue(systemFunctionType, out systemTypeList))
            {
                systemTypeList = new List <ECSDefine.SystemType>();
                function2SystemTypeDict.Add(systemFunctionType, systemTypeList);
            }
            systemTypeList.Add(systemType);
        }

        Dictionary <ECSDefine.SystemFunctionType, List <ECSDefine.SystemType> > .Enumerator systemFunctionTypeEnumerator = function2SystemTypeDict.GetEnumerator();
        while (systemFunctionTypeEnumerator.MoveNext())
        {
            List <ECSDefine.SystemType> systemTypeList = systemFunctionTypeEnumerator.Current.Value;
            systemTypeList.Sort(SystemFunctionTypeSystemSotr);
        }
    }
示例#2
0
    public void ExecuteSystem(int entityId, ECSDefine.SystemType systemType, BaseSystem.SystemExpandData expandData)
    {
        BaseEntity entity = ECSUnit.GetEntity(entityId);

        if (entity == null)
        {
            Debug.LogError($"[ECSModule] ExecuteSystem Fail. Entity Is nil. entityId:{entityId}");
            return;
        }

        int        systemId = systemIdDistributionChunk.Pop();
        BaseSystem system   = CreateImmediatelyExecuteSystem(systemType, systemId);

        if (system == null)
        {
            return;
        }

        do
        {
            if (system.GetSystemFunctionType() != ECSDefine.SystemFunctionType.Logic)
            {
                Debug.LogError($"[ECSModule] ExecuteSystem Fail. Only Can ImmediatelyExecute Logic Type. entityId:{entityId} systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
                break;
            }

            system.SetGlobalUnionId(GlobalUnionId);
            system.Execute(entityId, expandData);
        }while (false);

        DeleteImmediatelyExecuteSystem(system);//执行完毕回收
    }
    public void UpdateSystemExecute()
    {
        commandUnit.CacheCommandListToExecuteCommandList();

        //功能系统顺序
        for (int index = 0; index < systemFunctionTypePriorityArray.Length; index++)
        {
            ECSDefine.SystemFunctionType systemFunctionType = systemFunctionTypePriorityArray[index];

            List <ECSDefine.SystemType> systemTypeList;
            if (function2SystemTypeDict.TryGetValue(systemFunctionType, out systemTypeList))
            {
                // 执行系统顺序
                for (int systemIndex = 0; systemIndex < systemTypeList.Count; systemIndex++)
                {
                    ECSDefine.SystemType systemType = systemTypeList[systemIndex];

                    // 执行命令
                    commandUnit.PopSystemTypeCommandList(systemType);

                    // 执行功能系统
                    executeSystemUnit.UpdateFunctionSystemsByFunctionTyep(systemFunctionType, systemType);
                }

                if (GameUnitSystemFunctionType == systemFunctionType)
                {
                    for (int unitIndex = 0; unitIndex < ECSInstanceDefine.GameUnitPriorityList.Count; unitIndex++)
                    {
                        ECSInstanceDefine.GameUnitPriorityList[unitIndex].Update();
                    }
                }
            }
        }
    }
示例#4
0
    private BaseSystem CreateFunctionSystem(ECSDefine.SystemType systemType, int systemId)
    {
        ECSDefine.SystemFunctionType systemFunction;
        if (!ECSInstanceDefine.SystemType2Function.TryGetValue(systemType, out systemFunction))
        {
            Debug.LogError($"[ECSModule] CreateFunctionSystem Fail. No SystemFunctionType Reocrd. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            return(null);
        }

        PollingOperation functionSystemOperation;

        if (!functionSystemOperationDict.TryGetValue(systemFunction, out functionSystemOperation))
        {
            functionSystemOperation = new PollingOperation();

            functionSystemOperation.Init();
            functionSystemOperation.SetName(Enum.GetName(typeof(ECSDefine.SystemFunctionType), systemFunction) + "System");

            functionSystemOperationDict.Add(systemFunction, functionSystemOperation);
        }

        OperationObject operationObject = functionSystemOperation.AddOperationObject((int)systemType, systemId);

        if (operationObject == null)
        {
            Debug.LogError($"[ECSModule] CreateSystem Fail. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            return(null);
        }

        return(InitSystem(operationObject, systemType, systemId));
    }
示例#5
0
    public void UnRegSystem(int entityId, ECSDefine.SystemType systemType)
    {
        BaseEntity entity = ECSUnit.GetEntity(entityId);

        if (entity == null)
        {
            Debug.LogError($"[ECSModule] UnRegSystem Fail. Entity Is nil. entityId:{entityId}");
            return;
        }

        Dictionary <ECSDefine.SystemType, BaseSystem> regFunctionSystemDict;

        if (!entityRegFunctionSystemDict.TryGetValue(entityId, out regFunctionSystemDict))
        {
            return;
        }

        BaseSystem functionSystem;

        if (!regFunctionSystemDict.TryGetValue(systemType, out functionSystem))
        {
            return;
        }

        DeleteFunctionSystem(systemType, functionSystem);
    }
示例#6
0
    private BaseSystem InitSystem(OperationObject operationObject, ECSDefine.SystemType systemType, int systemId)
    {
        BaseSystem system = operationObject as BaseSystem;

        system.SetSystemId(systemId);
        system.SetSystemType(systemType);

        ECSDefine.SystemPriority systemPriority;
        if (!ECSInstanceDefine.SystemType2Priority.TryGetValue(systemType, out systemPriority))
        {
            Debug.LogError($"[ECSModule] GetSystemType2Priority Fail. No Reocrd. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            systemPriority = ECSDefine.SystemPriority.Normal;
        }
        system.SetSystemPriority(systemPriority);

        ECSDefine.SystemFunctionType systemFunctionType;
        if (!ECSInstanceDefine.SystemType2Function.TryGetValue(systemType, out systemFunctionType))
        {
            Debug.LogError($"[ECSModule] SystemType2Function Fail. No Reocrd. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            systemFunctionType = ECSDefine.SystemFunctionType.Logic;
        }
        system.SetSystemFunctionType(systemFunctionType);

        system.FillInComponentInfo();

        return(system);
    }
示例#7
0
    public List <BaseCommand> PopSystemTypeCommandList(ECSDefine.SystemType systemType)
    {
        List <BaseCommand> commandList;

        if (systemTypeCommandListDict.TryGetValue(systemType, out commandList))
        {
            return(commandList);
        }
        return(null);
    }
示例#8
0
    public void ReceiveCommand(int entityId, ECSDefine.SystemType systemType, BaseSystem.SystemExpandData expandData)
    {
        BaseCommand command = PopCommand(systemType);

        if (command != null)
        {
            command.FillIn(entityId, systemType, expandData);

            cacheCommandList.Add(command);
        }
    }
示例#9
0
    private BaseSystem CreateImmediatelyExecuteSystem(ECSDefine.SystemType systemType, int systemId)
    {
        OperationObject operationObject = systemOperation.CreateOperationObject((int)systemType, systemId);

        if (operationObject == null)
        {
            Debug.LogError($"[ECSModule] CreateSystem Fail. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            return(null);
        }

        return(InitSystem(operationObject, systemType, systemId));
    }
示例#10
0
    public void RequireCommand(int entityId, ECSDefine.SystemType systemType, BaseSystem.SystemExpandData expandData)
    {
        BaseCommand command = PopCommand(systemType);

        if (command != null)
        {
            command.FillIn(entityId, systemType, expandData);

            sendCommandList.Add(command);

            ExecuteSystemUnit.ExecuteSystem(entityId, systemType, expandData);
        }
    }
示例#11
0
    private BaseCommand PopCommand(ECSDefine.SystemType systemType)
    {
        int             commandId       = idDistributionChunk.Pop();
        OperationObject operationObject = commandOperation.CreateOperationObject((int)systemType, commandId);

        if (operationObject != null)
        {
            BaseCommand command = operationObject as BaseCommand;

            command.SetGlobalUnionId(GlobalUnionId);

            return(command);
        }

        return(null);
    }
    private int SystemFunctionTypeSystemSotr(ECSDefine.SystemType leftSystemType, ECSDefine.SystemType rightSystemType)
    {
        ECSDefine.SystemPriority leftSystemPriority;
        if (!ECSInstanceDefine.SystemType2Priority.TryGetValue(leftSystemType, out leftSystemPriority))
        {
            leftSystemPriority = ECSDefine.SystemPriority.Normal;
        }

        ECSDefine.SystemPriority rightSystemPriority;
        if (!ECSInstanceDefine.SystemType2Priority.TryGetValue(rightSystemType, out rightSystemPriority))
        {
            rightSystemPriority = ECSDefine.SystemPriority.Normal;
        }

        return((int)leftSystemPriority.CompareTo((int)rightSystemPriority));
    }
示例#13
0
    public void CacheCommandListToExecuteCommandList()
    {
        for (int index = 0; index < cacheCommandList.Count; index++)
        {
            BaseCommand command = cacheCommandList[index];

            ECSDefine.SystemType systemType = command.GetSystemType();

            List <BaseCommand> commandList;
            if (!systemTypeCommandListDict.TryGetValue(systemType, out commandList))
            {
                commandList = new List <BaseCommand>();
                systemTypeCommandListDict.Add(systemType, commandList);
            }
            commandList.Add(command);
        }
        cacheCommandList.Clear();
    }
示例#14
0
    public void RegSystem(int entityId, ECSDefine.SystemType systemType)
    {
        BaseEntity entity = ECSUnit.GetEntity(entityId);

        if (entity == null)
        {
            Debug.LogError($"[ECSModule] RegSystem Fail. Entity Is nil. entityId:{entityId}");
            return;
        }

        int        systemId = systemIdDistributionChunk.Pop();
        BaseSystem system   = CreateFunctionSystem(systemType, systemId);

        if (system == null)
        {
            return;
        }

        system.FillInExecute(entityId);
    }
示例#15
0
    public List <BaseCommand> PopSendCommands()
    {
        List <BaseCommand> commands = new List <BaseCommand>();

        for (int index = 0; index < sendCommandList.Count; index++)
        {
            BaseCommand command = sendCommandList[index];

            ECSDefine.SystemType systemType  = command.GetSystemType();
            BaseCommand          sendCommand = PopCommand(systemType);
            if (sendCommand != null)
            {
                sendCommand.FillIn(command.GetEntityId(), systemType, command.GetExpandData());
            }
            PushCommand(systemType, command);
        }
        sendCommandList.Clear();

        return(commands);
    }
示例#16
0
    private void DeleteFunctionSystem(ECSDefine.SystemType systemType, BaseSystem system)
    {
        ECSDefine.SystemFunctionType systemFunction;
        if (!ECSInstanceDefine.SystemType2Function.TryGetValue(systemType, out systemFunction))
        {
            Debug.LogError($"[ECSModule] CreateFunctionSystem Fail. No SystemFunctionType Reocrd. systemType:{Enum.GetName(typeof(ECSDefine.SystemType), systemType)}");
            return;
        }

        PollingOperation functionSystemOperation;

        if (!functionSystemOperationDict.TryGetValue(systemFunction, out functionSystemOperation))
        {
            functionSystemOperation = new PollingOperation();

            functionSystemOperation.Init();
            functionSystemOperation.SetName(Enum.GetName(typeof(ECSDefine.SystemFunctionType), systemFunction) + "System");

            functionSystemOperationDict.Add(systemFunction, functionSystemOperation);
        }

        functionSystemOperation.RemoveOperationObject((int)systemType, system);
    }
示例#17
0
 public void FillIn(int entityId, ECSDefine.SystemType systemType, BaseSystem.SystemExpandData expandData)
 {
     this.entityId   = entityId;
     this.systemType = systemType;
     this.expandData = expandData;
 }
示例#18
0
    public void UpdateFunctionSystemsByFunctionTyep(ECSDefine.SystemFunctionType systemFunctionType, ECSDefine.SystemType systemType)
    {
        PollingOperation functionSystems;

        if (!functionSystemOperationDict.TryGetValue(systemFunctionType, out functionSystems))
        {
            functionSystems.UpdateUpdateOperationObjectList();
            functionSystems.UpdatePollingOperationObjectByOperationObjectType((int)systemType);
        }
    }
示例#19
0
 public void PushCommand(ECSDefine.SystemType systemType, BaseCommand command)
 {
     commandOperation.DeleteOperationObject((int)systemType, command);
 }
示例#20
0
 private void DeleteImmediatelyExecuteSystem(BaseSystem system)
 {
     ECSDefine.SystemType systemType = system.GetSystemType();
     system.SetGlobalUnionId(0);
     systemOperation.DeleteOperationObject((int)systemType, system);
 }
示例#21
0
 public void SetSystemType(ECSDefine.SystemType systemType)
 {
     this.systemType = systemType;
 }