Пример #1
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            SimulationSession simulationSession;

            try
            {
                var persistedSimulation = _citySaveStateController
                                          .LoadFile(WebCityFileName);
                simulationSession =
                    new SimulationSession(new SimulationOptions(persistedSimulation,
                                                                new ProcessOptions(() => false, () => false)));
            }
            catch (Exception ex)
            {
                Logger.Instance.LogException(ex, $"Loading file: '{new FileInfo(WebCityFileName).FullName}'", 100);

                simulationSession = new SimulationSession(
                    new SimulationOptions(new Func <TerraformingOptions>(() =>
                {
                    var t             = new TerraformingOptions();
                    t.HorizontalRiver = t.VerticalRiver = true;
                    t.SetWoodlands(80);
                    t.SetLakes(30);
                    t.SetZoneWidthAndHeight(120);
                    return(t);
                })(), new ProcessOptions(() => false, () => false)));
            }
            simulationSession.StartSimulation();
            _gameServer = new GameServer(simulationSession, "http://+:80/", true);
            _gameServer.StartServer();
            return(Task.CompletedTask);
        }
Пример #2
0
 public void Start()
 {
     lock (_locker)
     {
         _graphicsManager.StartRendering();
         SimulationSession.StartSimulation();
     }
 }
Пример #3
0
        public static void Main()
        {
            Logger.Instance.OnLogMessage += Instance_OnLogMessage;

            HostFactory.Run(x =>
            {
                var citySaveStateController = new CitySaveStateController(z => { });

                SimulationSession simulationSession;

                try
                {
                    var persistedSimulation = citySaveStateController
                                              .LoadFile(WebCityFileName);
                    simulationSession =
                        new SimulationSession(new SimulationOptions(persistedSimulation,
                                                                    new ProcessOptions(() => false, () => false)));
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogException(ex, $"Loading file: '{new FileInfo(WebCityFileName).FullName}'", 100);

                    simulationSession = new SimulationSession(
                        new SimulationOptions(new Func <TerraformingOptions>(() =>
                    {
                        var t             = new TerraformingOptions();
                        t.HorizontalRiver = t.VerticalRiver = true;
                        t.SetWoodlands(80);
                        t.SetLakes(30);
                        t.SetZoneWidthAndHeight(120);
                        return(t);
                    })(), new ProcessOptions(() => false, () => false)));
                }

                x.Service <GameServer>(s =>
                {
                    s.ConstructUsing(name => new GameServer(simulationSession, "http://+:80/", true));
                    s.WhenStarted(tc =>
                    {
                        tc.StartServer();
                        simulationSession.StartSimulation();
                    });
                    s.WhenStopped(tc =>
                    {
                        citySaveStateController.SaveFile(WebCityFileName, tc.SimulationSession.GeneratePersistedArea());
                        tc.Dispose();
                    });
                });
                x.RunAsLocalSystem();

                x.SetDescription("Hosts the Urbanization web server on TCP Port 80 on all network devices. (For more information, see: https://github.com/Miragecoder/Urbanization)");
                x.SetDisplayName("Urbanization Web Server");
                x.SetServiceName("Urbanization");
            });
        }