Esempio n. 1
0
        /// <summary>
        /// Adds a new layer with the given name.
        /// </summary>
        /// <param name="name">Name of the layer.</param>
        internal SceneLayer AddLayer(string name)
        {
            name.EnsureNotNullOrEmpty(nameof(name));

            SceneLayer currentLayer = TryGetLayer(name);

            if (currentLayer != null)
            {
                throw new ArgumentException("There is already a SceneLayer with the given name!", "name");
            }

            // Create the new layer
            SceneLayer newLayer = new SceneLayer(name, this);

            newLayer.OrderID = m_sceneLayers.Max((actLayer) => actLayer.OrderID) + 1;
            m_sceneLayers.Add(newLayer);

            // Sort local layer list
            SortLayers();

            // Register all views on the newsly generated layer
            foreach (var actViewInfo in m_registeredViews)
            {
                newLayer.RegisterView(
                    m_registeredViews.IndexOf(actViewInfo),
                    actViewInfo,
                    m_registeredResourceDicts[actViewInfo.Device.DeviceIndex]);
            }

            return(newLayer);
        }
Esempio n. 2
0
        /// <summary>
        /// Deregisters the current scene and layer from this object.
        /// </summary>
        internal void ResetSceneAndLayer()
        {
            m_scene.EnsureNotNull(nameof(m_scene));
            m_sceneLayer.EnsureNotNull(nameof(m_sceneLayer));

            // Remember old scene
            Scene oldScene = m_scene;

            // Clear message subscriptions
            if (m_sceneMessageSubscriptions != null)
            {
                foreach (MessageSubscription actSubscription in m_sceneMessageSubscriptions)
                {
                    actSubscription.Unsubscribe();
                }
                m_sceneMessageSubscriptions = null;
            }

            // Clear references
            m_scene      = null;
            m_sceneLayer = null;

            // Call virtual event
            this.OnRemovedFromScene(oldScene);
        }
