SDLRuby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/SDLRuby/event/accessor.rb +62 -63
  4. data/lib/SDLRuby/event/type.rb +1 -1
  5. data/lib/SDLRuby/event.rb +98 -80
  6. data/lib/SDLRuby/sdl/include/SDL.h.rb +11 -0
  7. data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +125 -14
  8. data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +24 -0
  9. data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +10 -1
  10. data/lib/SDLRuby/sdl/include/SDL_error.h.rb +21 -2
  11. data/lib/SDLRuby/sdl/include/SDL_events.h.rb +458 -18
  12. data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +92 -11
  13. data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +10 -4
  14. data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +186 -1
  15. data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +72 -10
  16. data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +13 -4
  17. data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +287 -2
  18. data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +9 -2
  19. data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +50 -2
  20. data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +39 -8
  21. data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +271 -11
  22. data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +43 -14
  23. data/lib/SDLRuby/sdl/include/SDL_render.h.rb +112 -75
  24. data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +63 -19
  25. data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +248 -1
  26. data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +33 -6
  27. data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +42 -4
  28. data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +92 -29
  29. data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +1 -7
  30. data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +11 -3
  31. data/lib/SDLRuby/sdl/include/SDL_version.h.rb +10 -2
  32. data/lib/SDLRuby/sdl/include/SDL_video.h.rb +221 -74
  33. data/lib/SDLRuby/sdl/sdl.rb +0 -50
  34. data/lib/SDLRuby/sdl.rb +7 -8
  35. data/lib/SDLRuby/version.rb +1 -1
  36. data/sig/lib/SDLRuby/event/accessor.rbs +157 -0
  37. data/sig/lib/SDLRuby/event/type.rbs +67 -0
  38. data/sig/lib/SDLRuby/event.rbs +47 -0
  39. data/sig/lib/SDLRuby/sdl.rbs +655 -0
  40. metadata +6 -22
  41. data/lib/SDLRuby/sdl/sdl_audio.rb +0 -75
  42. data/lib/SDLRuby/sdl/sdl_blendmode.rb +0 -10
  43. data/lib/SDLRuby/sdl/sdl_error.rb +0 -5
  44. data/lib/SDLRuby/sdl/sdl_events.rb +0 -470
  45. data/lib/SDLRuby/sdl/sdl_hints.rb +0 -9
  46. data/lib/SDLRuby/sdl/sdl_keyboard.rb +0 -12
  47. data/lib/SDLRuby/sdl/sdl_locale.rb +0 -8
  48. data/lib/SDLRuby/sdl/sdl_message_box.rb +0 -7
  49. data/lib/SDLRuby/sdl/sdl_mouse.rb +0 -32
  50. data/lib/SDLRuby/sdl/sdl_palette.rb +0 -12
  51. data/lib/SDLRuby/sdl/sdl_pixels.rb +0 -138
  52. data/lib/SDLRuby/sdl/sdl_rect.rb +0 -11
  53. data/lib/SDLRuby/sdl/sdl_render.rb +0 -35
  54. data/lib/SDLRuby/sdl/sdl_rw_ops.rb +0 -29
  55. data/lib/SDLRuby/sdl/sdl_scancode.rb +0 -255
  56. data/lib/SDLRuby/sdl/sdl_surface.rb +0 -27
  57. data/lib/SDLRuby/sdl/sdl_version.rb +0 -5
  58. data/lib/SDLRuby/sdl/sdl_video.rb +0 -104
  59. data/sig/SDLRuby/event.rbs +0 -104
  60. data/sig/SDLRuby/sdl.rbs +0 -606
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7516a8b356b287a6f985881964b1a44f76922354a13d70000b9990dd2a67badd
4
- data.tar.gz: 358b7f4a6b40bd7a31e7249beaac18f77d3d7a08b21c9802f30203fce36628ed
3
+ metadata.gz: 9420fbe6427d0cc1c72c97f9da2ff735959cc6233c53df296a2fa75330c5ae8b
4
+ data.tar.gz: 7ea49cbccc75f54cc54cc105f8662270b671c182abec10f3bba8ba01868113be
5
5
  SHA512:
