1. pygame
  2. Untitled project
  3. pygame

Commits

marcus  committed 59c79bf

Changed sdl.base.init_subsystem() to call SDL_Init() beforehand.

  • Participants
  • Parent commits 143596d
  • Branches pgreloaded

Comments (0)

Files changed (2)

File doc/src/sdlbase.xml

View file
  • Ignore whitespace
       Initializes one or more SDL subsystems.
 
       In case a specific part of SDL was not initialized using
-      pygame2.sdl.init(), this funciton can be used to initialize it at
+      :func:`pygame2.sdl.init`, this funciton can be used to initialize it at
       a later time.
 
+      In contrast to the original SDL library, you do not need to call
+      :func:`pygame2.sdl.init` beforehand to initialize anything. In
+      case it was not done before, :func:`pygame2.sdl.init` will be
+      called implicitly with the passed *flags*.
+
       In case an error occured, False will be returned. The detailled
       error can be received using pygame2.sdl.get_error().
     </desc>

File src/sdl/sdlmod.c

View file
  • Ignore whitespace
 #include "pgsdl.h"
 #include "sdlbase_doc.h"
 
+
+typedef struct {
+    int initialized : 1;
+} _SDLState;
+
+#ifdef IS_PYTHON_3
+static struct PyModuleDef _sdlmodule = {
+    PyModuleDef_HEAD_INIT,
+    "base",
+    DOC_BASE,
+    sizeof (_SDLState),
+    _sdl_methods,
+    NULL,
+    _sdl_traverse,
+    _sdl_clear,
+    NULL
+};
+#define SDL_MOD_STATE(mod) ((_BaseState*)PyModule_GetState(mod))
+#define SDL_STATE SDL_MOD_STATE(PyState_FindModule(&_sdlmodule))
+#else
+_SDLState _modstate;
+#define SDL_MOD_STATE(mod) (&_modstate)
+#define SDL_STATE SDL_MOD_STATE(NULL)
+#endif
+
 static void _quit (void);
 static int _check_sdl (void);
 
 _quit (void)
 {
     SDL_Quit ();
+    SDL_STATE->initialized = 0;
 }
 
 static int
         return NULL;
     if (SDL_Init (flags) == -1)
         Py_RETURN_FALSE;
+
+    SDL_MOD_STATE (self)->initialized = 1;
     Py_RETURN_TRUE;
 }
 
     Uint32 flags;
     if (!PyArg_ParseTuple (args, "l:init_subsystem", &flags))
         return NULL;
+
+    if (SDL_MOD_STATE (self)->initialized == 0)
+        return _sdl_init (self, args);
+
     if (SDL_InitSubSystem (flags) == -1)
         Py_RETURN_FALSE;
     Py_RETURN_TRUE;
     static void *c_api[PYGAME_SDLBASE_SLOTS];
 
 #ifdef IS_PYTHON_3
-    static struct PyModuleDef _sdlmodule = {
-        PyModuleDef_HEAD_INIT,
-        "base",
-        DOC_BASE,
-        -1,
-        _sdl_methods,
-        NULL,
-        NULL,
-        NULL,
-        NULL
-    };
     mod = PyModule_Create (&_sdlmodule);
 #else
     mod = Py_InitModule3 ("base", _sdl_methods, DOC_BASE);
 #endif
     if (!mod)
         goto fail;
-    
+    SDL_MOD_STATE(mod)->initialized = 0;
+
     /* Export C API */
     c_api[PYGAME_SDLBASE_FIRSTSLOT] = Uint8FromObj;
     c_api[PYGAME_SDLBASE_FIRSTSLOT+1] = Uint16FromObj;