mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Have window resizing functions properly wait on each other
This commit is contained in:
parent
1a304da43d
commit
2c382d19aa
4 changed files with 29 additions and 2 deletions
|
@ -888,6 +888,7 @@ void Graphics::resizeScreen(int width, int height) {
|
|||
// width = clamp(width, 1, 640);
|
||||
// height = clamp(height, 1, 480);
|
||||
|
||||
p->threadData->rqWindowAdjust.wait();
|
||||
Vec2i size(width, height);
|
||||
|
||||
if (p->scRes == size)
|
||||
|
@ -904,8 +905,9 @@ void Graphics::resizeScreen(int width, int height) {
|
|||
|
||||
glState.scissorBox.set(IntRect(0, 0, p->scRes.x, p->scRes.y));
|
||||
|
||||
|
||||
p->threadData->rqWindowAdjust.set();
|
||||
shState->eThread().requestWindowResize(width, height);
|
||||
usleep(50000);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -957,6 +959,8 @@ void Graphics::reset() {
|
|||
void Graphics::center() {
|
||||
if (getFullscreen())
|
||||
return;
|
||||
|
||||
p->threadData->rqWindowAdjust.reset();
|
||||
p->threadData->ethread->requestWindowCenter();
|
||||
}
|
||||
|
||||
|
@ -979,6 +983,7 @@ void Graphics::setShowCursor(bool value) {
|
|||
double Graphics::getScale() const { return (double)p->scSize.y / p->scRes.y; }
|
||||
|
||||
void Graphics::setScale(double factor) {
|
||||
p->threadData->rqWindowAdjust.wait();
|
||||
factor = clamp(factor, 0.5, 2.0);
|
||||
|
||||
if (factor == getScale())
|
||||
|
@ -987,8 +992,8 @@ void Graphics::setScale(double factor) {
|
|||
int widthpx = p->scRes.x * factor;
|
||||
int heightpx = p->scRes.y * factor;
|
||||
|
||||
p->threadData->rqWindowAdjust.set();
|
||||
shState->eThread().requestWindowResize(widthpx, heightpx);
|
||||
usleep(50000);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -450,10 +450,12 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
|
||||
case REQUEST_WINRESIZE :
|
||||
SDL_SetWindowSize(win, event.window.data1, event.window.data2);
|
||||
rtData.rqWindowAdjust.clear();
|
||||
break;
|
||||
|
||||
case REQUEST_WINREPOSITION :
|
||||
SDL_SetWindowPosition(win, event.window.data1, event.window.data2);
|
||||
rtData.rqWindowAdjust.clear();
|
||||
break;
|
||||
|
||||
case REQUEST_WINCENTER :
|
||||
|
@ -462,6 +464,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
SDL_SetWindowPosition(win,
|
||||
(dm.w / 2) - (winW / 2),
|
||||
(dm.h / 2) - (winH / 2));
|
||||
rtData.rqWindowAdjust.clear();
|
||||
break;
|
||||
|
||||
case REQUEST_WINRENAME :
|
||||
|
@ -567,7 +570,9 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
if (SDL_JoystickGetAttached(js))
|
||||
SDL_JoystickClose(js);
|
||||
|
||||
#ifndef MKXPZ_BUILD_XCODE
|
||||
delete sMenu;
|
||||
#endif
|
||||
}
|
||||
|
||||
int EventThread::eventFilter(void *data, SDL_Event *event)
|
||||
|
|
|
@ -242,6 +242,9 @@ struct RGSSThreadData
|
|||
|
||||
/* Set when F12 is released */
|
||||
AtomicFlag rqResetFinish;
|
||||
|
||||
// Set when window is being adjusted (resize, reposition)
|
||||
AtomicFlag rqWindowAdjust;
|
||||
|
||||
EventThread *ethread;
|
||||
UnidirMessage<Vec2i> windowSizeMsg;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
struct AtomicFlag
|
||||
{
|
||||
|
@ -24,6 +25,19 @@ struct AtomicFlag
|
|||
{
|
||||
SDL_AtomicSet(&atom, 0);
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
while (SDL_AtomicGet(&atom)) {
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
wait();
|
||||
set();
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue