BlizzCrafter / MonoGame.Forms

MonoGame.Forms is the easiest way of integrating a MonoGame render window into your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.
Other
287 stars 28 forks source link

Add properties to GameControl to control when the game loop should up… #35

Closed aszpreece closed 2 years ago

aszpreece commented 3 years ago

…date.

Hi, Big thanks for this great library. I had a need in my own project for windows to keep updating even when they are not visible (i.e you have a different tab selected) and i thought it'd be useful for others. I also needed to be able to control whether or not the game loop update code should be called. To implement both of these I added two property flags to GameControl: UpdateGameLoopWhenNotVisible (defaults to false for backwards compatability) and ShouldUpdateGameLoop (defaults to true). These do what you would expect. For testing, I modified your welcome page test with two check boxes. I had to move the animation update logic to the 'Update' method, but that is about the only change.

Thanks again!

BlizzCrafter commented 3 years ago

Hey @aszpreece and thank you very much for your PR!

I looked into it and i'm thinking that it is a desirable feature. I will be happy to merge, but I have a couple of questions and suggestions.

Suggestions:

Questions:

In that case it seems a bit redundant to have 2 properties for the same thing. Setting UpdateGameLoopWhenNotVisible to true or false on demand would be enough, but then the name of this property would be a bit missleading. I would suggest to rename this property to "ForceUpdate" or "ForceGameLoop".

Then it would look like this in the condition: if ((Visible || ForceUpdate)

The end user can then simply set ForceUpdate to true or false on demand - simple and clean.

What do you think about these changes? Would that work for you?

aszpreece commented 3 years ago

Hi @sqrMin1 Thanks for the response.

I agree with you about the test window. I had originally attempted to create a separate tab for the testing but I had some issues adding one with my IDE. If you are satisfied that the code is working correctly then I will be more than happy to remove the test code. The reasoning behind changing the animation code was so that the animation was only ever updated from the update loop and not the draw loop in order to demonstrate that the flags were working. I was under the impression that Draw was not called from the GameLoop timer code that I had modified, but this may have been a mistake. I will look into this again, but regardless we will be removing my changes to this anyway!

The reasoning behind two flags was that I had a need to be able to:

My thoughts behind the (possibly obtuse) naming was to make it clear that it only affected the GameLoop and not the draw.

I hope this clears up any confusion!