/// <summary>
        /// Executes the background action behind this item.
        /// </summary>
        public async Task Execute()
        {
            // Create PerformanceAnalyzer for kinect logic
            PerformanceAnalyzer performanceAnalyzer = new PerformanceAnalyzer(
                TimeSpan.FromMilliseconds(Constants.KINECT_PERF_VALUE_INTERVAL_MS),
                TimeSpan.FromMilliseconds(Constants.KINECT_PERF_CALC_INTERVAL_MS));
            performanceAnalyzer.GenerateCurrentValueCollection = true;
            performanceAnalyzer.GenerateHistoricalCollection = Constants.KINECT_PERF_HISTORICAL_VALUE_COUNT > 0;
            performanceAnalyzer.MaxCountHistoricalEntries = Constants.KINECT_PERF_HISTORICAL_VALUE_COUNT;
            performanceAnalyzer.RunAsync(CancellationToken.None)
                .FireAndForget();

            // Create and start the KinectHandler
            KinectThread kinectThread = new KinectThread(performanceAnalyzer);
            await kinectThread.StartAsync();

            // Register created objects
            SeeingSharpApplication.Current.RegisterSingleton(kinectThread);
            SeeingSharpApplication.Current.Singletons.RegisterSingleton(performanceAnalyzer, Constants.KINECT_PERF_ANALYZER_NAME);

            // Create other processing objects
            KinectRawStreamPresenter rawStreamProcessor = new KinectRawStreamPresenter();
            SeeingSharpApplication.Current.Singletons.RegisterSingleton(rawStreamProcessor);

            // Creates the main engagement model for this application
            HandOverheadEngagementModel customEngagementModel = new HandOverheadEngagementModel();
            SeeingSharpApplication.Current.RegisterService<IKinectEngagementManager>(customEngagementModel);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsCore"/> class.
        /// </summary>
        protected GraphicsCore(bool debugEnabled, bool force2DFallback)
        {
            try
            {
                // Upate RK.Common members
                m_debugEnabled                      = debugEnabled;
                m_force2DFallback                   = force2DFallback;
                m_devices                           = new List <EngineDevice>();
                m_performanceCalculator             = new PerformanceAnalyzer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(2.0));
                m_performanceCalculator.SyncContext = SynchronizationContext.Current; // <-- TODO
                m_performanceCalculator.RunAsync(CancellationToken.None)
                .FireAndForget();

                m_configuration = new GraphicsCoreConfiguration();
                m_configuration.DebugEnabled = debugEnabled;

                // Create container object for all input handlers
                m_inputHandlerFactory = new InputHandlerFactory();
                m_importExporters     = new ImporterExporterRepository();

                // Create the key generator for resource keys
                m_resourceKeyGenerator = new UniqueGenericKeyGenerator();

                // Try to initialize global api factories (mostly for 2D rendering / operations)
                try
                {
                    if (s_throwDeviceInitError)
                    {
                        throw new SeeingSharpException("Simulated device initialization exception");
                    }

                    m_factoryHandlerWIC     = new FactoryHandlerWIC();
                    m_factoryHandlerD2D     = new FactoryHandlerD2D(this);
                    m_factoryHandlerDWrite  = new FactoryHandlerDWrite(this);
                    m_factoryHandlerXAudio2 = new FactoryHandlerXAudio2();
                }
                catch (Exception ex)
                {
                    m_initException = ex;

                    m_devices.Clear();
                    m_factoryHandlerWIC     = null;
                    m_factoryHandlerD2D     = null;
                    m_factoryHandlerDWrite  = null;
                    m_factoryHandlerXAudio2 = null;
                    return;
                }
                this.FactoryD2D    = m_factoryHandlerD2D.Factory;
                this.FactoryD2D_2  = m_factoryHandlerD2D.Factory2;
                this.FactoryDWrite = m_factoryHandlerDWrite.Factory;
                this.FactoryWIC    = m_factoryHandlerWIC.Factory;
                this.XAudioDevice  = m_factoryHandlerXAudio2.Device;

                // Create the SoundManager
                m_soundManager = new SoundManager(m_factoryHandlerXAudio2);

                // Try to initialize Media Foundation interface
                // (This is a separated init step because MF may not be available on some systems, e. g. Servers)
                try
                {
                    m_factoryHandlerMF = new FactoryHandlerMF();
                }
                catch (Exception)
                {
                    m_factoryHandlerMF = null;
                }

                // Create the object containing all hardware information
                m_hardwareInfo = new EngineHardwareInfo();
                int actIndex = 0;
                foreach (var actAdapterInfo in m_hardwareInfo.Adapters)
                {
                    EngineDevice actEngineDevice = new EngineDevice(
                        this,
                        m_configuration,
                        actAdapterInfo.Adapter,
                        actAdapterInfo.IsSoftwareAdapter,
                        debugEnabled);
                    if (actEngineDevice.IsLoadedSuccessfully)
                    {
                        actEngineDevice.DeviceIndex = actIndex;
                        actIndex++;

                        m_devices.Add(actEngineDevice);
                    }
                }
                m_defaultDevice = m_devices.FirstOrDefault();

                // Start input gathering
                m_inputGatherer = new InputGathererThread();
                m_inputGatherer.Start();

                // Start main loop
                m_mainLoop = new EngineMainLoop(this);
                if (m_devices.Count > 0)
                {
                    m_mainLoopCancelTokenSource = new CancellationTokenSource();
                    m_mainLoopTask = m_mainLoop.Start(m_mainLoopCancelTokenSource.Token);
                }
            }
            catch (Exception ex2)
            {
                m_initException = ex2;

                m_hardwareInfo = null;
                m_devices.Clear();
                m_configuration        = null;
                m_resourceKeyGenerator = null;
            }
        }