Пример #1
0
        protected override void OnLoaded()
        {
            if (this.visibilityStrategy == null)
            {
                this.visibilityStrategy = new DefaultRendererVisibilityStrategy();
            }

            if (this.serializeObj != null)
            {
                this.UnregisterManagerEvents();
                foreach (GameObject obj in this.serializeObj)
                {
                    obj.PerformSanitaryCheck();
                }
                foreach (GameObject obj in this.serializeObj)
                {
                    obj.ParentScene = this;
                    this.objectManager.AddObject(obj);
                    this.AddToManagers(obj);
                }
                this.RegisterManagerEvents();
                this.serializeObj = null;
            }

            base.OnLoaded();

            this.ApplyPrefabLinks();

            foreach (GameObject obj in this.objectManager.AllObjects)
            {
                obj.OnLoaded();
            }

            this.visibilityStrategy.Update();
        }
Пример #2
0
 private void UpdateVisibilityStrategy()
 {
     if (this.visibilityStrategy == null)
     {
         this.visibilityStrategy = new DefaultRendererVisibilityStrategy();
     }
     this.visibilityStrategy.Update(this.renderers.Cast <ICmpRenderer>());
 }
Пример #3
0
        /// <summary>
        /// Uses the specified <see cref="DrawDevice"/> to collect renderer drawcalls in the specified <see cref="Scene"/>.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="drawDevice"></param>
        /// <param name="pickingMap"></param>
        protected void CollectRendererDrawcalls(Scene scene, DrawDevice drawDevice)
        {
            //Profile.TimeCollectDrawcalls.BeginMeasure();
            try
            {
                // If no visibility groups are met, don't bother looking for renderers.
                // This is important to allow efficient drawcall injection with additional
                // "dummy" renderpasses. CamViewStates render their overlays by temporarily
                // adding 3 - 4 of these passes. Iterating over all objects again would be
                // devastating for performance and at the same time pointless.
                if ((drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
                {
                    return;
                }

                // Query renderers
                IRendererVisibilityStrategy visibilityStrategy = scene.VisibilityStrategy;
                if (visibilityStrategy == null)
                {
                    return;
                }

                //Profile.TimeQueryVisibleRenderers.BeginMeasure();

                if (this.collectRendererBuffer == null)
                {
                    this.collectRendererBuffer = new RawList <ICmpRenderer>();
                }
                this.collectRendererBuffer.Clear();

                visibilityStrategy.QueryVisibleRenderers(drawDevice, this.collectRendererBuffer);
                if (this.rendererFilter.Count > 0)
                {
                    this.collectRendererBuffer.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.rendererFilter.Count; i++)
                        {
                            if (!this.rendererFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                //Profile.TimeQueryVisibleRenderers.EndMeasure();

                this.OnCollectRendererDrawcalls(drawDevice, this.collectRendererBuffer, visibilityStrategy.IsRendererQuerySorted);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error while {0} was collecting renderer drawcalls: {1}", this, /*LogFormat.Exception(*/ e /*)*/);
            }
            //Profile.TimeCollectDrawcalls.EndMeasure();
        }
Пример #4
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;

            if (visibilityStrategy == null)
            {
                return;
            }
            IEnumerable <ICmpRenderer> rendererQuery = visibilityStrategy.QueryVisibleRenderers(this.drawDevice);

            if (this.editorRenderFilter.Count > 0)
            {
                rendererQuery = rendererQuery.Where(r =>
                {
                    for (int i = 0; i < this.editorRenderFilter.Count; i++)
                    {
                        if (!this.editorRenderFilter[i](r))
                        {
                            return(false);
                        }
                    }
                    return(true);
                });
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap = new List <ICmpRenderer>(rendererQuery);
                foreach (ICmpRenderer r in this.pickingMap)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                Profile.TimeCollectDrawcalls.BeginMeasure();

                foreach (ICmpRenderer r in rendererQuery)
                {
                    r.Draw(this.drawDevice);
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }
Пример #5
0
        protected override void OnLoaded()
        {
            if (this.visibilityStrategy == null)
            {
                this.visibilityStrategy = new DefaultRendererVisibilityStrategy();
            }

            if (this.serializeObj != null)
            {
                this.UnregisterManagerEvents();
                foreach (GameObject obj in this.serializeObj)
                {
                    obj.EnsureConsistentData();
                    obj.EnsureComponentOrder();
                }
                foreach (GameObject obj in this.serializeObj)
                {
                    obj.ParentScene = this;
                    this.objectManager.AddObject(obj);
                    this.AddToManagers(obj);
                }
                this.RegisterManagerEvents();
                this.serializeObj = null;
            }

            base.OnLoaded();

            this.ApplyPrefabLinks();

            // Initialize all loaded components, sorted by type
            List <ICmpInitializable> initList = this.FindComponents <ICmpInitializable>().ToList();

            for (int i = 0; i < initList.Count; i++)
            {
                initList[i].OnInit(Component.InitContext.Loaded);
            }

            this.visibilityStrategy.Update();
        }
Пример #6
0
 /// <summary>
 /// Set a custom visibility strategy for more efficient renderer culling.
 /// </summary>
 /// <param name="strategy"></param>
 public void SetRendererVisibilityStrategy(IRendererVisibilityStrategy strategy)
 {
     this.visibilityStrategy = strategy;
 }
Пример #7
0
        /// <summary>
        /// Creates a new, empty scene which does not contain any <see cref="GameObject">GameObjects</see>.
        /// </summary>
        public Scene()
        {
            this.RegisterManagerEvents();

            this.visibilityStrategy = new DefaultRendererVisibilityStrategy(renderers);
        }
Пример #8
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers.
            // This is important to allow efficient drawcall injection with additional
            // "dummy" renderpasses. CamViewStates render their overlays by temporarily
            // adding 3 - 4 of these passes. Iterating over all objects again would be
            // devastating for performance and at the same time pointless.
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;
            RawList <ICmpRenderer>      visibleRenderers;

            {
                if (visibilityStrategy == null)
                {
                    return;
                }
                Profile.TimeQueryVisibleRenderers.BeginMeasure();

                visibleRenderers = new RawList <ICmpRenderer>();
                visibilityStrategy.QueryVisibleRenderers(this.drawDevice, visibleRenderers);
                if (this.editorRenderFilter.Count > 0)
                {
                    visibleRenderers.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.editorRenderFilter.Count; i++)
                        {
                            if (!this.editorRenderFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                Profile.TimeQueryVisibleRenderers.EndMeasure();
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap.AddRange(visibleRenderers);
                foreach (ICmpRenderer r in visibleRenderers)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                bool profilePerType = visibilityStrategy.IsRendererQuerySorted;
                Profile.TimeCollectDrawcalls.BeginMeasure();

                Type           lastRendererType = null;
                Type           rendererType     = null;
                TimeCounter    activeProfiler   = null;
                ICmpRenderer[] data             = visibleRenderers.Data;
                for (int i = 0; i < data.Length; i++)
                {
                    if (i >= visibleRenderers.Count)
                    {
                        break;
                    }

                    // Manage profilers per Component type
                    if (profilePerType)
                    {
                        rendererType = data[i].GetType();
                        if (rendererType != lastRendererType)
                        {
                            if (activeProfiler != null)
                            {
                                activeProfiler.EndMeasure();
                            }
                            activeProfiler = Profile.RequestCounter <TimeCounter>(Profile.TimeCollectDrawcalls.FullName + @"\" + rendererType.Name);
                            activeProfiler.BeginMeasure();
                            lastRendererType = rendererType;
                        }
                    }

                    // Collect Drawcalls from this Component
                    data[i].Draw(this.drawDevice);
                }

                if (activeProfiler != null)
                {
                    activeProfiler.EndMeasure();
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }
Пример #9
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;
            RawList <ICmpRenderer>      visibleRenderers;

            {
                if (visibilityStrategy == null)
                {
                    return;
                }
                Profile.TimeQueryVisibleRenderers.BeginMeasure();

                visibleRenderers = new RawList <ICmpRenderer>();
                visibilityStrategy.QueryVisibleRenderers(this.drawDevice, visibleRenderers);
                if (this.editorRenderFilter.Count > 0)
                {
                    visibleRenderers.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.editorRenderFilter.Count; i++)
                        {
                            if (!this.editorRenderFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                Profile.TimeQueryVisibleRenderers.EndMeasure();
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap.AddRange(visibleRenderers);
                foreach (ICmpRenderer r in visibleRenderers)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                bool profilePerType = visibilityStrategy.IsRendererQuerySorted;
                Profile.TimeCollectDrawcalls.BeginMeasure();

                Type           lastRendererType = null;
                Type           rendererType     = null;
                TimeCounter    activeProfiler   = null;
                ICmpRenderer[] data             = visibleRenderers.Data;
                for (int i = 0; i < data.Length; i++)
                {
                    if (i >= visibleRenderers.Count)
                    {
                        break;
                    }

                    // Manage profilers per Component type
                    if (profilePerType)
                    {
                        rendererType = data[i].GetType();
                        if (rendererType != lastRendererType)
                        {
                            if (activeProfiler != null)
                            {
                                activeProfiler.EndMeasure();
                            }
                            activeProfiler = Profile.RequestCounter <TimeCounter>(Profile.TimeCollectDrawcalls.FullName + @"\" + rendererType.Name);
                            activeProfiler.BeginMeasure();
                            lastRendererType = rendererType;
                        }
                    }

                    // Collect Drawcalls from this Component
                    data[i].Draw(this.drawDevice);
                }

                if (activeProfiler != null)
                {
                    activeProfiler.EndMeasure();
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }