Пример #1
0
        private void InitHmfEntityData(String defineFilePath, String defineFileListName)
        {
            try
            {
                byte[] bs = null;
                if (m_isUseOutterConfig)
                {
                    bs = XMLParser.LoadBytes(defineFilePath + defineFileListName);
                }
                else
                {
                    bs = XMLParser.LoadBytes(defineFilePath + defineFileListName);
                }
                if (bs == null)
                {
                    LoggerHelper.Error("Entity file load failed: " + defineFilePath + defineFileListName);
                }
                var hmf    = new Hmf();
                var stream = new MemoryStream(bs);
                stream.Seek(0, SeekOrigin.Begin);
                var def      = (Dictionary <object, object>)hmf.ReadObject(stream);
                var elements = (List <object>)def["entities"];
                if (elements != null && elements.Count != 0)
                {
                    EntitysByName.Clear();
                    for (var i = 0; i < elements.Count; i++)
                    {
                        ParseEntitiesHmfFile(String.Concat(defineFilePath, (string)elements[i], m_fileExtention),
                                             (string)elements[i], (ushort)(i + 1));
                    }

                    //找父亲
                    foreach (var child in EntitysByName.Values)
                    {
                        foreach (var parent in EntitysByName.Values)
                        {
                            if (child.ParentName == parent.Name)
                            {
                                child.Parent = parent;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new DefineParseException(String.Format("Define parse error.\nreason: \n{0}", ex.Message), ex);
            }
        }
Пример #2
0
        private object FormatHmfData(string fileName, Type dicType, Type type)
        {
            object result = null;

            try
            {
                //var dicType = dicProp.PropertyType;
                result = result = dicType.GetConstructor(Type.EmptyTypes).Invoke(null);
                //LoggerHelper.Warning("fileName: " + fileName);
                byte[] bs = XMLParser.LoadBytes(fileName);
                System.IO.MemoryStream stream = new MemoryStream(bs);
                stream.Seek(0, SeekOrigin.Begin);

                Hmf h = new Hmf();
                Dictionary <object, object> map = (Dictionary <object, object>)h.ReadObject(stream);

                var props = type.GetProperties();//获取实体属性
                foreach (var item in map)
                {
                    var t = type.GetConstructor(Type.EmptyTypes).Invoke(null);//构造实体实例
                    foreach (var prop in props)
                    {
                        if (prop.Name == "id")
                        {
                            var v = Utils.GetValue((string)item.Key, prop.PropertyType);
                            prop.SetValue(t, v, null);
                        }
                        else
                        {
                            Dictionary <object, object> m = (Dictionary <object, object>)item.Value;
                            if (m.ContainsKey((object)prop.Name))
                            {
                                var value = Utils.GetValue((string)m[(object)prop.Name], prop.PropertyType);
                                prop.SetValue(t, value, null);
                            }
                        }
                    }
                    var v1 = Utils.GetValue((string)item.Key, typeof(Int32));
                    dicType.GetMethod("Add").Invoke(result, new object[] { v1, t });
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error("FormatData Error: " + fileName + "  " + ex.Message);
            }
            return(result);
        }
Пример #3
0
 private void InitHmfEntityData(string defineFilePath, string defineFileListName)
 {
     try
     {
         byte[] buffer = null;
         if (base.m_isUseOutterConfig)
         {
             buffer = XMLParser.LoadBytes(defineFilePath + defineFileListName);
         }
         else
         {
             buffer = XMLParser.LoadBytes(defineFilePath + defineFileListName);
         }
         if (buffer == null)
         {
             LoggerHelper.Error("Entity file load failed: " + defineFilePath + defineFileListName, true);
         }
         Hmf          hmf    = new Hmf();
         MemoryStream stream = new MemoryStream(buffer);
         stream.Seek(0L, SeekOrigin.Begin);
         Dictionary <object, object> dictionary = (Dictionary <object, object>)hmf.ReadObject(stream);
         List <object> list = (List <object>)dictionary["entities"];
         if ((list != null) && (list.Count != 0))
         {
             this.m_entitysByName.Clear();
             for (int i = 0; i < list.Count; i++)
             {
                 this.ParseEntitiesHmfFile(defineFilePath + ((string)list[i]) + base.m_fileExtention, (string)list[i], (ushort)(i + 1), false);
             }
             foreach (EntityDef def in this.m_entitysByName.Values)
             {
                 foreach (EntityDef def2 in this.m_entitysByName.Values)
                 {
                     if (def.ParentName == def2.Name)
                     {
                         def.Parent = def2;
                         break;
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw new DefineParseException(string.Format("Define parse error.\nreason: \n{0}", exception.Message), exception);
     }
 }
Пример #4
0
        public Dictionary <int, T> FormatHmfDataTem <T>(string fileName) where T : GameData, new()
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();

            //long f1 = 0;
            //long f2 = 0;
            //long f3 = 0;
            var result = new Dictionary <int, T>();

            try
            {
                var bs     = XMLParser.LoadBytes(fileName);
                var stream = new MemoryStream(bs);
                stream.Seek(0, SeekOrigin.Begin);

                var h   = new Hmf();
                var map = (Dictionary <object, object>)h.ReadObject(stream);
                //f1 = sw.ElapsedMilliseconds;

                var props      = typeof(T).GetProperties(); //获取实体属性
                var sortedData = new SortedList <int, T>();
                foreach (var item in map)
                {
                    var t = new T(); //构造实体实例
                    t.SetData(props, item);
                    //  var v1 = Utils.GetValue((string)item.Key, typeof(Int32));
                    sortedData.Add(t.id, t);
                }
                //f2 = sw.ElapsedMilliseconds;
                for (var i = 0; i < sortedData.Values.Count; i++)
                {
                    var t = sortedData.Values[i];
                    result.Add(t.id, t);
                }
                //f3 = sw.ElapsedMilliseconds;
                //sw.Stop();
                //if (sw.ElapsedMilliseconds > 100 || bs.Length > 30000)
                //    LoggerHelper.Info(String.Concat(fileName, " time: ", sw.ElapsedMilliseconds, " a: ", f1, " b: ", f2 - f1, " c: ", f3 - f2, " bs.Length: ", bs.Length), false);
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex, "FormatData Error: " + fileName);
            }

            return(result);
        }
Пример #5
0
    public void LoadConfig(int index)
    {
        Clear();
        if (!m_mapOfStoryMap.ContainsKey(index))
        {
            var path = string.Concat(SystemConfig.CONFIG_SUB_FOLDER, config_xml + index.ToString(), SystemConfig.CONFIG_FILE_EXTENSION);
            LoggerHelper.Warning("Load Story: " + path);
            if (SystemSwitch.UseHmf)
            {
                byte[] bs = XMLParser.LoadBytes(path);
                System.IO.MemoryStream stream = new MemoryStream(bs);
                stream.Seek(0, SeekOrigin.Begin);

                Hmf h = new Hmf();
                Dictionary <object, object> map        = (Dictionary <object, object>)h.ReadObject(stream);
                Dictionary <int, String>    m_storyMap = new Dictionary <int, String>();
                foreach (var node in map)
                {
                    Dictionary <object, object> m = (Dictionary <object, object>)node.Value;
                    m_storyMap.Add(int.Parse((string)node.Key), m[(object)"storyText"].ToString());
                }
#if UNITY_IPHONE
                m_mapOfStoryMap[index] = m_storyMap.SortByKey();
#else
                m_mapOfStoryMap[index] = m_storyMap.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
#endif
            }
            else
            {
                var xml = XMLParser.Load(path);
                if (xml != null)
                {
                    var map = XMLParser.LoadIntMap(xml, config_xml);
                    Dictionary <int, String> m_storyMap = new Dictionary <int, String>();
                    foreach (var node in map)
                    {
                        m_storyMap.Add(node.Key, node.Value["storyText"]);
                    }
                    m_mapOfStoryMap[index] = m_storyMap;
                }
            }
        }
    }
Пример #6
0
        private void ParseEntitiesHmfFile(string fileName, string etyName, ushort entityID, bool needMD5 = false)
        {
            byte[] buffer = null;
            if (base.m_isUseOutterConfig)
            {
                buffer = Utils.LoadByteFile(fileName.Replace('\\', '/'));
            }
            else
            {
                buffer = XMLParser.LoadBytes(fileName);
            }
            Hmf          hmf    = new Hmf();
            MemoryStream stream = new MemoryStream(buffer);

            stream.Seek(0L, SeekOrigin.Begin);
            Dictionary <object, object> def = (Dictionary <object, object>)hmf.ReadObject(stream);

            this.ParseEntitiesHmf(def, etyName, entityID);
        }
Пример #7
0
        private object FormatHmfData(string fileName, Type dicType, Type type)
        {
            object obj2 = null;

            try
            {
                obj2 = obj2 = dicType.GetConstructor(Type.EmptyTypes).Invoke(null);
                MemoryStream stream = new MemoryStream(XMLParser.LoadBytes(fileName));
                stream.Seek(0L, SeekOrigin.Begin);
                Hmf hmf = new Hmf();
                Dictionary <object, object> dictionary = (Dictionary <object, object>)hmf.ReadObject(stream);
                PropertyInfo[] properties = type.GetProperties();
                foreach (KeyValuePair <object, object> pair in dictionary)
                {
                    object obj3 = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    foreach (PropertyInfo info in properties)
                    {
                        if (info.Name == "id")
                        {
                            object obj4 = Utils.GetValue((string)pair.Key, info.PropertyType);
                            info.SetValue(obj3, obj4, null);
                        }
                        else
                        {
                            Dictionary <object, object> dictionary2 = (Dictionary <object, object>)pair.Value;
                            if (dictionary2.ContainsKey(info.Name))
                            {
                                object obj5 = Utils.GetValue((string)dictionary2[info.Name], info.PropertyType);
                                info.SetValue(obj3, obj5, null);
                            }
                        }
                    }
                    object obj6 = Utils.GetValue((string)pair.Key, typeof(int));
                    dicType.GetMethod("Add").Invoke(obj2, new object[] { obj6, obj3 });
                }
            }
            catch (Exception exception)
            {
                LoggerHelper.Error("FormatData Error: " + fileName + "  " + exception.Message, true);
            }
            return(obj2);
        }
Пример #8
0
        private void ParseEntitiesHmfFile(String fileName, String etyName, ushort entityID, bool needMD5 = false)
        {
            byte[] bs = null;
            if (m_isUseOutterConfig)
            {
                //strContent = Util.Utils.LoadFile(fileName.Replace('\\', '/'));
                bs = Util.Utils.LoadByteFile(fileName.Replace('\\', '/'));
            }
            else
            {
                bs = XMLParser.LoadBytes(fileName);
            }

            var hmf    = new Hmf();
            var stream = new MemoryStream(bs);

            stream.Seek(0, SeekOrigin.Begin);
            var def = (Dictionary <object, object>)hmf.ReadObject(stream);

            ParseEntitiesHmf(def, etyName, entityID);
        }
Пример #9
0
        private object FormatHmfData(string fileName, Type dicType, Type type)
        {
            var sw = new Stopwatch();

            sw.Start();

            long   f1     = 0;
            long   f2     = 0;
            long   f3     = 0;
            object result = null;

            try
            {
                var bs     = XMLParser.LoadBytes(fileName);
                var stream = new MemoryStream(bs);
                stream.Seek(0, SeekOrigin.Begin);

                var h   = new Hmf();
                var map = (Dictionary <object, object>)h.ReadObject(stream);
                f1     = sw.ElapsedMilliseconds;
                result = dicType.GetConstructor(new[] { typeof(int) }).Invoke(new object[] { map.Count });

                var props   = type.GetProperties(); //获取实体属性
                var tempDic = new Dictionary <int, object>();
                foreach (var item in map)
                {
                    var t = type.GetConstructor(Type.EmptyTypes).Invoke(null); //构造实体实例
                    foreach (var prop in props)
                    {
                        if (prop.Name == "id")
                        {
                            // var v = Utils.GetValue((string)item.Key, prop.PropertyType);
                            prop.SetValue(t, item.Key, null);
                        }
                        else
                        {
                            var m = (Dictionary <object, object>)item.Value;
                            if (m.ContainsKey(prop.Name))
                            {
                                var v = m[prop.Name];
                                if (v.GetType() == typeof(string))
                                {
                                    var value = Utils.GetValue((string)m[prop.Name], prop.PropertyType);
                                    prop.SetValue(t, value, null);
                                }

                                else
                                {
                                    // UnityEngine.Debug.Log(prop.Name);

                                    prop.SetValue(t, Utils.GetObjectValue(v, prop.PropertyType), null);
                                }
                            }
                        }
                    }
                    //  var v1 = Utils.GetValue((string)item.Key, typeof(Int32));
                    tempDic.Add((int)item.Key, t);
                }
                f2 = sw.ElapsedMilliseconds;
                var order = new List <int>();
                foreach (var v in tempDic)
                {
                    order.Add(v.Key);
                }
                order.Sort();
                var orderDic = new Dictionary <int, object>();
                foreach (var v in order)
                {
                    orderDic.Add(v, tempDic[v]);
                }

                foreach (var item in orderDic)
                {
                    dicType.GetMethod("Add").Invoke(result, new[] { item.Key, item.Value });
                }
                f3 = sw.ElapsedMilliseconds;


                sw.Stop();
                if (sw.ElapsedMilliseconds > 100)
                {
                    LoggerHelper.Info(
                        String.Concat(fileName, " time: ", sw.ElapsedMilliseconds, " a: ", f1, " b: ", f2 - f1, " c: ",
                                      f3 - f2, " count: ", map.Count), false);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Except(ex, "FormatData Error: " + fileName);
            }

            return(result);
        }