예제 #1
0
    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);//执行完毕回收
    }
예제 #3
0
    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);
    }
예제 #12
0
    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;
 }