Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MonoGame support #105

Merged
merged 5 commits into from
Feb 16, 2024
Merged

Add MonoGame support #105

merged 5 commits into from
Feb 16, 2024

Conversation

hadashiA
Copy link
Contributor

@hadashiA hadashiA commented Feb 15, 2024

Add extensions for MonoGame.

public class Game1 : Game
{
    public Game1()
    {
        var observableSystemComponent = new ObservableSystemComponent(this);
        Components.Add(observableSystemComponent);
    }
}

ObservableSystemComponent configure the following:

  • Setup TimeProvider and FrameProvider.
    • Time based operations are replaced with Game.Update(GameTime).
    • Frame based operations are replaced with Game.Update(GameTime).
  • Set UnhandledExceptionHandler. By default, the unhandled exception handler simply flows to System.Diagnostics.Trace.
    • If we want to change this, do the following:
      • new ObservableSystemComponent(this, ex => Console.WriteLine($"R3 UnhandledException: {ex}");

R3Extensions.MonoGame provides these providers.

  • MonoGameTimeProvider
  • MonoGameFrameProvider

And provides these custom operators.

// Observe the current GameTime value.
public static Observable<GameTime> GameTime(this Observable<Unit> source)

// observe the current GameTime and the value of the source observable.
public static Observable<(GameTime GameTime, T Item)> GameTime<T>(this Observable<T> source)

@hadashiA hadashiA marked this pull request as ready for review February 16, 2024 01:22
@hadashiA
Copy link
Contributor Author

I considered supporting GameComponent.AddTo, but decided against it.
There is no way to intercept in GameComponent.Dispose in an extension method. And GameComponent.Dispose seems to be called only in Game.Dispose by default.

@neuecc neuecc merged commit f4c338c into main Feb 16, 2024
@neuecc neuecc deleted the hadashiA/monogame branch February 16, 2024 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants