mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Move initialized flag into library struct
This commit is contained in:
parent
98bdd36231
commit
926d2beddb
14
src/init.c
14
src/init.c
@ -33,14 +33,12 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
// The three global variables below comprise all global data in GLFW.
|
// The global variables below comprise all global data in GLFW.
|
||||||
// Any other global variable is a bug.
|
// Any other global variable is a bug.
|
||||||
|
|
||||||
// Global state shared between compilation units of GLFW
|
// Global state shared between compilation units of GLFW
|
||||||
// These are documented in internal.h
|
|
||||||
//
|
//
|
||||||
GLFWbool _glfwInitialized = GLFW_FALSE;
|
_GLFWlibrary _glfw = { GLFW_FALSE };
|
||||||
_GLFWlibrary _glfw;
|
|
||||||
|
|
||||||
// This is outside of _glfw so it can be initialized and usable before
|
// This is outside of _glfw so it can be initialized and usable before
|
||||||
// glfwInit is called, which lets that function report errors
|
// glfwInit is called, which lets that function report errors
|
||||||
@ -119,7 +117,7 @@ void _glfwInputError(int error, const char* format, ...)
|
|||||||
|
|
||||||
GLFWAPI int glfwInit(void)
|
GLFWAPI int glfwInit(void)
|
||||||
{
|
{
|
||||||
if (_glfwInitialized)
|
if (_glfw.initialized)
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
|
|
||||||
memset(&_glfw, 0, sizeof(_glfw));
|
memset(&_glfw, 0, sizeof(_glfw));
|
||||||
@ -130,8 +128,7 @@ GLFWAPI int glfwInit(void)
|
|||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwInitialized = GLFW_TRUE;
|
_glfw.initialized = GLFW_TRUE;
|
||||||
|
|
||||||
_glfw.timerOffset = _glfwPlatformGetTimerValue();
|
_glfw.timerOffset = _glfwPlatformGetTimerValue();
|
||||||
|
|
||||||
// Not all window hints have zero as their default value
|
// Not all window hints have zero as their default value
|
||||||
@ -144,7 +141,7 @@ GLFWAPI void glfwTerminate(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfw.initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks));
|
memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks));
|
||||||
@ -171,7 +168,6 @@ GLFWAPI void glfwTerminate(void)
|
|||||||
_glfwPlatformTerminate();
|
_glfwPlatformTerminate();
|
||||||
|
|
||||||
memset(&_glfw, 0, sizeof(_glfw));
|
memset(&_glfw, 0, sizeof(_glfw));
|
||||||
_glfwInitialized = GLFW_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)
|
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)
|
||||||
|
@ -230,13 +230,13 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void);
|
|||||||
|
|
||||||
// Checks for whether the library has been initialized
|
// Checks for whether the library has been initialized
|
||||||
#define _GLFW_REQUIRE_INIT() \
|
#define _GLFW_REQUIRE_INIT() \
|
||||||
if (!_glfwInitialized) \
|
if (!_glfw.initialized) \
|
||||||
{ \
|
{ \
|
||||||
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
|
||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
#define _GLFW_REQUIRE_INIT_OR_RETURN(x) \
|
#define _GLFW_REQUIRE_INIT_OR_RETURN(x) \
|
||||||
if (!_glfwInitialized) \
|
if (!_glfw.initialized) \
|
||||||
{ \
|
{ \
|
||||||
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
|
||||||
return x; \
|
return x; \
|
||||||
@ -468,6 +468,8 @@ struct _GLFWjoystick
|
|||||||
*/
|
*/
|
||||||
struct _GLFWlibrary
|
struct _GLFWlibrary
|
||||||
{
|
{
|
||||||
|
GLFWbool initialized;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
_GLFWfbconfig framebuffer;
|
_GLFWfbconfig framebuffer;
|
||||||
_GLFWwndconfig window;
|
_GLFWwndconfig window;
|
||||||
@ -533,13 +535,7 @@ struct _GLFWlibrary
|
|||||||
// Global state shared between compilation units of GLFW
|
// Global state shared between compilation units of GLFW
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
/*! @brief Flag indicating whether GLFW has been successfully initialized.
|
/*! @brief All global data shared between compilation units.
|
||||||
*/
|
|
||||||
extern GLFWbool _glfwInitialized;
|
|
||||||
|
|
||||||
/*! @brief All global data protected by @ref _glfwInitialized.
|
|
||||||
* This should only be touched after a call to @ref glfwInit that has not been
|
|
||||||
* followed by a call to @ref glfwTerminate.
|
|
||||||
*/
|
*/
|
||||||
extern _GLFWlibrary _glfw;
|
extern _GLFWlibrary _glfw;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user