コード例 #1
0
        public void Start()
        {
            try
            {
                string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" };

                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    string assemblyName = $"{assembly.GetName().Name}.dll";
                    if (!assemblyNames.Contains(assemblyName))
                    {
                        continue;
                    }
                    Game.EventSystem.Add(assembly);
                }

                ProtobufHelper.Init();

                Game.Options = new Options();

                Game.EventSystem.Publish(new EventType.AppStart());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #2
0
        public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream)
        {
            try
            {
                if (opcode < OpcodeRangeDefine.PbMaxOpcode)
                {
                    ProtobufHelper.ToStream(obj, memoryStream);
                    return;
                }

                if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
                {
                    string s     = JsonHelper.ToJson(obj);
                    byte[] bytes = s.ToUtf8();
                    memoryStream.Write(bytes, 0, bytes.Length);
                    return;
                }
#if NOT_UNITY
                MongoHelper.ToStream(obj, memoryStream);
#else
                throw new Exception($"client no message: {opcode}");
#endif
            }
            catch (Exception e)
            {
                throw new Exception($"SerializeTo error: {opcode}", e);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wqaetly/ET
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Log.Error(e.ExceptionObject.ToString());
            };
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);

            try
            {
                //初始化EventSystem
                {
                    List <Type> types = new List <Type>();
                    types.AddRange(typeof(Game).Assembly.GetTypes());
                    types.AddRange(DllHelper.GetHotfixAssembly().GetTypes());
                    Game.EventSystem.AddRangeType(types);
                    Game.EventSystem.TypeMonoInit();
                    Game.EventSystem.EventSystemInit();
                }

                ProtobufHelper.Init();
                MongoHelper.Init();

                // 命令行参数
                Options options = null;
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { options = o; });

                GlobalDefine.Options = options;

                GlobalDefine.ILog = new NLogger(GlobalDefine.Options.AppType.ToString());

                LogManager.Configuration.Variables["appIdFormat"] = $"{GlobalDefine.Options.Process:000000}";

                Log.Info($"server start........................ {Game.Scene.Id}");

                Game.EventSystem.Publish(new EventType.AppStart());

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        Game.Update();
                        Game.LateUpdate();
                        Game.FrameFinish();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #4
0
ファイル: InitEntry.cs プロジェクト: wqaetly/ET
        public static void Start()
        {
            try
            {
                Log.Info("初始化EventSystem");
                {
                    List <Type> types = new List <Type>();
                    types.AddRange(HotfixHelper.GetAssemblyTypes());
                    Game.EventSystem.AddRangeType(types);
                    if (GlobalDefine.ILRuntimeMode)
                    {
                        Game.EventSystem.TypeIlrInit();
                    }
                    else
                    {
                        Game.EventSystem.TypeMonoInit();
                    }
                    Game.EventSystem.EventSystemInit();
                }
                ProtobufHelper.Init();

                GlobalDefine.Options = new Options();

                Game.EventSystem.Publish(new EventType.AppStart()).Coroutine();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #5
0
        public static void Start()
        {
            try
            {
                TypeHelper.Init();
                Game.EventSystem.Init();

                Log.Info("开始热更");

                // 注册热更层回调
                GameLoop.onUpdate          += Update;
                GameLoop.onLateUpdate      += LateUpdate;
                GameLoop.onApplicationQuit += OnApplicationQuit;

                ProtobufHelper.Init();

                Game.Options = new Options();

                Game.EventSystem.Publish(new EventType.AppStart());
            }
            catch (Exception _e)
            {
                Log.Error(_e);
            }
        }
コード例 #6
0
ファイル: Entry.cs プロジェクト: yfgumaths/ET
        public void Start()
        {
            try
            {
                SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);

                string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" };

                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    string assemblyName = assembly.ManifestModule.Name;
                    if (!assemblyNames.Contains(assemblyName))
                    {
                        continue;
                    }
                    Game.EventSystem.Add(assembly);
                }

                ProtobufHelper.Init();

                Game.Options = new Options();

                Game.EventSystem.Publish(new EventType.AppStart());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #7
0
        public static void LoadOneConfig(this ConfigComponent self, Type configType)
        {
            byte[] oneConfigBytes = self.ConfigLoader.GetOneConfigBytes(configType.FullName);

            object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);

            self.AllConfig[configType] = category;
        }
コード例 #8
0
        public static void LoadOneConfig(this ConfigComponent self, Type configType)
        {
            byte[] oneConfigBytes = Game.EventSystem.Callback <string, byte[]>(CallbackType.GetOneConfigBytes, configType.FullName);

            object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);

            self.AllConfig[configType] = category;
        }
