diff options
author | Zoryn <Zoryn4163@users.noreply.github.com> | 2016-03-23 04:25:07 -0400 |
---|---|---|
committer | Zoryn <Zoryn4163@users.noreply.github.com> | 2016-03-23 04:25:07 -0400 |
commit | afaf559f45ab4f6b0be289511b2b8130d112ebd8 (patch) | |
tree | e357d28971d3a32ae0949c72099681d20098d659 /StardewModdingAPI/Inheritance/SGame.cs | |
parent | 7076886f2c229db8c06f41dd29aa0bf7ac966dc2 (diff) | |
parent | e26db4415bf24f12c32841507b1a8a170cf6039c (diff) | |
download | SMAPI-afaf559f45ab4f6b0be289511b2b8130d112ebd8.tar.gz SMAPI-afaf559f45ab4f6b0be289511b2b8130d112ebd8.tar.bz2 SMAPI-afaf559f45ab4f6b0be289511b2b8130d112ebd8.zip |
Merge pull request #53 from Zoryn4163/master
config updates
Diffstat (limited to 'StardewModdingAPI/Inheritance/SGame.cs')
-rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 8ba76ed3..da6260be 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -29,16 +29,16 @@ namespace StardewModdingAPI.Inheritance public MouseState MStateNow { get; private set; }
public MouseState MStatePrior { get; private set; }
- public Keys[] CurrentlyPressedKeys { get; private set; }
- public Keys[] PreviouslyPressedKeys { get; private set; }
+ public Keys[] CurrentlyPressedKeys => KStateNow.GetPressedKeys();
+ public Keys[] PreviouslyPressedKeys => KStatePrior.GetPressedKeys();
public Keys[] FramePressedKeys
{
- get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
+ get { return CurrentlyPressedKeys.Except(PreviouslyPressedKeys).ToArray(); }
}
public Keys[] FrameReleasedKeys
{
- get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); }
+ get { return PreviouslyPressedKeys.Except(CurrentlyPressedKeys).ToArray(); }
}
public Buttons[][] PreviouslyPressedButtons;
@@ -180,6 +180,9 @@ namespace StardewModdingAPI.Inheritance private static SGame instance;
public static SGame Instance => instance;
+ public static float FramesPerSecond { get; private set; }
+ public static bool Debug { get; private set; }
+
public Farmer CurrentFarmer => player;
public SGame()
@@ -192,7 +195,6 @@ namespace StardewModdingAPI.Inheritance {
Log.Verbose("XNA Initialize");
ModItems = new Dictionary<Int32, SObject>();
- PreviouslyPressedKeys = new Keys[0];
PreviouslyPressedButtons = new Buttons[4][];
for (int i = 0; i < 4; ++i) PreviouslyPressedButtons[i] = new Buttons[0];
@@ -211,6 +213,11 @@ namespace StardewModdingAPI.Inheritance {
UpdateEventCalls();
+ if (FramePressedKeys.Contains(Keys.F3))
+ {
+ Debug = !Debug;
+ }
+
try
{
base.Update(gameTime);
@@ -250,8 +257,10 @@ namespace StardewModdingAPI.Inheritance if (CurrentUpdateTick >= 60)
CurrentUpdateTick = 0;
- PreviouslyPressedKeys = CurrentlyPressedKeys;
- for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ if (KStatePrior != KStateNow)
+ KStatePrior = KStateNow;
+
+ for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{
PreviouslyPressedButtons[(int)i] = GetButtonsDown(i);
}
@@ -259,8 +268,26 @@ namespace StardewModdingAPI.Inheritance protected override void Draw(GameTime gameTime)
{
- base.Draw(gameTime);
+ FramesPerSecond = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
+
+ try
+ {
+ base.Draw(gameTime);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("An error occured in the base draw loop: " + ex);
+ Console.ReadKey();
+ }
+
GraphicsEvents.InvokeDrawTick();
+
+ if (Debug)
+ {
+ spriteBatch.Begin();
+ spriteBatch.DrawString(dialogueFont, "FPS: " + FramesPerSecond, Vector2.Zero, Color.CornflowerBlue);
+ spriteBatch.End();
+ }
}
public static Int32 RegisterModItem(SObject modItem)
@@ -301,7 +328,6 @@ namespace StardewModdingAPI.Inheritance public void UpdateEventCalls()
{
KStateNow = Keyboard.GetState();
- CurrentlyPressedKeys = KStateNow.GetPressedKeys();
MStateNow = Mouse.GetState();
@@ -346,7 +372,6 @@ namespace StardewModdingAPI.Inheritance if (KStateNow != KStatePrior)
{
ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
- KStatePrior = KStateNow;
}
if (MStateNow != MStatePrior)
|