Exemplo n.º 1
0
        public static void InitGame(string logPath, string dataPath)
        {
            s_IsInited = true;
            s_LogicLogger.Init(logPath);
            HomePath.CurHomePath = dataPath;
            GlobalVariables.Instance.IsClient = true;
            GlobalVariables.Instance.IsDebug  = false;

            FileReaderProxy.RegisterReadFileHandler((string filePath) => {
                byte[] buffer = null;
                try {
                    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) {
                        buffer = new byte[fs.Length];
                        fs.Read(buffer, 0, (int)fs.Length);
                        fs.Close();
                    }
                } catch (Exception e) {
                    GfxSystem.GfxLog("Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return(null);
                }
                return(buffer);
            });

            LogSystem.OnOutput = (Log_Type type, string msg) => { GfxSystem.GfxLog("{0}", msg); s_LogicLogger.Log("{0}", msg); };

            GfxSystem.GfxLog("GameControler.InitGame");
            _InitSystems();
        }
Exemplo n.º 2
0
        /**
         * @brief 载入文件
         *
         * @param path
         *
         * @return
         */
        public bool Load(string path)
        {
            bool ret = false;

            if (path == "" || !FileReaderProxy.Exists(path))
            {
                return(ret);
            }

            Stream       ms = null;
            StreamReader sr = null;

            try {
                ms = FileReaderProxy.ReadFileAsMemoryStream(path);
                if (ms == null)
                {
                    LogSystem.Debug("DBC, Warning, Load file error or file is empty: {0}", path);
                    return(false);
                }

                m_FileName = path;
                ms.Seek(0, SeekOrigin.Begin);
                m_FileSize = ms.Length;
                if (m_FileSize <= 0 || m_FileSize >= int.MaxValue)
                {
                    return(ret);
                }

                System.Text.Encoding encoding = System.Text.Encoding.UTF8;
                sr = new StreamReader(ms, encoding);

                ret = LoadFromStream(sr);
                ret = true;
            } catch (Exception e) {
                string err = "Exception:" + e.Message + "\n" + e.StackTrace + "\n";
                System.Diagnostics.Debug.WriteLine(err);
            } finally {
                if (sr != null)
                {
                    sr.Close();
                }
                if (ms != null)
                {
                    ms.Close();
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
 public void Init(string filename)
 {
     if (!FileReaderProxy.Exists(filename))
     {
         return;
     }
     try {
         float w = 1, h = 1;
         using (MemoryStream fs = FileReaderProxy.ReadFileAsMemoryStream(filename)) {
             using (BinaryReader br = new BinaryReader(fs)) {
                 w = (float)br.ReadDouble();
                 h = (float)br.ReadDouble();
                 br.Close();
             }
         }
         Init(w, h);
     } catch (Exception e) {
         LogSystem.Error("{0}\n{1}", e.Message, e.StackTrace);
     }
 }