Beispiel #1
0
        private static void LaunchGame(LaunchSettings launchSettings)
        {
            if (!Directory.Exists(launchSettings.WorkDir))
            {
                Directory.CreateDirectory(launchSettings.WorkDir);
            }

            ConfigureNLog(launchSettings.WorkDir);

            if (launchSettings.Server == null && launchSettings.ConnectOnLaunch)
            {
                launchSettings.ConnectOnLaunch = false;
                Log.Warn($"No server specified, ignoring connect argument.");
            }

            if (!Clipboard.IsClipboardAvailable())
            {
                Log.Warn($"No suitable Clipboard implementation, clipboard will not be available! If you are on linux, install 'XClip' using 'apt install XClip'");
            }

            //Cef.Initialize(new Settings());

            Log.Info($"Starting...");

            using (var game = new Alex(launchSettings))
            {
                game.Run();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            LaunchSettings launchSettings = ParseArguments(args);

            if (!Directory.Exists(launchSettings.WorkDir))
            {
                Directory.CreateDirectory(launchSettings.WorkDir);
            }

            ConfigureNLog(launchSettings.WorkDir);

            if (launchSettings.Server == null && launchSettings.ConnectOnLaunch)
            {
                launchSettings.ConnectOnLaunch = false;
                Log.Warn($"No server specified, ignoring connect argument.");
            }

            //Cef.Initialize(new Settings());

            Log.Info($"Starting...");

            using (var game = new Alex(launchSettings))
            {
                game.Run();
            }
        }
Beispiel #3
0
        public Alex(LaunchSettings launchSettings)
        {
            Instance       = this;
            LaunchSettings = launchSettings;

            DeviceManager = new GraphicsDeviceManager(this)
            {
                PreferMultiSampling            = false,
                SynchronizeWithVerticalRetrace = false,
                GraphicsProfile = GraphicsProfile.Reach,
            };


            Content.RootDirectory = "assets";

            IsFixedTimeStep = false;
            // graphics.ToggleFullScreen();

            this.Window.AllowUserResizing  = true;
            this.Window.ClientSizeChanged += (sender, args) =>
            {
                if (DeviceManager.PreferredBackBufferWidth != Window.ClientBounds.Width ||
                    DeviceManager.PreferredBackBufferHeight != Window.ClientBounds.Height)
                {
                    if (DeviceManager.IsFullScreen)
                    {
                        DeviceManager.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                        DeviceManager.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                    }
                    else
                    {
                        DeviceManager.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                        DeviceManager.PreferredBackBufferHeight = Window.ClientBounds.Height;
                    }

                    DeviceManager.ApplyChanges();

                    //CefWindow.Size = new System.Drawing.Size(Window.ClientBounds.Width, Window.ClientBounds.Height);
                }
            };


            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                Converters = new List <JsonConverter>()
                {
                    new Texture2DJsonConverter(GraphicsDevice)
                },
                Formatting = Formatting.Indented
            };

            UIThreadQueue = new ConcurrentQueue <Action>();

            PluginManager = new PluginManager(this);
            FpsMonitor    = new FpsMonitor();
        }
