Example #1
0
        protected override void Update(GameTime gameTime)
        {
            if (DoExit)
            {
                Exit();
            }

            if (!IsActive)
            {
                assets.Update(true);

                return;
            }

            if (input.keyboard.Down(Microsoft.Xna.Framework.Input.Keys.LeftControl) && input.keyboard.Pressed(Microsoft.Xna.Framework.Input.Keys.F))
            {
                windowManager.Fullscreen = !windowManager.Fullscreen;
            }

            if (input.keyboard.Pressed(Microsoft.Xna.Framework.Input.Keys.S))
            {
                StateSave();
            }

            if (input.keyboard.Pressed(Microsoft.Xna.Framework.Input.Keys.L))
            {
                StateLoad();
            }

            if (Scene != null)
            {
                if (world != null)
                {
                    drawSystem.OnUnload();

                    for (int i = 0; i < systems.Length; i++)
                    {
                        systems[i].OnUnload();
                    }
                }

                world?.Dispose();

                world = new World();

                drawSystem.Reset();

                for (int i = 0; i < systems.Length; i++)
                {
                    systems[i].Reset();
                }

                Scene.Load();

                Scene = null;

                drawSystem.OnLoad();

                for (int i = 0; i < systems.Length; i++)
                {
                    systems[i].OnLoad();
                }

                GC.Collect();
            }

            input.Update();

            for (int i = 0; i < systems.Length; i++)
            {
                systems[i].Update();
            }

            windowManager.Update();

            assets.Update();

            base.Update(gameTime);

            if (RemovedEntities.Count > 0)
            {
                for (int i = 0; i < RemovedEntities.Count; i++)
                {
                    RemovedEntities[i].Dispose();

                    RemovedEntities[i] = default;
                }
            }
        }