示例#1
0
文件: Program.cs 项目: wegylexy/XPLM
    public XPlugin() : base()
    {
        // e.g. check for API support
        if (Utilities.Versions.XPLMVersion < 303)
        {
            throw new NotSupportedException("TCAS override not supported.");
        }

        // Example: finds datarefs
        _overrideTcas = DataRef.Find("sim/operation/override/override_TCAS") !;
        DataRef
            bearing  = DataRef.Find("sim/cockpit2/tcas/indicators/relative_bearing_degs") !,
            distance = DataRef.Find("sim/cockpit2/tcas/indicators/relative_distance_mtrs") !,
            altitude = DataRef.Find("sim/cockpit2/tcas/indicators/relative_altitude_mtrs") !;

        // Example: registers my flight loop
        _myLoop = new FlightLoop(FlightLoopPhase.AfterFlightModel, (elapsedSinceLastCall, elapsedTimeSinceLastFlightLoop, counter) =>
        {
            // TODO: set number of planes
            var count           = 2;
            Span <float> values = stackalloc float[count];
            // TODO: set bearings
            bearing.AsFloatVector(0).Write(values);
            // TODO: set distances
            distance.AsFloatVector(0).Write(values);
            // TODO: set altitudes
            altitude.AsFloatVector(0).Write(values);
            // Schedules for one second later
            return(1);
        });
    }
示例#2
0
        protected override bool OnStart()
        {
            _flightLoop = FlightLoop.Create(FlightLoopPhaseType.BeforeFlightModel, InitSound);
            _flightLoop.Schedule(-1, false);

            Menu.PluginsMenu
            .AddItem("OpenAL Sample (Shared Context)", item =>
                     item.CreateSubMenu()
                     .AddItem("Play Sound", out _, PlaySound)
                     );

            return(true);
        }
示例#3
0
        protected override void OnStop()
        {
            // Cleanup: nuke our context if we have it.  This is hacky and bad - we should really destroy
            // our buffers and sources.  I have _no_ idea if OpenAL will leak memory.
            if (_context != null)
            {
                XPlane.Trace.WriteLine($"[OpenAL Sample] Deleting my context 0x{(ulong)_context.Handle:X8}");
                ALC.DestroyContext(_context);
                _context = default;
            }

            if (_device != null)
            {
                ALC.CloseDevice(_device);
                _device = default;
            }

            _flightLoop.Dispose();
            _flightLoop = null;

            Menu.PluginsMenu.Dispose();
        }
示例#4
0
        protected override unsafe void OnStop()
        {
            // Cleanup: nuke our context if we have it.  This is hacky and bad - we should really destroy
            // our buffers and sources.  I have _no_ idea if OpenAL will leak memory.
            if (_alc.GetCurrentContext() != null)
            {
                XPlane.Trace.WriteLine($"[OpenAL Sample] Deleting snd {_soundBuffer}");
                if (_soundSource != 0)
                {
                    _al.DeleteSource(_soundSource);
                    _soundSource = 0;
                }

                if (_soundBuffer != 0)
                {
                    _al.DeleteBuffer(_soundBuffer);
                    _soundBuffer = 0;
                }
            }

            if (_context != null)
            {
                XPlane.Trace.WriteLine($"[OpenAL Sample] Deleting my context 0x{((ulong)_context):X8}");
                _alc.MakeContextCurrent(null);
                _alc.DestroyContext(_context);
            }

            if (_device != null)
            {
                _alc.CloseDevice(_device);
            }

            _flightLoop.Dispose();
            _flightLoop = null;

            Menu.PluginsMenu.Dispose();
        }
示例#5
0
        protected override bool OnStart()
        {
            try
            {
                _al  = AL.GetApi();
                _alc = ALContext.GetApi();
            }
            catch (Exception ex)
            {
                XPlane.Trace.WriteLine($"[OpenAL Sample] Failed to initialize Open AL: " + ex);
                return(false);
            }

            _flightLoop = FlightLoop.Create(FlightLoopPhaseType.BeforeFlightModel, InitSound);
            _flightLoop.Schedule(-1, false);

            Menu.PluginsMenu
            .AddItem("OpenAL Sample (Private Context)", item =>
                     item.CreateSubMenu()
                     .AddItem("Play Sound", out _, PlaySound)
                     );

            return(true);
        }