Exemple #1
0
        internal static void CleanUp()
        {
            while (markedForDestruction.Count > 0)
            {
                UnityObject obj = markedForDestruction.Dequeue();
                objects.Remove(obj.GetInstanceID());

                if (obj is GameObject)
                {
                    (obj as GameObject).DoDestroy();
                }

                Component cmp = (obj as Component);
                if (cmp != null)
                {
                    if (cmp is Renderer)
                    {
                        Camera.RemoveRenderer(cmp as Renderer);
                    }

                    if (cmp is Camera)
                    {
                        Camera.RemoveCamera(cmp as Camera);
                    }

                    if (cmp.gameObject != null)
                    {
                        cmp.gameObject.RemoveComponent(cmp);
                    }

                    if (cmp is PressPlay.FFWD.Interfaces.IUpdateable)
                    {
                        PressPlay.FFWD.Interfaces.IUpdateable upd = cmp as PressPlay.FFWD.Interfaces.IUpdateable;
                        if (updateComponents.Contains(upd))
                        {
                            updateComponents.Remove(upd);
                        }
                        if (lateUpdateComponents.Contains(upd))
                        {
                            lateUpdateComponents.Remove(upd);
                        }
                    }

                    if (cmp is IFixedUpdateable)
                    {
                        if (fixedUpdateComponents.Contains(cmp as IFixedUpdateable))
                        {
                            fixedUpdateComponents.Remove(cmp as IFixedUpdateable);
                        }
                    }

                    if (cmp is MonoBehaviour)
                    {
                        if (guiComponents.Contains(cmp as MonoBehaviour))
                        {
                            guiComponents.Remove(cmp as MonoBehaviour);
                        }
                    }

                    for (int j = invokeCalls.Count - 1; j >= 0; j--)
                    {
                        if (invokeCalls[j].behaviour == cmp)
                        {
                            invokeCalls.RemoveAt(j);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            Time.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            Input.IsInDraw();

            hasDrawBeenCalled = true;

            frameCounter++;
#if DEBUG
            updateTime.Start();
#endif

            StartComponents();
            ChangeComponentActivity();
            int count = updateComponents.Count;
            for (int i = 0; i < count; i++)
            {
                PressPlay.FFWD.Interfaces.IUpdateable cmp = updateComponents[i];
                if (cmp.gameObject == null || !cmp.gameObject.active)
                {
                    continue;
                }
#if DEBUG && COMPONENT_PROFILE
                componentProfiler.StartUpdateCall(updateComponents[i] as Component);
#endif
                cmp.Update();

#if DEBUG && COMPONENT_PROFILE
                componentProfiler.EndUpdateCall();
#endif
            }
            ChangeComponentActivity();
            UpdateInvokeCalls();
            Animation.SampleAnimations();
#if DEBUG
            updateTime.Stop();
            lateUpdateTime.Start();
#endif
            StartComponents();
            ChangeComponentActivity();
            count = lateUpdateComponents.Count;
            for (int i = 0; i < count; i++)
            {
                Component c = lateUpdateComponents[i] as Component;
                if (c.gameObject != null && c.gameObject.active)
                {
                    lateUpdateComponents[i].LateUpdate();
                }
            }
            ChangeComponentActivity();
            CleanUp();
#if DEBUG
            lateUpdateTime.Stop();
            graphics.Start();
#endif
            Camera.Culling();
            Camera.DoRender(GraphicsDevice);
            ChangeComponentActivity();
            CleanUp();
#if DEBUG
            graphics.Stop();
            double total = fixedUpdateTime.Elapsed.TotalSeconds + lateUpdateTime.Elapsed.TotalSeconds + updateTime.Elapsed.TotalSeconds + graphics.Elapsed.TotalSeconds + physics.Elapsed.TotalSeconds;

#if COMPONENT_PROFILE
            componentProfiler.Sort();
            Debug.Display("GetWorst()", componentProfiler.GetWorst());
            componentProfiler.FlushData();
#endif
            if (ApplicationSettings.ShowRaycastTime)
            {
                Debug.Display("Raycasts ms", Application.raycastTimer.ElapsedMilliseconds);
                raycastTimer.Reset();
            }
            if (ApplicationSettings.ShowTurnOffTime)
            {
                Debug.Display("TurnOffTime ms", Application.turnOffTimer.ElapsedMilliseconds);
                turnOffTimer.Reset();
            }
            if (ApplicationSettings.ShowParticleAnimTime)
            {
                Debug.Display("Particle Anim ms", Application.particleAnimTimer.ElapsedMilliseconds);
                particleAnimTimer.Reset();
                Debug.Display("Particle Emit ms", Application.particleEmitTimer.ElapsedMilliseconds);
                particleEmitTimer.Reset();
                Debug.Display("Particle Draw ms", Application.particleDrawTimer.ElapsedMilliseconds);
                particleDrawTimer.Reset();
                Debug.Display("Particle Draw calls", Application.particleDraws);
                Application.particleDraws = 0;
            }
            if (ApplicationSettings.ShowTimeBetweenUpdates)
            {
                Debug.Display("TimeBetweenUpdates", timeUpdateEndUpdateStart.ElapsedMilliseconds);
                timeUpdateEndUpdateStart.Reset();
            }

            if (ApplicationSettings.ShowFPSCounter)
            {
                Debug.Display("FPS", String.Format("{0}, ms {1}, UR {2}", frameRate, frameTime.ElapsedMilliseconds, updateRate));
                //Debug.Display("frame time", frameTime.ElapsedMilliseconds);
                frameTime.Reset();
                frameTime.Start();
            }
            if (ApplicationSettings.ShowPerformanceBreakdown)
            {
                //Debug.Display("% S | P | G", String.Format("{0:P1} | {1:P1} | {2:P1}", scripts.Elapsed.TotalSeconds / total, physics.Elapsed.TotalSeconds / total, graphics.Elapsed.TotalSeconds / total));
                Debug.Display("ms U | P | G", String.Format("{0}ms | {1}ms | {2}ms", updateTime.Elapsed.Milliseconds + fixedUpdateTime.Elapsed.Milliseconds + lateUpdateTime.Elapsed.Milliseconds, physics.Elapsed.Milliseconds, graphics.Elapsed.Milliseconds));
                Debug.Display("Active comps U | F | L", String.Format("{0} | {1} | {2}", updateComponents.Count, fixedUpdateComponents.Count, lateUpdateComponents.Count));
            }
            if (ApplicationSettings.ShowDebugDisplays)
            {
                spriteBatch.Begin();
                Debug.DrawStrings(spriteBatch);
                spriteBatch.End();
            }
#if WINDOWS_PHONE
            if (ApplicationSettings.ShowPeakMemory)
            {
                Debug.Display("Peak memory", String.Format("{0:0.00}Mb", (float)Microsoft.Phone.Info.DeviceStatus.ApplicationPeakMemoryUsage / 1048576f));
            }
#endif

            updateTime.Reset();
            lateUpdateTime.Reset();
            fixedUpdateTime.Reset();
            physics.Reset();
            graphics.Reset();

            timeUpdateEndUpdateStart.Start(); //measure time from draw ended to beginning of Update, to try and measure graphics performance
#endif
            Input.ClearStates();
        }