SDLRuby 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -19
  3. data/LICENSE.txt +21 -21
  4. data/README.md +31 -31
  5. data/Rakefile +12 -12
  6. data/SDLRuby.gemspec +38 -0
  7. data/examples/alert.rb +8 -0
  8. data/examples/window.rb +7 -0
  9. data/lib/SDLRuby/event/accessor.rb +2 -2
  10. data/lib/SDLRuby/event.rb +101 -101
  11. data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -61
  12. data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -95
  13. data/lib/SDLRuby/rw/operational.rb +116 -0
  14. data/lib/SDLRuby/rw/read_closure.rb +28 -0
  15. data/lib/SDLRuby/rw/seek_closure.rb +22 -0
  16. data/lib/SDLRuby/rw/size_closure.rb +21 -0
  17. data/lib/SDLRuby/rw/write_closure.rb +21 -0
  18. data/lib/SDLRuby/rw_ops/mem_close.rb +27 -0
  19. data/lib/SDLRuby/rw_ops/rw_object.rb +13 -107
  20. data/lib/SDLRuby/rw_ops.rb +40 -165
  21. data/lib/SDLRuby/sdl/include/SDL.h.rb +44 -44
  22. data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +160 -160
  23. data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +30 -30
  24. data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -10
  25. data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -13
  26. data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -27
  27. data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +12 -12
  28. data/lib/SDLRuby/sdl/include/SDL_error.h.rb +28 -28
  29. data/lib/SDLRuby/sdl/include/SDL_events.h.rb +472 -472
  30. data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -6
  31. data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +147 -147
  32. data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -12
  33. data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +13 -13
  34. data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +199 -199
  35. data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +131 -131
  36. data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +35 -35
  37. data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +292 -292
  38. data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +13 -13
  39. data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -3
  40. data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +58 -58
  41. data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -5
  42. data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +57 -57
  43. data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +285 -285
  44. data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -3
  45. data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -6
  46. data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +46 -46
  47. data/lib/SDLRuby/sdl/include/SDL_render.h.rb +131 -131
  48. data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -2
  49. data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +78 -78
  50. data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +252 -252
  51. data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -25
  52. data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +40 -40
  53. data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +62 -62
  54. data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +100 -100
  55. data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -6
  56. data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +10 -10
  57. data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +21 -21
  58. data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -15
  59. data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -3
  60. data/lib/SDLRuby/sdl/include/SDL_version.h.rb +14 -14
  61. data/lib/SDLRuby/sdl/include/SDL_video.h.rb +264 -264
  62. data/lib/SDLRuby/sdl.rb +6 -6
  63. data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -54
  64. data/lib/SDLRuby/version.rb +5 -5
  65. data/lib/SDLRuby/window/surfacer.rb +37 -37
  66. data/lib/SDLRuby.rb +32 -16
  67. data/sig/SDLRuby.rbs +4 -4
  68. data/sig/lib/SDLRuby/event/accessor.rbs +157 -157
  69. data/sig/lib/SDLRuby/event/type.rbs +67 -67
  70. data/sig/lib/SDLRuby/event.rbs +47 -47
  71. data/sig/lib/SDLRuby/keyboard.rbs +25 -25
  72. data/sig/lib/SDLRuby/mouse.rbs +35 -35
  73. data/sig/lib/SDLRuby/sdl.rbs +655 -655
  74. data/sig/lib/SDLRuby/timer.rbs +7 -7
  75. metadata +12 -3
@@ -1,50 +1,53 @@
1
+ require 'stringio'
2
+ require_relative 'rw/operational'
1
3
  require_relative 'rw_ops/rw_object'
2
4
 
3
5
  module SDLRuby
4
6
  class RWOps
5
- include Fiddle, SDL
7
+ include Fiddle, RW::Operational, SDL
6
8
 
7
9
  class << self
