Exemplo n.º 1
0
        void InternalStartEHSI()
        {
            if (!startingEhsi && !EHSI.Running && Running && GameScene == KRPC.Client.Services.KRPC.GameScene.Flight && Vessel != null)
            {
                startingEhsi = true;
                Task task = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        var flight = Vessel.Flight(Vessel.SurfaceReferenceFrame);

                        flightstream = Connection.AddStream(() => flight.Heading);
                        flightstream.AddCallback((float h) => EHSI.FlightHeading = h);
                        flightstream.Start(false);

                        longitudestream = Connection.AddStream(() => flight.Longitude);
                        longitudestream.AddCallback((double l) => EHSI.Longitude = l);
                        longitudestream.Start(false);

                        altitudestream = Connection.AddStream(() => flight.MeanAltitude);
                        altitudestream.AddCallback((double a) => EHSI.MeanAltitude = a);
                        altitudestream.Start(false);

                        latitudestream = Connection.AddStream(() => flight.Latitude);
                        latitudestream.AddCallback((double l) =>
                        {
                            EHSI.Latitude = l;
                            try
                            {
                                EHSI.CalculateWaypoint();
                            }
                            catch (Exception ex)
                            {
                                Status = ex.Message;
                            }
                        });
                        latitudestream.Start();
                        EHSI.Running = true;
                    }
                    catch (Exception ex)
                    {
                        Status = ex.Message;
                    }
                    startingEhsi = false;
                });
                if (!task.Wait(10000))
                {
                    task.GetAwaiter();
                }
            }
        }
Exemplo n.º 2
0
        private int ConnectionBackgroundProcessor(BackgroundWorker bw, int a)
        {
            _logger.Info($"Beginning background connection handler");

            if (this.KSPManager is null)
            {
                _logger.Trace($"kspMgr was null, creating connection");

                var kspMgr = new KSPManager("KSPController", IPAddress.Parse("192.168.1.71"), _logger);

                if (!(kspMgr.Connection?.KRPC()?.GetStatus()?.Version is null))
                {
                    Stream<float> science = kspMgr.Connection.AddStream(() => kspMgr.Connection.SpaceCenter().Science);
                    Stream<double> funds = kspMgr.Connection.AddStream(() => kspMgr.Connection.SpaceCenter().Funds);
                    Stream<float> reputation = kspMgr.Connection.AddStream(() => kspMgr.Connection.SpaceCenter().Reputation);
                    Stream<GameScene> scene = kspMgr.Connection.AddStream(() => kspMgr.Connection.KRPC().CurrentGameScene);

                    int scienceTag = science.AddCallback((float x) => { UpdateScienceResourceLabel(Math.Round(x, 0).ToString()); });
                    int fundsTag = funds.AddCallback((double x) => { UpdateFundsResourceLabel(Math.Round(x, 0).ToString()); });
                    int reputationTag = reputation.AddCallback((float x) => { UpdateReputationResourceLabel(Math.Round(x, 0).ToString()); });
                    int sceneTag = scene.AddCallback((GameScene x) => { UpdateGameSceneLabel(x); UpdateButtons(); });

                    science.Start();
                    funds.Start();
                    reputation.Start();
                    scene.Start();

                    TouchScience(science, scienceTag);
                    TouchFunds(funds, fundsTag);
                    TouchReputation(reputation, reputationTag);
                    TouchGameScene(scene, sceneTag);

                    UpdateManager(kspMgr);
                    UpdateConnection(kspMgr.Connection);
                    UpdateConnectionLabel($"{kspMgr.Connection.KRPC().GetStatus().Version}");

                    UpdateButtons();
                }
            }
            return 0;
        }