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

[rcore] [SDL2] Add implementation for FLAG_WINDOW_ALWAYS_RUN #4598

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

asdqwe
Copy link
Contributor

@asdqwe asdqwe commented Dec 12, 2024

@raysan5
Copy link
Owner

raysan5 commented Dec 15, 2024

@asdqwe Actually, stop running is my expected behaviour when minimizing the Window, I think it's the optimal option, so being default.

About the other platforms, the ones that have the minimizing option I think implement similar alternatives (afair, Android also pauses the Activity and Web browsers pauses tabs activity when minimized/unselected tab).

I prefer to let the user configure it for the sub-optimal use case that is ALWAYS_RUN, but maybe the time counter can be reseted/paused if the flag is active.

Also, about the othe Desktop backends (SDL, RGFW), probably behaviour should be the same, just forgot about it when added.

Just thinking... what is the default behaviour for games on Windows?

@asdqwe asdqwe changed the title [rcore] Enable FLAG_WINDOW_ALWAYS_RUN by default on PLATFORM_DESKTOP_GLFW [rcore] [SDL2] Add implementation for FLAG_WINDOW_ALWAYS_RUN Dec 17, 2024
@raysan5
Copy link
Owner

raysan5 commented Dec 18, 2024

@asdqwe thank you very much for the testing and detailed explanations, I'm still thinking about it and the best way to address it. Maybe letting control to the user is the right way... but I'm afraid many users would not control it and just let the application running at full speed on background... but maybe more advanced/professional users would prefer to control it... 🤔

The other option is letting raylib to control it, like now, but instead of halting, reducing framerate... but in that case, probably better to give full control to user...

@Volcanic-Penguin
Copy link

Since I was the one who posted issue #4588 which led to this issue being opened I figured I should give my two cents. I don't really care that much if the game stops or not when you minimize the game, but I do think it's bad if you minimize the game for 5 minutes and then when you open the game again GetFrameTime() returns 300 as it can cause all kinds of unexpected bugs.

As a developer I currently have two options to get around this.

A) Set FLAG_WINDOW_ALWAYS_RUN to true to avoid the issue entirely.
B) Replace all of my calls to GetFrameTime() with a wrapper function that calls GetFrameTime() and then caps the returning float to 0.1 or something like that.

@raysan5
Copy link
Owner

raysan5 commented Dec 18, 2024

@Volcanic-Penguin yeah, definitely GetFrameTime() should be reseted if not FLAG_WINDOW_ALWAYS_RUN and window is minimized/iconified.

@veins1
Copy link
Contributor

veins1 commented Dec 19, 2024

There's a whole bunch of reasons a game can get stalled which results in high frame time. If a game can't handle it then this change is not going to help. As such I find this kind of thing unnecessary.

@asdqwe
Copy link
Contributor Author

asdqwe commented Dec 19, 2024

As requested (ref, ref), the PR was updated to instead add implementation for FLAG_WINDOW_ALWAYS_RUN on PLATFORM_DESKTOP_SDL and also reset the GetFrameTime() when FLAG_WINDOW_ALWAYS_RUN is not set and the window was iconified on PLATFORM_DESKTOP_GLFW and PLATFORM_DESKTOP_SDL.

PR can be tested with:
#include "raylib.h"
int main(void) {
    InitWindow(800, 450, "test");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {

        if (IsKeyPressed(KEY_ONE))   { MinimizeWindow();                         TraceLog(LOG_INFO, "MINIMIZED");      }
        if (IsKeyPressed(KEY_TWO))   { SetWindowState(FLAG_WINDOW_ALWAYS_RUN);   TraceLog(LOG_INFO, "ALWAYS RUN ON");  }
        if (IsKeyPressed(KEY_THREE)) { ClearWindowState(FLAG_WINDOW_ALWAYS_RUN); TraceLog(LOG_INFO, "ALWAYS RUN OFF"); }

        TraceLog(LOG_INFO, "GetTime():%f   GetFrameTime():%f", GetTime(), GetFrameTime());

        BeginDrawing();
        ClearBackground(RAYWHITE);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

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.

4 participants