6
- metadata.gz: b5f6c08130fa89f6aa74009a02a5d4a7ada123839f0a2eef2894347ac358e0e75b188bbfd0a657004be3d54207166484b8b842b43edb5ee5dbf6340c4f13f095
7
- data.tar.gz: 26017bbb155bb41c032396b13e9981ee62c72954b66501b2ab818356a9cedcbb295a74f810f742ecaf83b1ba52dd6c69b658e39859b35443a59f575fe0d72423
6
+ metadata.gz: 59ac04bd9bade02f0865dc35e1977926b907bc535629d412a0c801b7913c10a886641b29cb706e905a8eacac23983dc10971d36009f2daa9d71b0c820e92b880
7
+ data.tar.gz: 518572826202fab87596afd4241b87fe743fb3b1055d75d6825a54fe91db9604d965cf074b300941fb84a3f89af47e790c6b9de74c420e352b6af57feabf9824
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-09-13
4
+
5
+ - Implementation of the Event Object. SDL event queue is now available.
6
+
3
7
  ## [0.1.0] - 2023-08-30
4
8
 
5
9
  - Initial release
@@ -3,37 +3,21 @@ module SDLRuby
3
3
  module Accessor
4
4
  include SDL
5
5
 
6
- union_members = SDL_Event.members.inject([]) do |result, (name, members)|
7
- if members
8
- # ネストした構造体の場合は親のみを選択する。
9
- result << [name, members.flatten(1).select { |a| !(Array === a) }]
10
- end
11
-
12
- result
13
- end
6
+ @modules = Hash.new
14
7
 
15
- @modules = Hash.new do |_, key|
16
- raise KeyError, "undefined SDL_Event member(#{key})"
17
- end
18
-
19
- union_members.each do |name, members|
8
+ (SDL_Event.members - %w[type padding]).each do |name, members|
20
9
  @modules[name.to_sym] = Module.new do
21
10
  extend Forwardable
22
-
23
- def_delegators :entity, *members
11
+ # ネストした構造体の場合は親のみを選択する。
12
+ #
13
+ def_delegators :entity, *members.flatten(1).select { |a| !(Array === a) }
24
14
  end
25
15
  end
26
16
 
27
17
  class << self
28
- def [](sym) = @modules[sym]
29
- end
30
-
31
- self[:adevice].module_eval do
32
- def capture? = entity.iscapture != 0
33
- end
34
-
35
- self[:cbutton].module_eval do
36
- def pressed? = state == SDL_PRESSED
18
+ def [](sym)
19
+ @modules[sym] || raise(KeyError, "undefined member(#{sym})")
20
+ end
37
21
  end
38
22
 
39
23
  self[:drop].module_eval do
@@ -41,14 +25,14 @@ module SDLRuby
41
25
 
42
26
  def file = char_ptr_to_str(entity.file)
43
27
 
44
- alias_method :text, :file
28
+ alias text file
45
29
 
46
30
  def self.extended(obj)
47
- @_ptr ||= entity.file.tap { |ptr| ptr.free = SDL_FREE unless ptr.null? }
31
+ obj.__send__(:keep_member_pointer, :file)
48
32
  end
49
33
  end
50
34
 
51
- self[:edit].module_eval do
35
+ self[:edit].module_eval do
52
36
  undef text
53
37
 
54
38
  def text = char_ary_to_str(entity.text)
@@ -60,68 +44,83 @@ module SDLRuby
60
44
  def text = char_ptr_to_str(entity.text)
61
45
 
62
46
  def self.extended(obj)
63
- @_ptr ||= entity.text.tap { |ptr| ptr.free = SDL_FREE }
47
+ obj.__send__(:keep_member_pointer, :text)
64
48
  end
65
49
  end
66
50
 
67
- self[:jbutton].module_eval do
68
- def pressed? = state == SDL_PRESSED
69
- end
70
-
71
51
  self[:key].module_eval do
72
52
  undef keysym
73
53
 
74
54
  def keysym = entity.keysym.to_h
75
55
  end
76
56
 
77
- self[:syswm].module_eval do
78
- undef msg
79
-
80
- def msg = entity.msg
81
- end
82
-
83
57
  self[:text].module_eval do
84
58
  undef text
85
59
 
86
60
  def text = char_ary_to_str(entity.text)
87
61
  end
88
62
 
