Ejemplo n.º 1
0
        /// <summary>
        /// Triggers scene manipulation using the given lambda action.
        /// The action gets processed directly before scene update process.
        ///
        /// Be carefull: The action is called by worker-threads of SeeingSharp!
        /// </summary>
        /// <param name="manipulatorAction">The action which is able to manipulate the scene.</param>
        public Task ManipulateSceneAsync(Action <SceneManipulator> manipulatorAction)
        {
            manipulatorAction.EnsureNotNull(nameof(manipulatorAction));

            SceneManipulator manipulator = new SceneManipulator(this);

            return(this.PerformBeforeUpdateAsync(() =>
            {
                try
                {
                    manipulator.IsValid = true;
                    manipulatorAction(manipulator);
                }
                finally
                {
                    manipulator.IsValid = false;
                }
            }));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Detaches this component from a scene.
 /// Be careful, this method gets called from a background thread of seeing#!
 /// It may also be called from multiple scenes in parallel.
 /// </summary>
 /// <param name="manipulator">The manipulator of the scene we attach to.</param>
 /// <param name="correspondingView">The view which attached this component.</param>
 protected abstract void Detach(SceneManipulator manipulator, ViewInformation correspondingView);
Ejemplo n.º 3
0
 internal override void DetachInternal(SceneManipulator manipulator, ViewInformation correspondingView, object componentContext)
 {
     this.Detach(manipulator, correspondingView);
 }
Ejemplo n.º 4
0
 internal override object AttachInternal(SceneManipulator manipulator, ViewInformation correspondingView)
 {
     this.Attach(manipulator, correspondingView);
     return(null);
 }
        /// <summary>
        /// Internal method for updating all scene components.
        /// </summary>
        /// <param name="updateState">Current update state.</param>
        internal void UpdateSceneComponents(SceneRelatedUpdateState updateState)
        {
            // Update all components
            int attachedComponentsCount = m_attachedComponents.Count;

            for (int loop = 0; loop < attachedComponentsCount; loop++)
            {
                m_attachedComponents[loop].Component.UpdateInternal(
                    updateState,
                    m_attachedComponents[loop].CorrespondingView,
                    m_attachedComponents[loop].Context);
            }

            // Attach all components which are comming in
            SceneComponentRequest actRequest = default(SceneComponentRequest);
            int actIndex = 0;

            while (m_componentRequests.Dequeue(out actRequest))
            {
                SceneComponentInfo actComponent;
                int actComponentIndex = -1;
                switch (actRequest.RequestType)
                {
                case SceneComponentRequestType.Attach:
                    if (actRequest.Component == null)
                    {
                        continue;
                    }
                    if (TryGetAttachedComponent(
                            actRequest.Component, actRequest.CorrespondingView,
                            out actComponent, out actComponentIndex))
                    {
                        // We've already attached this component, so skip this request
                        continue;
                    }

                    // Trigger removing of all components with the same group like the new one
                    //  (new components replace old components with same group name)
                    if (!string.IsNullOrEmpty(actRequest.Component.ComponentGroup))
                    {
                        foreach (SceneComponentInfo actObsoleteComponent in GetExistingComponentsByGroup(
                                     actRequest.Component.ComponentGroup,
                                     actRequest.Component.IsViewSpecific ? actRequest.CorrespondingView : null))
                        {
                            m_componentRequests.Enqueue(new SceneComponentRequest()
                            {
                                RequestType       = SceneComponentRequestType.Detach,
                                Component         = actObsoleteComponent.Component,
                                CorrespondingView = actObsoleteComponent.CorrespondingView
                            });
                        }
                    }

                    SceneManipulator actManipulator = new SceneManipulator(m_owner);
                    actManipulator.IsValid = true;
                    try
                    {
                        SceneComponentInfo newRegisteredComponentInfo = new SceneComponentInfo();
                        newRegisteredComponentInfo.Component         = actRequest.Component;
                        newRegisteredComponentInfo.CorrespondingView = actRequest.CorrespondingView;
                        newRegisteredComponentInfo.Context           = actRequest.Component.AttachInternal(
                            actManipulator, actRequest.CorrespondingView);
                        actIndex++;

                        // Register the component on local list of attached ones
                        m_attachedComponents.Add(newRegisteredComponentInfo);
                    }
                    finally
                    {
                        actManipulator.IsValid = false;
                    }
                    break;

                case SceneComponentRequestType.Detach:
                    if (actRequest.Component == null)
                    {
                        continue;
                    }
                    if (!TryGetAttachedComponent(
                            actRequest.Component, actRequest.CorrespondingView,
                            out actComponent, out actComponentIndex))
                    {
                        // We don't have any component that is like the requested one
                        continue;
                    }

                    actManipulator         = new SceneManipulator(m_owner);
                    actManipulator.IsValid = true;
                    try
                    {
                        actComponent.Component.DetachInternal(
                            actManipulator, actComponent.CorrespondingView, actComponent.Context);

                        // Remove the component
                        m_attachedComponents.RemoveAt(actComponentIndex);
                    }
                    finally
                    {
                        actManipulator.IsValid = false;
                    }
                    break;

                case SceneComponentRequestType.DetachAll:
                    while (m_attachedComponents.Count > 0)
                    {
                        actManipulator         = new SceneManipulator(m_owner);
                        actManipulator.IsValid = true;
                        try
                        {
                            actComponent = m_attachedComponents[0];
                            actComponent.Component.DetachInternal(
                                actManipulator, actComponent.CorrespondingView, actComponent.Context);

                            // Remove the component
                            m_attachedComponents.RemoveAt(0);
                        }
                        finally
                        {
                            actManipulator.IsValid = false;
                        }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 6
0
 internal abstract void DetachInternal(SceneManipulator manipulator, ViewInformation correspondingView, object componentContext);
Ejemplo n.º 7
0
 internal abstract object AttachInternal(SceneManipulator manipulator, ViewInformation correspondingView);