コード例 #9
0
ファイル: MessagePackHelper.cs プロジェクト: warpten2001/ET-1
        public static object DeserializeFrom(ushort opcode, Type type, byte[] bytes, int index, int count)
        {
            if (opcode >= 20000)
            {
                return(ProtobufHelper.FromBytes(type, bytes, index, count));
            }

            return(MongoHelper.FromBson(type, bytes, index, count));
        }
コード例 #10
0
ファイル: MessagePackHelper.cs プロジェクト: warpten2001/ET-1
        public static object DeserializeFrom(ushort opcode, Type type, MemoryStream stream)
        {
            if (opcode >= 20000)
            {
                return(ProtobufHelper.FromStream(type, stream));
            }

            return(MongoHelper.FromStream(type, stream));
        }
コード例 #11
0
ファイル: MessagePackHelper.cs プロジェクト: warpten2001/ET-1
        public static void SerializeTo(ushort opcode, object obj, MemoryStream stream)
        {
            if (opcode >= 20000)
            {
                ProtobufHelper.ToStream(obj, stream);
                return;
            }

            MongoHelper.ToBson(obj, stream);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: zwinter/ET
        private static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                Log.Error(e.ExceptionObject.ToString());
            };

            ETTask.ExceptionHandler += Log.Error;

            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);

            try
            {
                Game.EventSystem.Add(typeof(Game).Assembly);

                ProtobufHelper.Init();
                MongoRegister.Init();

                // 命令行参数
                Options options = null;
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { options = o; });

                Options.Instance = options;

                Log.ILog = new NLogger(Game.Options.AppType.ToString());
                LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";

                Log.Info($"server start........................ {Game.Scene.Id}");

                switch (Game.Options.AppType)
                {
                case AppType.ExcelExporter:
                {
                    Game.Options.Console = 1;
                    ExcelExporter.Export();
                    return(0);
                }

                case AppType.Proto2CS:
                {
                    Game.Options.Console = 1;
                    Proto2CS.Export();
                    return(0);
                }
                }
            }
            catch (Exception e)
            {
                Log.Console(e.ToString());
            }
            return(1);
        }
コード例 #13
0
        private static void LoadOneInThread(this ConfigComponent self, Type configType, Dictionary <string, byte[]> configBytes)
        {
            byte[] oneConfigBytes = configBytes[configType.Name];

            object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);

            lock (self)
            {
                self.AllConfig[configType] = category;
            }
        }
コード例 #14
0
ファイル: MessageSerializeHelper.cs プロジェクト: x00568/ET
        public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream)
        {
            if (opcode < OpcodeRangeDefine.PbMaxOpcode)
            {
                return(ProtobufHelper.FromStream(type, memoryStream));
            }

            if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
            {
                return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position))));
            }
            return(MongoHelper.FromStream(type, memoryStream));
        }
コード例 #15
0
ファイル: ConfigComponentSystem.cs プロジェクト: wqaetly/ET
        private static void LoadOneInThread(this ConfigComponent self, Type configType, Dictionary <string, byte[]> configBytes)
        {
            byte[] oneConfigBytes = configBytes[configType.Name];
            object category       = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);

#if !SERVER
            MethodInfo methodInfo = category.GetType().GetMethod("AfterDeserialization");
            methodInfo?.Invoke(category, null);
#endif
            lock (self)
            {
                self.AllConfig[configType] = category;
            }
        }