89
- self[:user].module_eval do
90
- undef data1, data2
63
+ # イベント構造体へのアクセスをSTIとして実装する。
64
+ # メンバー全てのゲッターに応答できるようにする。(NoMethodErrorを出さない)
65
+ # ※これはKernel#yメソッドにオブジェクトが応答してしまうため、
66
+ # 事前にattr_readerでオーバーライドする。
67
+ #
68
+ attr_reader *%w[
69
+ axis ball button clicks code dDist dTheta data data1 data2 direction
70
+ display dx dy error event file finger fingerId gestureId hat iscapture
71
+ keysym length level mouseX mouseY msg numFingers
72
+ padding padding1 padding2 padding3 padding4
73
+ preciseX preciseY pressure repeat sensor start state text timestamp
74
+ timestamp_us touchId touchpad type value which windowID x xrel y yrel
75
+ ]
91
76
 
92
- def data1 = entity.data1
77
+ # Ruby like accessor
78
+ #
79
+ alias d_dist dDist
80
+ alias d_theta dTheta
81
+ alias finger_id fingerId
82
+ alias gesture_id gestureId
83
+ alias mouse_x mouseX
84
+ alias mouse_y mouseY
85
+ alias num_fingers numFingers
86
+ alias precise_x preciseX
87
+ alias precise_y preciseY
88
+ alias touch_id touchId
89
+ alias window_id windowID
90
+
91
+ # for adevice
92
+ #
93
+ # iscapture = nil => false
94
+ # iscapture = 0 => false
95
+ # iscapture = 1 => true
96
+ #
97
+ def capture? = iscapture&.nonzero? ? true : false
93
98
 
94
- def data2 = entity.data2
95
- end
99
+ # for button, cbutton, jbutton
100
+ #
101
+ def pressed? = state == SDL_PRESSED
96
102
 
97
- # STIの実装としてメンバー全てのゲッターに例外を出さず応答するようにする。
98
- # これは"y"メソッドにRubyが応答してしまうため。事前にオーバーライドしておく。
103
+ # for key
99
104
  #
100
- all_members = union_members.map { |a| a.last }.flatten.uniq
105
+ def scancode = keysym&.[]("scancode")
101
106
 
102
- attr_reader(*all_members)
107
+ def sym = keysym&.[]("sym")
103
108
 
104
- # Ruby like accessor
105
- #
106
- alias_method :d_dist, :dDist
107
- alias_method :d_theta, :dTheta
108
- alias_method :finger_id, :fingerId
109
- alias_method :gesture_id, :gestureId
110
- alias_method :mouse_x, :mouseX
111
- alias_method :mouse_y, :mouseY
112
- alias_method :num_fingers, :numFingers
113
- alias_method :precise_x, :preciseX
114
- alias_method :precise_y, :preciseY
115
- alias_method :touch_id, :touchId
116
- alias_method :window_id, :windowID
117
-
118
- private def char_ary_to_str(a)
109
+ def mod = keysym&.[]("mod")
110
+
111
+ private
112
+
113
+ def char_ary_to_str(a)
119
114
  a[0, a.find_index(0)].pack("C*").force_encoding("UTF-8")
120
115
  end
121
116
 
122
- private def char_ptr_to_str(ptr)
117
+ def char_ptr_to_str(ptr)
123
118
  ptr.null? ? "" : ptr.to_s.force_encoding("UTF-8")
124
119
  end
120
+
121
+ def keep_member_pointer(attr)
122
+ @_ptr ||= entity.__send__(attr).tap { |ptr| ptr.free = SDL_FREE }
123
+ end
125
124
  end
126
125
  end
127
126
  end
@@ -34,7 +34,7 @@ module SDLRuby
34
34
  USER_EVENT = SDL_USEREVENT...SDL_LASTEVENT
35
35
 
36
36
  class << self
37
- def to_sym(type)
37
+ def [](type)
38
38
  case type
39
39
  when DISPLAY_EVENT then :display
40
40
  when WINDOW_EVENT then :window