Beispiel #4
0
        public Alex(LaunchSettings launchSettings)
        {
            Instance        = this;
            LaunchSettings  = launchSettings;
            OperatingSystem = $"{System.Runtime.InteropServices.RuntimeInformation.OSDescription} ({System.Runtime.InteropServices.RuntimeInformation.OSArchitecture})";

            DeviceManager = new GraphicsDeviceManager(this)
            {
                PreferMultiSampling            = false,
                SynchronizeWithVerticalRetrace = false,
                GraphicsProfile = GraphicsProfile.Reach,
            };

            DeviceManager.PreparingDeviceSettings += (sender, args) =>
            {
                Gpu = args.GraphicsDeviceInformation.Adapter.Description;
                args.GraphicsDeviceInformation.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;
                DeviceManager.PreferMultiSampling = true;
            };

            Content = new StreamingContentManager(base.Services, "assets");
            //	Content.RootDirectory = "assets";

            IsFixedTimeStep = false;
            // graphics.ToggleFullScreen();

            this.Window.AllowUserResizing  = true;
            this.Window.ClientSizeChanged += (sender, args) =>
            {
                if (DeviceManager.PreferredBackBufferWidth != Window.ClientBounds.Width ||
                    DeviceManager.PreferredBackBufferHeight != Window.ClientBounds.Height)
                {
                    if (DeviceManager.IsFullScreen)
                    {
                        DeviceManager.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                        DeviceManager.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                    }
                    else
                    {
                        DeviceManager.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                        DeviceManager.PreferredBackBufferHeight = Window.ClientBounds.Height;
                    }

                    DeviceManager.ApplyChanges();

                    //CefWindow.Size = new System.Drawing.Size(Window.ClientBounds.Width, Window.ClientBounds.Height);
                }
            };


            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                Converters = new List <JsonConverter>()
                {
                    new Texture2DJsonConverter(GraphicsDevice)
                },
                Formatting = Formatting.Indented
            };

            IServiceCollection serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);

            Services = serviceCollection.BuildServiceProvider();

            UIThreadQueue = new ConcurrentQueue <Action>();

            PluginManager = new PluginManager(Services);
            FpsMonitor    = new FpsMonitor();

            Resources = Services.GetRequiredService <ResourceManager>();

            ThreadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount,
                                                                                 ThreadType.Background, "Dedicated ThreadPool"));

            PacketFactory.CustomPacketFactory = new AlexPacketFactory();

            KeyboardInputListener.InstanceCreated += KeyboardInputCreated;
        }
Beispiel #5
0
        private static LaunchSettings ParseArguments(string[] args)
        {
            LaunchSettings launchSettings    = new LaunchSettings();
            bool           nextIsServer      = false;
            bool           nextIsuuid        = false;
            bool           nextIsaccessToken = false;
            bool           nextIsUsername    = false;
            bool           nextIsWorkDir     = false;

            foreach (var arg in args)
            {
                if (nextIsServer)
                {
                    nextIsServer = false;
                    var s = arg.Split(':');
                    if (IPAddress.TryParse(s[0], out IPAddress val))
                    {
                        if (ushort.TryParse(s[1], out ushort reee))
                        {
                            launchSettings.Server = new IPEndPoint(val, reee);
                        }
                    }
                }

                if (nextIsaccessToken)
                {
                    nextIsaccessToken         = false;
                    launchSettings.AccesToken = arg;
                    continue;
                }

                if (nextIsuuid)
                {
                    nextIsuuid          = false;
                    launchSettings.UUID = arg;
                    continue;
                }

                if (nextIsUsername)
                {
                    nextIsUsername          = false;
                    launchSettings.Username = arg;
                    continue;
                }

                if (nextIsWorkDir)
                {
                    nextIsWorkDir          = false;
                    launchSettings.WorkDir = arg;
                    continue;
                }

                if (arg == "--server")
                {
                    nextIsServer = true;
                }

                if (arg == "--bedrock")
                {
                    launchSettings.ConnectToBedrock = true;
                }

                if (arg == "--accessToken")
                {
                    nextIsaccessToken = true;
                }

                if (arg == "--uuid")
                {
                    nextIsuuid = true;
                }

                if (arg == "--username")
                {
                    nextIsUsername = true;
                }

                if (arg == "--direct")
                {
                    launchSettings.ConnectOnLaunch = true;
                }

                if (arg == "--console")
                {
                    launchSettings.ShowConsole = true;
                }

                if (arg == "--workDir")
                {
                    nextIsWorkDir = true;
                }

                if (arg == "--debug")
                {
                    launchSettings.ModelDebugging = true;
                }
            }

            return(launchSettings);
        }
