Beispiel #1
0
 private unsafe int XPLMDrawHook(XPDrawingPhase inPhase, int inIsBefore, void *inRefcon)
 {
     try
     {
         var ret = m_loopDelegate(inPhase, inIsBefore);
         return(ret);
     }
     catch (Exception exc)
     {
         PluginBridge.Log.Log(exc);
         return(1);                // If an exception happens in the draw hook, then let X-Plane draw
     }
 }
Beispiel #2
0
        public unsafe XPDrawingLoopHook(DrawDelegate drawCallbackDelegate, XPDrawingPhase inPhase, int inWantsBefore)
        {
            m_loopDelegate  = drawCallbackDelegate;
            m_inPhase       = inPhase;
            m_inWantsBefore = inWantsBefore;
            m_hookDelegate  = new XPLMDrawCallback_f(XPLMDrawHook);

            var res = PluginBridge.ApiFunctions.XPLMRegisterDrawCallback(m_hookDelegate, m_inPhase, m_inWantsBefore, null);

            if (res == 0)
            {
                throw new ArgumentException($"Phase {m_inPhase} does not exist in this version of X-Plane");
            }
            else if (res > 1)
            {
                throw new Exception($"Unexpected return value {res}.");
            }
        }
Beispiel #3
0
        /// <summary>
        /// This hook is called for drawing an object. Be aware that this
        /// is a deprecated way of drawing, but we still support it as long
        /// as the SDK supports it.
        /// </summary>
        private int DrawingHook(XPDrawingPhase inPhase, int inIsBefore)
        {
            m_api.Log.Log("GraphicsTestPlugin: Entering drawing hook");

            var(x, y, z) = m_api.Graphics.WorldToLocal(47.439444, 19.261944, 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);
            var positions = Enumerable
                            .Range(0, 10)
                            .Select(i => new XPDrawInfo(res.LocationX, res.LocationY + i * 10, res.LocationZ, 0.0f, 0.0f, 0.0f))
                            .ToArray();

            m_testTug.Draw(0, 0, positions);

            m_api.Log.Log("GraphicsTestPlugin: Leaving drawing hook");
            return(1);
        }
Beispiel #4
0
 public IXPDrawingLoopHook RegisterDrawHook(DrawDelegate drawDelegate, XPDrawingPhase inPhase, int inWantsBefore)
 {
     return(new XPDrawingLoopHook(drawDelegate, inPhase, inWantsBefore));
 }