data/lib/SDLRuby/event.rb CHANGED
@@ -1,80 +1,98 @@
1
- require_relative 'event/accessor'
2
- require_relative 'event/type'
3
-
4
- module SDLRuby
5
- class Event
6
- include Accessor, Fiddle, SDL
7
-
8
- class << self
9
- include SDL
10
-
11
- # SDL_WaitEvent, SDL_WaitEventTimeoutはRubyのスレッドを停止させるため実装しない。
12
- # ※C関数呼び出し時にGVLを外せれば可能か?
13
- # SDL_RegisterEventsはSDLに対応するゲッターがないため実装しない。
14
- # SDL_PushEventは必要ならば実装する。ただしEventコンストラクターを含むため規模が大きい。
15
- #
16
- # SDL_AddEventWatch, SDL_SetEventFilterおよびSDL_FilterEventsは実装しない。
17
- # イベントにポインターを含む場合、RubyのGCの管理下に置く方法が複雑なため。
18
- # ※現実装ではイベントを取り込んだ時点でポインターをRubyの管理下に置いている。
19
- # メンバーのポインター管理をファイナライザーに移行できれば可能だろう。
20
- # ※そしてファイナライザーを設定するかどうか選択する。
21
- # いずれもSDL_EventPumpを呼び出さなければ動作しない。
22
- # 非同期にイベントを取得できるわけではない。
23
- # SDL_PeepEventsは実装しない。
24
- # SDL_ADDEVENT:
25
- # イベントのメンバーにポインターを含む場合、それのSDL側へのコピーが必要になる。
26
- # SDL_PushEventが実装されれば、それが同等の機能を持つ。
27
- # SDL_PEEKEVENT:
28
- # SDL_FilterEventsが実装できれば、それが同等の機能を持つ。
29
- # SDL_GETEVENT:
30
- # キューの削除が目的だと思う。それを行うならSDL_PollEventを利用して欲しい。
31
- # イベントキューはコレクションではない。
32
- #
33
- # SDL_PeepEventsは実行中にキューをロックすることに注意。
34
- # また、SDL_SYSWMEVENTのmsgメンバーにコピーが必要か分からない。(要調査)
35
- # ※このポインターだけSDLが管理しているようだ。
36
-
37
- def clear = (pump or flash)
38
-
39
- def count = SDL.SDL_PeepEvents(nil, 0, SDL_PEEKEVENT, 0, -1)
40
-
41
- def disable(type) = SDL.SDL_EventState(type, 0)
42
-
43
- def enable(type) = SDL.SDL_EventState(type, 1)
44
-
45
- def flash = SDL.SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT)
46
-
47
- def get = poll(e = new)
48
-
49
- private :new
50
-
51
- private def poll(e) = (SDL.SDL_PollEvent(e).nonzero? and e.update)
52
-
53
- def pump = SDL.SDL_PumpEvents
54
-
55
- alias update pump
56
-
57
- def quit? = (pump or SDL.SDL_HasEvent(SDL_QUIT) != 0)
58
- end
59
-
60
- def initialize
61
- @st = SDL_Event.malloc(RUBY_FREE)
62
- end
63
-
64
- private attr_reader :entity
65
-
66
- def to_ptr = @st.to_ptr
67
-
68
- def to_sym = Type.to_sym(@st.type)
69
-
70
- def update
71
- unless @entity
72
- sym = to_sym
73
- @entity = @st.__send__(sym)
74
- extend(Accessor[sym])
75
- end
76
-
77
- self
78
- end
79
- end
80
- end
1
+ require_relative 'event/accessor'
2
+ require_relative 'event/type'
3
+
4
+ module SDLRuby
5
+ class Event
6
+ include Accessor, Fiddle, SDL
7
+
8
+ class << self
9
+ include SDL
10
+
11
+ private def __malloc__ = Fiddle.malloc(SDL_Event.size)
12
+
13
+ def clear = SDL.SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT)
14
+
15
+ # The deq method can be called from any thread.
16
+ #
17
+ def deq(non_block = false)
18
+ if non_block && empty?
19
+ raise SDLError, "event queue empty"
20
+ end
21
+
22
+ e = __malloc__
23
+
24
+ case SDL.SDL_PeepEvents(e, 1, SDL_GETEVENT, 0, -1)
25
+ when 1
26
+ return new(e)
27
+ when 0
28
+ sleep(0.001)
29
+ else # -1 "The event system has been shut down"
30
+ return
31
+ end while true
32
+ end
33
+
34
+ def disable(type) = SDL.SDL_EventState(type, 0)
35
+
36
+ def empty? = SDL.SDL_PeepEvents(nil, 1, SDL_PEEKEVENT, 0, -1) != 1
37
+
38
+ def enable(type) = SDL.SDL_EventState(type, 1)
39
+
40
+ def get
41
+ unless Thread.current == Thread.main
42
+ raise SDLError, "called from a non-main thread"
43
+ end
44
+
45
+ e = __malloc__
46
+ SDL.SDL_WaitEvent(e)
47
+ new(e)
48
+ end
49
+
50
+ def length = SDL.SDL_PeepEvents(nil, 0, SDL_PEEKEVENT, 0, -1)
51
+ alias size length
52
+
53
+ def quit? = (update or SDL.SDL_HasEvent(SDL_QUIT) == 1)
54
+
55
+ def reserve(num)
56
+ base = SDL.SDL_RegisterEvents(num)
57
+
58
+ if base == 0xFFFF_FFFF
59
+ raise SDLError, "cannot register any more user events"
60
+ end
61
+
62
+ base
63
+ end
64
+
65
+ def update
66
+ unless Thread.current == Thread.main
67
+ raise SDLError, "called from a non-main thread"
68
+ end
69
+
70
+ SDL.SDL_PumpEvents
71
+ end
72
+
73
+ def wait(timeout = nil)
74
+ return self unless empty?
75
+
76
+ return nil unless Thread.current == Thread.main
77
+
78
+ if timeout
79
+ SDL.SDL_WaitEventTimeout(nil, timeout * 1000)
80
+ else
81
+ SDL.SDL_WaitEvent(nil)
82
+ end == 1 ? self : nil
83
+ end
84
+ end
85
+
86
+ def initialize(ptr)
87
+ st = SDL_Event.new(ptr)
88
+ sym = Type[st.type]
89
+ @entity = st.__send__(sym)
90
+ @entity.to_ptr.free = RUBY_FREE
91
+ extend(Accessor[sym])
92
+ end
93
+
94
+ private attr_reader :entity
95
+
96
+ def to_ptr = @entity.to_ptr
97
+ end
98
+ end
@@ -25,6 +25,17 @@ module SDLRuby::SDL
25
25
  require_relative 'SDL_locale.h.rb'
