comparison 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
comparison
equal deleted inserted replaced
537:63440d1e0717 538:1abb6f7db8cc
50 class SDL(object): 50 class SDL(object):
51 def __init__(self, sound=True): 51 def __init__(self, sound=True):
52 self.sound = sound 52 self.sound = sound
53 53
54 def __enter__(self): 54 def __enter__(self):
55 global keyboard_state
56
55 IF UNAME_SYSNAME == "Windows": 57 IF UNAME_SYSNAME == "Windows":
56 SDL_SetMainReady() 58 SDL_SetMainReady()
57 init(SDL_INIT_VIDEO) 59 init(SDL_INIT_VIDEO)
58 img_init(IMG_INIT_PNG) 60 img_init(IMG_INIT_PNG)
59 ttf_init() 61 ttf_init()
62
63 keyboard_state = SDL_GetKeyboardState(NULL)
60 64
61 if self.sound: 65 if self.sound:
62 mix_init(0) 66 mix_init(0)
63 try: 67 try:
64 mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096) 68 mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096)
283 elif event.type == SDL_WINDOWEVENT: 287 elif event.type == SDL_WINDOWEVENT:
284 ret.append((event.type, event.window.event, event.window.data1, event.window.data2)) 288 ret.append((event.type, event.window.event, event.window.data1, event.window.data2))
285 return ret 289 return ret
286 290
287 291
288 cdef const Uint8* get_keyboard_state() nogil:
289 return SDL_GetKeyboardState(NULL)
290
291
292 cdef Surface load_png(file_): 292 cdef Surface load_png(file_):
293 data = file_.read() 293 data = file_.read()
294 rwops = SDL_RWFromConstMem(<char*>data, len(data)) 294 rwops = SDL_RWFromConstMem(<char*>data, len(data))
295 surface = Surface() 295 surface = Surface()
296 surface.surface = IMG_LoadPNG_RW(rwops) 296 surface.surface = IMG_LoadPNG_RW(rwops)