diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-31 20:43:03 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-31 20:43:03 -0400 |
commit | 685d56894f837fd9739a7dc021adc9b13d56be00 (patch) | |
tree | 27bd3cf6601df59fc6236cc170baac0232903903 /src/SMAPI | |
parent | 828be405e11dd8bc7f8a3692d2c74517734f67a5 (diff) | |
download | SMAPI-685d56894f837fd9739a7dc021adc9b13d56be00.tar.gz SMAPI-685d56894f837fd9739a7dc021adc9b13d56be00.tar.bz2 SMAPI-685d56894f837fd9739a7dc021adc9b13d56be00.zip |
switch SGame back to callbacks
Callbacks are simpler and more efficient in this case.
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 13 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 32 |
2 files changed, 25 insertions, 20 deletions
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 } /// <summary>Raised after the game finishes loading its initial content.</summary> - 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 /// <summary>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.</summary> private readonly Action<string> ExitGameImmediately; + /// <summary>Raised after the game finishes loading its initial content.</summary> + private readonly Action OnGameContentLoaded; + + /// <summary>Raised when the game is updating its state (roughly 60 times per second).</summary> + private readonly Action<GameTime, Action> OnGameUpdating; + + /// <summary>Raised before the game exits.</summary> + private readonly Action OnGameExiting; + /********* ** Accessors @@ -58,15 +67,6 @@ namespace StardewModdingAPI.Framework /// <remarks>This must be static because the game accesses it before the <see cref="SGame"/> constructor is called.</remarks> public static Func<IServiceProvider, string, LocalizedContentManager> CreateContentManagerImpl; - /// <summary>Raised after the game finishes loading its initial content.</summary> - public event Action OnGameContentLoaded; - - /// <summary>Raised before the game exits.</summary> - public event Action OnGameExiting; - - /// <summary>Raised when the game is updating its state (roughly 60 times per second).</summary> - public event Action<GameTime, Action> OnGameUpdating; - /********* ** Public methods @@ -78,7 +78,10 @@ namespace StardewModdingAPI.Framework /// <param name="modHooks">Handles mod hooks provided by the game.</param> /// <param name="multiplayer">The core multiplayer logic.</param> /// <param name="exitGameImmediately">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.</param> - public SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action<string> exitGameImmediately) + /// <param name="onGameContentLoaded">Raised after the game finishes loading its initial content.</param> + /// <param name="onGameUpdating">Raised when the game is updating its state (roughly 60 times per second).</param> + /// <param name="onGameExiting">Raised before the game exits.</param> + public SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action<string> exitGameImmediately, Action onGameContentLoaded, Action<GameTime, 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; } /// <summary>Get the observable location list.</summary> @@ -111,7 +117,7 @@ namespace StardewModdingAPI.Framework { base.LoadContent(); - this.OnGameContentLoaded?.Invoke(); + this.OnGameContentLoaded(); } /// <summary>Perform cleanup logic when the game exits.</summary> @@ -120,7 +126,7 @@ namespace StardewModdingAPI.Framework /// <remarks>This overrides the logic in <see cref="Game1.exitEvent"/> to let SMAPI clean up before exit.</remarks> protected override void OnExiting(object sender, EventArgs args) { - this.OnGameExiting?.Invoke(); + this.OnGameExiting(); } /// <summary>Construct a content manager to read game content files.</summary> @@ -138,7 +144,7 @@ namespace StardewModdingAPI.Framework /// <param name="gameTime">A snapshot of the game timing state.</param> protected override void Update(GameTime gameTime) { - this.OnGameUpdating?.Invoke(gameTime, () => base.Update(gameTime)); + this.OnGameUpdating(gameTime, () => base.Update(gameTime)); } /// <summary>The method called to draw everything to the screen.</summary> |