Closed 1vanK closed 6 months ago
My idea is to prevent SDL_PollEvent() from blocking when the user moves or resizes the window
FYI, this has already been discussed a lot in https://github.com/libsdl-org/SDL/issues/1059, with a solution implemented for SDL3.
kinda hilarious to see that my work over the course of maybe 20 hours is still apparently the most accessible information on this a decade later.
as Starbuck mentioned, SDL3 provides a much more rugged, portable, and simpler solution to this problem by resolving the fundamental conflict between rolling your own main loop with rendering external to event processing and how the OS or compositor wants you to write your main loop (or in many cases, to not do that at all). SDL3 provides an optional callback interface as described in docs/README-main-functions.md use that instead of fighting the OS.
docs/README-main-functions.md
I use own main() for console version of app, which accepts command line arguments in utf-8 encoding
https://github.com/dviglo2d/dviglo2d/blob/main/libs/dviglo/main/main.hpp#L32-L38 https://github.com/dviglo2d/dviglo2d/blob/main/libs/dviglo/main/main.cpp#L14-L32
https://github.com/libsdl-org/SDL/commit/02f356439d1fedf0b4e5f96cd23c2d570e2f7be2
When using event watcher, I get SDL_EVENT_WINDOW_EXPOSED message even without changing or moving the window. This hack sjould have its own event name, otherwise, in addition to this crutch, you will have to invent an additional crutch to check that the update and rendering were not called twice per frame: from the main loop and from the watcher.
In addition, using functions int SDL_AppIterate(void), etc
breaks the logic of object-oriented applications with overriding virtual methods update(), render(). Even hack with DL_EVENT_WINDOW_EXPOSED break OOP
I'm not sure what you mean by "breaks the logic": SDL_AppIterate would be the appropriate place for all your per-frame logic, you'll just need to make your state global or singleton - or better, encapsulate them in a single global state machine.
You can absolutely make this interface work, developers using high level portable UI frameworks have been pushed to do it forever.
docs/README-main-functions.md
I need to open log file before SDL init and close after SDL destruction. How can I do this?
With callbacks when user clicks on app window title, but does not move the window immediately, microfreeze occurs.
https://gamedev.net/forums/topic/440341-wm_syscommand-and-moving-a-window/3919110/
As you can see, there's a 500ms delay between WM_SYSCOMMAND and the next message.
Could this issue be reopened? The current solution doesn't work.
Even this not fix the problem
since the frieze occurs within the modal loop and the timer doesn't even work
This dirty code with manual moving window solve this problem:
I need to open log file before SDL init and close after SDL destruction. How can I do this?
in the constructor for a static object; same way you make stuff happen before main() gets called.
https://gamedev.net/forums/topic/440341-wm_syscommand-and-moving-a-window/3919110/
As you can see, there's a 500ms delay between WM_SYSCOMMAND and the next message.
oof. has to be waiting on something inside DefWndProc. At this point though, it's basically an OS bug.
At this point though, it's basically an OS bug.
96% of gamers use Windows: https://store.steampowered.com/hwsurvey/
Therefore, it is not so important whether it is a bug or a feature. The problem cannot just be ignored
how many games are routinely played in a bordered window?
and do any of those games that are routinely played in a bordered window not have this issue?
What difference will any answer make? If SDL solves the problem, there will be more working games. Moreover, SDL is used not only for games, but also for applications.
why would you expect SDL to solve this specific problem of DefWindowProc introducing delays?
Can we please not get into this argument again? I already had to lock one issue about this topic.
Sorry. On this topic, would it be possible to ensure that the new GPU API can portably be used in a single non-main thread with some basic rules? Since the SDL event queue is already thread-safe, that would enable a good best practice for dealing with this type of problem by moving the entire gameloop to another thread and just using the main thread as an event pump, even if it wouldn't extend to the old SDL2 APIs.
how many games are routinely played in a bordered window?
and do any of those games that are routinely played in a bordered window not have this issue?
Vampire Survivors
I tested version 1.4.
There is no frieze when you click on the window title.
According to Wikipedia, they changed the engine in version 1.6, which I have not tested.
Also cookie clicker (Steam version)
Of course, these applications are based on a web component and Google was able to solve this problem. But you couldn't.
Okay, I see we're all doing this again, so I'm locking this thread.
On Windows, dragging or resizing a window blocks the main thread. Currently the recommended main loop looks like this:
Is it possible to write this in the form:
p.s. SDL_AppIterate() is no good for me. Also I read about SDL_AddEventWatch(), but such things should be hidden inside SDL.