gosu 1.1.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/dependencies/SDL/include/SDL.h +108 -14
- data/dependencies/SDL/include/SDL_assert.h +81 -50
- data/dependencies/SDL/include/SDL_atomic.h +135 -35
- data/dependencies/SDL/include/SDL_audio.h +960 -355
- data/dependencies/SDL/include/SDL_bits.h +11 -6
- data/dependencies/SDL/include/SDL_blendmode.h +91 -14
- data/dependencies/SDL/include/SDL_clipboard.h +30 -7
- data/dependencies/SDL/include/SDL_config.h +277 -27
- data/dependencies/SDL/include/SDL_config_android.h +13 -38
- data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
- data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
- data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
- data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
- data/dependencies/SDL/include/SDL_config_psp.h +16 -37
- data/dependencies/SDL/include/SDL_config_windows.h +28 -91
- data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
- data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
- data/dependencies/SDL/include/SDL_copying.h +1 -1
- data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
- data/dependencies/SDL/include/SDL_egl.h +906 -280
- data/dependencies/SDL/include/SDL_endian.h +101 -47
- data/dependencies/SDL/include/SDL_error.h +70 -19
- data/dependencies/SDL/include/SDL_events.h +387 -79
- data/dependencies/SDL/include/SDL_filesystem.h +73 -64
- data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
- data/dependencies/SDL/include/SDL_gesture.h +36 -6
- data/dependencies/SDL/include/SDL_haptic.h +304 -210
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +1286 -897
- data/dependencies/SDL/include/SDL_joystick.h +577 -130
- data/dependencies/SDL/include/SDL_keyboard.h +162 -63
- data/dependencies/SDL/include/SDL_keycode.h +7 -5
- data/dependencies/SDL/include/SDL_loadso.h +42 -8
- data/dependencies/SDL/include/SDL_locale.h +34 -32
- data/dependencies/SDL/include/SDL_log.h +212 -19
- data/dependencies/SDL/include/SDL_main.h +72 -17
- data/dependencies/SDL/include/SDL_messagebox.h +70 -23
- data/dependencies/SDL/include/SDL_metal.h +27 -32
- data/dependencies/SDL/include/SDL_misc.h +19 -15
- data/dependencies/SDL/include/SDL_mouse.h +262 -110
- data/dependencies/SDL/include/SDL_mutex.h +286 -66
- data/dependencies/SDL/include/SDL_name.h +1 -1
- data/dependencies/SDL/include/SDL_opengl.h +1 -1
- data/dependencies/SDL/include/SDL_opengles.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2.h +2 -2
- data/dependencies/SDL/include/SDL_pixels.h +199 -34
- data/dependencies/SDL/include/SDL_platform.h +39 -2
- data/dependencies/SDL/include/SDL_power.h +23 -10
- data/dependencies/SDL/include/SDL_quit.h +1 -1
- data/dependencies/SDL/include/SDL_rect.h +78 -28
- data/dependencies/SDL/include/SDL_render.h +1204 -472
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_rwops.h +605 -33
- data/dependencies/SDL/include/SDL_scancode.h +1 -1
- data/dependencies/SDL/include/SDL_sensor.h +76 -42
- data/dependencies/SDL/include/SDL_shape.h +38 -27
- data/dependencies/SDL/include/SDL_stdinc.h +96 -24
- data/dependencies/SDL/include/SDL_surface.h +571 -139
- data/dependencies/SDL/include/SDL_system.h +339 -101
- data/dependencies/SDL/include/SDL_syswm.h +50 -20
- data/dependencies/SDL/include/SDL_test.h +1 -1
- data/dependencies/SDL/include/SDL_test_assert.h +2 -2
- data/dependencies/SDL/include/SDL_test_common.h +23 -6
- data/dependencies/SDL/include/SDL_test_compare.h +1 -1
- data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
- data/dependencies/SDL/include/SDL_test_font.h +3 -3
- data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
- data/dependencies/SDL/include/SDL_test_harness.h +6 -6
- data/dependencies/SDL/include/SDL_test_images.h +1 -1
- data/dependencies/SDL/include/SDL_test_log.h +1 -1
- data/dependencies/SDL/include/SDL_test_md5.h +1 -1
- data/dependencies/SDL/include/SDL_test_memory.h +1 -1
- data/dependencies/SDL/include/SDL_test_random.h +2 -2
- data/dependencies/SDL/include/SDL_thread.h +226 -128
- data/dependencies/SDL/include/SDL_timer.h +129 -22
- data/dependencies/SDL/include/SDL_touch.h +48 -8
- data/dependencies/SDL/include/SDL_types.h +1 -1
- data/dependencies/SDL/include/SDL_version.h +72 -46
- data/dependencies/SDL/include/SDL_video.h +1266 -460
- data/dependencies/SDL/include/SDL_vulkan.h +100 -161
- data/dependencies/SDL/include/begin_code.h +22 -1
- data/dependencies/SDL/include/close_code.h +1 -1
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +83 -7
- data/dependencies/SDL_sound/SDL_sound.h +4 -4
- data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
- data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
- data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
- data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
- data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
- data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
- data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
- data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
- data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
- data/dependencies/SDL_sound/dr_flac.h +618 -220
- data/dependencies/SDL_sound/dr_mp3.h +263 -94
- data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
- data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
- data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
- data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
- data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
- data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
- data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
- data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
- data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
- data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
- data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
- data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
- data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
- data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
- data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
- data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
- data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
- data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
- data/dependencies/SDL_sound/stb_vorbis.h +508 -325
- data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
- data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
- data/dependencies/mojoAL/mojoal.c +4594 -0
- data/ext/gosu/extconf.rb +33 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Color.hpp +63 -107
- data/include/Gosu/Font.hpp +44 -50
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Graphics.hpp +64 -75
- data/include/Gosu/GraphicsBase.hpp +32 -39
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/Math.hpp +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Utility.hpp +10 -8
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +73 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +28 -37
- data/lib/gosu/swig_patches.rb +31 -3
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +9 -1
- data/src/Audio.cpp +86 -86
- data/src/AudioFile.hpp +6 -6
- data/src/AudioFileAudioToolbox.cpp +1 -1
- data/src/AudioFileSDLSound.cpp +1 -1
- data/src/AudioImpl.hpp +5 -5
- data/src/Bitmap.cpp +13 -13
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +62 -55
- data/src/EmptyImageData.hpp +16 -18
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +52 -57
- data/src/GosuViewController.cpp +2 -0
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +42 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +120 -113
- data/src/LargeImageData.hpp +18 -16
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +124 -169
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/RenderState.hpp +5 -5
- data/src/Resolution.cpp +114 -61
- data/src/RubyGosu.cxx +470 -501
- data/src/RubyGosu.h +3 -2
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +58 -59
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +108 -108
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +27 -23
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +82 -23
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +103 -86
- data/src/WindowUIKit.cpp +48 -51
- metadata +8 -20
- data/dependencies/SDL/include/SDL_config_os2.h +0 -188
- data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
- data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
- data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
- data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
- data/dependencies/al_soft/AL/alext.h +0 -585
- data/dependencies/al_soft/AL/efx-creative.h +0 -3
- data/dependencies/al_soft/AL/efx-presets.h +0 -402
- data/dependencies/al_soft/AL/efx.h +0 -762
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib64/OpenAL32.dll +0 -0
- data/src/UtilityApple.cpp +0 -16
- data/src/UtilityWin.cpp +0 -17
data/lib/gosu/compat.rb
CHANGED
@@ -16,25 +16,7 @@ module Gosu
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.
|
20
|
-
send(:remove_const, name) if const_defined?(name)
|
21
|
-
|
22
|
-
@@_deprecated_constants ||= {}
|
23
|
-
@@_deprecated_constants[name] = repl
|
24
|
-
end
|
25
|
-
|
26
|
-
# Constant deprecation works by undefining the original constant and then re-adding it in
|
27
|
-
# const_missing, so that each deprecation warning is only printed once.
|
28
|
-
def self.const_missing(const_name)
|
29
|
-
if @@_deprecated_constants && repl = @@_deprecated_constants[const_name]
|
30
|
-
Gosu.deprecation_message(self, const_name, repl)
|
31
|
-
const_get(repl)
|
32
|
-
else
|
33
|
-
super
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.deprecation_message(klass_or_full_message, name=nil, repl=nil)
|
19
|
+
def self.deprecation_message(klass_or_full_message, name = nil, repl = nil)
|
38
20
|
@@_deprecations_shown ||= {}
|
39
21
|
|
40
22
|
msg = if klass_or_full_message.is_a?(String) and name.nil? and repl.nil?
|
@@ -81,9 +63,9 @@ class Gosu::Image
|
|
81
63
|
if args[0].is_a? Gosu::Window
|
82
64
|
Gosu.deprecation_message("Passing a Window to Image#initialize has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
|
83
65
|
if args.size == 7
|
84
|
-
initialize_without_window args[1], :
|
66
|
+
initialize_without_window args[1], tileable: args[2], rect: args[3..-1]
|
85
67
|
else
|
86
|
-
initialize_without_window args[1], :
|
68
|
+
initialize_without_window args[1], tileable: args[2]
|
87
69
|
end
|
88
70
|
else
|
89
71
|
initialize_without_window(*args)
|
@@ -97,11 +79,12 @@ class Gosu::Image
|
|
97
79
|
def self.from_text(*args)
|
98
80
|
if args.size == 4
|
99
81
|
Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
|
100
|
-
from_text_without_window(args[1], args[3], :
|
82
|
+
from_text_without_window(args[1], args[3], font: args[2])
|
101
83
|
elsif args.size == 7
|
102
84
|
Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html ")
|
103
|
-
from_text_without_window(args[1], args[3],
|
104
|
-
|
85
|
+
from_text_without_window(args[1], args[3],
|
86
|
+
font: args[2], spacing: args[4], width: args[5],
|
87
|
+
align: args[6])
|
105
88
|
else
|
106
89
|
from_text_without_window(*args)
|
107
90
|
end
|
@@ -137,7 +120,7 @@ end
|
|
137
120
|
class Gosu::Font
|
138
121
|
alias_method :draw, :draw_markup
|
139
122
|
Gosu.deprecate Gosu::Font, :draw, "Font#draw_text or Font#draw_markup"
|
140
|
-
|
123
|
+
|
141
124
|
alias_method :draw_rel, :draw_markup_rel
|
142
125
|
Gosu.deprecate Gosu::Font, :draw_rel, "Font#draw_text_rel or Font#draw_markup_rel"
|
143
126
|
|
@@ -178,28 +161,36 @@ end
|
|
178
161
|
module Gosu
|
179
162
|
# This was renamed because it's not actually a "copyright notice".
|
180
163
|
# (https://en.wikipedia.org/wiki/Copyright_notice)
|
181
|
-
|
182
|
-
|
164
|
+
GOSU_COPYRIGHT_NOTICE = LICENSES
|
165
|
+
deprecate_constant :GOSU_COPYRIGHT_NOTICE
|
166
|
+
|
183
167
|
module Button; end
|
184
|
-
|
168
|
+
|
185
169
|
# Channel was called SampleInstance before Gosu 0.13.0.
|
186
170
|
SampleInstance = Channel
|
187
|
-
|
171
|
+
deprecate_constant :SampleInstance
|
188
172
|
|
189
173
|
# Support for KbLeft instead of KB_LEFT and Gp3Button2 instead of GP_3_BUTTON_2.
|
190
174
|
Gosu.constants.grep(/^KB_|MS_|GP_/).each do |new_name|
|
191
175
|
old_name = case new_name
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
176
|
+
when :KB_ISO then "KbISO"
|
177
|
+
when :KB_NUMPAD_PLUS then "KbNumpadAdd"
|
178
|
+
when :KB_NUMPAD_MINUS then "KbNumpadSubtract"
|
179
|
+
when :KB_EQUALS then "KbEqual"
|
180
|
+
when :KB_LEFT_BRACKET then "KbBracketLeft"
|
181
|
+
when :KB_RIGHT_BRACKET then "KbBracketRight"
|
182
|
+
else new_name.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
|
183
|
+
end
|
200
184
|
Gosu.const_set old_name, Gosu.const_get(new_name)
|
185
|
+
deprecate_constant old_name
|
201
186
|
|
202
187
|
# Also import old-style constants into Gosu::Button.
|
203
188
|
Gosu::Button.const_set old_name, Gosu.const_get(new_name)
|
204
189
|
end
|
190
|
+
|
191
|
+
deprecate_constant :Button
|
192
|
+
|
193
|
+
def self.language
|
194
|
+
@language_cache ||= (user_languages.first || "en_US")
|
195
|
+
end
|
205
196
|
end
|
data/lib/gosu/swig_patches.rb
CHANGED
@@ -20,7 +20,7 @@ class Gosu::Window
|
|
20
20
|
end
|
21
21
|
|
22
22
|
%w(update draw needs_redraw? needs_cursor?
|
23
|
-
lose_focus button_down button_up
|
23
|
+
gain_focus lose_focus button_down button_up
|
24
24
|
gamepad_connected gamepad_disconnected drop).each do |callback|
|
25
25
|
define_method "protected_#{callback}" do |*args|
|
26
26
|
begin
|
@@ -35,13 +35,13 @@ class Gosu::Window
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def protected_draw_2
|
40
40
|
protected_draw
|
41
41
|
$gosu_gl_blocks_2 = $gosu_gl_blocks
|
42
42
|
$gosu_gl_blocks = nil
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
alias_method :show_internal, :show
|
46
46
|
def show
|
47
47
|
show_internal
|
@@ -54,6 +54,21 @@ class Gosu::Window
|
|
54
54
|
raise @_exception
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
alias_method :tick_internal, :tick
|
59
|
+
def tick
|
60
|
+
value = tick_internal
|
61
|
+
# Try to format the message nicely, without any useless patching that we are
|
62
|
+
# doing here.
|
63
|
+
if defined? @_exception
|
64
|
+
if @_exception.backtrace.is_a? Array and not @_exception.backtrace.frozen?
|
65
|
+
@_exception.backtrace.reject! { |line| line.include? "lib/gosu/swig_patches.rb" }
|
66
|
+
end
|
67
|
+
raise @_exception
|
68
|
+
end
|
69
|
+
|
70
|
+
value
|
71
|
+
end
|
57
72
|
end
|
58
73
|
|
59
74
|
module Gosu
|
@@ -73,6 +88,19 @@ end
|
|
73
88
|
# SWIG somehow maps the instance method "argb" as an overload of the class
|
74
89
|
# method of the same name.
|
75
90
|
class Gosu::Color
|
91
|
+
alias_method :initialize_without_argb, :initialize
|
92
|
+
|
93
|
+
# The (a,r,g,b) constructor overload was dropped in C++ to reduce ambiguity,
|
94
|
+
# adding it via %extend in gosu.i does not work, so patch it here.
|
95
|
+
def initialize(*args)
|
96
|
+
if args.size == 4
|
97
|
+
initialize_without_argb(args[1], args[2], args[3])
|
98
|
+
self.alpha = args[0]
|
99
|
+
else
|
100
|
+
initialize_without_argb(*args)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
76
104
|
alias_method :argb, :to_i
|
77
105
|
end
|
78
106
|
|
data/lib/gosu.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
|
3
|
-
if RUBY_PLATFORM =~ /mswin$|
|
3
|
+
if RUBY_PLATFORM =~ /mswin$|mingw|win32\-|\-win32/
|
4
4
|
binary_path = File.dirname(__FILE__)
|
5
5
|
# 64-bit builds of Windows use "x64-mingw32" as RUBY_PLATFORM
|
6
6
|
binary_path += "64" if RUBY_PLATFORM =~ /^x64-/
|
7
|
-
|
7
|
+
|
8
8
|
begin
|
9
9
|
# Make DLLs available as shown here:
|
10
10
|
# https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers
|
data/lib64/SDL2.dll
CHANGED
Binary file
|
data/rdoc/gosu.rb
CHANGED
@@ -481,7 +481,7 @@ module Gosu
|
|
481
481
|
# Draws the image rotated, with its rotational center at (x, y).
|
482
482
|
#
|
483
483
|
# @return [void]
|
484
|
-
# @param angle [Float]
|
484
|
+
# @param angle [Float] the angle to rotate, in degrees.
|
485
485
|
# @param center_x [Float] the relative horizontal rotation origin.
|
486
486
|
# @param center_y [Float] the relative vertical rotation origin.
|
487
487
|
# @param (see #draw)
|
@@ -960,6 +960,14 @@ module Gosu
|
|
960
960
|
# @see Gosu.gamepad_name
|
961
961
|
def gamepad_disconnected(index); end
|
962
962
|
|
963
|
+
##
|
964
|
+
# Called when the window gains focus
|
965
|
+
def gain_focus; end
|
966
|
+
|
967
|
+
##
|
968
|
+
# Called when the windows loses focus
|
969
|
+
def lose_focus; end
|
970
|
+
|
963
971
|
# @!endgroup
|
964
972
|
end
|
965
973
|
|
data/src/Audio.cpp
CHANGED
@@ -1,33 +1,32 @@
|
|
1
|
-
#include "AudioImpl.hpp"
|
2
|
-
#include "AudioFile.hpp"
|
3
|
-
|
4
1
|
#include <Gosu/Audio.hpp>
|
5
|
-
#include <Gosu/Math.hpp>
|
6
2
|
#include <Gosu/IO.hpp>
|
7
|
-
#include <Gosu/
|
8
|
-
#include
|
9
|
-
|
10
|
-
#include <cassert>
|
11
|
-
#include <cstdlib>
|
3
|
+
#include <Gosu/Math.hpp>
|
4
|
+
#include "AudioFile.hpp"
|
5
|
+
#include "AudioImpl.hpp"
|
12
6
|
#include <algorithm>
|
13
|
-
|
7
|
+
#include <cassert>
|
14
8
|
|
9
|
+
// These are global variables and not even thread-safe at that, but Gosu::Song is a legacy construct
|
10
|
+
// that will be replaced by a unified Sound class anyway in #562.
|
11
|
+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
15
12
|
static Gosu::Song* cur_song = nullptr;
|
13
|
+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
16
14
|
static bool cur_song_looping;
|
17
15
|
|
18
|
-
struct Gosu::Sample::Impl
|
16
|
+
struct Gosu::Sample::Impl : Gosu::Noncopyable
|
19
17
|
{
|
20
18
|
ALuint buffer;
|
21
19
|
|
22
|
-
Impl(AudioFile&& audio_file)
|
20
|
+
explicit Impl(AudioFile&& audio_file)
|
21
|
+
: buffer{}
|
23
22
|
{
|
24
23
|
al_initialize();
|
25
24
|
alGenBuffers(1, &buffer);
|
26
25
|
alBufferData(buffer, audio_file.format(), &audio_file.decoded_data().front(),
|
27
26
|
static_cast<ALsizei>(audio_file.decoded_data().size()),
|
28
|
-
audio_file.sample_rate());
|
27
|
+
static_cast<ALsizei>(audio_file.sample_rate()));
|
29
28
|
}
|
30
|
-
|
29
|
+
|
31
30
|
~Impl()
|
32
31
|
{
|
33
32
|
// It's hard to free things in the right order in Ruby/Gosu.
|
@@ -42,103 +41,104 @@ Gosu::Sample::Sample()
|
|
42
41
|
{
|
43
42
|
}
|
44
43
|
|
45
|
-
Gosu::Sample::Sample(const string& filename)
|
44
|
+
Gosu::Sample::Sample(const std::string& filename)
|
45
|
+
: m_impl{new Impl(AudioFile(filename))}
|
46
46
|
{
|
47
|
-
pimpl.reset(new Impl(AudioFile(filename)));
|
48
47
|
}
|
49
48
|
|
50
49
|
Gosu::Sample::Sample(Gosu::Reader reader)
|
50
|
+
: m_impl{new Impl(AudioFile(reader))}
|
51
51
|
{
|
52
|
-
pimpl.reset(new Impl(AudioFile(reader)));
|
53
52
|
}
|
54
53
|
|
55
54
|
Gosu::Channel Gosu::Sample::play(double volume, double speed, bool looping) const
|
56
55
|
{
|
57
|
-
return play_pan(0, volume, speed, looping);
|
56
|
+
return play_pan(0.0, volume, speed, looping);
|
58
57
|
}
|
59
58
|
|
60
59
|
Gosu::Channel Gosu::Sample::play_pan(double pan, double volume, double speed, bool looping) const
|
61
60
|
{
|
62
|
-
if (!
|
61
|
+
if (!m_impl) return Channel{};
|
63
62
|
|
64
63
|
Channel channel = allocate_channel();
|
65
|
-
|
64
|
+
|
66
65
|
// Couldn't allocate a free channel.
|
67
66
|
if (channel.current_channel() == NO_CHANNEL) return channel;
|
68
|
-
|
67
|
+
|
69
68
|
ALuint source = al_source_for_channel(channel.current_channel());
|
70
|
-
alSourcei(source, AL_BUFFER,
|
71
|
-
alSource3f(source, AL_POSITION, pan * 10, 0, 0);
|
72
|
-
alSourcef(source, AL_GAIN, max(volume, 0.0));
|
73
|
-
alSourcef(source, AL_PITCH, speed);
|
69
|
+
alSourcei(source, AL_BUFFER, static_cast<ALint>(m_impl->buffer));
|
70
|
+
alSource3f(source, AL_POSITION, static_cast<ALfloat>(pan * 10), 0, 0);
|
71
|
+
alSourcef(source, AL_GAIN, static_cast<ALfloat>(std::max(volume, 0.0)));
|
72
|
+
alSourcef(source, AL_PITCH, static_cast<ALfloat>(speed));
|
74
73
|
alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
|
75
74
|
alSourcePlay(source);
|
76
75
|
return channel;
|
77
76
|
}
|
78
77
|
|
79
78
|
// AudioFile impl
|
80
|
-
struct Gosu::Song::Impl
|
79
|
+
struct Gosu::Song::Impl : Gosu::Noncopyable
|
81
80
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
private:
|
82
|
+
double m_volume = 1.0;
|
83
|
+
std::unique_ptr<AudioFile> m_file;
|
84
|
+
ALuint m_buffers[2];
|
85
|
+
|
86
86
|
void apply_volume()
|
87
87
|
{
|
88
|
-
alSourcef(al_source_for_songs(), AL_GAIN, max(volume(), 0.0));
|
88
|
+
alSourcef(al_source_for_songs(), AL_GAIN, static_cast<ALfloat>(std::max(volume(), 0.0)));
|
89
89
|
}
|
90
|
-
|
90
|
+
|
91
91
|
bool stream_to_buffer(ALuint buffer)
|
92
92
|
{
|
93
93
|
char audio_data[4096 * 8];
|
94
|
-
size_t read_bytes =
|
94
|
+
size_t read_bytes = m_file->read_data(audio_data, sizeof audio_data);
|
95
95
|
if (read_bytes > 0) {
|
96
|
-
alBufferData(buffer,
|
97
|
-
static_cast<ALsizei>(
|
96
|
+
alBufferData(buffer, m_file->format(), audio_data, static_cast<ALsizei>(read_bytes),
|
97
|
+
static_cast<ALsizei>(m_file->sample_rate()));
|
98
98
|
}
|
99
99
|
return read_bytes > 0;
|
100
100
|
}
|
101
|
-
|
101
|
+
|
102
102
|
public:
|
103
|
-
explicit Impl(const string& filename)
|
103
|
+
explicit Impl(const std::string& filename)
|
104
|
+
: m_buffers{},
|
105
|
+
m_file{new AudioFile{filename}}
|
104
106
|
{
|
105
|
-
file.reset(new AudioFile(filename));
|
106
|
-
|
107
107
|
al_initialize();
|
108
|
-
alGenBuffers(2,
|
108
|
+
alGenBuffers(2, m_buffers);
|
109
109
|
}
|
110
110
|
|
111
111
|
explicit Impl(Reader reader)
|
112
|
+
: m_buffers{},
|
113
|
+
m_file{new AudioFile{reader}}
|
112
114
|
{
|
113
|
-
file.reset(new AudioFile(reader));
|
114
|
-
|
115
115
|
al_initialize();
|
116
|
-
alGenBuffers(2,
|
116
|
+
alGenBuffers(2, m_buffers);
|
117
117
|
}
|
118
|
-
|
118
|
+
|
119
119
|
~Impl()
|
120
120
|
{
|
121
121
|
// It's hard to free things in the right order in Ruby/Gosu.
|
122
122
|
// Make sure buffers aren't deleted after the context/device are shut down.
|
123
123
|
if (!al_initialized()) return;
|
124
|
-
|
125
|
-
alDeleteBuffers(2,
|
124
|
+
|
125
|
+
alDeleteBuffers(2, m_buffers);
|
126
126
|
}
|
127
|
-
|
128
|
-
void play(
|
127
|
+
|
128
|
+
void play()
|
129
129
|
{
|
130
130
|
ALuint source = al_source_for_songs();
|
131
131
|
|
132
132
|
alSource3f(source, AL_POSITION, 0, 0, 0);
|
133
|
-
alSourcef(source, AL_GAIN, max(volume(), 0.0));
|
133
|
+
alSourcef(source, AL_GAIN, static_cast<ALfloat>(std::max(volume(), 0.0)));
|
134
134
|
alSourcef(source, AL_PITCH, 1);
|
135
135
|
alSourcei(source, AL_LOOPING, AL_FALSE); // need to implement this manually...
|
136
136
|
|
137
|
-
stream_to_buffer(
|
138
|
-
stream_to_buffer(
|
139
|
-
|
137
|
+
stream_to_buffer(m_buffers[0]);
|
138
|
+
stream_to_buffer(m_buffers[1]);
|
139
|
+
|
140
140
|
// TODO: Not good for songs with less than two buffers full of data.
|
141
|
-
alSourceQueueBuffers(source, 2,
|
141
|
+
alSourceQueueBuffers(source, 2, m_buffers);
|
142
142
|
alSourcePlay(source);
|
143
143
|
}
|
144
144
|
|
@@ -148,7 +148,7 @@ public:
|
|
148
148
|
|
149
149
|
alSourceStop(source);
|
150
150
|
|
151
|
-
//
|
151
|
+
// Dequeue all buffers for this source.
|
152
152
|
// The number of QUEUED buffers apparently includes the number of PROCESSED ones,
|
153
153
|
// so getting rid of the QUEUED ones is enough.
|
154
154
|
ALuint buffer;
|
@@ -157,27 +157,27 @@ public:
|
|
157
157
|
while (queued--) {
|
158
158
|
alSourceUnqueueBuffers(source, 1, &buffer);
|
159
159
|
}
|
160
|
-
|
161
|
-
|
160
|
+
|
161
|
+
m_file->rewind();
|
162
162
|
}
|
163
|
-
|
164
|
-
void pause()
|
163
|
+
|
164
|
+
static void pause() //
|
165
165
|
{
|
166
166
|
alSourcePause(al_source_for_songs());
|
167
167
|
}
|
168
|
-
|
169
|
-
void resume()
|
168
|
+
|
169
|
+
static void resume() //
|
170
170
|
{
|
171
171
|
alSourcePlay(al_source_for_songs());
|
172
172
|
}
|
173
|
-
|
174
|
-
bool paused()
|
173
|
+
|
174
|
+
static bool paused()
|
175
175
|
{
|
176
176
|
ALint state;
|
177
177
|
alGetSourcei(al_source_for_songs(), AL_SOURCE_STATE, &state);
|
178
178
|
return state == AL_PAUSED;
|
179
179
|
}
|
180
|
-
|
180
|
+
|
181
181
|
void update()
|
182
182
|
{
|
183
183
|
ALuint source = al_source_for_songs();
|
@@ -185,14 +185,14 @@ public:
|
|
185
185
|
ALuint buffer;
|
186
186
|
int processed;
|
187
187
|
bool active = true;
|
188
|
-
|
188
|
+
|
189
189
|
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
190
190
|
for (int i = 0; i < processed; ++i) {
|
191
191
|
alSourceUnqueueBuffers(source, 1, &buffer);
|
192
192
|
active = stream_to_buffer(buffer);
|
193
193
|
if (active) alSourceQueueBuffers(source, 1, &buffer);
|
194
194
|
}
|
195
|
-
|
195
|
+
|
196
196
|
ALint state;
|
197
197
|
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
198
198
|
if (active && state != AL_PLAYING && state != AL_PAUSED) {
|
@@ -205,7 +205,7 @@ public:
|
|
205
205
|
|
206
206
|
if (cur_song_looping) {
|
207
207
|
// Start anew.
|
208
|
-
play(
|
208
|
+
play();
|
209
209
|
}
|
210
210
|
else {
|
211
211
|
// Let the world know we're finished.
|
@@ -213,27 +213,27 @@ public:
|
|
213
213
|
}
|
214
214
|
}
|
215
215
|
}
|
216
|
-
|
216
|
+
|
217
217
|
double volume() const
|
218
218
|
{
|
219
|
-
return
|
219
|
+
return m_volume;
|
220
220
|
}
|
221
|
-
|
221
|
+
|
222
222
|
void set_volume(double volume)
|
223
223
|
{
|
224
|
-
|
224
|
+
m_volume = std::clamp(volume, 0.0, 1.0);
|
225
225
|
apply_volume();
|
226
226
|
}
|
227
227
|
};
|
228
228
|
|
229
|
-
Gosu::Song::Song(const string& filename)
|
229
|
+
Gosu::Song::Song(const std::string& filename)
|
230
|
+
: m_impl{new Impl(filename)}
|
230
231
|
{
|
231
|
-
pimpl.reset(new Impl(filename));
|
232
232
|
}
|
233
233
|
|
234
234
|
Gosu::Song::Song(Reader reader)
|
235
|
+
: m_impl{new Impl(reader)}
|
235
236
|
{
|
236
|
-
pimpl.reset(new Impl(reader));
|
237
237
|
}
|
238
238
|
|
239
239
|
Gosu::Song::~Song()
|
@@ -249,18 +249,18 @@ Gosu::Song* Gosu::Song::current_song()
|
|
249
249
|
void Gosu::Song::play(bool looping)
|
250
250
|
{
|
251
251
|
if (paused()) {
|
252
|
-
|
252
|
+
m_impl->resume();
|
253
253
|
}
|
254
|
-
|
254
|
+
|
255
255
|
if (cur_song && cur_song != this) {
|
256
256
|
cur_song->stop();
|
257
|
-
assert
|
257
|
+
assert(cur_song == nullptr);
|
258
258
|
}
|
259
|
-
|
259
|
+
|
260
260
|
if (cur_song == nullptr) {
|
261
|
-
|
261
|
+
m_impl->play();
|
262
262
|
}
|
263
|
-
|
263
|
+
|
264
264
|
cur_song = this;
|
265
265
|
cur_song_looping = looping;
|
266
266
|
}
|
@@ -268,41 +268,41 @@ void Gosu::Song::play(bool looping)
|
|
268
268
|
void Gosu::Song::pause()
|
269
269
|
{
|
270
270
|
if (cur_song == this) {
|
271
|
-
|
271
|
+
m_impl->pause();
|
272
272
|
}
|
273
273
|
}
|
274
274
|
|
275
275
|
bool Gosu::Song::paused() const
|
276
276
|
{
|
277
|
-
return cur_song == this &&
|
277
|
+
return cur_song == this && m_impl->paused();
|
278
278
|
}
|
279
279
|
|
280
280
|
void Gosu::Song::stop()
|
281
281
|
{
|
282
282
|
if (cur_song == this) {
|
283
|
-
|
283
|
+
m_impl->stop();
|
284
284
|
cur_song = nullptr;
|
285
285
|
}
|
286
286
|
}
|
287
287
|
|
288
288
|
bool Gosu::Song::playing() const
|
289
289
|
{
|
290
|
-
return cur_song == this && !
|
290
|
+
return cur_song == this && !m_impl->paused();
|
291
291
|
}
|
292
292
|
|
293
293
|
double Gosu::Song::volume() const
|
294
294
|
{
|
295
|
-
return
|
295
|
+
return m_impl->volume();
|
296
296
|
}
|
297
297
|
|
298
298
|
void Gosu::Song::set_volume(double volume)
|
299
299
|
{
|
300
|
-
|
300
|
+
m_impl->set_volume(volume);
|
301
301
|
}
|
302
302
|
|
303
303
|
void Gosu::Song::update()
|
304
304
|
{
|
305
305
|
if (current_song()) {
|
306
|
-
current_song()->
|
306
|
+
current_song()->m_impl->update();
|
307
307
|
}
|
308
308
|
}
|
data/src/AudioFile.hpp
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#include <Gosu/IO.hpp>
|
4
4
|
|
5
|
-
#ifdef
|
5
|
+
#ifdef GOSU_IS_IPHONE
|
6
6
|
// Ignore OpenAL deprecation warnings. If macOS stops shipping OpenAL, it's more likely that we bundle our own version
|
7
7
|
// of it than that we switch to another audio API.
|
8
8
|
#define OPENAL_DEPRECATED
|
@@ -21,20 +21,20 @@ namespace Gosu
|
|
21
21
|
{
|
22
22
|
struct Impl;
|
23
23
|
std::unique_ptr<Impl> pimpl;
|
24
|
-
|
24
|
+
|
25
25
|
public:
|
26
26
|
explicit AudioFile(const std::string& filename);
|
27
27
|
explicit AudioFile(Reader reader);
|
28
28
|
~AudioFile();
|
29
29
|
|
30
30
|
ALenum format() const;
|
31
|
-
|
31
|
+
|
32
32
|
ALuint sample_rate() const;
|
33
|
-
|
33
|
+
|
34
34
|
std::size_t read_data(void* dest, std::size_t length);
|
35
|
-
|
35
|
+
|
36
36
|
void rewind();
|
37
|
-
|
37
|
+
|
38
38
|
const std::vector<char>& decoded_data();
|
39
39
|
};
|
40
40
|
}
|
@@ -35,7 +35,7 @@ static void throw_os_error(OSStatus status, unsigned line)
|
|
35
35
|
|
36
36
|
#define CHECK_OS(status) do { if (status) throw_os_error(status, __LINE__); } while (0)
|
37
37
|
|
38
|
-
struct Gosu::AudioFile::Impl
|
38
|
+
struct Gosu::AudioFile::Impl : Gosu::Noncopyable
|
39
39
|
{
|
40
40
|
Buffer buffer;
|
41
41
|
AudioFileID file_id;
|
data/src/AudioFileSDLSound.cpp
CHANGED
data/src/AudioImpl.hpp
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#include <Gosu/Audio.hpp>
|
4
4
|
#include <Gosu/Platform.hpp>
|
5
|
-
#ifdef
|
5
|
+
#ifdef GOSU_IS_IPHONE
|
6
6
|
// Ignore OpenAL deprecation warnings. If macOS stops shipping OpenAL, it's more likely that we bundle our own version
|
7
7
|
// of it than that we switch to another audio API.
|
8
8
|
#define OPENAL_DEPRECATED
|
@@ -17,18 +17,18 @@ namespace Gosu
|
|
17
17
|
{
|
18
18
|
void al_initialize();
|
19
19
|
bool al_initialized();
|
20
|
-
|
20
|
+
|
21
21
|
// Will initialize OpenAL if necessary.
|
22
22
|
ALCdevice* al_device();
|
23
23
|
// Will initialize OpenAL if necessary.
|
24
24
|
ALCcontext* al_context();
|
25
|
-
|
25
|
+
|
26
26
|
const int NO_CHANNEL = -1;
|
27
|
-
|
27
|
+
|
28
28
|
// Returns an expired Channel if no channel is free.
|
29
29
|
// Will initialize OpenAL if necessary.
|
30
30
|
Channel allocate_channel();
|
31
|
-
|
31
|
+
|
32
32
|
bool channel_expired(int channel, int token);
|
33
33
|
ALuint al_source_for_channel(int channel);
|
34
34
|
ALuint al_source_for_songs();
|