Start() public method

public Start ( ) : void
return void
示例#1
0
        static void Main(string[] args)
        {
            var factory       = Platform.Start <IObjectFactory>();
            var extensibility = factory.Resolve <IExtensibilityProvider>();
            var plugins       = extensibility.FindPlugins <ServiceBase>();

            factory.RegisterTypes(plugins);
            var services =
                (from p in plugins
                 select factory.Resolve <ServiceBase>(p))
                .ToArray();

            if (services.Length == 0)
            {
                throw new ApplicationException("No services found");
            }
            if (args.Length == 1 && (args[0] == "-console" || args[0] == "/console"))
            {
                foreach (var s in services)
                {
                    Console.WriteLine(s.GetType());
                }
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                foreach (var s in services)
                {
                    s.Stop();
                }
            }
            else
            {
                ServiceBase.Run(new HostService(services));
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            foreach (var arg in args)
            {
                var i = arg.IndexOf('=');
                if (i != -1)
                {
                    var name  = arg.Substring(0, i);
                    var value = arg.Substring(i + 1);
                    ConfigurationManager.AppSettings[name] = value;
                }
            }
            var httpServer = ConfigurationManager.AppSettings["Revenj.HttpServer"];

            /*Platform.Container container;
             * if (!Enum.TryParse<Platform.Container>(ConfigurationManager.AppSettings["Revenj.Container"], out container))
             *      container = Platform.Container.Autofac;*/
            Console.WriteLine("Starting server");
            if (httpServer == "Socket")
            {
                var server = Platform.Start <HttpSocketServer>();               //container);
                server.Run();
            }
            else
            {
                var server = Platform.Start <HttpListenerServer>();               //container);
                server.Run();
            }
        }
示例#3
0
        public void LoadGeneralsMaps()
        {
            var rootFolder   = InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGenerals);
            var installation = new GameInstallation(new GeneralsDefinition(), rootFolder);
            var fileSystem   = installation.CreateFileSystem();

            var maps = fileSystem.GetFiles("maps").Where(x => x.FilePath.EndsWith(".map")).ToList();

            Platform.Start();

            using (var window = new GameWindow("OpenSAGE test runner", 100, 100, 800, 600, GraphicsBackend.Direct3D11))
            {
                using (var game = GameFactory.CreateGame(installation, fileSystem, GamePanel.FromGameWindow(window)))
                {
                    foreach (var map in maps)
                    {
                        _testOutputHelper.WriteLine($"Loading {map.FilePath}...");

                        var scene = game.ContentManager.Load <Scene3D>(map.FilePath);
                        Assert.NotNull(scene);

                        game.ContentManager.Unload();
                    }
                }
            }

            Platform.Stop();
        }
示例#4
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var register = new[] { typeof(RestApplication), typeof(SoapApplication), typeof(CommandConverter) };
            var logger   = Platform.Start <ILogFactory>(register);

            logger.Create("Revenj.Wcf").Info("Started at " + DateTime.Now);
        }
示例#5
0
        static void Main(string[] args)
        {
            var server = Platform.Start <HttpServer>();

            Console.WriteLine("Starting server");
            server.Run();
        }
示例#6
0
        public void LoadGeneralsMaps()
        {
            var rootFolder   = InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGenerals);
            var installation = new GameInstallation(new GeneralsDefinition(), rootFolder);

            Platform.Start();

            using (var game = new Game(installation, GraphicsBackend.Direct3D11))
            {
                var maps = game.ContentManager.FileSystem.GetFiles("maps").Where(x => x.FilePath.EndsWith(".map")).ToList();

                foreach (var map in maps)
                {
                    _testOutputHelper.WriteLine($"Loading {map.FilePath}...");

                    game.AssetStore.PushScope();

                    throw new System.NotImplementedException();

                    // TODO: Need to update to use new way of starting game.
                    //using (var scene = game.LoadMap(map.FilePath))
                    //{
                    //    Assert.NotNull(scene);
                    //}

                    game.AssetStore.PopScope();
                }
            }

            Platform.Stop();
        }
示例#7
0
        public SaveFileTests()
        {
            var rootFolder   = InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGenerals);
            var installation = new GameInstallation(new GeneralsDefinition(), rootFolder);

            Platform.Start();

            _game = new Game(installation, GraphicsBackend.Direct3D11);
        }
示例#8
0
        public GameFixture()
        {
            var rootFolder   = InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGenerals);
            var installation = new GameInstallation(new GeneralsDefinition(), rootFolder);

            Platform.Start();

            Game = new Game(installation);
        }
示例#9
0
        protected void Application_Start(object sender, EventArgs e)
        {
            /*Platform.Container container;
             * if (!Enum.TryParse<Platform.Container>(ConfigurationManager.AppSettings["Revenj.Container"], out container))
             *      container = Platform.Container.Autofac;*/
            var register = new[] { typeof(RestApplication), typeof(SoapApplication), typeof(CommandConverter) };

            Platform.Start <IServiceProvider>(register);
            TraceSource.TraceEvent(TraceEventType.Start, 1001);
        }