8
- def [](src, autoclose: nil, readonly: nil)
9
- case src
10
- when RWOps
11
- return src
12
- when String
13
- size = src.bytesize
14
- ptr = if readonly
15
- SDL.SDL_RWFromConstMem(src, size)
16
- else
17
- SDL.SDL_RWFromMem(src, size)
18
- end
19
- raise SDLError if ptr.null?
20
- when Fiddle::Pointer
21
- size = src.size
22
- ptr = if readonly
23
- SDL.SDL_RWFromConstMem(src, size)
10
+ def [](obj)
11
+ return obj if obj.kind_of?(RWOps)
12
+
13
+ case obj
14
+ in Fiddle::Pointer
15
+ ptr = if obj.frozen?
16
+ SDL.SDL_RWFromConstMem(obj, obj.size)
24
17
  else
25
- SDL.SDL_RWFromMem(src, size)
18
+ SDL.SDL_RWFromMem(obj, obj.size)
26
19
  end
27
20
  raise SDLError if ptr.null?
21
+ in String
22
+ obj = RWObject.new(StringIO.new(obj))
23
+ ptr = obj.to_ptr
28
24
  else
29
- src = RWObject.new(src)
30
- ptr = src.to_ptr
25
+ obj = RWObject.new(obj)
26
+ ptr = obj.to_ptr
31
27
  end
32
28
 
33
- obj = allocate
34
- obj.__send__(:initialize, ptr, src)
35
- obj
29
+ rw = allocate
30
+ rw.__send__(:initialize, ptr, obj)
31
+ rw
36
32
  end
37
33
 
38
34
  def new(file, mode = "rb")
39
- ptr = SDL.SDL_RWFromFile(file, mode)
35
+ path = if file.instance_of?(String)
36
+ file
37
+ elsif file.respond_to?(:to_path)
38
+ file.to_path
39
+ end
40
+ ptr = SDL.SDL_RWFromFile(path, mode)
40
41
  raise SDLError if ptr.null?
41
42
 
42
43
  rw = super(ptr)
43
44
 
44
45
  if block_given?
45
- obj = yield(rw)
46
- rw.close
47
- obj
46
+ begin
47
+ yield(rw)
48
+ ensure
49
+ rw.close
50
+ end
48
51
  else
49
52
  rw
50
53
  end
@@ -54,163 +57,35 @@ module SDLRuby
54
57
  end
55
58
 
56
59
  def initialize(ptr, obj = nil)
57
- @st = SDL_RWops.new(ptr)
58
60
  @obj = obj
59
61
 
62
+ @st = SDL_RWops.new(ptr)
63
+
60
64
  # ポインターへC実装のfree関数を与えるため、終了時のGC処理でコアダンプしない。
61
65
  #
62
- @st.to_ptr.free = @st.close
66
+ @st.to_ptr.free = @st["close"]
63
67
 
64
68
  # close関数の差し替えをすることで、SDLがcloseを行ってもRuby側に伝達できる。
65
69
  # int (*close) (SDL_RWops *context)
66
70
  #
67
- st = @st
68
- @st.close = @close = Closure::BlockCaller.new(
69
- TYPE_INT, [TYPE_VOIDP]
70
- ) do |context|
71
+ @st["close"] = @close = Closure::BlockCaller.new(TYPE_INT, [TYPE_VOIDP]) do |_|
71
72
  # call_free はclose関数の戻り値が渡されないためcloseの失敗は分からない。
72
- st.to_ptr.call_free
73
+ to_ptr.call_free
73
74
 
74
75
  if $DEBUG
75
- warn "SDL_RWops(0x#{st.to_i.to_s(16)}) closed."
76
+ warn format("SDL_RWops(0x%016x) closed", to_ptr.to_int)
76
77
  end
77
78
 
78
79
  0
79
80
  end
80
81
  end
81
82
 
82
- def close
83
- unless closed?
84
- err = SDL.SDL_RWclose(self)
85
-
86
- raise SDLError if err != 0
87
- end
88
- end
89
-
90
- def closed? = @st.to_ptr.freed?
91
-
92
- def eof?
93
- raise IOError, "closed" if closed?
83
+ def initialize_copy(other)
84
+ raise SDLError, "closed stream" if closed?
94
85
 
95
- s = SDL.SDL_RWsize(self)
96
- raise SDLError if s < 0
97
-
98
- t = SDL.SDL_RWtell(self)
99
- raise SDLError if t < 0
100
-
101
- s == t
86
+ super
102
87
  end
