From 0c76c568a4a031e5c4e39388f2f5ccde2181458a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 19 Sep 2023 17:04:28 -0700 Subject: [PATCH] document the Game class --- src/Game.cs | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Game.cs b/src/Game.cs index 183ddea7..4376ad0b 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -9,6 +9,12 @@ using System.Diagnostics; namespace MoonWorks { + /// + /// This class is your entry point into controlling your game.
+ /// It manages the main game loop and subsystems.
+ /// You should inherit this class and implement Update and Draw methods.
+ /// Then instantiate your Game subclass from your Program.Main method and call the Run method. + ///
public abstract class Game { public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100); @@ -33,8 +39,18 @@ namespace MoonWorks public AudioDevice AudioDevice { get; } public Inputs Inputs { get; } + /// + /// This Window is automatically created when your Game is instantiated. + /// public Window MainWindow { get; } + /// + /// Instantiates your Game. + /// + /// The parameters that will be used to create the MainWindow. + /// The frame limiter settings. + /// How often Game.Update will run in terms of ticks per second. + /// If true, enables extra debug checks. Should be turned off for release builds. public Game( WindowCreateInfo windowCreateInfo, FrameLimiterSettings frameLimiterSettings, @@ -77,6 +93,9 @@ namespace MoonWorks AudioDevice = new AudioDevice(); } + /// + /// Initiates the main game loop. Call this once from your Program.Main method. + /// public void Run() { MainWindow.Show(); @@ -106,6 +125,9 @@ namespace MoonWorks SDL.SDL_Quit(); } + /// + /// Updates the frame limiter settings. + /// public void SetFrameLimiter(FrameLimiterSettings settings) { FramerateCapped = settings.Mode == FrameLimiterMode.Capped; @@ -120,23 +142,42 @@ namespace MoonWorks } } + /// + /// Starts the game shutdown process. + /// public void Quit() { quit = true; } + /// + /// Will execute at the specified targetTimestep you provided when instantiating your Game class. + /// + /// protected abstract void Update(TimeSpan delta); + + /// + /// If the frame limiter mode is Capped, this will run at most Cap times per second.
+ /// Otherwise it will run as many times as possible. + ///
+ /// A value from 0-1 describing how "in-between" update ticks it is called. Useful for interpolation. protected abstract void Draw(double alpha); + + /// + /// You can optionally override this to perform cleanup tasks before the game quits. + /// protected virtual void Destroy() {} - // Called when a file is dropped on the game window. + /// + /// Called when a file is dropped on the game window. + /// protected virtual void DropFile(string filePath) {} - /* Required to distinguish between multiple files dropped at once - * vs multiple files dropped one at a time. - * - * Called once for every multi-file drop. - */ + /// + /// Required to distinguish between multiple files dropped at once + /// vs multiple files dropped one at a time. + /// Called once for every multi-file drop. + /// protected virtual void DropBegin() {} protected virtual void DropComplete() {}