Mercurial > touhou
annotate pytouhou/lib/sdl.pyx @ 455:6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 02 Sep 2013 22:16:38 +0200 |
parents | 17a7f3b028f3 |
children | cae1ae9de430 |
rev | line source |
---|---|
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 INIT_VIDEO = SDL_INIT_VIDEO |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
16 INIT_PNG = IMG_INIT_PNG |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 GL_CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 GL_CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 GL_DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 GL_DEPTH_SIZE = SDL_GL_DEPTH_SIZE |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 WINDOW_OPENGL = SDL_WINDOW_OPENGL |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 WINDOW_SHOWN = SDL_WINDOW_SHOWN |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 SCANCODE_Z = SDL_SCANCODE_Z |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 SCANCODE_X = SDL_SCANCODE_X |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 SCANCODE_LSHIFT = SDL_SCANCODE_LSHIFT |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 SCANCODE_UP = SDL_SCANCODE_UP |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 SCANCODE_DOWN = SDL_SCANCODE_DOWN |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 SCANCODE_LEFT = SDL_SCANCODE_LEFT |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 SCANCODE_RIGHT = SDL_SCANCODE_RIGHT |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 SCANCODE_LCTRL = SDL_SCANCODE_LCTRL |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 SCANCODE_ESCAPE = SDL_SCANCODE_ESCAPE |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 KEYDOWN = SDL_KEYDOWN |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 QUIT = SDL_QUIT |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
40 DEFAULT_FORMAT = MIX_DEFAULT_FORMAT |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
41 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 class SDLError(Exception): |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 pass |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 cdef class Window: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 def __init__(self, const char *title, int x, int y, int w, int h, Uint32 flags): |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 self.window = SDL_CreateWindow(title, x, y, w, h, flags) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 if self.window == NULL: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 raise SDLError(SDL_GetError()) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
53 def __dealloc__(self): |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
54 if self.context != NULL: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
55 SDL_GL_DeleteContext(self.context) |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
56 if self.window != NULL: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
57 SDL_DestroyWindow(self.window) |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
59 cdef void gl_create_context(self) except *: |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 self.context = SDL_GL_CreateContext(self.window) |
453
17a7f3b028f3
Raise an exception if GL context creation fails instead of failing silently.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
61 if self.context == NULL: |
17a7f3b028f3
Raise an exception if GL context creation fails instead of failing silently.
Thibaut Girka <thib@sitedethib.com>
parents:
450
diff
changeset
|
62 raise SDLError(SDL_GetError()) |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
64 cdef void gl_swap_window(self) nogil: |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 SDL_GL_SwapWindow(self.window) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
67 cdef void set_window_size(self, int width, int height) nogil: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
68 SDL_SetWindowSize(self.window, width, height) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
69 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
71 cdef class Surface: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
72 def __dealloc__(self): |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
73 if self.surface != NULL: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
74 SDL_FreeSurface(self.surface) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
75 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
76 property pixels: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
77 def __get__(self): |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
78 return bytes(self.surface.pixels[:self.surface.w * self.surface.h * 4]) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
79 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
80 cdef void blit(self, Surface other): |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
81 if SDL_BlitSurface(other.surface, NULL, self.surface, NULL) < 0: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
82 raise SDLError(SDL_GetError()) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
83 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
84 cdef void set_alpha(self, Surface alpha_surface) nogil: |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
85 nb_pixels = self.surface.w * self.surface.h |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
86 image = self.surface.pixels |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
87 alpha = alpha_surface.surface.pixels |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
88 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
89 for i in xrange(nb_pixels): |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
90 # Only use the red value, assume the others are equal. |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
91 image[3+4*i] = alpha[3*i] |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
92 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
93 |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
94 cdef class Music: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
95 def __dealloc__(self): |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
96 if self.music != NULL: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
97 Mix_FreeMusic(self.music) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
98 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
99 cdef void play(self, int loops) nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
100 Mix_PlayMusic(self.music, loops) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
101 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
102 cdef void set_loop_points(self, double start, double end) nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
103 #Mix_SetLoopPoints(self.music, start, end) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
104 pass |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
105 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
106 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
107 cdef class Chunk: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
108 def __dealloc__(self): |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
109 if self.chunk != NULL: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
110 Mix_FreeChunk(self.chunk) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
111 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
112 cdef void play(self, int channel, int loops) nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
113 Mix_PlayChannel(channel, self.chunk, loops) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
114 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
115 cdef void set_volume(self, float volume) nogil: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
116 Mix_VolumeChunk(self.chunk, int(volume * 128)) |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
117 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
118 |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
119 cdef void init(Uint32 flags) except *: |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 if SDL_Init(flags) < 0: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 raise SDLError(SDL_GetError()) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
124 cdef void img_init(Uint32 flags) except *: |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
125 if IMG_Init(flags) != flags: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
126 raise SDLError(SDL_GetError()) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
127 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
128 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
129 cdef void mix_init(int flags) except *: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
130 if Mix_Init(flags) != flags: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
131 raise SDLError(SDL_GetError()) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
132 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
133 |
450
2a352118c55a
Add back Windows support, using GLEW for OpenGL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
134 IF UNAME_SYSNAME == "Windows": |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
135 cdef void set_main_ready(): |
450
2a352118c55a
Add back Windows support, using GLEW for OpenGL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
136 SDL_SetMainReady() |
2a352118c55a
Add back Windows support, using GLEW for OpenGL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
137 |
2a352118c55a
Add back Windows support, using GLEW for OpenGL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
138 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
139 cdef void quit() nogil: |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 SDL_Quit() |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
143 cdef void img_quit() nogil: |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
144 IMG_Quit() |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
145 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
146 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
147 cdef void mix_quit() nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
148 Mix_Quit() |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
149 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
150 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
151 cdef void gl_set_attribute(SDL_GLattr attr, int value) except *: |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 if SDL_GL_SetAttribute(attr, value) < 0: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 raise SDLError(SDL_GetError()) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
156 cdef list poll_events(): |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 cdef SDL_Event event |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 ret = [] |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 while SDL_PollEvent(&event): |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 if event.type == SDL_KEYDOWN: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 ret.append((event.type, event.key.keysym.scancode)) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 elif event.type == SDL_QUIT: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 ret.append((event.type,)) |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 return ret |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
167 cdef const Uint8* get_keyboard_state() nogil: |
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
168 return SDL_GetKeyboardState(NULL) |
419
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
169 |
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
170 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
171 cdef Surface load_png(file_): |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
172 data = file_.read() |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
173 rwops = SDL_RWFromConstMem(<char*>data, len(data)) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
174 surface = Surface() |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
175 surface.surface = IMG_LoadPNG_RW(rwops) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
176 SDL_RWclose(rwops) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
177 if surface.surface == NULL: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
178 raise SDLError(SDL_GetError()) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
179 return surface |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
180 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
181 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
182 cdef Surface create_rgb_surface(int width, int height, int depth, Uint32 rmask=0, Uint32 gmask=0, Uint32 bmask=0, Uint32 amask=0): |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
183 surface = Surface() |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
184 surface.surface = SDL_CreateRGBSurface(0, width, height, depth, rmask, gmask, bmask, amask) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
185 if surface.surface == NULL: |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
186 raise SDLError(SDL_GetError()) |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
187 return surface |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
188 |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
419
diff
changeset
|
189 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
190 cdef void mix_open_audio(int frequency, Uint16 format_, int channels, int chunksize) except *: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
191 if Mix_OpenAudio(frequency, format_, channels, chunksize) < 0: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
192 raise SDLError(SDL_GetError()) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
193 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
194 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
195 cdef void mix_close_audio() nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
196 Mix_CloseAudio() |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
197 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
198 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
199 cdef void mix_allocate_channels(int numchans) except *: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
200 if Mix_AllocateChannels(numchans) != numchans: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
201 raise SDLError(SDL_GetError()) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
202 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
203 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
204 cdef int mix_volume(int channel, float volume) nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
205 return Mix_Volume(channel, int(volume * 128)) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
206 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
207 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
208 cdef int mix_volume_music(float volume) nogil: |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
209 return Mix_VolumeMusic(int(volume * 128)) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
210 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
211 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
212 cdef Music load_music(const char *filename): |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
213 music = Music() |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
214 music.music = Mix_LoadMUS(filename) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
215 if music.music == NULL: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
216 raise SDLError(SDL_GetError()) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
217 return music |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
218 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
219 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
220 cdef Chunk load_chunk(file_): |
421
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
221 cdef SDL_RWops *rwops |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
222 chunk = Chunk() |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
223 data = file_.read() |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
224 rwops = SDL_RWFromConstMem(<char*>data, len(data)) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
225 chunk.chunk = Mix_LoadWAV_RW(rwops, 1) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
226 if chunk.chunk == NULL: |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
227 raise SDLError(SDL_GetError()) |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
228 return chunk |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
229 |
b1248bab2d0f
Add back music and SFX playback using SDL_mixer instead of pyglet, and add FLAC and Vorbis support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
230 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
231 cdef Uint32 get_ticks() nogil: |
419
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
232 return SDL_GetTicks() |
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
233 |
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
234 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
453
diff
changeset
|
235 cdef void delay(Uint32 ms) nogil: |
419
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
236 SDL_Delay(ms) |