예제 #1
0
        public unsafe XPFlightLoopHook(FlightLoopTime initialSchedule, FlightLoopDelegate loopDelegate)
        {
            m_loopDelegate = loopDelegate;
            m_hookDelegate = new XPLMFlightLoop_f(XPLMFlightHookCallback);

            PluginBridge.ApiFunctions.XPLMRegisterFlightLoopCallback(m_hookDelegate, initialSchedule.Time, inRefcon: null);
        }
예제 #2
0
        private FlightLoopTime TurnTheWheel(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"GraphicsTestPlugin: Entering TurnTheWheel flightloop");
            var(x, y, z) = m_api.Graphics.WorldToLocal(47.437644, 19.259498, 0);
            var res = m_probe.ProbeTerrainXYZ((float)x, 0, (float)z);

            m_api.Log.Log($"Probed terrain, got result {res.LocationY} with code {res.Result}");

            var(lat, lon, alt) = m_api.Graphics.LocalToWorld(res.LocationX, res.LocationY, res.LocationZ);

            int height = 0;

            foreach (var instance in m_testTugInstances)
            {
                instance.SetPosition(new XPDrawInfo((float)res.LocationX, (float)res.LocationY + (10 * height++), (float)res.LocationZ, (float)0, (float)0, (float)0),
                                     new float[] { m_tireAngle });
            }

            m_tireAngle++;
            if (m_tireAngle > 45)
            {
                m_tireAngle -= 90;
            }
            m_api.Log.Log($"GraphicsTestPlugin: Leaving TurnTheWheel flightloop");

            return(FlightLoopTime.FromCycles(1));
        }
예제 #3
0
        /// <summary>
        /// This is a hook that is called when the flight look starts to run,
        /// that is, when the simulator is fully loaded. Only then will <see cref="IXPlaneScenery.LookupObjects(string, float, float)"/>
        /// reasonable results, because the scenery indexes are loaded only after the
        /// plugins are started.  After the work is done the flight loop hook is
        /// disposed because we no longer need it.
        /// </summary>
        private FlightLoopTime SimLoaded(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"GraphicsTestPlugin: Entered SimLoaded flightloop (just called once)");

            m_api.Log.Log($"GraphicsTestPlugin: Loading objects with path {TUGPATH}");
            var tugs = m_api.Scenery.LookupObjects(TUGPATH, 0, 0);

            foreach (var p in tugs)
            {
                m_api.Log.Log($"GraphicsTestPlugin: Filename: {p}");
            }

            m_testTug          = m_api.Scenery.LoadObject(tugs.First());
            m_testTugInstances = Enumerable.Range(0, 10).Select(_ => m_api.Instance.Create(m_testTug, new string[]
            {
                "sim/graphics/animation/ground_traffic/tire_steer_deg"
            })).ToList();

            m_tireTurning = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), TurnTheWheel);

            m_api.Log.Log($"Loaded and still living, reference is {m_testTug}");
            m_firstFlightLoopHook.Dispose();
            m_firstFlightLoopHook = null;
            m_api.Log.Log($"GraphicsTestPlugin: Leaving SimLoaded flightloop");

            return(FlightLoopTime.Unscheduled);
        }
예제 #4
0
        private FlightLoopTime OnFlightLoopHook(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"LoggerPlugin: Hook(Now = {DateTime.Now.ToString("T")}, SinceLastCall = {elapsedTimeSinceLastCall.TotalSeconds}s, SinceLastLoop = {elapsedTimeSinceLastFlightLoop}s, Counter = {counter:000000})");
            LogDataRefs();
            m_api.Log.Log("");

            return(FlightLoopTime.FromSeconds(1.0f));
        }
