/// <summary>
        /// Initializes a new instance of the <see cref="KinectHandler"/> class.
        /// </summary>
        /// <param name="Messenger">The Messenger which is used for thread- und component-synchronization.</param>
        /// <param name="performanceAnalyzer">The PerformanceAnalyzer which tracks the kinect's performance values.</param>
        public KinectHandler(
            SeeingSharpMessenger Messenger,
            PerformanceAnalyzer performanceAnalyzer)
        {
            if (!SeeingSharpApplication.IsInitialized) { return; }

            m_Messenger = Messenger;
            m_performanceAnalyzer = performanceAnalyzer;

            m_sensor = KinectSensor.GetDefault();
            if (m_sensor == null) { return; }

            m_sensor.IsAvailableChanged += OnSensor_IsAvailableChanged;
            m_sensor.Open();
        }
Beispiel #2
0
        /// <summary>
        /// Deregisters this scene from ApplicationMessaging logic.
        /// </summary>
        public void DeregisterMessaging()
        {
            if (this.CountViews > 0)
            {
                throw new SeeingSharpGraphicsException("Unable to deregister messaging as long this Scene is associated to a view!");
            }

            if (m_syncContext != null)
            {
                SynchronizationContext syncContext = m_syncContext;
                SeeingSharpMessenger   Messenger   = m_messenger;

                m_syncContext = null;
                Messenger.DiscardGlobalSynchronization();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Scene" /> class.
        /// </summary>
        /// <param name="name">The global name of this scene.</param>
        /// <param name="registerOnMessenger">
        /// Do register this scene for application messaging?
        /// If true, then the caller has to ensure that the name is only used once
        /// across the currently executed application.
        /// </param>
        public Scene(
            string name = "",
            bool registerOnMessenger = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = DEFAULT_SCENE_NAME;
            }
            this.Name = name;

            m_perFrameData = new CBPerFrame();

            m_transformMode2D     = Graphics2DTransformMode.Custom;
            m_customTransform2D   = Matrix3x2.Identity;
            m_virtualScreenSize2D = new Size2F();

            m_sceneLayers = new List <SceneLayer>();
            m_sceneLayers.Add(new SceneLayer(DEFAULT_LAYER_NAME, this));
            m_sceneLayersPublic = new ReadOnlyCollection <SceneLayer>(m_sceneLayers);

            m_drawing2DLayers = new List <Custom2DDrawingLayer>();

            m_sceneComponents = new SceneComponentFlyweight(this);

            m_asyncInvokesBeforeUpdate          = new ThreadSaveQueue <Action>();
            m_asyncInvokesUpdateBesideRendering = new ThreadSaveQueue <Action>();

            m_registeredResourceDicts = new IndexBasedDynamicCollection <ResourceDictionary>();
            m_registeredViews         = new IndexBasedDynamicCollection <ViewInformation>();
            m_renderParameters        = new IndexBasedDynamicCollection <SceneRenderParameters>();

            this.CachedUpdateState = new SceneRelatedUpdateState(this);

            // Try to initialize this scene object
            InitializeResourceDictionaries(false);

            // Register the scene for ApplicationMessaging
            if (registerOnMessenger)
            {
                m_syncContext = new SceneSynchronizationContext(this);
                m_messenger   = new SeeingSharpMessenger();
                m_messenger.ApplyForGlobalSynchronization(
                    SeeingSharpMessageThreadingBehavior.EnsureMainSyncContextOnSyncCalls,
                    this.Name,
                    m_syncContext);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes the UI environment.
        /// </summary>
        public void InitializeUIEnvironment()
        {
            // Get and check ui synchronization context
            m_uiSynchronizationContext = SynchronizationContext.Current;
            if ((m_uiSynchronizationContext == null) ||
                (m_uiSynchronizationContext.GetType() == typeof(SynchronizationContext)))
            {
                throw new InvalidOperationException("Unable to initialize RKApplication object: No valid UI SynchronizationContext found!");
            }

            // Create the UI messenger
            m_uiMessenger = new SeeingSharpMessenger();
            m_uiMessenger.ApplyForGlobalSynchronization(
                SeeingSharpMessageThreadingBehavior.EnsureMainSyncContextOnSyncCalls,
                SeeingSharpConstants.THREAD_NAME_GUI,
                m_uiSynchronizationContext);
        }
Beispiel #5
0
        public void Check_SceneMessenger_Registration_Deregistration()
        {
            Scene dummyScene = new Scene(
                name: "DummyScene",
                registerOnMessenger: true);

            try
            {
                Assert.True(SeeingSharpMessenger.CountGlobalMessengers == 1);
                Assert.True(SeeingSharpMessenger.GetByName("DummyScene") == dummyScene.Messenger);
            }
            finally
            {
                dummyScene.DeregisterMessaging();
            }

            Assert.True(SeeingSharpMessenger.CountGlobalMessengers == 0);
        }