/// <summary> /// Tries the get information about a currently attached component. /// </summary> private bool TryGetAttachedComponent( SceneComponentBase component, ViewInformation correspondingView, out SceneComponentInfo componentInfo, out int componentIndex) { int attachedComponentCount = m_attachedComponents.Count; for (int loop = 0; loop < m_attachedComponents.Count; loop++) { if (component.IsViewSpecific) { if ((component == m_attachedComponents[loop].Component) && (correspondingView != null) && (correspondingView == m_attachedComponents[loop].CorrespondingView)) { componentInfo = m_attachedComponents[loop]; componentIndex = loop; return(true); } } else { if (component == m_attachedComponents[loop].Component) { componentInfo = m_attachedComponents[loop]; componentIndex = loop; return(true); } } } componentInfo = default(SceneComponentInfo); componentIndex = -1; return(false); }
/// <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; } } }