Skip to content

Commit

Permalink
Merge branch 'MonoGame:develop' into patch-mgfx-error-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulaxin committed May 22, 2024
2 parents 19f8d7a + 11f34db commit 7ae787e
Show file tree
Hide file tree
Showing 56 changed files with 1,321 additions and 311 deletions.
2 changes: 1 addition & 1 deletion MonoGame.Framework/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public PlaneIntersectionType Intersects(Plane plane)
/// </param>
public void Intersects(ref Plane plane, out PlaneIntersectionType result)
{
// See http://zach.in.tu-clausthal.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html
// See https://cgvr.informatik.uni-bremen.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html

Vector3 positiveVertex;
Vector3 negativeVertex;
Expand Down
4 changes: 2 additions & 2 deletions MonoGame.Framework/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected virtual void Dispose(bool disposing)
/// <para>
/// Before a ContentManager can load an asset, you need to add the asset to your game project using
/// the steps described in
/// <see href="https://monogame.net/articles/content_pipeline/index.html">Adding Content - MonoGame</see>.
/// <see href="https://docs.monogame.net/articles/content_pipeline/index.html">Adding Content - MonoGame</see>.
/// </para>
/// </remarks>
/// <typeparam name="T">
Expand Down Expand Up @@ -299,7 +299,7 @@ public virtual T LoadLocalized<T> (string assetName)
/// <remarks>
/// Before a ContentManager can load an asset, you need to add the asset to your game project using
/// the steps described in
/// <see href="https://monogame.net/articles/content_pipeline/index.html">Adding Content - MonoGame</see>.
/// <see href="https://docs.monogame.net/articles/content_pipeline/index.html">Adding Content - MonoGame</see>.
/// </remarks>
/// <typeparam name="T">
/// <para>
Expand Down
21 changes: 21 additions & 0 deletions MonoGame.Framework/Content/ResourceContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@

namespace Microsoft.Xna.Framework.Content
{
/// <summary>
/// Subclass of <see cref="ContentManager"/>, which is specialized to read
/// from <i>.resx</i> resource files rather than directly from individual files on disk.
/// </summary>
public class ResourceContentManager : ContentManager
{
private ResourceManager resource;

/// <summary>
/// Creates a new instance of <see cref="ResourceContentManager"/>.
/// </summary>
/// <param name="servicesProvider">
/// The service provider the <b>ResourceContentManager</b> should use to locate services.
/// </param>
/// <param name="resource">The resource manager for the <b>ResourceContentManager</b> to read from.</param>
/// <exception cref="ArgumentNullException"><paramref name="resource"/> is <see langword="null"/>.</exception>
public ResourceContentManager(IServiceProvider servicesProvider, ResourceManager resource)
: base(servicesProvider)
{
Expand All @@ -19,6 +31,15 @@ public ResourceContentManager(IServiceProvider servicesProvider, ResourceManager
this.resource = resource;
}

/// <summary>
/// Opens a stream for reading the specified resource.
/// Derived classes can replace this to implement pack files or asset compression.
/// </summary>
/// <param name="assetName">The name of the asset being read.</param>
/// <exception cref="ContentLoadException">
/// Error loading <paramref name="assetName"/>.
/// The resource was not a binary resource, or the resource was not found.
/// </exception>
protected override System.IO.Stream OpenStream(string assetName)
{
object obj = this.resource.GetObject(assetName);
Expand Down
24 changes: 22 additions & 2 deletions MonoGame.Framework/DrawableGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
namespace Microsoft.Xna.Framework
{
/// <summary>
/// A <see cref="GameComponent"/> that is drawn when its <see cref="Game"/> is drawn.
/// A drawable object that, when added to the <see cref="Game.Components">Game.Components</see> collection of a
/// <see cref="Game"/> instance, will have it's <see cref="Draw(GameTime)">Draw(GameTime)</see> method called when
/// <see cref="Game.Draw(GameTime)">Game.Draw(GameTime)</see> is called.
/// </summary>
/// <remarks>
/// This inherits from <see cref="GameComponent"/> so it's <see cref="GameComponent.Update(GameTime)">Update(GameTime)</see>
/// method will also be called when <see cref="Game.Update(GameTime)">Game.Update(GameTime)</see> is called.
/// </remarks>
public class DrawableGameComponent : GameComponent, IDrawable
{
private bool _initialized;
Expand All @@ -21,9 +27,17 @@ public class DrawableGameComponent : GameComponent, IDrawable
/// </summary>
public Graphics.GraphicsDevice GraphicsDevice
{
get { return this.Game.GraphicsDevice; }
get { return this.Game.GraphicsDevice; }
}

/// <summary>
/// Gets the order in which this component should be drawn, relative to other components that are in the
/// same <see cref="GameComponentCollection"/>.
/// </summary>
/// <remarks>
/// This value can be any integer. Components in the <see cref="GameComponentCollection"/> are drawn in
/// ascending order based on their <b>DrawOrder</b>.
/// </remarks>
public int DrawOrder
{
get { return _drawOrder; }
Expand All @@ -37,6 +51,10 @@ public int DrawOrder
}
}

/// <summary>
/// Gets or Sets a value that indicates whether the <see cref="Draw(GameTime)"/> method of this component
/// should be called.
/// </summary>
public bool Visible
{
get { return _visible; }
Expand Down Expand Up @@ -65,6 +83,7 @@ public DrawableGameComponent(Game game)
{
}

/// <inheritdoc />
public override void Initialize()
{
if (!_initialized)
Expand All @@ -74,6 +93,7 @@ public override void Initialize()
}
}

/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (!_disposed)
Expand Down
15 changes: 15 additions & 0 deletions MonoGame.Framework/ExitingEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Microsoft.Xna.Framework
{
/// <summary>
/// Event arguments for <see cref="Game.Exiting"/>.
/// </summary>
public class ExitingEventArgs : EventArgs
{
/// <summary>
/// Set to <c>true</c> to cancel closing the game.
/// </summary>
public bool Cancel { get; set; }
}
}
54 changes: 30 additions & 24 deletions MonoGame.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public Game()

}

/// <summary/>
~Game()
{
Dispose(false);
Expand All @@ -101,13 +102,15 @@ internal void Log(string Message)
#region IDisposable Implementation

private bool _isDisposed;
/// <inheritdoc cref="IDisposable.Dispose()"/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
EventHelpers.Raise(this, Disposed, EventArgs.Empty);
}

/// <summary/>
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
Expand Down Expand Up @@ -193,6 +196,9 @@ public GameComponentCollection Components
get { return _components; }
}

/// <summary>
/// Gets or sets time to sleep between frames when the game is not active
/// </summary>
public TimeSpan InactiveSleepTime
{
get { return _inactiveSleepTime; }
Expand Down Expand Up @@ -374,7 +380,7 @@ internal bool Initialized
/// <summary>
/// Raised when this game is exiting.
/// </summary>
public event EventHandler<EventArgs> Exiting;
public event EventHandler<ExitingEventArgs> Exiting;

#if WINDOWS_UAP
[CLSCompliant(false)]
Expand Down Expand Up @@ -402,11 +408,11 @@ public void Exit()
/// </summary>
public void ResetElapsedTime()
{
Platform.ResetElapsedTime();
if (_gameTimer != null)
{
_gameTimer.Reset();
_gameTimer.Start();
Platform.ResetElapsedTime();
if (_gameTimer != null)
{
_gameTimer.Reset();
_gameTimer.Start();
}

_accumulatedElapsedTime = TimeSpan.Zero;
Expand Down Expand Up @@ -489,8 +495,6 @@ public void Run(GameRunBehavior runBehavior)
DoUpdate(new GameTime());

Platform.RunLoop();
EndRun();
DoExiting();
break;
default:
throw new ArgumentException(string.Format(
Expand Down Expand Up @@ -534,11 +538,11 @@ public void Tick()
#endif
}

// Advance the accumulated elapsed time.
if (_gameTimer == null)
{
_gameTimer = new Stopwatch();
_gameTimer.Start();
// Advance the accumulated elapsed time.
if (_gameTimer == null)
{
_gameTimer = new Stopwatch();
_gameTimer.Start();
}
var currentTicks = _gameTimer.Elapsed.Ticks;
_accumulatedElapsedTime += TimeSpan.FromTicks(currentTicks - _previousTicks);
Expand Down Expand Up @@ -625,8 +629,18 @@ public void Tick()

if (_shouldExit)
{
Platform.Exit();
_shouldExit = false; //prevents perpetual exiting on platforms supporting resume.
var exitingEventArgs = new ExitingEventArgs();

OnExiting(this, exitingEventArgs);

if (!exitingEventArgs.Cancel)
{
Platform.Exit();
EndRun();
UnloadContent();
}

_shouldExit = false;
}
}

Expand Down Expand Up @@ -737,7 +751,7 @@ protected virtual void Update(GameTime gameTime)
/// </summary>
/// <param name="sender">This <see cref="Game"/>.</param>
/// <param name="args">The arguments to the <see cref="Exiting"/> event.</param>
protected virtual void OnExiting(object sender, EventArgs args)
protected virtual void OnExiting(object sender, ExitingEventArgs args)
{
EventHelpers.Raise(sender, Exiting, args);
}
Expand Down Expand Up @@ -789,8 +803,6 @@ private void Platform_AsyncRunLoopEnded(object sender, EventArgs e)

var platform = (GamePlatform)sender;
platform.AsyncRunLoopEnded -= Platform_AsyncRunLoopEnded;
EndRun();
DoExiting();
}

#endregion Event Handlers
Expand Down Expand Up @@ -865,12 +877,6 @@ internal void DoInitialize()
_components.ComponentRemoved += Components_ComponentRemoved;
}

internal void DoExiting()
{
OnExiting(this, EventArgs.Empty);
UnloadContent();
}

#endregion Internal Methods

internal GraphicsDeviceManager graphicsDeviceManager
Expand Down
13 changes: 13 additions & 0 deletions MonoGame.Framework/GameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class GameComponent : IGameComponent, IUpdateable, IDisposable
/// </summary>
public Game Game { get; private set; }

/// <summary>
/// Indicates whether <see cref="Update(GameTime)">GameComponent.Update(GameTime)</see> should be
/// called when <see cref="Game.Update(GameTime)">Game.Update(GameTime)</see> is called.
/// </summary>
public bool Enabled
{
get { return _enabled; }
Expand All @@ -33,6 +37,11 @@ public bool Enabled
}
}

/// <summary>
/// Indicates the order in which the <see cref="GameComponent"/>
/// should be updated relative to other <see cref="GameComponent"/> instances.
/// Lower values are updated first.
/// </summary>
public int UpdateOrder
{
get { return _updateOrder; }
Expand Down Expand Up @@ -61,11 +70,15 @@ public GameComponent(Game game)
this.Game = game;
}

/// <summary/>
~GameComponent()
{
Dispose(false);
}

/// <summary>
/// Called when the <see cref="GameComponent"/> needs to be initialized.
/// </summary>
public virtual void Initialize() { }

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions MonoGame.Framework/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ protected void OnOrientationChanged ()
EventHelpers.Raise(this, OrientationChanged, EventArgs.Empty);
}

/// <summary>
/// Called when the window needs to be painted.
/// </summary>
protected void OnPaint ()
{
}
Expand Down Expand Up @@ -254,6 +257,10 @@ internal void OnFileDrop(FileDropEventArgs e)
EventHelpers.Raise(this, FileDrop, e);
}

/// <summary>
/// Sets the supported display orientations.
/// </summary>
/// <param name="orientations">Supported display orientations</param>
protected internal abstract void SetSupportedOrientations (DisplayOrientation orientations);

/// <summary>
Expand Down
Loading

0 comments on commit 7ae787e

Please sign in to comment.