diff pytouhou/lib/sdl.pyx @ 538:1abb6f7db8cc

Don’t retrieve the keyboard_state pointer at each frame.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 24 Apr 2014 20:01:42 +0200
parents a7dc55ad9380
children c34b23e29d16
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pyx
+++ b/pytouhou/lib/sdl.pyx
@@ -52,12 +52,16 @@ class SDL(object):
         self.sound = sound
 
     def __enter__(self):
+        global keyboard_state
+
         IF UNAME_SYSNAME == "Windows":
             SDL_SetMainReady()
         init(SDL_INIT_VIDEO)
         img_init(IMG_INIT_PNG)
         ttf_init()
 
+        keyboard_state = SDL_GetKeyboardState(NULL)
+
         if self.sound:
             mix_init(0)
             try:
@@ -285,10 +289,6 @@ cdef list poll_events():
     return ret
 
 
-cdef const Uint8* get_keyboard_state() nogil:
-    return SDL_GetKeyboardState(NULL)
-
-
 cdef Surface load_png(file_):
     data = file_.read()
     rwops = SDL_RWFromConstMem(<char*>data, len(data))