26
26
  require_relative 'SDL_misc.h.rb'
27
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
+
28
39
  extern "int SDL_Init(Uint32 flags)"
29
40
  extern "int SDL_InitSubSystem(Uint32 flags)"
30
41
  extern "void SDL_QuitSubSystem(Uint32 flags)"
@@ -1,32 +1,140 @@
1
1
  module SDLRuby::SDL
2
- require_relative 'SDL_stdinc.h.rb'
3
- require_relative 'SDL_error.h.rb'
4
- require_relative 'SDL_endian.h.rb'
5
- require_relative 'SDL_rwops.h.rb'
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
6
 
7
7
  typealias "SDL_AudioFormat", "Uint16"
8
- typealias "SDL_AudioDeviceID", "Uint32"
9
- typealias "SDL_AudioStream", "struct _SDL_AudioStream"
10
- typealias "SDL_AudioStatus", "int"
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
+
11
105
  extern "int SDL_GetNumAudioDrivers(void)"
12
106
  extern "const char * SDL_GetAudioDriver(int index)"
13
107
  extern "int SDL_AudioInit(const char *driver_name)"
14
108
  extern "void SDL_AudioQuit(void)"
15
109
  extern "const char * SDL_GetCurrentAudioDriver(void)"
16
- extern "int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)"
110
+ extern "int SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)"
111
+
112
+ typealias "SDL_AudioDeviceID", "Uint32"
113
+
17
114
  extern "int SDL_GetNumAudioDevices(int iscapture)"
18
115
  extern "const char * SDL_GetAudioDeviceName(int index, int iscapture)"
19
116
  extern "int SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)"
20
117
  extern "int SDL_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)"
21
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
+
22
125
  extern "SDL_AudioStatus SDL_GetAudioStatus(void)"
23
126
  extern "SDL_AudioStatus SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev)"
24
127
  extern "void SDL_PauseAudio(int pause_on)"
25
128
  extern "void SDL_PauseAudioDevice(SDL_AudioDeviceID dev, int pause_on)"
26
- extern "SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)"
27
- extern "void SDL_FreeWAV(Uint8 *audio_buf)"
28
- 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)"
29
- extern "int SDL_ConvertAudio(SDL_AudioCVT *cvt)"
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)"
30
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)"
31
139
  extern "int SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)"
32
140
  extern "int SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)"
