Exemplo n.º 1
0
        protected override void OnUpdate(float dt)
        {
            // Advance state
            m_timeInStage += dt;
            switch (m_stage)
            {
            case LoadStage.LoadingNewAssets:
            {
                // Start asset load
                if (m_loadTask == null)
                {
                    m_loadTask = StartLoad();
                }

                // Load some assets
                m_loadTask.LoadSome(new TimeSpan(250 * TimeSpan.TicksPerMillisecond));
                var loadProgress = (m_loadTask.Total > 0) ? ((float)m_loadTask.Loaded / (float)m_loadTask.Total) : 1.0f;
                SetProgress(loadProgress);

                // Continue
                if (m_loadTask.Remaining == 0)
                {
                    if (m_loadTask.Total > 0)
                    {
                        App.Log("Loaded {0} assets", m_loadTask.Total);
                    }
                    NextStage();
                }
                break;
            }

            case LoadStage.UnloadingOldAssets:
            {
                // Unload some assets
                var loaded = Assets.Count;
                Assets.UnloadUnsourced();
                if (loaded > Assets.Count)
                {
                    App.Log("Unloaded {0} assets", loaded - Assets.Count);
                }
                NextStage();
                break;
            }

            case LoadStage.LoadingAtlases:
            {
                TextureAtlas.Reload("models/tiles");
                NextStage();
                break;
            }

            case LoadStage.LoadingAnims:
            {
                LuaAnimation.ReloadAll();
                NextStage();
                break;
            }

            case LoadStage.Finalising:
            {
                Game.SelectLanguage();
                GC.Collect();
                NextStage();
                break;
            }

            case LoadStage.Animating:
            {
                // Loading is done. Make the robot blink
                m_widget.Texture = Texture.Get("gui/load_complete.png", true);
                if (m_timeInStage < 0.4f || m_timeInStage >= 0.55f)
                {
                    m_widget.Area = new Quad(0.0f, 0.0f, 0.5f, 1.0f);
                }
                else
                {
                    m_widget.Area = new Quad(0.5f, 0.0f, 0.5f, 1.0f);
                }
                if (m_timeInStage >= 1.0f)
                {
                    NextStage();
                }
                break;
            }

            default:
            {
                NextStage();
                break;
            }
            }
        }
Exemplo n.º 2
0
        protected override void OnUpdate(float dt)
        {
            if (m_justPressed >= 0)
            {
                m_justPressed = -1;
                UpdateColours();
            }

            // Update status text
            if (Visible)
            {
                m_statusText[0].String = string.Format("FPS: {0:F0}Hz Tris/Calls: {1}/{2}", App.FPS, RenderStats.Triangles, RenderStats.DrawCalls);

                var level = (m_game.CurrentState is LevelState) ? ((LevelState)m_game.CurrentState).LevelLoadPath : null;
                m_statusText[1].String = (level != null) ? level : "";

                var cameraTransInv = m_game.Camera.Transform;
                MathUtils.FastInvert(ref cameraTransInv);

                var cameraPos = Vector3.TransformPosition(Vector3.Zero, cameraTransInv);
                if (m_game.CurrentState is LevelState)
                {
                    var levelTransInv = ((LevelState)m_game.CurrentState).Level.Transform;
                    MathUtils.FastInvert(ref levelTransInv);
                    cameraPos = Vector3.TransformPosition(cameraPos, levelTransInv);
                }
                m_statusText[2].String = string.Format("{0:N2},{1:N2},{2:N2}", cameraPos.X, cameraPos.Y, cameraPos.Z);
            }

            // Update log
            if (Visible)
            {
                string[] log = App.RecentLog.ToArray();
                for (int i = 0; i < m_recentLogText.Length; ++i)
                {
                    var logIndex = i - (m_recentLogText.Length - log.Length);
                    if (logIndex >= 0)
                    {
                        var text  = log[logIndex];
                        var error = text.ToLowerInvariant().Contains("error");
                        m_recentLogText[i].String = text;
                        m_recentLogText[i].Colour = error ? UIColours.Important : UIColours.Text;
                    }
                    else
                    {
                        m_recentLogText[i].String = "";
                    }
                }
            }

            // Handle option selection
            if (Screen.Keyboard.Keys[Key.F1].Pressed)
            {
                Visible = !Visible;
                if (Visible)
                {
                    GC.Collect();
                }
                m_justPressed = 1;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F2].Pressed)
            {
                m_pendingScreenshot = m_game.QueueScreenshot();
                m_justPressed       = 2;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F3].Pressed)
            {
                m_game.RenderUI = !m_game.RenderUI;
                m_justPressed   = 3;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F4].Pressed)
            {
                m_game.UseDebugCamera = !m_game.UseDebugCamera;
                m_justPressed         = 4;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F5].Pressed)
            {
                App.Log("Reloading assets");
                Assets.ReloadAll();
                TextureAtlas.ReloadAll();
                LuaAnimation.ReloadAll();
                var state = m_game.CurrentState;
                if (state is LevelState)
                {
                    ((LevelState)state).OnReloadAssets();
                }
                GC.Collect();
                m_justPressed = 5;
                UpdateColours();
                App.Log("Assets reloaded", LogLevel.User);
            }
            if (Screen.Keyboard.Keys[Key.F6].Pressed)
            {
                if (m_game.Language.IsDebug)
                {
                    var desiredLanguageCode = m_game.Network.LocalUser.Language;
                    if (m_game.User.Settings.Language != "system")
                    {
                        desiredLanguageCode = m_game.User.Settings.Language;
                    }
                    m_game.Language = Language.GetMostSimilarTo(desiredLanguageCode);
                }
                else
                {
                    m_game.Language = Language.Get("languages/debug.lang");
                }
                var state = m_game.CurrentState;
                if (state is LevelState)
                {
                    ((LevelState)state).OnReloadAssets();
                }
                m_justPressed = 6;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F11].Pressed)
            {
                m_game.Window.Fullscreen        = !m_game.Window.Fullscreen;
                m_game.User.Settings.Fullscreen = m_game.Window.Fullscreen;
                m_game.User.Settings.Save();
                m_justPressed = 7;
                UpdateColours();
            }

            // Handle requested screenshots
            if (m_pendingScreenshot != null && m_pendingScreenshot.Status != Status.Waiting)
            {
                if (m_pendingScreenshot.Status == Status.Complete)
                {
                    var screenshot = m_pendingScreenshot.Result;
                    screenshot.Save(
                        Path.Combine(
                            App.SavePath,
                            Path.Combine("screenshots", DateTime.Now.ToString("s").Replace(":", "-") + ".png")
                            )
                        );
                    screenshot.Dispose();
                }
                m_pendingScreenshot = null;
            }
        }