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

Split up FNAPlatform.RunLoop #322

Closed
8 tasks
flibitijibibo opened this issue Aug 2, 2020 · 1 comment
Closed
8 tasks

Split up FNAPlatform.RunLoop #322

flibitijibibo opened this issue Aug 2, 2020 · 1 comment
Assignees

Comments

@flibitijibibo
Copy link
Member

This one's mostly for @TheSpydog who's currently exploring wasm, but also applies to @jfmajor who needs this feature for their editor.

Currently the loop is held entirely in the FNAPlatform function, but this is a problem for 2 reasons:

  1. RunOneFrame needs to poll events before Tick(), to handle certain updates (key up/down, hotplugging, text input, things like that)
  2. Every FNAPlatform conceivable is going to have a loop anyway, and a lot of code at the top and bottom of RunLoop could easily be shared

This is a proposed refactor, but could change depending on performance/accuracy issues we've not encountered yet:

  • FNAPlatform.RegisterGame shows the game window and adds it to activeGames
  • FNAPlatform.UnregisterGame removes the game from activeGames
  • FNAPlatform.PollEvents contains the SDL_Event loop, add this to RunOneFrame()
  • OSXUseSpaces becomes a static readonly variable
  • List<Keys> keys is initialized in Keyboard.cs instead
  • Text input variables become Game instance variables
  • displayIndex becomes a GraphicsAdapter rather than an int
  • Game would get a new RunLoop that looks like this:
private void RunLoop()
{
    while (RunApplication)
    {
        FNAPlatform.PollEvents(
            this,
            currentAdapter,
            textInputControlDown,
            textInputControlRepeat,
            ref textInputSuppress
        );
        Tick();
    }
    Exit();
}

protected virtual void BeginRun()
{
    if (loopBegan)
    {
        return;
    }

    currentAdapter = FNAPlatform.RegisterGame(this);

    Rectangle windowBounds = Window.ClientBounds;
    Mouse.INTERNAL_WindowWidth = windowBounds.Width;
    Mouse.INTERNAL_WindowHeight = windowBounds.Height;

    // Perform initial check for a touch device
    TouchPanel.TouchDeviceExists = GetTouchCapabilities().IsConnected;

    loopBegan = true;
}

protected virtual void EndRun()
{
    if (loopBegan)
    {
        FNAPlatform.UnregisterGame(this);
        loopBegan = false;
    }
}
@flibitijibibo
Copy link
Member Author

Fixed by #324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants