-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement resizable GUI #64
base: master
Are you sure you want to change the base?
Conversation
The crash in SDL_GL_SwapWindow on Linux is because of Mesa bug #7875, where the reference count of a resource was too low so it was freed before it should have been and then Mesa tries to use the freed resource. |
I had to make these changes to Globulation 2 to get it to compile on MSYS2: https://gist.github.com/Quipyowert2/d2e1d3077efdbbc6b161a505445f1bce with the addition of prepending "/msys64" to each of the files in @stephanemagnenat how do I fix the resize glitch? |
Part of the reason why I can't seem to get this to work right is because the game draws too slowly. When I measured the time for one frame, it was 41ms, but that might have been the result of too much locking/unlocking of mutexen. My laptop's screen runs at 60Hz, so it would have to draw in 16ms or faster to be able to live resize the window without draw lag on Windows 10. |
a2ede94
to
a329e27
Compare
a329e27
to
e83dd3a
Compare
Rebased on latest master so I could develop the PR in Visual Studio and extracted drawing code from MapEdit::run into MapEdit::draw. |
When trying to compile this PR in Visual Studio, I keep getting the error "xtime: ambiguous symbol" pointing at the condition_variable header and saying it could be either "xtime" or "boost::xtime". https://gist.github.com/Quipyowert2/10923de2138d5f4faf63e2e5cc7c802a The above compile error has been fixed by PR #83. |
73576a5
to
4d12c90
Compare
I have rebased again to fix xtime error and added another commit. I think I fixed the flickering of the globules, but the custom cursor flickers sometimes and the cursor animation goes too fast when resizing. When maximizing the window and then dragging the window downward on Windows 10, part of the tutorial message turns white and stays that way. |
1784f25
to
ff21033
Compare
I've partially solved the globule, land, and tutorial message flickering problem during resize. |
Resizing on the title screen works fine except for some flickering.
This fixes a bug where one of the booleans was 238.
On the title screen, the background was white instead of the green texture background and the buttons had white rectangles where the text should be.
Also fix game when running without a window (nox mode).
I don't know why, but removing the glOrtho call makes the window stop going black when resizing.
EventListener::paint can indirectly recurse by way of WindowProc.
Textures still turn white when letting go of the mouse button, though.
dd57b9d
to
8e21b7c
Compare
Oops, forgot to initialize The main problem with this PR now is that the CPU load bar always goes into the red when starting the tutorial. The reason might just be that my computer has been running slowly lately. |
I tried this out and it looks very glitchy. I think the rendering needs to be paused until the resizing is finished or something but even the edge I'm grabbing jumps around and doesn't stick to the mouse cursor. Screencast.from.2023-11-15.21-22-56.webm |
Maybe the reason for the persistent solid white flickering is that when calling SDL_GL_MakeCurrent in GraphicContext::createGLContext, it errors with The reason I am trying to render from the other thread is that the master branch of the game freezes when I drag or resize the window. There is probably a simpler solution I am overlooking. Also, sometimes the game deadlocks when I resize or move it, because EventListener::paint is waiting for the renderMutex to be unlocked, but the main thread is trying to call SDL_SetWindowSize. The edge of the window moving around when resizing might be caused by the |
The SDL bug with freezing when moving/resizing the window is reportedly fixed in SDL 2.30. |
The resizing is a little buggy but it mostly works. One bug I noticed was that the buttons on title screen get mangled during resizing or the button disappears and only the text of the button shows. Another bug is the game sometimes flashes red when resizing, not sure why.
The way this works is the main thread spawns a secondary thread and then opens the window, listens for events and adds to an events queue until told to stop. The second thread handles events, logic and rendering. When exiting the game, the second thread tells main thread to quit the event loop. Then the main thread joins the secondary thread, closes the window, and exits.
SDL_PollEvent will block the thread calling it during resize on Windows, so that's why I had to start another thread to handle everything else. I changed SDL_PollEvent to
el->poll
so that the resize doesn't block the event loop.Just tested this in a Linux VM and it crashes in SDL_GL_SwapWindow. It works on Windows 10 though.
TODO:
MapEdit::run
into a separate draw method.