From 685d56894f837fd9739a7dc021adc9b13d56be00 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 31 Aug 2020 20:43:03 -0400 Subject: switch SGame back to callbacks Callbacks are simpler and more efficient in this case. --- src/SMAPI/Framework/SCore.cs | 13 ++++++------- src/SMAPI/Framework/SGame.cs | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3645fb9c..eedbfc64 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -258,15 +258,14 @@ namespace StardewModdingAPI.Framework eventManager: this.EventManager, modHooks: modHooks, multiplayer: multiplayer, - exitGameImmediately: this.ExitGameImmediately + exitGameImmediately: this.ExitGameImmediately, + + onGameContentLoaded: this.OnGameContentLoaded, + onGameUpdating: this.OnGameUpdating, + onGameExiting: this.OnGameExiting ); StardewValley.Program.gamePtr = this.Game; - // hook game events - this.Game.OnGameContentLoaded += this.OnLoadContent; - this.Game.OnGameUpdating += this.OnGameUpdating; - this.Game.OnGameExiting += this.OnGameExiting; - // apply game patches new GamePatcher(this.Monitor).Apply( new EventErrorPatch(this.LogManager.MonitorForGame), @@ -445,7 +444,7 @@ namespace StardewModdingAPI.Framework } /// Raised after the game finishes loading its initial content. - private void OnLoadContent() + private void OnGameContentLoaded() { // override map display device Game1.mapDisplayDevice = new SDisplayDevice(Game1.content, Game1.game1.GraphicsDevice); diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 9f8a07e6..ae2c028d 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -41,6 +41,15 @@ namespace StardewModdingAPI.Framework /// Immediately exit the game without saving. This should only be invoked when an irrecoverable fatal error happens that risks save corruption or game-breaking bugs. private readonly Action ExitGameImmediately; + /// Raised after the game finishes loading its initial content. + private readonly Action OnGameContentLoaded; + + /// Raised when the game is updating its state (roughly 60 times per second). + private readonly Action OnGameUpdating; + + /// Raised before the game exits. + private readonly Action OnGameExiting; + /********* ** Accessors @@ -58,15 +67,6 @@ namespace StardewModdingAPI.Framework /// This must be static because the game accesses it before the constructor is called. public static Func CreateContentManagerImpl; - /// Raised after the game finishes loading its initial content. - public event Action OnGameContentLoaded; - - /// Raised before the game exits. - public event Action OnGameExiting; - - /// Raised when the game is updating its state (roughly 60 times per second). - public event Action OnGameUpdating; - /********* ** Public methods @@ -78,7 +78,10 @@ namespace StardewModdingAPI.Framework /// Handles mod hooks provided by the game. /// The core multiplayer logic. /// Immediately exit the game without saving. This should only be invoked when an irrecoverable fatal error happens that risks save corruption or game-breaking bugs. - public SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action exitGameImmediately) + /// Raised after the game finishes loading its initial content. + /// Raised when the game is updating its state (roughly 60 times per second). + /// Raised before the game exits. + public SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action exitGameImmediately, Action onGameContentLoaded, Action onGameUpdating, Action onGameExiting) { // init XNA Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; @@ -94,6 +97,9 @@ namespace StardewModdingAPI.Framework this.Events = eventManager; this.Reflection = reflection; this.ExitGameImmediately = exitGameImmediately; + this.OnGameContentLoaded = onGameContentLoaded; + this.OnGameUpdating = onGameUpdating; + this.OnGameExiting = onGameExiting; } /// Get the observable location list. @@ -111,7 +117,7 @@ namespace StardewModdingAPI.Framework { base.LoadContent(); - this.OnGameContentLoaded?.Invoke(); + this.OnGameContentLoaded(); } /// Perform cleanup logic when the game exits. @@ -120,7 +126,7 @@ namespace StardewModdingAPI.Framework /// This overrides the logic in to let SMAPI clean up before exit. protected override void OnExiting(object sender, EventArgs args) { - this.OnGameExiting?.Invoke(); + this.OnGameExiting(); } /// Construct a content manager to read game content files. @@ -138,7 +144,7 @@ namespace StardewModdingAPI.Framework /// A snapshot of the game timing state. protected override void Update(GameTime gameTime) { - this.OnGameUpdating?.Invoke(gameTime, () => base.Update(gameTime)); + this.OnGameUpdating(gameTime, () => base.Update(gameTime)); } /// The method called to draw everything to the screen. -- cgit