예제 #5
0
        public GraphicsTestPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException(nameof(api));

            m_api.Log.Log("GraphicsTestPlugin: Displaytest started");
            m_drawingLoopHook = m_api.Display.RegisterDrawHook(DrawingHook, XPLMDrawingPhase.xplm_Phase_Airplanes, 0);
            m_flightLoopHook  = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), SimLoaded);
            m_api.Log.Log("GraphicsTestPlugin: And now create a probe");
            m_probe = m_api.Scenery.CreateProbe();
            m_api.Log.Log("GraphicsTestPlugin: Probe created");
        }
예제 #6
0
        public unsafe void SetInterval(FlightLoopTime time, bool relativeToNow)
        {
            if (m_inLoopDelegate)
            {
                throw new InvalidOperationException("Interval must not be set from within the loop delegate.  Change the interval within the loop delegate using the delegate's return value instead.");
            }

            PluginBridge.ApiFunctions.XPLMSetFlightLoopCallbackInterval(
                m_hookDelegate, time.Time, inRelativeToNow: relativeToNow ? 1 : 0, inRefcon: null
                );
        }
예제 #7
0
        private FlightLoopTime OnFlightLoopHook(TimeSpan elapsedTimeSinceLastCall, TimeSpan elapsedTimeSinceLastFlightLoop, int counter)
        {
            m_api.Log.Log($"LoggerPlugin: Hook(Now = {DateTime.Now.ToString("T")}, SinceLastCall = {elapsedTimeSinceLastCall.TotalSeconds}s, SinceLastLoop = {elapsedTimeSinceLastFlightLoop}s, Counter = {counter:000000})");
            LogDataRefs();
            m_api.Log.Log("ard_after_flight_hook_logdatarefs");
            var cmd = m_api.Commands.GetCommand("sim/GPS/g430n1_cdi");

            cmd.InvokeOnce();
            m_api.Log.Log("cmd_sent_sim / GPS / g430n1_cdi");

            return(FlightLoopTime.FromSeconds(1.0f));
        }
예제 #8
0
        public GraphicsTestPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException(nameof(api));

            m_api.Log.Log("GraphicsTestPlugin: Displaytest started");
            m_drawingLoopHook     = m_api.Display.RegisterDrawHook(DrawingHook, XPDrawingPhase.Airplanes, 0);
            m_firstFlightLoopHook = m_api.Processing.RegisterFlightLoopHook(FlightLoopTime.FromCycles(1), SimLoaded);
            m_api.Data.RegisterDataAccessor("BSUB/CounterDataRef",
                                            getDataf: () => 3);
            m_api.Log.Log("GraphicsTestPlugin: And now create a probe");
            m_probe = m_api.Scenery.CreateProbe();
            m_api.Log.Log("GraphicsTestPlugin: Probe created");
        }
예제 #9
0
        public LoggerPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException(nameof(api));

            m_api.Log.Log("LoggerPlugin: Started");

            m_api.ConfigChanged += OnConfigurationChanged;

            m_flightLoopHook = m_api.Processing.RegisterFlightLoopHook(
                FlightLoopTime.FromSeconds(1.0f), OnFlightLoopHook
                );

            ReloadDataRefs();
        }
예제 #10
0
        public LoggerPlugin(IXPlaneApi api)
        {
            m_api = api ?? throw new ArgumentNullException("api");

            m_api.Log.Log("LoggerPlugin: Started");

            m_api.ConfigChanged += OnConfigurationChanged;

            m_api.Messages.MessageReceived += Messages_MessageReceived;
            m_api.Messages.PlaneCrashed    += Messages_PlaneCrashed;
            m_api.Messages.PlaneLoaded     += Messages_PlaneLoaded;

            m_flightLoopHook = m_api.Processing.RegisterFlightLoopHook(
                FlightLoopTime.FromSeconds(1.0f), OnFlightLoopHook
                );

            ReloadDataRefs();
        }
예제 #11
0
 public IXPFlightLoopHook RegisterFlightLoopHook(FlightLoopTime initialSchedule, FlightLoopDelegate loopDelegate)
 {
     return(new XPFlightLoopHook(initialSchedule, loopDelegate));
 }