コード例 #16
0
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);

            try
            {
                Game.EventSystem.Add(typeof(Game).Assembly);
                Game.EventSystem.Add(DllHelper.GetHotfixAssembly());

                ProtobufHelper.Init();
                MongoHelper.Init();

                // 命令行参数
                Options options = null;
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { options = o; });

                Game.Options = options;

                Game.ILog = new NLogger(Game.Options.AppType.ToString());

                LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";

                Log.Info($"server start........................ {Game.Scene.Id}");

                Game.EventSystem.Publish(new EventType.AppStart());

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        Game.Update();
                        Game.LateUpdate();
                        Game.FrameFinish();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #17
0
        public static object ToActorMessage(this MemoryStream memoryStream)
        {
            ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), 8);
            Type   type   = OpcodeTypeComponent.Instance.GetType(opcode);

            if (opcode < MessageSerializeHelper.PbMaxOpcode)
            {
                return(ProtobufHelper.FromBytes(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10));
            }

            if (opcode >= MessageSerializeHelper.JsonMinOpcode)
            {
                return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr(10, (int)(memoryStream.Length - 10))));
            }
            return(MongoHelper.FromBson(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10));
        }
コード例 #18
0
        public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream)
        {
            if (opcode < OpcodeRangeDefine.PbMaxOpcode)
            {
                return(ProtobufHelper.FromStream(type, memoryStream));
            }

            if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
            {
                return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position))));
            }
#if NOT_UNITY
            return(MongoHelper.FromStream(type, memoryStream));
#else
            throw new Exception($"client no message: {opcode}");
#endif
        }
コード例 #19
0
        public static T LoadOneConfig <T>(this ConfigComponent self, string name = "", bool cache = false) where T : ProtoObject
        {
            Type configType = typeof(T);

            if (string.IsNullOrEmpty(name))
            {
                name = configType.FullName;
            }
            byte[] oneConfigBytes = self.ConfigLoader.GetOneConfigBytes(name);

            object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length);

            if (cache)
            {
                self.AllConfig[configType] = category;
            }

            return(category as T);
        }
コード例 #20
0
        public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream)
        {
            if (opcode < PbMaxOpcode)
            {
                ProtobufHelper.ToStream(obj, memoryStream);
                return;
            }

            if (opcode >= JsonMinOpcode)
            {
                string s     = JsonHelper.ToJson(obj);
                byte[] bytes = s.ToUtf8();
                memoryStream.Write(bytes, 0, bytes.Length);
                return;
            }
#if SERVER
            MongoHelper.ToStream(obj, memoryStream);
#else
            throw new Exception($"client no message: {opcode}");
#endif
        }
コード例 #21
0
        public static void Start()
        {
            try
            {
                Game.EventSystem.Add(typeof(Entry).Assembly);

                CodeLoader.Instance.Update            = Game.Update;
                CodeLoader.Instance.LateUpdate        = Game.LateUpdate;
                CodeLoader.Instance.OnApplicationQuit = Game.Close;

                ProtobufHelper.Init();

                Game.Options = new Options();

                Game.EventSystem.Publish(new EventType.AppStart()).Coroutine();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #22
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public byte[] SerializeTo(object obj)
 {
     return(ProtobufHelper.ToBytes(obj));
 }
コード例 #23
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public object DeserializeFrom(object instance, MemoryStream stream)
 {
     return(ProtobufHelper.FromStream(instance, stream));
 }
コード例 #24
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public object DeserializeFrom(Type type, MemoryStream stream)
 {
     return(ProtobufHelper.FromStream(type, stream));
 }
コード例 #25
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public object DeserializeFrom(object instance, byte[] bytes, int index, int count)
 {
     return(ProtobufHelper.FromBytes(instance, bytes, index, count));
 }
コード例 #26
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public object DeserializeFrom(Type type, byte[] bytes, int index, int count)
 {
     return(ProtobufHelper.FromBytes(type, bytes, index, count));
 }
コード例 #27
0
ファイル: ProtobufPacker.cs プロジェクト: xwmeteor/ET-QiPai
 public void SerializeTo(object obj, MemoryStream stream)
 {
     ProtobufHelper.ToStream(obj, stream);
 }
コード例 #28
0
ファイル: ProtoObject.cs プロジェクト: chanayy123/ET
 public object Clone()
 {
     byte[] bytes = ProtobufHelper.ToBytes(this);
     return(ProtobufHelper.FromBytes(this.GetType(), bytes, 0, bytes.Length));
 }