Ejemplo n.º 1
0
        /// <summary>
        /// Gets called from OpenTK whenever it is time for an update
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void Update(object sender, FrameEventArgs e)
        {
            FrameCounter++;

            MemoryTracer.NextStage("Update Frame: " + FrameCounter);

            MemoryTracer.AddSubStage("Scene Update");
            CurrentScene?.Update((float)e.Time);
            MemoryTracer.NextStage("World Update");
            CurrentScene?.Update((float)e.Time);

            MemoryTracer.NextStage("Physics Update");
            PhysicsEngine.Update((float)e.Time);

            if (_changeScene)
            {
                MemoryTracer.NextStage("Scene Intialization");
                _changeScene = false;


                MemoryTracer.AddSubStage("Removing Old Scene");

                CurrentScene?._Destroy();

                CurrentScene?.DestroyScene(); //Call on destroy on the scene itself.

                MemoryTracer.NextStage("Removing World");

                CurrentScene?.RemoveDestroyedObjects();


                MemoryTracer.NextStage("Create New Scene");

                CurrentScene = (AbstractScene)Activator.CreateInstance(_nextScene);

                MemoryTracer.NextStage("Initialize New Scene");

                CurrentScene._initializeScene();

                MemoryTracer.ReturnFromSubStage();
            }


            //Cleanup
            MemoryTracer.NextStage("Clean up Destroyed Objects");
            CurrentScene?.RemoveDestroyedObjects();
            MemoryTracer.ReturnFromSubStage(); //Returning to root.
            //ResourceManager.ProcessDeleteQueue();
        }