Move WindowShouldClose out of rcore

This commit is contained in:
michaelfiber 2023-09-14 13:20:24 -04:00
parent cc5249b82c
commit 2125da5926
5 changed files with 51 additions and 35 deletions

View File

@ -419,41 +419,6 @@ const char *TextFormat(const char *text, ...); // Formatting of text with
// Module Functions Definition - Window and OpenGL Context Functions // Module Functions Definition - Window and OpenGL Context Functions
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Check if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
#if defined(PLATFORM_WEB)
// Emterpreter-Async required to run sync code
// https://github.com/emscripten-core/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code
// By default, this function is never called on a web-ready raylib example because we encapsulate
// frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously
// but now emscripten allows sync code to be executed in an interpreted way, using emterpreter!
emscripten_sleep(16);
return false;
#endif
#if defined(PLATFORM_DESKTOP)
if (CORE.Window.ready)
{
// While window minimized, stop loop execution
while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents();
CORE.Window.shouldClose = glfwWindowShouldClose(CORE.Window.handle);
// Reset close status for next frame
glfwSetWindowShouldClose(CORE.Window.handle, GLFW_FALSE);
return CORE.Window.shouldClose;
}
else return true;
#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_DRM)
if (CORE.Window.ready) return CORE.Window.shouldClose;
else return true;
#endif
}
// Check if window has been initialized successfully // Check if window has been initialized successfully
bool IsWindowReady(void) bool IsWindowReady(void)
{ {

View File

@ -1284,4 +1284,12 @@ void CloseWindow(void)
CORE.Window.ready = false; CORE.Window.ready = false;
TRACELOG(LOG_INFO, "Window closed successfully"); TRACELOG(LOG_INFO, "Window closed successfully");
}
// Check if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
if (CORE.Window.ready) return CORE.Window.shouldClose;
else return true;
} }

View File

@ -500,4 +500,24 @@ void CloseWindow(void)
CORE.Window.ready = false; CORE.Window.ready = false;
TRACELOG(LOG_INFO, "Window closed successfully"); TRACELOG(LOG_INFO, "Window closed successfully");
}
// Check if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
if (CORE.Window.ready)
{
// While window minimized, stop loop execution
while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents();
CORE.Window.shouldClose = glfwWindowShouldClose(CORE.Window.handle);
// Reset close status for next frame
glfwSetWindowShouldClose(CORE.Window.handle, GLFW_FALSE);
return CORE.Window.shouldClose;
}
else return true;
} }

View File

@ -1001,4 +1001,13 @@ void CloseWindow(void)
CORE.Window.ready = false; CORE.Window.ready = false;
TRACELOG(LOG_INFO, "Window closed successfully"); TRACELOG(LOG_INFO, "Window closed successfully");
}
// Check if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
if (CORE.Window.ready) return CORE.Window.shouldClose;
else return true;
} }

View File

@ -1073,4 +1073,18 @@ void CloseWindow(void)
CORE.Window.ready = false; CORE.Window.ready = false;
TRACELOG(LOG_INFO, "Window closed successfully"); TRACELOG(LOG_INFO, "Window closed successfully");
}
// Check if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
// Emterpreter-Async required to run sync code
// https://github.com/emscripten-core/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code
// By default, this function is never called on a web-ready raylib example because we encapsulate
// frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously
// but now emscripten allows sync code to be executed in an interpreted way, using emterpreter!
emscripten_sleep(16);
return false;
} }