Skip to content

Commit

Permalink
pass some window things off to the event thread
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Aug 15, 2024
1 parent 3474bbf commit 0850bb2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
9 changes: 6 additions & 3 deletions binding/osfm-screen-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ RB_METHOD(monitorWindowInit) {
int w = NUM2INT(vw);
int h = NUM2INT(vh);

if (w < 1 || h < 1)
rb_raise(rb_eArgError, "Invalid window size");

const char* name = " ";
unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_UTILITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_TRANSPARENT;
if (!NIL_P(kwargs)) {
Expand Down Expand Up @@ -395,11 +398,11 @@ RB_METHOD(monitorWindowResize) {
int w, h;
rb_get_args(argc, argv, "ii", &w, &h RB_ARG_END);

window->scene.resize(w, h);
if (w < 1 || h < 1)
rb_raise(rb_eArgError, "Invalid window size");

SDL_SetWindowSize(window->window, w, h);

GFX_UNLOCK;
window->scene.resize(w, h);

return Qnil;
}
Expand Down
26 changes: 25 additions & 1 deletion src/eventthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ enum
REQUEST_SETTINGS,
REQUEST_NEW_WINDOW,
REQUEST_DESTROY_WINDOW,
REQUEST_WINDOW_VISIBLE,

UPDATE_FPS,
UPDATE_SCREEN_RECT,
Expand Down Expand Up @@ -615,6 +616,15 @@ void EventThread::process(RGSSThreadData &rtData)
SDL_DestroyWindow(static_cast<SDL_Window*>(event.user.data1));
break;
}
case REQUEST_WINDOW_VISIBLE:
{
SDL_Window *window = static_cast<SDL_Window*>(event.user.data1);
if (event.user.data2)
SDL_ShowWindow(window);
else
SDL_HideWindow(window);
break;
}

case UPDATE_FPS :
if (rtData.config.printFPS)
Expand Down Expand Up @@ -869,9 +879,23 @@ SDL_Window *EventThread::requestNewWindow(const CreateWindowArgs *args)
new_window = nullptr; // reset
SDL_PushEvent(&event);
while (!new_window)
SDL_Delay(1);
// we want to delay ~0.1ms
// ideally the delay should be long enough that the window is created in one loop,
// but short enough that we aren't waiting for a long time after the window is created
SDL_DelayNS(10000);
return (SDL_Window*) new_window;
}

void EventThread::requestWindowVisible(SDL_Window *window, bool visible)
{
SDL_Event event;
event.type = usrIdStart + REQUEST_WINDOW_VISIBLE;
event.user.data1 = window;
event.user.data2 = (void*) visible;

SDL_PushEvent(&event);
}

void EventThread::destroySDLWindow(SDL_Window *window)
{
SDL_Event event;
Expand Down
13 changes: 7 additions & 6 deletions src/eventthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ class EventThread
// get random freezes without doing this on the event thread
SDL_Window* requestNewWindow(const CreateWindowArgs *args);
void destroySDLWindow(SDL_Window *window);
void requestWindowVisible(SDL_Window *window, bool visible);

void requestTextInputMode(bool mode);
void requestSettingsMenu();
void requestTextInputMode(bool mode);

void requestSettingsMenu();

void requestTerminate();

bool getFullscreen() const;
bool getShowCursor() const;
bool getControllerConnected() const;
SDL_Gamepad *controller() const;
bool getControllerConnected() const;

SDL_Gamepad *controller() const;

void showMessageBox(const char *body, int flags = 0);

Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,10 @@ static SDL_GLContext initGL(SDL_Window *win, Config &conf,

printGLInfo();

bool vsync = conf.vsync || conf.syncToRefreshrate;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
//bool vsync = conf.vsync || conf.syncToRefreshrate;
// SDL_GL_SetSwapInterval(vsync ? 1 : 0);
// For various reasons, we don't want vsync. So, we just force it off for now.
SDL_GL_SetSwapInterval(0);

// GLDebugLogger dLogger;
return glCtx;
Expand Down

0 comments on commit 0850bb2

Please sign in to comment.