@@ -34,8 +142,11 @@ module SDLRuby::SDL
34
142
  extern "int SDL_AudioStreamFlush(SDL_AudioStream *stream)"
35
143
  extern "void SDL_AudioStreamClear(SDL_AudioStream *stream)"
36
144
  extern "void SDL_FreeAudioStream(SDL_AudioStream *stream)"
37
- extern "void SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume)"
38
- extern "void SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, int volume)"
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)"
39
150
  extern "int SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len)"
40
151
  extern "Uint32 SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len)"
41
152
  extern "Uint32 SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev)"
@@ -1,6 +1,30 @@
1
1
  module SDLRuby::SDL
2
+ SDL_BLENDMODE_NONE = 0x00000000
3
+ SDL_BLENDMODE_BLEND = 0x00000001
4
+ SDL_BLENDMODE_ADD = 0x00000002
5
+ SDL_BLENDMODE_MOD = 0x00000004
6
+ SDL_BLENDMODE_MUL = 0x00000008
7
+ SDL_BLENDMODE_INVALID = 0x7FFFFFFF
2
8
  typealias "SDL_BlendMode", "int"
9
+
10
+ SDL_BLENDOPERATION_ADD = 0x1
11
+ SDL_BLENDOPERATION_SUBTRACT = 0x2
12
+ SDL_BLENDOPERATION_REV_SUBTRACT = 0x3
13
+ SDL_BLENDOPERATION_MINIMUM = 0x4
14
+ SDL_BLENDOPERATION_MAXIMUM = 0x5
3
15
  typealias "SDL_BlendOperation", "int"
16
+
17
+ SDL_BLENDFACTOR_ZERO = 0x1
18
+ SDL_BLENDFACTOR_ONE = 0x2
19
+ SDL_BLENDFACTOR_SRC_COLOR = 0x3
20
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4
21
+ SDL_BLENDFACTOR_SRC_ALPHA = 0x5
22
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6
23
+ SDL_BLENDFACTOR_DST_COLOR = 0x7
24
+ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8
25
+ SDL_BLENDFACTOR_DST_ALPHA = 0x9
26
+ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA
4
27
  typealias "SDL_BlendFactor", "int"
28
+
5
29
  extern "SDL_BlendMode SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor, SDL_BlendOperation colorOperation, SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor, SDL_BlendOperation alphaOperation)"
6
30
  end
@@ -1,3 +1,12 @@
1
1
  module SDLRuby::SDL
2
- require_relative 'SDL_stdinc.h.rb'
2
+ require_relative "SDL_stdinc.h"
3
+
4
+ SDL_LIL_ENDIAN = 1234
5
+ SDL_BIG_ENDIAN = 4321
6
+
7
+ if "\x01\x02\x03\x04".unpack("I") == 0x1020304
8
+ SDL_BYTEORDER = SDL_BIG_ENDIAN
9
+ else
10
+ SDL_BYTEORDER = SDL_LIL_ENDIAN
11
+ end
3
12
  end
@@ -1,9 +1,28 @@
1
1
  module SDLRuby::SDL
2
- require_relative 'SDL_stdinc.h.rb'
2
+ require_relative "SDL_stdinc.h"
3
3
 
4
- typealias "SDL_errorcode", "int"
4
+ extern "int SDL_SetError(const char *fmt, ...)"
5
5
  extern "const char * SDL_GetError(void)"
6
6
  extern "char * SDL_GetErrorMsg(char *errstr, int maxlen)"
7
7
  extern "void SDL_ClearError(void)"
8
+
9
+ def self.SDL_OutOfMemory()
10
+ SDL_Error(SDL_ENOMEM)
11
+ end
12
+ def self.SDL_Unsupported()
13
+ SDL_Error(SDL_UNSUPPORTED)
14
+ end
15
+ def self.SDL_InvalidParamError(param)
16
+ SDL_SetError("Parameter '%s' is invalid", (param))
17
+ end
18
+
19
+ SDL_ENOMEM = 0
20
+ SDL_EFREAD = 1
21
+ SDL_EFWRITE = 2
22
+ SDL_EFSEEK = 3
23
+ SDL_UNSUPPORTED = 4
24
+ SDL_LASTERROR = 5
25
+ typealias "SDL_errorcode", "int"
26
+
8
27
  extern "int SDL_Error(SDL_errorcode code)"
9
28
  end