diff --git a/Pulsarc/Pulsarc.cs b/Pulsarc/Pulsarc.cs index 2326130..4877935 100644 --- a/Pulsarc/Pulsarc.cs +++ b/Pulsarc/Pulsarc.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Pulsarc.UI; +using Pulsarc.UI.Screens; using Pulsarc.UI.Screens.Gameplay; using Pulsarc.UI.Screens.MainMenu; using Pulsarc.UI.Screens.SongSelect; @@ -107,6 +108,8 @@ internal class PulsarcGame : Game // Map Converting Flag private bool converting = false; + private PulsarcScreen lastScreen = null; + public PulsarcGame() { // Set up stored Data access @@ -219,8 +222,12 @@ protected override void UnloadContent() /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { + Thread.Yield(); + PulsarcTime.Update(); + CheckDiscord(); + cursor.SetPos(MouseManager.CurrentState.Position); // Temporary measure for converting intralism or osu!mania beatmaps @@ -255,6 +262,17 @@ protected override void Update(GameTime gameTime) base.Update(gameTime); } + private void CheckDiscord() + { + if (ScreenManager.Screens.Peek() != lastScreen) + { + PulsarcScreen currentScreen = (PulsarcScreen)ScreenManager.Screens.Peek(); + lastScreen = currentScreen; + + currentScreen.UpdateDiscord(); + } + } + /// /// This is called when the game should draw itself. /// diff --git a/Pulsarc/UI/Screens/Gameplay/GameplayEngine.cs b/Pulsarc/UI/Screens/Gameplay/GameplayEngine.cs index 2988e62..5723fdf 100644 --- a/Pulsarc/UI/Screens/Gameplay/GameplayEngine.cs +++ b/Pulsarc/UI/Screens/Gameplay/GameplayEngine.cs @@ -110,13 +110,6 @@ public class GameplayEngine : PulsarcScreen // Time distance (in ms) from which hitobjects are neither updated not drawn public int IgnoreTime { get; private set; } = 500; - public override string DiscordDetails => $"Playing Singleplayer"; - - public override string DiscordState => CurrentBeatmap.Title; - - //public override int DiscordTimer => CurrentBeatmap.Arcs[CurrentBeatmap.Arcs.Count -1].Time; - public override bool DiscordTimer => true; - /// /// The engine that handles the gameplay of Pulsarc. /// @@ -313,6 +306,7 @@ private void StartGameplay() { AudioManager.StartGamePlayer(); + GameplayEngine.Active = true; Pulsarc.DisplayCursor = false; } @@ -323,8 +317,6 @@ private void StartGameplay() /// The current GameTime public override void Update(GameTime gameTime) { - base.Update(gameTime); - // If not active, don't update. if (!Active) return; @@ -656,6 +648,7 @@ public void EndGameplay(bool save = false) ResultScreen next = new ResultScreen(Judgements, errors, scoreDisplay, maxCombo, Rate, 0, CurrentBeatmap, Background, !AutoPlay && save); Pulsarc.DisplayCursor = true; Reset(); + // Switch to results screen ScreenManager.RemoveScreen(true); ScreenManager.AddScreen(next); @@ -663,5 +656,10 @@ public void EndGameplay(bool save = false) // TODO: restart GC when out of gameplay GC.Collect(); } + + public override void UpdateDiscord() + { + PulsarcDiscord.SetStatus("Playing Singleplayer", CurrentBeatmap.Title); + } } } diff --git a/Pulsarc/UI/Screens/InProgressScreen.cs b/Pulsarc/UI/Screens/InProgressScreen.cs index 3cda647..3f8f0ed 100644 --- a/Pulsarc/UI/Screens/InProgressScreen.cs +++ b/Pulsarc/UI/Screens/InProgressScreen.cs @@ -13,9 +13,12 @@ public InProgressScreen() { View = new InProgressScreenView(this); } + public override void Init() { ScreenManager.RemoveScreen(); } + + public override void UpdateDiscord() { } } } diff --git a/Pulsarc/UI/Screens/MainMenu/Menu.cs b/Pulsarc/UI/Screens/MainMenu/Menu.cs index 7801b79..7dfd7ba 100644 --- a/Pulsarc/UI/Screens/MainMenu/Menu.cs +++ b/Pulsarc/UI/Screens/MainMenu/Menu.cs @@ -1,4 +1,6 @@ -using Wobble.Screens; +using Microsoft.Xna.Framework; +using Pulsarc.Utils; +using Wobble.Screens; namespace Pulsarc.UI.Screens.MainMenu { @@ -6,10 +8,23 @@ class Menu : PulsarcScreen { public override ScreenView View { get; protected set; } + private const string DISCORD_DETAILS = "In the menus"; + public Menu() { View = new MenuView(this); - DiscordDetails = "In the menus"; + PulsarcDiscord.SetStatus("", DISCORD_DETAILS); + } + + public override void Update(GameTime gameTime) + { + View?.Update(gameTime); + } + + public override void UpdateDiscord() + { + if (PulsarcDiscord.Presence.Details != DISCORD_DETAILS) + PulsarcDiscord.SetStatus("", DISCORD_DETAILS); } } } diff --git a/Pulsarc/UI/Screens/PulsarcScreen.cs b/Pulsarc/UI/Screens/PulsarcScreen.cs index b92db07..e48da7b 100644 --- a/Pulsarc/UI/Screens/PulsarcScreen.cs +++ b/Pulsarc/UI/Screens/PulsarcScreen.cs @@ -11,21 +11,11 @@ public abstract class PulsarcScreen : Screen { public bool Initialized { get; protected set; } = false; - public virtual string DiscordDetails { get; protected set; } = ""; - public virtual string DiscordState { get; protected set; } = ""; - public virtual bool DiscordTimer => false; - public virtual void Init() { Initialized = true; } - public override void Update(GameTime gameTime) - { - base.Update(gameTime); - - if (PulsarcDiscord.Presence.Details != DiscordDetails || PulsarcDiscord.Presence.State != DiscordState) - PulsarcDiscord.SetStatus(DiscordDetails, DiscordState, DiscordTimer); - } + public abstract void UpdateDiscord(); } } diff --git a/Pulsarc/UI/Screens/Quit/QuitScreen.cs b/Pulsarc/UI/Screens/Quit/QuitScreen.cs index 8d24bc0..dd8f4ed 100644 --- a/Pulsarc/UI/Screens/Quit/QuitScreen.cs +++ b/Pulsarc/UI/Screens/Quit/QuitScreen.cs @@ -20,5 +20,7 @@ public override void Init() Pulsarc.Exit(); Environment.Exit(0); } + + public override void UpdateDiscord() { } } } diff --git a/Pulsarc/UI/Screens/Result/ResultScreen.cs b/Pulsarc/UI/Screens/Result/ResultScreen.cs index c994340..5a94ccf 100644 --- a/Pulsarc/UI/Screens/Result/ResultScreen.cs +++ b/Pulsarc/UI/Screens/Result/ResultScreen.cs @@ -1,4 +1,5 @@ -using Pulsarc.Beatmaps; +using Microsoft.Xna.Framework; +using Pulsarc.Beatmaps; using Pulsarc.UI.Common; using Pulsarc.UI.Screens.Gameplay; using Pulsarc.Utils; @@ -34,6 +35,8 @@ class ResultScreen : PulsarcScreen // Whether or not a full combo was achieved. public bool FullCombo { get; private set; } + private ScoreData scoreData; + /// /// The screen that summarizes the last play. /// @@ -71,17 +74,24 @@ public ResultScreen(List judgements, List SortBeatmaps(List beatmaps, string sort, bool asce public override void Update(GameTime gameTime) { - base.Update(gameTime); - HandleKeyboardPresses(); HandleMouseInput(); View?.Update(gameTime); } + public override void UpdateDiscord() + { + PulsarcDiscord.SetStatus("", "Browsing Maps"); + } + private void HandleKeyboardPresses() { while (InputManager.KeyboardPresses.Count > 0) diff --git a/Pulsarc/Utils/AssetsManager.cs b/Pulsarc/Utils/AssetsManager.cs index e0006e7..e726a46 100644 --- a/Pulsarc/Utils/AssetsManager.cs +++ b/Pulsarc/Utils/AssetsManager.cs @@ -31,8 +31,11 @@ public static void Initialize(ContentManager content) public static Texture2D Load(string path) { - if (StoredTexture.ContainsKey(path) && StoredTexture[path].Value + textureExpireTimeMs > PulsarcTime.CurrentElapsedTime) - return StoredTexture[path].Key; + if (StoredTexture.ContainsKey(path)) + if (StoredTexture[path].Value + textureExpireTimeMs > PulsarcTime.CurrentElapsedTime) + return StoredTexture[path].Key; + else + StoredTexture.Remove(path); Texture2D newTexture = null; diff --git a/Pulsarc/Utils/InputManager.cs b/Pulsarc/Utils/InputManager.cs index f83afa1..28af088 100644 --- a/Pulsarc/Utils/InputManager.cs +++ b/Pulsarc/Utils/InputManager.cs @@ -40,6 +40,7 @@ static public void InputUpdater() while (running) { + Thread.Yield(); if (threadLimiterWatch.ElapsedMilliseconds >= 1) { threadLimiterWatch.Restart();