示例#10
0
        public override void FinishedLaunching(NSObject notification)
        {
            var appSettings = new AppSettings ("Blimey Engine Demo") {
                FullScreen = true,
                MouseGeneratesTouches = true
            };

            var entryPoint = new Demo ();
            var api = new Api ();

            platform = new Platform (api);
            platform.Start (appSettings, entryPoint);
        }
示例#11
0
        static void Main(string[] args)
        {
            Platform.Start();

            var rootPath = Launcher();

            if (rootPath != null)
            {
                GameWindowAdapter(rootPath);
            }

            Platform.Stop();
        }
示例#12
0
        static void Main(string[] args)
        {
            var httpServer = ConfigurationManager.AppSettings["Revenj.HttpServer"];

            try
            {
                foreach (var arg in args)
                {
                    var i = arg.IndexOf('=');
                    if (i != -1)
                    {
                        var name  = arg.Substring(0, i);
                        var value = arg.Substring(i + 1);
                        //TODO: Mono doesn't support changing app settings. Make exception for specifying web server
                        if (name == "Revenj.HttpServer")
                        {
                            httpServer = value;
                        }
                        else
                        {
                            ConfigurationManager.AppSettings[name] = value;
                        }
                    }
                }
            }
            catch (NotSupportedException ex)
            {
                throw new NotSupportedException(@"Mono has read only appSettings. 
They can't be changed in runtime via command line arguments.
Specify arguments in config file using <add key=... value=... />", ex);
            }
            Console.WriteLine("Starting server");
            if (httpServer == "Socket" || httpServer == "Revenj")
            {
                var server = Platform.Start <HttpSocketServer>();
                server.Run();
            }
            else
            {
                var server = Platform.Start <HttpListenerServer>();
                server.Run();
            }
        }
示例#13
0
        public static void Main( string[] args )
        {
            var appSettings = new AppSettings ("Blimey Engine Demo") {
                FullScreen = true,
                MouseGeneratesTouches = true
            };

            var entryPoint = new Demo();

            IApi api = new Api ();

            using (var platform = new Platform (api))
            {
                platform.Start (appSettings, entryPoint);

                (api as Api).Run ();

                platform.Stop ();
            }
        }
示例#14
0
    private static void Run(Options opts)
    {
        Platform.Start();

        var definition   = GameDefinition.FromGame(opts.SageGame);
        var installation = InstallationLocators.FindAllInstallations(definition).First();
        var game         = new Game(installation);

        // Read .sav file from binary file.
        using var stream = File.OpenRead(opts.SaveFilePath);
        SaveFile.LoadFromStream(stream, game);

        // Write .sav file to JSON.
        var outputPath = Path.ChangeExtension(opts.SaveFilePath, ".json");

        using var jsonWriter = new JsonSaveWriter(game, outputPath);
        SaveFile.Persist(jsonWriter);

        game.EndGame();

        Platform.Stop();
    }
示例#15
0
        static void Main(string[] args)
        {
            var address = ConfigurationManager.AppSettings["HttpAddress"];

            if (args.Length == 1)
            {
                address = args[0];
            }
            if (address == null && args.Length == 0)
            {
                Console.WriteLine("HttpAddress not defined in config and no address passed as command line argument");
                return;
            }
            var locator = Platform.Start();

            NotifyHub.Model = locator.Resolve <IDomainModel>();
            NotifyHub.ChangeNotification = locator.Resolve <IDataChangeNotification>();
            using (WebApp.Start <Startup>(address))
            {
                Console.WriteLine("SignalR started. Listening on " + address);
                Thread.Sleep(Timeout.Infinite);
            }
        }
示例#16
0
        protected void Application_Start(object sender, EventArgs e)
        {
            bool cd;

            if (bool.TryParse(ConfigurationManager.AppSettings["SignalR.CrossDomain"], out cd) && cd)
            {
                RouteTable.Routes.MapHubs(new HubConfiguration {
                    EnableCrossDomain = cd
                });
            }
            else
            {
                RouteTable.Routes.MapHubs();
            }
            int ct;

            if (int.TryParse(ConfigurationManager.AppSettings["SignalR.ConnectionTimeout"], out ct) && ct > 0)
            {
                GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(ct);
            }
            int dt;

            if (int.TryParse(ConfigurationManager.AppSettings["SignalR.DisconnectTimeout"], out dt) && dt > 0)
            {
                GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(dt);
            }
            int ka;

            if (int.TryParse(ConfigurationManager.AppSettings["SignalR.KeepAlive"], out ka) && ka > 0)
            {
                GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(ka);
            }
            var locator = Platform.Start <IServiceLocator>();

            NotifyHub.Model = locator.Resolve <IDomainModel>();
            NotifyHub.ChangeNotification = locator.Resolve <IDataChangeNotification>();
        }
示例#17
0
        public void LoadGeneralsMaps()
        {
            var rootFolder   = InstalledFilesTestData.GetInstallationDirectory(SageGame.CncGenerals);
            var installation = new GameInstallation(new GeneralsDefinition(), rootFolder);

            Platform.Start();

            using (var game = new Game(installation, GraphicsBackend.Direct3D11))
            {
                var maps = game.ContentManager.FileSystem.GetFiles("maps").Where(x => x.FilePath.EndsWith(".map")).ToList();

                foreach (var map in maps)
                {
                    _testOutputHelper.WriteLine($"Loading {map.FilePath}...");

                    var scene = game.ContentManager.Load <Scene3D>(map.FilePath);
                    Assert.NotNull(scene);

                    game.ContentManager.Unload();
                }
            }

            Platform.Stop();
        }
示例#18
0
        public static void Main(string[] args)
        {
            var             noShellMap       = false;
            var             definition       = GameDefinition.FromGame(SageGame.CncGenerals);
            string          mapName          = null;
            GraphicsBackend?preferredBackend = null;

            ArgumentSyntax.Parse(args, syntax =>
            {
                string preferredBackendString = null;
                syntax.DefineOption("renderer", ref preferredBackendString, false, $"Choose which renderer backend should be used. Valid options: {string.Join(",", Enum.GetNames(typeof(GraphicsBackend)))}");
                if (preferredBackendString != null)
                {
                    if (Enum.TryParse <GraphicsBackend>(preferredBackendString, out var preferredBackendTemp))
                    {
                        preferredBackend = preferredBackendTemp;
                    }
                    else
                    {
                        syntax.ReportError($"Unknown renderer backend: {preferredBackendString}");
                    }
                }

                syntax.DefineOption("noshellmap", ref noShellMap, false, "Disables loading the shell map, speeding up startup time.");

                string gameName    = null;
                var availableGames = string.Join(", ", GameDefinition.All.Select(def => def.Game.ToString()));

                syntax.DefineOption("game", ref gameName, false, $"Chooses which game to start. Valid options: {availableGames}");

                // If a game has been specified, make sure it's valid.
                if (gameName != null && !GameDefinition.TryGetByName(gameName, out definition))
                {
                    syntax.ReportError($"Unknown game: {gameName}");
                }

                syntax.DefineOption("map", ref mapName, false,
                                    "Immediately starts a new skirmish with default settings in the specified map. The map file must be specified with the full path.");
            });

            Platform.Start();

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            using (var window = new GameWindow("OpenSAGE (master)", 100, 100, 1024, 768, preferredBackend))
                using (var gamePanel = GamePanel.FromGameWindow(window))
                    using (var game = GameFactory.CreateGame(definition, gamePanel))
                    {
                        game.Configuration.LoadShellMap = !noShellMap;

                        if (mapName == null)
                        {
                            game.ShowMainMenu();
                        }
                        else
                        {
                            game.StartGame(mapName, new EchoConnection(), new[] { "America", "GLA" }, 0);
                        }

                        while (game.IsRunning)
                        {
                            if (!window.PumpEvents())
                            {
                                break;
                            }
                            game.Tick();
                        }

                        game.Dispose();
                    }

            Platform.Stop();
        }
示例#19
0
        public static void Run(Options opts)
        {
            var             definition       = GameDefinition.FromGame(opts.Game);
            GraphicsBackend?preferredBackend = null;

            var installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();

            if (installation == null)
            {
                Console.WriteLine($"OpenSAGE was unable to find any installations of {definition.DisplayName}.\n");

                Console.WriteLine("You can manually specify the installation path by setting the following environment variable:");
                Console.WriteLine($"\t{definition.Identifier.ToUpper()}_PATH=<installation path>\n");

                Console.WriteLine("OpenSAGE doesn't yet detect every released version of every game. Please report undetected versions to our GitHub page:");
                Console.WriteLine("\thttps://github.com/OpenSAGE/OpenSAGE/issues");

                Console.WriteLine("\n\n Press any key to exit.");

                Console.ReadLine();

                Environment.Exit(1);
            }

            if (opts.Renderer != Renderer.Default)
            {
                preferredBackend = (GraphicsBackend)opts.Renderer;
            }

            Platform.Start();

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            using (var window = new GameWindow("OpenSAGE (master)", 100, 100, 1024, 768, preferredBackend))
                using (var gamePanel = GamePanel.FromGameWindow(window))
                    using (var game = GameFactory.CreateGame(installation, installation.CreateFileSystem(), gamePanel))
                    {
                        window.GraphicsDevice.SyncToVerticalBlank = !opts.DisableVsync;

                        game.Configuration.LoadShellMap = !opts.NoShellmap;

                        if (opts.Map == null)
                        {
                            game.ShowMainMenu();
                        }
                        else
                        {
                            game.StartGame(opts.Map, new EchoConnection(), new[] { "America", "GLA" }, 0);
                        }

                        while (game.IsRunning)
                        {
                            if (!window.PumpEvents())
                            {
                                break;
                            }

                            game.Tick();
                        }
                    }

            Platform.Stop();
        }
示例#20
0
        public static void Run(Options opts)
        {
            logger.Info("Starting...");

            var DetectedGame = opts.Game;
            var GameFolder   = opts.GamePath;
            var UseLocators  = true;

            if (GameFolder == null)
            {
                GameFolder = Environment.CurrentDirectory;
            }

            foreach (var gameDef in GameDefinition.All)
            {
                if (gameDef.Probe(GameFolder))
                {
                    DetectedGame = gameDef.Game;
                    UseLocators  = false;
                }
            }

            var definition = GameDefinition.FromGame(DetectedGame);
            GameInstallation installation;

            if (UseLocators)
            {
                installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();
            }
            else
            {
                installation = new GameInstallation(definition, GameFolder);
            }

            if (installation == null)
            {
                Console.WriteLine($"OpenSAGE was unable to find any installations of {definition.DisplayName}.\n");

                Console.WriteLine("You can manually specify the installation path by setting the following environment variable:");
                Console.WriteLine($"\t{definition.Identifier.ToUpper()}_PATH=<installation path>\n");

                Console.WriteLine("OpenSAGE doesn't yet detect every released version of every game. Please report undetected versions to our GitHub page:");
                Console.WriteLine("\thttps://github.com/OpenSAGE/OpenSAGE/issues");

                Console.WriteLine("\n\n Press any key to exit.");

                Console.ReadLine();

                Environment.Exit(1);
            }

            logger.Debug($"Have installation of {definition.DisplayName}");

            Platform.Start();

            var traceEnabled = !string.IsNullOrEmpty(opts.TraceFile);

            if (traceEnabled)
            {
                GameTrace.Start(opts.TraceFile);
            }

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            var config = new Configuration()
            {
                UseFullscreen = opts.Fullscreen,
                UseRenderDoc  = opts.RenderDoc,
                LoadShellMap  = !opts.NoShellmap,
            };

            if (opts.LanIPAddress != "")
            {
                try {
                    config.LanIpAddress = IPAddress.Parse(opts.LanIPAddress);
                }catch (FormatException) {
                    logger.Error($"Could not parse specified LAN IP address: {opts.LanIPAddress}");
                }
            }

            logger.Debug($"Have configuration");

            using (var game = new Game(installation, opts.Renderer, config))
            {
                game.GraphicsDevice.SyncToVerticalBlank = !opts.DisableVsync;

                game.DeveloperModeEnabled = opts.DeveloperMode;

                if (opts.DeveloperMode)
                {
                    game.Window.Maximized = true;
                }

                if (opts.ReplayFile != null)
                {
                    var replayFile = game.ContentManager.UserDataFileSystem?.GetFile(Path.Combine("Replays", opts.ReplayFile));
                    if (replayFile == null)
                    {
                        logger.Debug("Could not find entry for Replay " + opts.ReplayFile);
                        game.ShowMainMenu();
                    }

                    game.LoadReplayFile(replayFile);
                }
                else if (opts.Map != null)
                {
                    game.Restart = StartMap;
                    StartMap();

                    void StartMap()
                    {
                        var mapCache = game.AssetStore.MapCaches.GetByName(opts.Map);

                        if (mapCache == null)
                        {
                            logger.Debug("Could not find MapCache entry for map " + opts.Map);
                            game.ShowMainMenu();
                        }
                        else if (mapCache.IsMultiplayer)
                        {
                            var pSettings = new PlayerSetting?[]
                            {
                                new PlayerSetting(null, game.AssetStore.PlayerTemplates.GetByName("FactionAmerica"), new ColorRgb(255, 0, 0), PlayerOwner.Player),
                                new PlayerSetting(null, game.AssetStore.PlayerTemplates.GetByName("FactionGLA"), new ColorRgb(0, 255, 0), PlayerOwner.EasyAi),
                            };

                            logger.Debug("Starting multiplayer game");

                            game.StartMultiPlayerGame(opts.Map,
                                                      new EchoConnection(),
                                                      pSettings,
                                                      0);
                        }
                        else
                        {
                            logger.Debug("Starting singleplayer game");

                            game.StartSinglePlayerGame(opts.Map);
                        }
                    }
                }
                else
                {
                    logger.Debug("Showing main menu");
                    game.ShowMainMenu();
                }

                logger.Debug("Starting game");

                game.Run();
            }

            if (traceEnabled)
            {
                GameTrace.Stop();
            }

            Platform.Stop();
        }
示例#21
0
        public static void Run(Options opts)
        {
            logger.Info("Starting...");

            var definition = GameDefinition.FromGame(opts.Game);

            var installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();

            if (installation == null)
            {
                Console.WriteLine($"OpenSAGE was unable to find any installations of {definition.DisplayName}.\n");

                Console.WriteLine("You can manually specify the installation path by setting the following environment variable:");
                Console.WriteLine($"\t{definition.Identifier.ToUpper()}_PATH=<installation path>\n");

                Console.WriteLine("OpenSAGE doesn't yet detect every released version of every game. Please report undetected versions to our GitHub page:");
                Console.WriteLine("\thttps://github.com/OpenSAGE/OpenSAGE/issues");

                Console.WriteLine("\n\n Press any key to exit.");

                Console.ReadLine();

                Environment.Exit(1);
            }

            logger.Debug($"Have installation of {definition.DisplayName}");

            Platform.Start();

            var traceEnabled = !string.IsNullOrEmpty(opts.TraceFile);

            if (traceEnabled)
            {
                GameTrace.Start(opts.TraceFile);
            }

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            var config = new Configuration()
            {
                UseFullscreen = opts.Fullscreen,
                UseRenderDoc  = opts.RenderDoc,
                LoadShellMap  = !opts.NoShellmap,
            };

            logger.Debug($"Have configuration");

            using (var game = new Game(installation, opts.Renderer, config))
            {
                game.GraphicsDevice.SyncToVerticalBlank = !opts.DisableVsync;

                game.DeveloperModeEnabled = opts.DeveloperMode;

                if (opts.ReplayFile != null)
                {
                    using (var fileSystem = new FileSystem(Path.Combine(game.UserDataFolder, "Replays")))
                    {
                        game.LoadReplayFile(fileSystem.GetFile(opts.ReplayFile));
                    }
                }
                else if (opts.Map != null)
                {
                    var pSettings = new PlayerSetting?[]
                    {
                        new PlayerSetting(null, "America", new ColorRgb(255, 0, 0)),
                        new PlayerSetting(null, "GLA", new ColorRgb(255, 255, 255)),
                    };

                    logger.Debug("Starting multiplayer game");
                    game.StartMultiPlayerGame(opts.Map,
                                              new EchoConnection(),
                                              pSettings,
                                              0);
                }
                else
                {
                    logger.Debug("Showing main menu");
                    game.ShowMainMenu();
                }

                logger.Debug("Starting game");

                game.Run();
            }

            if (traceEnabled)
            {
                GameTrace.Stop();
            }

            Platform.Stop();
        }
 public void BeforeEachTest()
 {
     app = platform.Start();
 }
示例#23
0
        public static void Main(string[] args)
        {
            var             noShellMap       = false;
            var             definition       = GameDefinition.FromGame(SageGame.CncGenerals);
            string          mapName          = null;
            GraphicsBackend?preferredBackend = null;

            ArgumentSyntax.Parse(args, syntax =>
            {
                string preferredBackendString = null;
                syntax.DefineOption("renderer", ref preferredBackendString, false, $"Choose which renderer backend should be used. Valid options: {string.Join(",", Enum.GetNames(typeof(GraphicsBackend)))}");
                if (preferredBackendString != null)
                {
                    if (Enum.TryParse <GraphicsBackend>(preferredBackendString, out var preferredBackendTemp))
                    {
                        preferredBackend = preferredBackendTemp;
                    }
                    else
                    {
                        syntax.ReportError($"Unknown renderer backend: {preferredBackendString}");
                    }
                }

                syntax.DefineOption("noshellmap", ref noShellMap, false, "Disables loading the shell map, speeding up startup time.");

                string gameName    = null;
                var availableGames = string.Join(", ", GameDefinition.All.Select(def => def.Game.ToString()));

                syntax.DefineOption("game", ref gameName, false, $"Chooses which game to start. Valid options: {availableGames}");

                // If a game has been specified, make sure it's valid.
                if (gameName != null && !GameDefinition.TryGetByName(gameName, out definition))
                {
                    syntax.ReportError($"Unknown game: {gameName}");
                }

                syntax.DefineOption("map", ref mapName, false,
                                    "Immediately starts a new skirmish with default settings in the specified map. The map file must be specified with the full path.");
            });

            var installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();

            if (installation == null)
            {
                Console.WriteLine($"OpenSAGE was unable to find any installations of {definition.DisplayName}.\n");

                Console.WriteLine("You can manually specify the installation path by setting the following environment variable:");
                Console.WriteLine($"\t{definition.Identifier.ToUpper()}_PATH=<installation path>\n");

                Console.WriteLine("OpenSAGE doesn't yet detect every released version of every game. Please report undetected versions to our GitHub page:");
                Console.WriteLine("\thttps://github.com/OpenSAGE/OpenSAGE/issues");

                Environment.Exit(1);
            }

            Platform.Start();

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            using (var window = new GameWindow("OpenSAGE (master)", 100, 100, 1024, 768, preferredBackend))
                using (var gamePanel = GamePanel.FromGameWindow(window))
                    using (var game = GameFactory.CreateGame(installation, installation.CreateFileSystem(), gamePanel))
                    {
                        game.Configuration.LoadShellMap = !noShellMap;

                        if (mapName == null)
                        {
                            game.ShowMainMenu();
                        }
                        else
                        {
                            game.StartGame(mapName, new EchoConnection(), new[] { "America", "GLA" }, 0);
                        }

                        while (game.IsRunning)
                        {
                            if (!window.PumpEvents())
                            {
                                break;
                            }

                            game.Tick();
                        }
                    }

            Platform.Stop();
        }
示例#24
0
        static void Main(string[] args)
        {
            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(100, 100, initialWidth, initialHeight, WindowState.Normal, "OpenSAGE Big Editor"),
                out var window,
                out var graphicsDevice);

            graphicsDevice.SyncToVerticalBlank = true;

            using (var commandList = graphicsDevice.ResourceFactory.CreateCommandList())
                using (var imGuiRenderer = new ImGuiRenderer(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                    using (var gameTimer = new GameTimer())
                    {
                        window.Resized += () =>
                        {
                            graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);
                            imGuiRenderer.WindowResized(window.Width, window.Height);
                        };

                        var windowOpen = true;
                        window.Closed += () => windowOpen = false;

                        gameTimer.Start();

                        using (var mainForm = new MainForm())
                        {
                            while (windowOpen)
                            {
                                commandList.Begin();

                                gameTimer.Update();

                                var inputSnapshot = window.PumpEvents();

                                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);

                                commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                imGuiRenderer.Update(
                                    (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                    inputSnapshot);

                                mainForm.Draw(window);

                                imGuiRenderer.Render(graphicsDevice, commandList);

                                commandList.End();

                                graphicsDevice.SubmitCommands(commandList);

                                graphicsDevice.SwapBuffers();
                            }
                        }
                    }

            graphicsDevice.Dispose();

            Platform.Stop();
        }
示例#25
0
        public static void Run(Options opts)
        {
            GraphicsBackend?preferredBackend = null;

            if (opts.Renderer != Renderer.Default)
            {
                preferredBackend = (GraphicsBackend)opts.Renderer;
            }

            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            using (var window = new GameWindow("OpenSAGE Viewer", 100, 100, initialWidth, initialHeight, preferredBackend))
                using (var commandList = window.GraphicsDevice.ResourceFactory.CreateCommandList())
                    using (var imGuiRenderer = new ImGuiRenderer(window.GraphicsDevice, window.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                        using (var gameTimer = new GameTimer())
                        {
                            window.ClientSizeChanged += (sender, e) =>
                            {
                                imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
                            };

                            gameTimer.Start();

                            using (var mainForm = new MainForm(window, imGuiRenderer))
                            {
                                var emptyInputSnapshot = new EmptyInputSnapshot();
                                var isGameViewFocused  = false;

                                while (true)
                                {
                                    commandList.Begin();

                                    gameTimer.Update();

                                    if (!window.PumpEvents())
                                    {
                                        break;
                                    }

                                    commandList.SetFramebuffer(window.GraphicsDevice.MainSwapchain.Framebuffer);

                                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                    if (isGameViewFocused)
                                    {
                                        if (window.CurrentInputSnapshot.KeyEvents.Any(x => x.Down && x.Key == Key.Escape))
                                        {
                                            isGameViewFocused = false;
                                        }
                                    }

                                    var inputSnapshot = isGameViewFocused
                            ? emptyInputSnapshot
                            : window.CurrentInputSnapshot;

                                    imGuiRenderer.Update(
                                        (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                        inputSnapshot);

                                    mainForm.Draw(ref isGameViewFocused);

                                    imGuiRenderer.Render(window.GraphicsDevice, commandList);

                                    commandList.End();

                                    window.GraphicsDevice.SubmitCommands(commandList);

                                    window.GraphicsDevice.SwapBuffers();
                                }
                            }
                        }

            Platform.Stop();
        }
示例#26
0
        static void Main(string[] args)
        {
            var httpServer = ConfigurationManager.AppSettings["Revenj.HttpServer"];

            try
            {
                foreach (var arg in args)
                {
                    var i = arg.IndexOf('=');
                    if (i != -1)
                    {
                        var name  = arg.Substring(0, i);
                        var value = arg.Substring(i + 1);
                        //TODO: Mono doesn't support changing app settings. Make exception for specifying web server
                        if (name == "Revenj.HttpServer")
                        {
                            httpServer = value;
                        }
                        else
                        {
                            ConfigurationManager.AppSettings[name] = value;
                        }
                    }
                }
            }
            catch (NotSupportedException ex)
            {
                throw new NotSupportedException(@"Mono has read only appSettings. 
They can't be changed in runtime via command line arguments.
Specify arguments in config file using <add key=... value=... />", ex);
            }

            /*Platform.Container container;
             * if (!Enum.TryParse<Platform.Container>(ConfigurationManager.AppSettings["Revenj.Container"], out container))
             *      container = Platform.Container.Autofac;*/
            Console.WriteLine("Starting server");
            if (httpServer == "Socket" || httpServer == "Revenj")
            {
                var server = Platform.Start <HttpSocketServer>();               //container);
                server.Run();
            }
            else
            {
                try
                {
                    var server = Platform.Start <HttpListenerServer>();                   //container);
                    server.Run();
                }
                catch (Exception ex)
                {
                    var tle = ex.InnerException as TypeLoadException;
                    if (tle != null && tle.TypeName == "System.Net.HttpListener")
                    {
                        throw new TypeLoadException(@"Unable to load HttpListener. 
Newer Mono versions (4.2+) have incompatible Mono.Security.
Either delete Mono.Security.dll from the Revenj folder so it can use Mono default one,
use an older Mono version (pre 4.2) or use Revenj builtin web server.
To run Revenj builtin web server add Revenj.HttpServer=Revenj to command line or add
	<add key=""Revenj.HttpServer"" value=""Socket""/>
to <appSettings>", ex.InnerException);
                    }
                    throw;
                }
            }
        }
示例#27
0
 public HttpService()
 {
     InitializeComponent();
     Locator = Platform.Start();
 }
示例#28
0
        public static void Run(Options opts)
        {
            logger.Info("Starting...");

            var DetectedGame = opts.Game;
            var GameFolder   = opts.GamePath;
            var UseLocators  = true;

            if (GameFolder == null)
            {
                GameFolder = Environment.CurrentDirectory;
            }

            foreach (var gameDef in GameDefinition.All)
            {
                if (gameDef.Probe(GameFolder))
                {
                    DetectedGame = gameDef.Game;
                    UseLocators  = false;
                }
            }

            var definition = GameDefinition.FromGame(DetectedGame);
            GameInstallation installation;

            if (UseLocators)
            {
                installation = GameInstallation
                               .FindAll(new[] { definition })
                               .FirstOrDefault();
            }
            else
            {
                installation = new GameInstallation(definition, GameFolder);
            }

            if (installation == null)
            {
                Console.WriteLine($"OpenSAGE was unable to find any installations of {definition.DisplayName}.\n");

                Console.WriteLine("You can manually specify the installation path by setting the following environment variable:");
                Console.WriteLine($"\t{definition.Identifier.ToUpper()}_PATH=<installation path>\n");

                Console.WriteLine("OpenSAGE doesn't yet detect every released version of every game. Please report undetected versions to our GitHub page:");
                Console.WriteLine("\thttps://github.com/OpenSAGE/OpenSAGE/issues");

                Console.WriteLine("\n\n Press any key to exit.");

                Console.ReadLine();

                Environment.Exit(1);
            }

            logger.Debug($"Have installation of {definition.DisplayName}");

            Platform.Start();

            var traceEnabled = !string.IsNullOrEmpty(opts.TraceFile);

            if (traceEnabled)
            {
                GameTrace.Start(opts.TraceFile);
            }

            // TODO: Read game version from assembly metadata or .git folder
            // TODO: Set window icon.
            var config = new Configuration()
            {
                UseRenderDoc   = opts.RenderDoc,
                LoadShellMap   = !opts.NoShellmap,
                UseUniquePorts = opts.UseUniquePorts
            };

            UPnP.InitializeAsync(TimeSpan.FromSeconds(10)).ContinueWith(_ => logger.Info($"UPnP status: {UPnP.Status}"));

            logger.Debug($"Have configuration");

            using (var window = new GameWindow($"OpenSAGE - {installation.Game.DisplayName} - master", 100, 100, 1024, 768, opts.Fullscreen))
                using (var game = new Game(installation, opts.Renderer, config, window))
                    using (var textureCopier = new TextureCopier(game, window.Swapchain.Framebuffer.OutputDescription))
                        using (var developerModeView = new DeveloperModeView(game, window))
                        {
                            game.GraphicsDevice.SyncToVerticalBlank = !opts.DisableVsync;

                            var developerModeEnabled = opts.DeveloperMode;

                            if (opts.DeveloperMode)
                            {
                                window.Maximized = true;
                            }

                            if (opts.ReplayFile != null)
                            {
                                var replayFile = game.ContentManager.UserDataFileSystem?.GetFile(Path.Combine("Replays", opts.ReplayFile));
                                if (replayFile == null)
                                {
                                    logger.Debug("Could not find entry for Replay " + opts.ReplayFile);
                                    game.ShowMainMenu();
                                }

                                game.LoadReplayFile(replayFile);
                            }
                            else if (opts.Map != null)
                            {
                                game.Restart = StartMap;
                                StartMap();

                                void StartMap()
                                {
                                    var mapCache = game.AssetStore.MapCaches.GetByName(opts.Map);

                                    if (mapCache == null)
                                    {
                                        logger.Debug("Could not find MapCache entry for map " + opts.Map);
                                        game.ShowMainMenu();
                                    }
                                    else if (mapCache.IsMultiplayer)
                                    {
                                        var pSettings = new PlayerSetting[]
                                        {
                                            new PlayerSetting(null, "FactionAmerica", new ColorRgb(255, 0, 0), 0, PlayerOwner.Player),
                                            new PlayerSetting(null, "FactionGLA", new ColorRgb(0, 255, 0), 0, PlayerOwner.EasyAi),
                                        };

                                        logger.Debug("Starting multiplayer game");

                                        game.StartSkirmishOrMultiPlayerGame(opts.Map,
                                                                            new EchoConnection(),
                                                                            pSettings,
                                                                            Environment.TickCount,
                                                                            false);
                                    }
                                    else
                                    {
                                        logger.Debug("Starting singleplayer game");

                                        game.StartSinglePlayerGame(opts.Map);
                                    }
                                }
                            }
                            else
                            {
                                logger.Debug("Showing main menu");
                                game.ShowMainMenu();
                            }

                            game.InputMessageBuffer.Handlers.Add(
                                new CallbackMessageHandler(
                                    HandlingPriority.Window,
                                    message =>
                            {
                                if (message.MessageType == InputMessageType.KeyDown && message.Value.Key == Key.Enter && (message.Value.Modifiers & ModifierKeys.Alt) != 0)
                                {
                                    window.Fullscreen = !window.Fullscreen;
                                    return(InputMessageResult.Handled);
                                }

                                if (message.MessageType == InputMessageType.KeyDown && message.Value.Key == Key.F11)
                                {
                                    developerModeEnabled = !developerModeEnabled;
                                    return(InputMessageResult.Handled);
                                }

                                return(InputMessageResult.NotHandled);
                            }));

                            logger.Debug("Starting game");

                            game.StartRun();

                            while (game.IsRunning)
                            {
                                if (!window.PumpEvents())
                                {
                                    break;
                                }

                                if (developerModeEnabled)
                                {
                                    developerModeView.Tick();
                                }
                                else
                                {
                                    game.Update(window.MessageQueue);

                                    game.Panel.EnsureFrame(window.ClientBounds);

                                    game.Render();

                                    textureCopier.Execute(
                                        game.Panel.Framebuffer.ColorTargets[0].Target,
                                        window.Swapchain.Framebuffer);
                                }

                                window.MessageQueue.Clear();

                                game.GraphicsDevice.SwapBuffers(window.Swapchain);
                            }
                        }

            if (traceEnabled)
            {
                GameTrace.Stop();
            }

            Platform.Stop();
        }
示例#29
0
        public static void Main(string[] args)
        {
            GraphicsBackend?preferredBackend = null;

            ArgumentSyntax.Parse(args, syntax =>
            {
                string preferredBackendString = null;
                syntax.DefineOption("renderer", ref preferredBackendString, false, $"Choose which renderer backend should be used. Valid options: {string.Join(",", Enum.GetNames(typeof(GraphicsBackend)))}");
                if (preferredBackendString != null)
                {
                    if (Enum.TryParse <GraphicsBackend>(preferredBackendString, out var preferredBackendTemp))
                    {
                        preferredBackend = preferredBackendTemp;
                    }
                    else
                    {
                        syntax.ReportError($"Unknown renderer backend: {preferredBackendString}");
                    }
                }
            });

            Platform.Start();

            const int initialWidth  = 1024;
            const int initialHeight = 768;

            using (var window = new GameWindow("OpenSAGE Viewer", 100, 100, initialWidth, initialHeight, preferredBackend))
                using (var commandList = window.GraphicsDevice.ResourceFactory.CreateCommandList())
                    using (var imGuiRenderer = new ImGuiRenderer(window.GraphicsDevice, window.GraphicsDevice.MainSwapchain.Framebuffer.OutputDescription, initialWidth, initialHeight))
                        using (var gameTimer = new GameTimer())
                        {
                            window.ClientSizeChanged += (sender, e) =>
                            {
                                imGuiRenderer.WindowResized(window.ClientBounds.Width, window.ClientBounds.Height);
                            };

                            gameTimer.Start();

                            using (var mainForm = new MainForm(window, imGuiRenderer))
                            {
                                var emptyInputSnapshot = new EmptyInputSnapshot();
                                var isGameViewFocused  = false;

                                while (true)
                                {
                                    commandList.Begin();

                                    gameTimer.Update();

                                    if (!window.PumpEvents())
                                    {
                                        break;
                                    }

                                    commandList.SetFramebuffer(window.GraphicsDevice.MainSwapchain.Framebuffer);

                                    commandList.ClearColorTarget(0, RgbaFloat.Clear);

                                    if (isGameViewFocused)
                                    {
                                        if (window.CurrentInputSnapshot.KeyEvents.Any(x => x.Down && x.Key == Key.Escape))
                                        {
                                            isGameViewFocused = false;
                                        }
                                    }

                                    var inputSnapshot = isGameViewFocused
                            ? emptyInputSnapshot
                            : window.CurrentInputSnapshot;

                                    imGuiRenderer.Update(
                                        (float)gameTimer.CurrentGameTime.ElapsedGameTime.TotalSeconds,
                                        inputSnapshot);

                                    mainForm.Draw(ref isGameViewFocused);

                                    imGuiRenderer.Render(window.GraphicsDevice, commandList);

                                    commandList.End();

                                    window.GraphicsDevice.SubmitCommands(commandList);

                                    window.GraphicsDevice.SwapBuffers();
                                }
                            }
                        }

            Platform.Stop();
        }