From 4dc88e1540d2fea7635eb2c376da8ec6c141e4be Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期三, 13 二月 2019 17:56:24 +0800
Subject: [PATCH] 3335 配置表读取重构。

---
 Core/GameEngine/Model/ConfigManager.cs |  370 ----------------------------------------------------
 1 files changed, 0 insertions(+), 370 deletions(-)

diff --git a/Core/GameEngine/Model/ConfigManager.cs b/Core/GameEngine/Model/ConfigManager.cs
index 35bc3a0..1e0146b 100644
--- a/Core/GameEngine/Model/ConfigManager.cs
+++ b/Core/GameEngine/Model/ConfigManager.cs
@@ -20,24 +20,6 @@
         private set { m_Inited = value; }
     }
 
-    Dictionary<int, Dictionary<string, ConfigBase>> configDictionary = new Dictionary<int, Dictionary<string, ConfigBase>>();
-
-    public void RegisterGlobalEvent()
-    {
-        SnxxzGame.Instance.RemoveApplicationOutAction(OnApplicationOut);
-        SnxxzGame.Instance.AddApplicationOutAction(OnApplicationOut);
-    }
-
-    public void LoadPriorBundleConfig()
-    {
-    }
-
-    public void PreLoadConfigs()
-    {
-    }
-
-    List<ConfigTask> configTasks = new List<ConfigTask>();
-
     public IEnumerator Co_LoadConfigs()
     {
 
@@ -91,49 +73,6 @@
 
     public void SyncLoadConfigs()
     {
-    }
-
-    public bool AllCompleted()
-    {
-        foreach (var task in configTasks)
-        {
-            if (task.state != TaskState.ParseSuccess)
-            {
-                // DesignDebug.LogFormat("鏈畬鎴愭槸閰嶇疆瑙f瀽浠诲姟锛歿0},褰撳墠鐘舵�侊細{1}", task.taskName, task.state);
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    public float GetProgress()
-    {
-        var count = 0;
-        foreach (var task in configTasks)
-        {
-            if (task.state == TaskState.ParseSuccess)
-            {
-                count++;
-            }
-        }
-
-        return (float)count / configTasks.Count;
-    }
-
-    public int GetTaskCount()
-    {
-        return configTasks.Count;
-    }
-
-    public void ConfigParsePostProcess()
-    {
-        foreach (var task in configTasks)
-        {
-            configDictionary[task.token] = task.container;
-        }
-
-        inited = true;
     }
 
     int GetMinWorkingTaskCount()
@@ -204,315 +143,6 @@
             default:
                 return 5;
         }
-    }
-
-    ConfigTask AddAsyncTask<T>() where T : ConfigBase, new()
-    {
-        var typeName = typeof(T).Name;
-        var path = string.Empty;
-        var fileName = typeName.Substring(0, typeName.Length - 6);
-
-        if (AssetSource.refdataFromEditor)
-        {
-            path = ResourcesPath.CONFIG_FODLER + "/" + fileName + ".txt";
-        }
-        else
-        {
-            path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact("config/", fileName, ".txt"));
-        }
-
-        var task = new ConfigTask(typeof(T), path);
-        Action<ConfigTask> launch = (ConfigTask _task) => { ReadFile(_task, OnEndReadFile<T>); };
-        task.launch = launch;
-        configTasks.Add(task);
-
-        return task;
-    }
-
-    void StartAsyncTask(ConfigTask _task)
-    {
-        _task.state = TaskState.Working;
-        _task.launch(_task);
-    }
-
-    void ReadFile(ConfigTask _task, Action<ConfigTask> _callBack)
-    {
-        ThreadPool.QueueUserWorkItem(
-            (object _obj) =>
-            {
-                string[] lines = null;
-                try
-                {
-                    lines = File.ReadAllLines(_task.filePath, Encoding.UTF8);
-                    _task.state = TaskState.ReadFileSuccess;
-                }
-                catch (Exception ex)
-                {
-                    _task.state = TaskState.ReadFileFailure;
-                    DebugEx.Log(ex);
-                }
-                finally
-                {
-                    _task.contentLines = lines;
-                    if (_callBack != null)
-                    {
-                        _callBack(_task);
-                    }
-                }
-            }
-            );
-
-    }
-
-    void AsyncParseConfig<T>(ConfigTask _task, Action<ConfigTask> _callBack) where T : ConfigBase, new()
-    {
-        ThreadPool.QueueUserWorkItem(
-            (object _obj) =>
-            {
-                try
-                {
-                    var count = 0;
-
-                    var container = _task.container as Dictionary<string, ConfigBase>;
-                    for (int i = 3; i < _task.contentLines.Length; i++)
-                    {
-                        var newConfig = new T();
-                        newConfig.Parse(_task.contentLines[i]);
-                        if (newConfig is IConfigPostProcess)
-                        {
-                            (newConfig as IConfigPostProcess).OnConfigParseCompleted();
-                        }
-
-                        container[newConfig.getKey()] = newConfig;
-                        count++;
-                        if (count >= 500)
-                        {
-                            count = 0;
-                            Thread.Sleep(30);
-                        }
-                    }
-
-                    _task.state = TaskState.ParseSuccess;
-                }
-                catch (Exception ex)
-                {
-                    _task.state = TaskState.ParseFailure;
-                    DebugEx.Log(ex);
-                }
-                finally
-                {
-                    if (_callBack != null)
-                    {
-                        _callBack(_task);
-                    }
-                }
-            }
-            );
-    }
-
-    private void OnEndReadFile<T>(ConfigTask _task) where T : ConfigBase, new()
-    {
-        if (isPlaying && _task.state == TaskState.ReadFileFailure)
-        {
-            Thread.Sleep(30);
-            ReadFile(_task, OnEndReadFile<T>);
-        }
-        else
-        {
-            _task.capacity = Mathf.Max(_task.contentLines.Length - 3, 0);
-            _task.container = new Dictionary<string, ConfigBase>(_task.capacity);
-            AsyncParseConfig<T>(_task, OnEndParse<T>);
-        }
-    }
-
-    private void OnEndParse<T>(ConfigTask _task) where T : ConfigBase, new()
-    {
-        if (isPlaying && _task.state == TaskState.ParseFailure)
-        {
-            Debug.LogFormat("閰嶇疆琛ㄨВ鏋愬け璐ワ細{0}", _task.taskName);
-            Thread.Sleep(30);
-            ReadFile(_task, OnEndReadFile<T>);
-        }
-    }
-
-    private void StartSyncTask<T>() where T : ConfigBase, new()
-    {
-        var typeName = typeof(T).Name;
-        var fileName = typeName.Substring(0, typeName.Length - 6);
-        var path = string.Empty;
-
-        if (Application.isEditor || AssetSource.refdataFromEditor)
-        {
-            path = ResourcesPath.CONFIG_FODLER + "/" + fileName + ".txt";
-        }
-        else
-        {
-            path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact("config/", fileName, ".txt"));
-        }
-
-        var task = new ConfigTask(typeof(T), path);
-        task.contentLines = File.ReadAllLines(path, Encoding.UTF8);
-        if (task.contentLines != null && task.contentLines.Length > 3)
-        {
-            var length = Mathf.Max(task.contentLines.Length - 3, 0);
-            task.capacity = length;
-            task.container = new Dictionary<string, ConfigBase>(length);
-            task.state = TaskState.ReadFileSuccess;
-            SyncParseConfig<T>(task);
-        }
-        else
-        {
-            task.state = TaskState.ReadFileFailure;
-        }
-    }
-
-    private void SyncParseConfig<T>(ConfigTask _task) where T : ConfigBase, new()
-    {
-        try
-        {
-            for (int i = 3; i < _task.contentLines.Length; i++)
-            {
-                var newConfig = new T();
-                newConfig.Parse(_task.contentLines[i]);
-
-                if (newConfig is IConfigPostProcess)
-                {
-                    (newConfig as IConfigPostProcess).OnConfigParseCompleted();
-                }
-
-                _task.container[newConfig.getKey()] = newConfig;
-            }
-        }
-        catch (Exception ex)
-        {
-            DebugEx.Log(ex);
-        }
-        finally
-        {
-            _task.state = TaskState.ParseSuccess;
-            configDictionary[_task.token] = _task.container;
-        }
-
-    }
-
-    public T Get<T>(string _dwTemplateID) where T : ConfigBase, new()
-    {
-        if (string.IsNullOrEmpty(_dwTemplateID))
-        {
-            return null;
-        }
-
-        var token = typeof(T).MetadataToken;
-        if (configDictionary.ContainsKey(token) == false)
-        {
-            DebugEx.LogErrorFormat("not find the config:{0}", token);
-            return null;
-        }
-
-        ConfigBase config = null;
-        var dic = configDictionary[token];
-        if (!dic.ContainsKey(_dwTemplateID))
-        {
-            DebugEx.LogFormat("not find the config:{0},<color=#ff0000ff>ID:{1}</color>", typeof(T).Name, _dwTemplateID);
-        }
-        else
-        {
-            config = dic[_dwTemplateID];
-        }
-
-        return config as T;
-    }
-
-    public T Get<T>(int _dwTemplateID) where T : ConfigBase, new()
-    {
-        return Get<T>(_dwTemplateID.ToString());
-    }
-
-    public bool ContainKey<T>(int _id)
-    {
-        return ContainKey<T>(_id.ToString());
-    }
-
-    public bool ContainKey<T>(string _key)
-    {
-        if (string.IsNullOrEmpty(_key))
-        {
-            return false;
-        }
-
-        var token = typeof(T).MetadataToken;
-        if (configDictionary.ContainsKey(token) == false)
-        {
-            return false;
-        }
-
-        var dic = configDictionary[token];
-        return dic.ContainsKey(_key);
-    }
-
-    public List<string> GetAllKeys<T>() where T : ConfigBase
-    {
-        var token = typeof(T).MetadataToken;
-        if (!configDictionary.ContainsKey(token))
-        {
-            DebugEx.LogErrorFormat("not find the dic of config: {0}", typeof(T).Name);
-            return null;
-        }
-
-        var dicTemplate = configDictionary[token];
-        return new List<string>(dicTemplate.Keys);
-    }
-
-    public List<T> GetAllValues<T>() where T : ConfigBase, new()
-    {
-        var token = typeof(T).MetadataToken;
-        if (!configDictionary.ContainsKey(token))
-        {
-            DebugEx.LogErrorFormat("not find the dic of config: {0}", typeof(T).Name);
-            return null;
-        }
-
-        var configs = new List<T>();
-        var dicTemplate = configDictionary[token];
-        foreach (var value in dicTemplate.Values)
-        {
-            configs.Add(value as T);
-        }
-
-        return configs;
-    }
-
-    class ConfigTask
-    {
-        public readonly Type type;
-        public readonly int token;
-        public readonly string taskName;
-        public readonly string filePath;
-
-        public Action<ConfigTask> launch;
-        public int capacity = 0;
-        public string[] contentLines;
-        public Dictionary<string, ConfigBase> container;
-        public TaskState state = TaskState.None;
-
-        public ConfigTask(Type _type, string _filePath)
-        {
-            type = _type;
-            taskName = type.Name;
-            token = type.MetadataToken;
-
-            filePath = _filePath;
-        }
-    }
-
-    public enum TaskState
-    {
-        None = 0,
-        Working = 1,
-        ReadFileSuccess = 2,
-        ReadFileFailure = 3,
-        ParseFailure = 4,
-        ParseSuccess = 5,
     }
 
     private void OnApplicationOut()

--
Gitblit v1.8.0