Esempio n. 3
0
        /// <summary>
        /// Clears the scene.
        /// </summary>
        /// <param name="clearResources">Clear all resources too?</param>
        internal void Clear(bool clearResources)
        {
            // Clear all layers
            for (int loop = 0; loop < m_sceneLayers.Count; loop++)
            {
                SceneLayer actLayer = m_sceneLayers[loop];
                actLayer.ClearObjects();

                if (actLayer.Name != DEFAULT_LAYER_NAME)
                {
                    m_sceneLayers.RemoveAt(loop);
                    loop--;
                }
            }

            // Clears all 2D drawing layers
            m_drawing2DLayers.Clear();

            // Clear all resources
            if (clearResources)
            {
                foreach (ResourceDictionary actDictionary in m_registeredResourceDicts)
                {
                    actDictionary.Clear();
                }
                m_renderParameters.Clear();

                for (int loop = 0; loop < m_sceneLayers.Count; loop++)
                {
                    SceneLayer actLayer = m_sceneLayers[loop];
                    actLayer.ClearResources();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Clears the layer with the given name.
        /// </summary>
        /// <param name="layerName">The name of the layer.</param>
        internal void ClearLayer(string layerName)
        {
            layerName.EnsureNotNullOrEmpty(nameof(layerName));

            SceneLayer layerToClear = GetLayer(layerName);

            ClearLayer(layerToClear);
        }
        /// <summary>
        /// Sets the order id of the given layer.
        /// </summary>
        /// <param name="layer">The name of the layer.</param>
        /// <param name="oderID">The order id to set.</param>
        public void SetLayerOrderID(string layer, int oderID)
        {
            CheckValid();

            SceneLayer layerObject = m_owner.GetLayer(layer);

            m_owner.SetLayerOrderID(layerObject, oderID);
        }
Esempio n. 6
0
        /// <summary>
        /// Removes the layer with the given name.
        /// </summary>
        /// <param name="layerName">Name of the layer.</param>
        internal void RemoveLayer(string layerName)
        {
            layerName.EnsureNotNullOrEmpty(nameof(layerName));

            SceneLayer layerToRemove = TryGetLayer(layerName);

            if (layerToRemove != null)
            {
                RemoveLayer(layerToRemove);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the layer with the given name.
        /// </summary>
        /// <param name="layerName">Name of the layer.</param>
        internal SceneLayer GetLayer(string layerName)
        {
            layerName.EnsureNotNullOrEmpty(nameof(layerName));

            SceneLayer result = TryGetLayer(layerName);

            if (result == null)
            {
                throw new ArgumentException($"Layer {layerName} not found!");
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Removes the given object from the scene.
        /// </summary>
        /// <param name="sceneObject">Object to remove.</param>
        /// <param name="layerName">Layer on wich the scene object was added.</param>
        internal void Remove(SceneObject sceneObject, string layerName)
        {
            sceneObject.EnsureNotNull(nameof(sceneObject));
            layerName.EnsureNotNullOrEmpty(nameof(layerName));

            SceneLayer layerObject = GetLayer(layerName);

            layerObject.RemoveObject(sceneObject);

            if (m_messenger != null)
            {
                m_messenger.Publish(new SceneObjectRemovedMessage(sceneObject));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Sets the order id of the given layer.
        /// </summary>
        /// <param name="layer">The layer to modify.</param>
        /// <param name="newOrderID">the new order id.</param>
        internal void SetLayerOrderID(SceneLayer layer, int newOrderID)
        {
            layer.EnsureNotNull(nameof(layer));

            if (!m_sceneLayers.Contains(layer))
            {
                throw new ArgumentException("This scene does not contain the given layer!");
            }

            // Change the order id
            layer.OrderID = newOrderID;

            // Sort local layer list
            this.SortLayers();
        }
Esempio n. 10
0
        /// <summary>
        /// Clears the given layer.
        /// </summary>
        /// <param name="layer">The layer to be cleared.</param>
        internal void ClearLayer(SceneLayer layer)
        {
            layer.EnsureNotNull(nameof(layer));

            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }
            if (layer.Scene != this)
            {
                throw new ArgumentException("Given layer does not belong to this scene!", "layer");
            }

            layer.ClearObjects();
        }
Esempio n. 11
0
        /// <summary>
        /// Called just before the update pass of a scene object starts.
        /// </summary>
        /// <param name="targetScene">The scene for which to prepare this state object</param>
        /// <param name="updateState">The update state.</param>
        /// <param name="inputFrames">A list containing all gathered InputFrames since last update pass.</param>
        internal void OnStartSceneUpdate(Scene targetScene, UpdateState updateState, IEnumerable <InputFrame> inputFrames)
        {
            targetScene.EnsureNotNull(nameof(targetScene));
            updateState.EnsureNotNull(nameof(updateState));

            m_isPaused         = targetScene.IsPaused;
            m_ignorePauseState = updateState.IgnorePauseState;

            m_world.ResetStackToIdentity();

            m_updateState = updateState;
            m_sceneLayer  = null;

            m_inputFrames = inputFrames;
            if (m_inputFrames == null)
            {
                m_inputFrames = DUMMY_FRAME_COLLECTION;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Registers the given scene and layer on this object.
        /// </summary>
        /// <param name="scene">The scene.</param>
        /// <param name="sceneLayer">The scene layer.</param>
        internal void SetSceneAndLayer(Scene scene, SceneLayer sceneLayer)
        {
            scene.EnsureNotNull(nameof(scene));
            sceneLayer.EnsureNotNull(nameof(sceneLayer));
            m_scene.EnsureNull(nameof(m_scene));
            m_sceneLayer.EnsureNull(nameof(m_sceneLayer));

            m_scene      = scene;
            m_sceneLayer = sceneLayer;

            // Register message handlers
            if (m_scene.Messenger != null)
            {
                m_sceneMessageSubscriptions = m_scene.Messenger.SubscribeAll(this);
            }

            // Call virtual event
            this.OnAddedToScene(m_scene);
        }
Esempio n. 13
0
        /// <summary>
        /// Adds the given object to the scene.
        /// </summary>
        /// <param name="sceneObject">Object to add.</param>
        /// <param name="layer">Layer on wich the object should be added.</param>
        internal T Add <T>(T sceneObject, string layer)
            where T : SceneObject
        {
            sceneObject.EnsureNotNull(nameof(sceneObject));
            layer.EnsureNotNullOrEmpty(nameof(layer));

            InitializeResourceDictionaries(true);

            SceneLayer layerObject = GetLayer(layer);

            if (!layerObject.AddObject(sceneObject))
            {
                return(null);
            }

            // Fire object added message
            if (m_messenger != null)
            {
                m_messenger.Publish(new SceneObjectAddedMessage(sceneObject));
            }

            return(sceneObject);
        }
Esempio n. 14
0
        /// <summary>
        /// Removes the given layer from the scene.
        /// </summary>
        /// <param name="layer">Layer to remove.</param>
        internal void RemoveLayer(SceneLayer layer)
        {
            layer.EnsureNotNull(nameof(layer));

            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }
            if (layer.Scene != this)
            {
                throw new ArgumentException("Given layer does not belong to this scene!", "layer");
            }
            if (layer.Name == DEFAULT_LAYER_NAME)
            {
                throw new ArgumentNullException("Unable to remove the default layer!", "layer");
            }

            layer.UnloadResources();
            m_sceneLayers.Remove(layer);

            // Sort local layer list
            SortLayers();
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewRelatedSceneLayerSubset" /> class.
        /// </summary>
        internal ViewRelatedSceneLayerSubset(SceneLayer sceneLayer, ViewInformation viewInformation, ResourceDictionary resources, int viewIndex)
        {
            m_scene           = sceneLayer.Scene;
            m_sceneLayer      = sceneLayer;
            m_viewInformation = viewInformation;
            m_device          = ViewInformation.Device;
            m_resources       = resources;
            ViewIndex         = viewIndex;

            m_invalidObjects             = new Dictionary <SceneObject, object>();
            m_invalidObjectsToDeregister = new Queue <SceneObject>();

            // Create temporary collections
            m_tmpChangedVisibilities = new List <Tuple <SceneObject, bool, bool> >();

            // Create all specialized render pass lists
            m_objectsPassPlainRender       = new PassSubscribionProperties();
            m_objectsPassLineRender        = new PassSubscribionProperties();
            m_objectsPassTransparentRender = new PassSubscribionProperties();
            m_objectsPassSpriteBatchRender = new PassSubscribionProperties();
            m_objectsPass2DOverlay         = new PassSubscribionProperties();

            // Create dictionary for fast access to all render pass list
            m_objectsPerPassDict = new Dictionary <RenderPassInfo, PassSubscribionProperties>();
            m_objectsPerPassDict[RenderPassInfo.PASS_PLAIN_RENDER]       = m_objectsPassPlainRender;
            m_objectsPerPassDict[RenderPassInfo.PASS_LINE_RENDER]        = m_objectsPassLineRender;
            m_objectsPerPassDict[RenderPassInfo.PASS_TRANSPARENT_RENDER] = m_objectsPassTransparentRender;
            m_objectsPerPassDict[RenderPassInfo.PASS_SPRITE_BATCH]       = m_objectsPassSpriteBatchRender;
            m_objectsPerPassDict[RenderPassInfo.PASS_2D_OVERLAY]         = m_objectsPass2DOverlay;
            m_objectsPerPass = new List <PassSubscribionProperties>(m_objectsPerPassDict.Values);

            m_anythingUnsubscribed = false;

            // Create and load all render pass relevant resources
            RefreshDeviceDependentResources();
        }
Esempio n. 16
0
        /// <summary>
        /// Clears the given layer.
        /// </summary>
        /// <param name="layer">The layer to be cleared.</param>
        public void ClearLayer(SceneLayer layer)
        {
            CheckValid();

            m_owner.ClearLayer(layer);
        }
Esempio n. 17
0
        /// <summary>
        /// Sets the order id of the given layer.
        /// </summary>
        /// <param name="layerObject">The layer object.</param>
        /// <param name="oderID">The order id to set.</param>
        public void SetLayerOrderID(SceneLayer layerObject, int oderID)
        {
            CheckValid();

            m_owner.SetLayerOrderID(layerObject, oderID);
        }
Esempio n. 18
0
        /// <summary>
        /// Removes the given layer from the scene.
        /// </summary>
        /// <param name="layer">Layer to remove.</param>
        public void RemoveLayer(SceneLayer layer)
        {
            CheckValid();

            m_owner.RemoveLayer(layer);
        }
Esempio n. 19
0
 /// <summary>
 /// Sets current environment data.
 /// </summary>
 /// <param name="layerToFilter">The SceneLayer that gets filtered.</param>
 /// <param name="viewInformation">The information object of the corresponding view.</param>
 public override void SetEnvironmentData(SceneLayer layerToFilter, ViewInformation viewInformation)
 {
     m_viewInfo        = viewInformation;
     m_boundingFrustum = viewInformation.CameraBoundingFrustum;
 }
Esempio n. 20
0
 /// <summary>
 /// Sets some informational data telling the filter where it is used.
 /// </summary>
 /// <param name="layerToFilter">The SceneLayer that gets filtered.</param>
 /// <param name="viewInformation">The information object of the corresponding view.</param>
 public virtual void SetEnvironmentData(SceneLayer layerToFilter, ViewInformation viewInformation)
 {
 }