103
88
 
104
- def read(length = nil, buffer = nil)
105
- raise IOError, "closed" if closed?
106
-
107
- len = if length.nil?
108
- size - tell
109
- else
110
- length.to_i
111
- end
112
-
113
- if len < 0
114
- raise ArgumentError, "length"
115
- elsif len > 0 && eof?
116
- return nil
117
- end
118
-
119
- case buffer
120
- when nil
121
- return "" if len == 0
122
-
123
- buffer = "\x00" * len
124
- buf_size = len
125
- when String
126
- return buffer.clear if len == 0
127
-
128
- buffer = buffer
129
- buf_size = buffer.bytesize
130
- when Fiddle::Pointer
131
- if len == 0
132
- buffer.size = 0
133
- return buffer
134
- end
135
-
136
- buffer = buffer
137
- buf_size = buffer.size
138
- else
139
- raise TypeError, "buffer"
140
- end
141
-
142
- if len > buf_size
143
- raise ArgumentError, "length is greater than buffer size."
144
- end
145
-
146
- n = SDL.SDL_RWread(self, buffer, 1, len)
147
- raise SDLError if n == 0
148
-
149
- if String === buffer
150
- buffer.slice!(n, buffer.bytesize)
151
- else
152
- buffer.size = n
153
- end
154
-
155
- buffer
156
- end
157
-
158
- def seek(offset, whence = IO::SEEK_SET)
159
- raise IOError, "closed" if closed?
160
-
161
- n = SDL.SDL_RWseek(self, offset, whence)
162
- raise SDLError if n < 0
163
- n
164
- end
165
-
166
- alias pos= seek
167
-
168
- def size
169
- raise IOError, "closed" if closed?
170
-
171
- n = SDL.SDL_RWsize(self)
172
- raise SDLError if n < 0
173
- n
174
- end
175
-
176
- def tell
177
- raise IOError, "closed" if closed?
178
-
179
- n = SDL.SDL_RWtell(self)
180
- raise SDLError if n < 0
181
- n
182
- end
183
-
184
- alias pos tell
185
-
186
- def to_ptr
187
- raise SDLError, "released" if closed?
188
- @st.to_ptr
189
- end
190
-
191
- def type
192
- raise SDLError, "released" if closed?
193
- @st.type
194
- end
195
-
196
- def write(obj)
197
- raise IOError, "closed" if closed?
198
-
199
- case obj
200
- when String
201
- ptr = obj
202
- len = obj.bytesize
203
- when Fiddle::Pointer
204
- ptr = obj
205
- len = obj.size
206
- else
207
- ptr = obj.to_s
208
- len = ptr.bytesize
209
- end
210
-
211
- n = SDL.SDL_RWwrite(self, ptr, 1, len)
212
- raise SDLError if n < len
213
- n
214
- end
89
+ def to_ptr = @st.to_ptr
215
90
  end
216
91
  end