Beispiel #6
0
        public Alex(LaunchSettings launchSettings)
        {
            EntityProperty.Factory = new AlexPropertyFactory();

            /*MiNET.Utils.DedicatedThreadPool fastThreadPool =
             *      ReflectionHelper.GetPrivateStaticPropertyValue<MiNET.Utils.DedicatedThreadPool>(
             *              typeof(MiNetServer), "FastThreadPool");
             *
             * fastThreadPool?.Dispose();
             * fastThreadPool?.WaitForThreadsExit();
             *
             * ReflectionHelper.SetPrivateStaticPropertyValue<MiNET.Utils.DedicatedThreadPool>(
             *      typeof(MiNetServer), "FastThreadPool",
             *      new MiNET.Utils.DedicatedThreadPool(
             *              new MiNET.Utils.DedicatedThreadPoolSettings(8, "MiNETServer Fast")));*/

            ThreadPool.GetMaxThreads(out _, out var completionPortThreads);
            //ThreadPool.SetMaxThreads(Environment.ProcessorCount, completionPortThreads);

            Instance       = this;
            LaunchSettings = launchSettings;

            OperatingSystem =
                $"{System.Runtime.InteropServices.RuntimeInformation.OSDescription} ({System.Runtime.InteropServices.RuntimeInformation.OSArchitecture})";

            DeviceManager = new GraphicsDeviceManager(this)
            {
                PreferMultiSampling            = false,
                SynchronizeWithVerticalRetrace = false,
                GraphicsProfile = GraphicsProfile.Reach,
            };

            DeviceManager.PreparingDeviceSettings += (sender, args) =>
            {
                Gpu = args.GraphicsDeviceInformation.Adapter.Description;
                args.GraphicsDeviceInformation.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;
                DeviceManager.PreferMultiSampling = true;
            };

            Content = new StreamingContentManager(base.Services, "assets");
            //	Content.RootDirectory = "assets";

            IsFixedTimeStep = false;
            // graphics.ToggleFullScreen();

            this.Window.AllowUserResizing = true;

            this.Window.ClientSizeChanged += (sender, args) =>
            {
                if (DeviceManager.PreferredBackBufferWidth != Window.ClientBounds.Width ||
                    DeviceManager.PreferredBackBufferHeight != Window.ClientBounds.Height)
                {
                    if (DeviceManager.IsFullScreen)
                    {
                        DeviceManager.PreferredBackBufferWidth =
                            GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;

                        DeviceManager.PreferredBackBufferHeight =
                            GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                    }
                    else
                    {
                        DeviceManager.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                        DeviceManager.PreferredBackBufferHeight = Window.ClientBounds.Height;
                    }

                    DeviceManager.ApplyChanges();

                    //CefWindow.Size = new System.Drawing.Size(Window.ClientBounds.Width, Window.ClientBounds.Height);
                }
            };


            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                Converters = new List <JsonConverter>()
                {
                    new Texture2DJsonConverter(GraphicsDevice)
                },
                Formatting = Formatting.Indented
            };

            ServerTypeManager = new ServerTypeManager();
            PluginManager     = new PluginManager();

            Storage = new StorageSystem(LaunchSettings.WorkDir);
            Options = new OptionsProvider(Storage);

            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <Alex>(this);
            serviceCollection.AddSingleton <ContentManager>(Content);
            serviceCollection.AddSingleton <IStorageSystem>(Storage);
            serviceCollection.AddSingleton <IOptionsProvider>(Options);

            InitiatePluginSystem(serviceCollection);

            AudioEngine = new AudioEngine(Storage);

            ConfigureServices(serviceCollection);

            Services = serviceCollection.BuildServiceProvider();

            PluginManager.Setup(Services);

            PluginManager.LoadPlugins();

            ServerTypeManager.TryRegister("java", new JavaServerType(this));

            ServerTypeManager.TryRegister(
                "bedrock", new BedrockServerType(this, Services.GetService <XboxAuthService>()));

            UIThreadQueue = new ConcurrentQueue <Action>();

            FpsMonitor = new FpsMonitor();

            Resources = Services.GetRequiredService <ResourceManager>();

            // ThreadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount,
            //    ThreadType.Background, "Dedicated ThreadPool"));

            KeyboardInputListener.InstanceCreated += KeyboardInputCreated;

            TextureUtils.RenderThread        = Thread.CurrentThread;
            TextureUtils.QueueOnRenderThread = action => UIThreadQueue.Enqueue(action);
        }