@@ -1,44 +1,44 @@
1
- module SDLRuby::SDL
2
- require_relative 'SDL_main.h.rb'
3
- require_relative 'SDL_stdinc.h.rb'
4
- require_relative 'SDL_audio.h.rb'
5
- require_relative 'SDL_clipboard.h.rb'
6
- require_relative 'SDL_cpuinfo.h.rb'
7
- require_relative 'SDL_endian.h.rb'
8
- require_relative 'SDL_error.h.rb'
9
- require_relative 'SDL_events.h.rb'
10
- require_relative 'SDL_filesystem.h.rb'
11
- require_relative 'SDL_gamecontroller.h.rb'
12
- require_relative 'SDL_guid.h.rb'
13
- require_relative 'SDL_hints.h.rb'
14
- require_relative 'SDL_joystick.h.rb'
15
- require_relative 'SDL_messagebox.h.rb'
16
- require_relative 'SDL_power.h.rb'
17
- require_relative 'SDL_render.h.rb'
18
- require_relative 'SDL_rwops.h.rb'
19
- require_relative 'SDL_sensor.h.rb'
20
- require_relative 'SDL_shape.h.rb'
21
- require_relative 'SDL_system.h.rb'
22
- require_relative 'SDL_timer.h.rb'
23
- require_relative 'SDL_version.h.rb'
24
- require_relative 'SDL_video.h.rb'
25
- require_relative 'SDL_locale.h.rb'
26
- require_relative 'SDL_misc.h.rb'
27
-
28
- SDL_INIT_TIMER = 0x00000001
29
- SDL_INIT_AUDIO = 0x00000010
30
- SDL_INIT_VIDEO = 0x00000020
31
- SDL_INIT_JOYSTICK = 0x00000200
32
- SDL_INIT_HAPTIC = 0x00001000
33
- SDL_INIT_GAMECONTROLLER = 0x00002000
34
- SDL_INIT_EVENTS = 0x00004000
35
- SDL_INIT_SENSOR = 0x00008000
36
- SDL_INIT_NOPARACHUTE = 0x00100000
37
- SDL_INIT_EVERYTHING = ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR )
38
-
39
- extern "int SDL_Init(Uint32 flags)"
40
- extern "int SDL_InitSubSystem(Uint32 flags)"
41
- extern "void SDL_QuitSubSystem(Uint32 flags)"
42
- extern "Uint32 SDL_WasInit(Uint32 flags)"
43
- extern "void SDL_Quit(void)"
44
- end
1
+ module SDLRuby::SDL
2
+ require_relative 'SDL_main.h.rb'
3
+ require_relative 'SDL_stdinc.h.rb'
4
+ require_relative 'SDL_audio.h.rb'
5
+ require_relative 'SDL_clipboard.h.rb'
6
+ require_relative 'SDL_cpuinfo.h.rb'
7
+ require_relative 'SDL_endian.h.rb'
8
+ require_relative 'SDL_error.h.rb'
9
+ require_relative 'SDL_events.h.rb'
10
+ require_relative 'SDL_filesystem.h.rb'
11
+ require_relative 'SDL_gamecontroller.h.rb'
12
+ require_relative 'SDL_guid.h.rb'
13
+ require_relative 'SDL_hints.h.rb'
14
+ require_relative 'SDL_joystick.h.rb'
15
+ require_relative 'SDL_messagebox.h.rb'
16
+ require_relative 'SDL_power.h.rb'
17
+ require_relative 'SDL_render.h.rb'
18
+ require_relative 'SDL_rwops.h.rb'
19
+ require_relative 'SDL_sensor.h.rb'
20
+ require_relative 'SDL_shape.h.rb'
21
+ require_relative 'SDL_system.h.rb'
22
+ require_relative 'SDL_timer.h.rb'
23
+ require_relative 'SDL_version.h.rb'
24
+ require_relative 'SDL_video.h.rb'
25
+ require_relative 'SDL_locale.h.rb'
26
+ require_relative 'SDL_misc.h.rb'
27
+
28
+ SDL_INIT_TIMER = 0x00000001
29
+ SDL_INIT_AUDIO = 0x00000010
30
+ SDL_INIT_VIDEO = 0x00000020
31
+ SDL_INIT_JOYSTICK = 0x00000200
32
+ SDL_INIT_HAPTIC = 0x00001000
33
+ SDL_INIT_GAMECONTROLLER = 0x00002000
34
+ SDL_INIT_EVENTS = 0x00004000
35
+ SDL_INIT_SENSOR = 0x00008000
36
+ SDL_INIT_NOPARACHUTE = 0x00100000
37
+ SDL_INIT_EVERYTHING = ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR )
38
+
39
+ extern "int SDL_Init(Uint32 flags)"
40
+ extern "int SDL_InitSubSystem(Uint32 flags)"
41
+ extern "void SDL_QuitSubSystem(Uint32 flags)"
42
+ extern "Uint32 SDL_WasInit(Uint32 flags)"
43
+ extern "void SDL_Quit(void)"
44
+ end
@@ -1,160 +1,160 @@
1
- module SDLRuby::SDL
2
- require_relative "SDL_stdinc.h"
3
- require_relative "SDL_error.h"
4
- require_relative "SDL_endian.h"
5
- require_relative "SDL_rwops.h"
6
-
7
- typealias "SDL_AudioFormat", "Uint16"
8
-
9
- SDL_AUDIO_MASK_BITSIZE = (0xFF)
10
- SDL_AUDIO_MASK_DATATYPE = (1<<8)
11
- SDL_AUDIO_MASK_ENDIAN = (1<<12)
12
- SDL_AUDIO_MASK_SIGNED = (1<<15)
13
-
14
- def self.SDL_AUDIO_BITSIZE(x)
15
- (x & SDL_AUDIO_MASK_BITSIZE)
16
- end
17
- def self.SDL_AUDIO_ISFLOAT(x)
18
- (x & SDL_AUDIO_MASK_DATATYPE)
19
- end
20
- def self.SDL_AUDIO_ISBIGENDIAN(x)
21
- (x & SDL_AUDIO_MASK_ENDIAN)
22
- end
23
- def self.SDL_AUDIO_ISSIGNED(x)
24
- (x & SDL_AUDIO_MASK_SIGNED)
25
- end
26
- def self.SDL_AUDIO_ISINT(x)
27
- (!SDL_AUDIO_ISFLOAT(x))
28
- end
29
- def self.SDL_AUDIO_ISLITTLEENDIAN(x)
30
- (!SDL_AUDIO_ISBIGENDIAN(x))
31
- end
32
- def self.SDL_AUDIO_ISUNSIGNED(x)
33
- (!SDL_AUDIO_ISSIGNED(x))
34
- end
35
-
36
- AUDIO_U8 = 0x0008
37
- AUDIO_S8 = 0x8008
38
- AUDIO_U16LSB = 0x0010
39
- AUDIO_S16LSB = 0x8010
40
- AUDIO_U16MSB = 0x1010
41
- AUDIO_S16MSB = 0x9010
42
- AUDIO_U16 = AUDIO_U16LSB
43
- AUDIO_S16 = AUDIO_S16LSB
44
- AUDIO_S32LSB = 0x8020
45
- AUDIO_S32MSB = 0x9020
46
- AUDIO_S32 = AUDIO_S32LSB
47
- AUDIO_F32LSB = 0x8120
48
- AUDIO_F32MSB = 0x9120
49
- AUDIO_F32 = AUDIO_F32LSB
50
-
51
- if SDL_BYTEORDER == SDL_LIL_ENDIAN
52
- AUDIO_U16SYS = AUDIO_U16LSB
53
- AUDIO_S16SYS = AUDIO_S16LSB
54
- AUDIO_S32SYS = AUDIO_S32LSB
55
- AUDIO_F32SYS = AUDIO_F32LSB
56
- else
57
- AUDIO_U16SYS = AUDIO_U16MSB
58
- AUDIO_S16SYS = AUDIO_S16MSB
59
- AUDIO_S32SYS = AUDIO_S32MSB
60
- AUDIO_F32SYS = AUDIO_F32MSB
61
- end
62
-
63
- SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = 0x00000001
64
- SDL_AUDIO_ALLOW_FORMAT_CHANGE = 0x00000002
65
- SDL_AUDIO_ALLOW_CHANNELS_CHANGE = 0x00000004
66
- SDL_AUDIO_ALLOW_SAMPLES_CHANGE = 0x00000008
67
- SDL_AUDIO_ALLOW_ANY_CHANGE = (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE)
68
-
69
- typealias "SDL_AudioCallback", "void*"
70
-
71
- SDL_AudioSpec = struct(
72
- [
73
- "int freq",
74
- "SDL_AudioFormat format",
75
- "Uint8 channels",
76
- "Uint8 silence",
77
- "Uint16 samples",
78
- "Uint16 padding",
79
- "Uint32 size",
80
- "SDL_AudioCallback callback",
81
- "void *userdata",
82
- ]
83
- )
84
-
85
- typealias "SDL_AudioFilter", "void*"
86
-
87
- SDL_AUDIOCVT_MAX_FILTERS = 9
88
-
89
- SDL_AudioCVT = struct(
90
- [
91
- "int needed",
92
- "SDL_AudioFormat src_format",
93
- "SDL_AudioFormat dst_format",
94
- "double rate_incr",
95
- "Uint8 *buf",
96
- "int len",
97
- "int len_cvt",
98
- "int len_mult",
99
- "double len_ratio",
100
- "SDL_AudioFilter filters[#{SDL_AUDIOCVT_MAX_FILTERS + 1}]",
101
- "int filter_index",
102
- ]
103
- )
104
-
105
- extern "int SDL_GetNumAudioDrivers(void)"
106
- extern "const char * SDL_GetAudioDriver(int index)"
107
- extern "int SDL_AudioInit(const char *driver_name)"
108
- extern "void SDL_AudioQuit(void)"
109
- extern "const char * SDL_GetCurrentAudioDriver(void)"
110
- extern "int SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)"
111
-
112
- typealias "SDL_AudioDeviceID", "Uint32"
113
-
114
- extern "int SDL_GetNumAudioDevices(int iscapture)"
115
- extern "const char * SDL_GetAudioDeviceName(int index, int iscapture)"
116
- extern "int SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)"
117
- extern "int SDL_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)"
118
- extern "SDL_AudioDeviceID SDL_OpenAudioDevice( const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes)"
119
-
120
- SDL_AUDIO_STOPPED = 0
121
- SDL_AUDIO_PLAYING = 1
122
- SDL_AUDIO_PAUSED = 2
123
- typealias "SDL_AudioStatus", "int"
124
-
125
- extern "SDL_AudioStatus SDL_GetAudioStatus(void)"
126
- extern "SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev)"
127
- extern "void SDL_PauseAudio(int pause_on)"
128
- extern "void SDL_PauseAudioDevice(SDL_AudioDeviceID dev, int pause_on)"
129
- extern "SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops * src, int freesrc, SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)"
130
-
131
- def self.SDL_LoadWAV(file, spec, audio_buf, audio_len)
132
- SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
133
- end
134
-
135
- extern "void SDL_FreeWAV(Uint8 * audio_buf)"
136
- extern "int SDL_BuildAudioCVT(SDL_AudioCVT * cvt, SDL_AudioFormat src_format, Uint8 src_channels, int src_rate, SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate)"
137
- extern "int SDL_ConvertAudio(SDL_AudioCVT * cvt)"
138
- extern "SDL_AudioStream * SDL_NewAudioStream(const SDL_AudioFormat src_format, const Uint8 src_channels, const int src_rate, const SDL_AudioFormat dst_format, const Uint8 dst_channels, const int dst_rate)"
139
- extern "int SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)"
140
- extern "int SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)"
141
- extern "int SDL_AudioStreamAvailable(SDL_AudioStream *stream)"
142
- extern "int SDL_AudioStreamFlush(SDL_AudioStream *stream)"
143
- extern "void SDL_AudioStreamClear(SDL_AudioStream *stream)"
144
- extern "void SDL_FreeAudioStream(SDL_AudioStream *stream)"
145
-
146
- SDL_MIX_MAXVOLUME = 128
147
-
148
- extern "void SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)"
149
- extern "void SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format, Uint32 len, int volume)"
150
- extern "int SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len)"
151
- extern "Uint32 SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len)"
152
- extern "Uint32 SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev)"
153
- extern "void SDL_ClearQueuedAudio(SDL_AudioDeviceID dev)"
154
- extern "void SDL_LockAudio(void)"
155
- extern "void SDL_LockAudioDevice(SDL_AudioDeviceID dev)"
156
- extern "void SDL_UnlockAudio(void)"
157
- extern "void SDL_UnlockAudioDevice(SDL_AudioDeviceID dev)"
158
- extern "void SDL_CloseAudio(void)"
159
- extern "void SDL_CloseAudioDevice(SDL_AudioDeviceID dev)"
160
- end
1
+ module SDLRuby::SDL
2
+ require_relative "SDL_stdinc.h"
3
+ require_relative "SDL_error.h"
4
+ require_relative "SDL_endian.h"
5
+ require_relative "SDL_rwops.h"
6
+
7
+ typealias "SDL_AudioFormat", "Uint16"
8
+
9
+ SDL_AUDIO_MASK_BITSIZE = (0xFF)
10
+ SDL_AUDIO_MASK_DATATYPE = (1<<8)
11
+ SDL_AUDIO_MASK_ENDIAN = (1<<12)
12
+ SDL_AUDIO_MASK_SIGNED = (1<<15)
13
+
14
+ def self.SDL_AUDIO_BITSIZE(x)
15
+ (x & SDL_AUDIO_MASK_BITSIZE)
16
+ end
17
+ def self.SDL_AUDIO_ISFLOAT(x)
18
+ (x & SDL_AUDIO_MASK_DATATYPE)
19
+ end
20
+ def self.SDL_AUDIO_ISBIGENDIAN(x)
21
+ (x & SDL_AUDIO_MASK_ENDIAN)
22
+ end
23
+ def self.SDL_AUDIO_ISSIGNED(x)
24
+ (x & SDL_AUDIO_MASK_SIGNED)
25
+ end
26
+ def self.SDL_AUDIO_ISINT(x)
27
+ (!SDL_AUDIO_ISFLOAT(x))
28
+ end
29
+ def self.SDL_AUDIO_ISLITTLEENDIAN(x)
30
+ (!SDL_AUDIO_ISBIGENDIAN(x))
31
+ end
32
+ def self.SDL_AUDIO_ISUNSIGNED(x)
33
+ (!SDL_AUDIO_ISSIGNED(x))
34
+ end
35
+
36
+ AUDIO_U8 = 0x0008
37
+ AUDIO_S8 = 0x8008
38
+ AUDIO_U16LSB = 0x0010
39
+ AUDIO_S16LSB = 0x8010
40
+ AUDIO_U16MSB = 0x1010
41
+ AUDIO_S16MSB = 0x9010
42
+ AUDIO_U16 = AUDIO_U16LSB
43
+ AUDIO_S16 = AUDIO_S16LSB
44
+ AUDIO_S32LSB = 0x8020
45
+ AUDIO_S32MSB = 0x9020
46
+ AUDIO_S32 = AUDIO_S32LSB
47
+ AUDIO_F32LSB = 0x8120
48
+ AUDIO_F32MSB = 0x9120
49
+ AUDIO_F32 = AUDIO_F32LSB
50
+
51
+ if SDL_BYTEORDER == SDL_LIL_ENDIAN
52
+ AUDIO_U16SYS = AUDIO_U16LSB
53
+ AUDIO_S16SYS = AUDIO_S16LSB
54
+ AUDIO_S32SYS = AUDIO_S32LSB
55
+ AUDIO_F32SYS = AUDIO_F32LSB
56
+ else
57
+ AUDIO_U16SYS = AUDIO_U16MSB
58
+ AUDIO_S16SYS = AUDIO_S16MSB
59
+ AUDIO_S32SYS = AUDIO_S32MSB
60
+ AUDIO_F32SYS = AUDIO_F32MSB
61
+ end
62
+
63
+ SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = 0x00000001
64
+ SDL_AUDIO_ALLOW_FORMAT_CHANGE = 0x00000002
65
+ SDL_AUDIO_ALLOW_CHANNELS_CHANGE = 0x00000004
66
+ SDL_AUDIO_ALLOW_SAMPLES_CHANGE = 0x00000008
67
+ SDL_AUDIO_ALLOW_ANY_CHANGE = (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE)
68
+
69
+ typealias "SDL_AudioCallback", "void*"
70
+
71
+ SDL_AudioSpec = struct(
72
+ [
73
+ "int freq",
74
+ "SDL_AudioFormat format",
75
+ "Uint8 channels",
76
+ "Uint8 silence",
77
+ "Uint16 samples",
78
+ "Uint16 padding",
79
+ "Uint32 size",
80
+ "SDL_AudioCallback callback",
81
+ "void *userdata",
82
+ ]
83
+ )
84
+
85
+ typealias "SDL_AudioFilter", "void*"
86
+
87
+ SDL_AUDIOCVT_MAX_FILTERS = 9
88
+
89
+ SDL_AudioCVT = struct(
90
+ [
91
+ "int needed",
92
+ "SDL_AudioFormat src_format",
93
+ "SDL_AudioFormat dst_format",
94
+ "double rate_incr",
95
+ "Uint8 *buf",
96
+ "int len",
97
+ "int len_cvt",
98
+ "int len_mult",
99
+ "double len_ratio",
100
+ "SDL_AudioFilter filters[#{SDL_AUDIOCVT_MAX_FILTERS + 1}]",
101
+ "int filter_index",
102
+ ]
103
+ )
104
+
105
+ extern "int SDL_GetNumAudioDrivers(void)"
106
+ extern "const char * SDL_GetAudioDriver(int index)"
107
+ extern "int SDL_AudioInit(const char *driver_name)"
108
+ extern "void SDL_AudioQuit(void)"
109
+ extern "const char * SDL_GetCurrentAudioDriver(void)"
110
+ extern "int SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)"
111
+
112
+ typealias "SDL_AudioDeviceID", "Uint32"
113
+
114
+ extern "int SDL_GetNumAudioDevices(int iscapture)"
115
+ extern "const char * SDL_GetAudioDeviceName(int index, int iscapture)"
116
+ extern "int SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)"
117
+ extern "int SDL_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)"
118
+ extern "SDL_AudioDeviceID SDL_OpenAudioDevice( const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes)"
119
+
120
+ SDL_AUDIO_STOPPED = 0
121
+ SDL_AUDIO_PLAYING = 1
122
+ SDL_AUDIO_PAUSED = 2
123
+ typealias "SDL_AudioStatus", "int"
124
+
125
+ extern "SDL_AudioStatus SDL_GetAudioStatus(void)"
126
+ extern "SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev)"
127
+ extern "void SDL_PauseAudio(int pause_on)"
128
+ extern "void SDL_PauseAudioDevice(SDL_AudioDeviceID dev, int pause_on)"
129
+ extern "SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops * src, int freesrc, SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)"
130
+
131
+ def self.SDL_LoadWAV(file, spec, audio_buf, audio_len)
132
+ SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
133
+ end
134
+
135
+ extern "void SDL_FreeWAV(Uint8 * audio_buf)"
136
+ extern "int SDL_BuildAudioCVT(SDL_AudioCVT * cvt, SDL_AudioFormat src_format, Uint8 src_channels, int src_rate, SDL_AudioFormat dst_format, Uint8 dst_channels, int dst_rate)"
137
+ extern "int SDL_ConvertAudio(SDL_AudioCVT * cvt)"
138
+ extern "SDL_AudioStream * SDL_NewAudioStream(const SDL_AudioFormat src_format, const Uint8 src_channels, const int src_rate, const SDL_AudioFormat dst_format, const Uint8 dst_channels, const int dst_rate)"
139
+ extern "int SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)"
140
+ extern "int SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)"
141
+ extern "int SDL_AudioStreamAvailable(SDL_AudioStream *stream)"
142
+ extern "int SDL_AudioStreamFlush(SDL_AudioStream *stream)"
143
+ extern "void SDL_AudioStreamClear(SDL_AudioStream *stream)"
144
+ extern "void SDL_FreeAudioStream(SDL_AudioStream *stream)"
145
+
146
+ SDL_MIX_MAXVOLUME = 128
147
+
148
+ extern "void SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)"
149
+ extern "void SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format, Uint32 len, int volume)"
150
+ extern "int SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len)"
151
+ extern "Uint32 SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len)"
152
+ extern "Uint32 SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev)"
153
+ extern "void SDL_ClearQueuedAudio(SDL_AudioDeviceID dev)"
154
+ extern "void SDL_LockAudio(void)"
155
+ extern "void SDL_LockAudioDevice(SDL_AudioDeviceID dev)"
156
+ extern "void SDL_UnlockAudio(void)"
157
+ extern "void SDL_UnlockAudioDevice(SDL_AudioDeviceID dev)"
158
+ extern "void SDL_CloseAudio(void)"
159
+ extern "void SDL_CloseAudioDevice(SDL_AudioDeviceID dev)"
160
+ end