gosu 1.1.1.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +63 -107
  140. data/include/Gosu/Font.hpp +44 -48
  141. data/include/Gosu/Fwd.hpp +1 -1
  142. data/include/Gosu/Graphics.hpp +64 -75
  143. data/include/Gosu/GraphicsBase.hpp +32 -39
  144. data/include/Gosu/Image.hpp +56 -62
  145. data/include/Gosu/ImageData.hpp +23 -27
  146. data/include/Gosu/Inspection.hpp +1 -4
  147. data/include/Gosu/Math.hpp +4 -16
  148. data/include/Gosu/Platform.hpp +1 -51
  149. data/include/Gosu/Text.hpp +37 -40
  150. data/include/Gosu/TextInput.hpp +34 -40
  151. data/include/Gosu/Utility.hpp +10 -8
  152. data/include/Gosu/Version.hpp +1 -1
  153. data/include/Gosu/Window.hpp +73 -70
  154. data/lib/SDL2.dll +0 -0
  155. data/lib/gosu/compat.rb +28 -37
  156. data/lib/gosu/swig_patches.rb +31 -3
  157. data/lib/gosu.rb +2 -2
  158. data/lib64/SDL2.dll +0 -0
  159. data/rdoc/gosu.rb +9 -1
  160. data/src/Audio.cpp +88 -86
  161. data/src/AudioFile.hpp +6 -6
  162. data/src/AudioFileAudioToolbox.cpp +1 -1
  163. data/src/AudioFileSDLSound.cpp +1 -1
  164. data/src/AudioImpl.hpp +5 -5
  165. data/src/Bitmap.cpp +13 -13
  166. data/src/BitmapIO.cpp +0 -20
  167. data/src/BlockAllocator.cpp +2 -1
  168. data/src/Channel.cpp +22 -20
  169. data/src/Color.cpp +62 -55
  170. data/src/EmptyImageData.hpp +16 -18
  171. data/src/FileUnix.cpp +1 -1
  172. data/src/FileWin.cpp +1 -1
  173. data/src/Font.cpp +52 -57
  174. data/src/GosuViewController.cpp +2 -0
  175. data/src/Graphics.cpp +135 -143
  176. data/src/Image.cpp +42 -42
  177. data/src/Input.cpp +1 -1
  178. data/src/InputUIKit.cpp +1 -1
  179. data/src/LargeImageData.cpp +120 -113
  180. data/src/LargeImageData.hpp +18 -16
  181. data/src/Log.hpp +6 -6
  182. data/src/Macro.cpp +35 -37
  183. data/src/Macro.hpp +11 -11
  184. data/src/Math.cpp +8 -1
  185. data/src/RenderState.hpp +5 -5
  186. data/src/Resolution.cpp +12 -7
  187. data/src/RubyGosu.cxx +471 -502
  188. data/src/RubyGosu.h +3 -2
  189. data/src/TexChunk.cpp +50 -41
  190. data/src/TexChunk.hpp +22 -22
  191. data/src/Text.cpp +58 -59
  192. data/src/TextBuilder.cpp +60 -57
  193. data/src/TextBuilder.hpp +20 -20
  194. data/src/TextInput.cpp +127 -135
  195. data/src/TrueTypeFont.cpp +108 -108
  196. data/src/TrueTypeFont.hpp +39 -38
  197. data/src/TrueTypeFontApple.cpp +27 -23
  198. data/src/TrueTypeFontUnix.cpp +21 -26
  199. data/src/TrueTypeFontWin.cpp +30 -30
  200. data/src/Utility.cpp +82 -23
  201. data/src/WinUtility.hpp +2 -1
  202. data/src/Window.cpp +103 -86
  203. data/src/WindowUIKit.cpp +48 -51
  204. metadata +8 -20
  205. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  206. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  207. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  208. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  209. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  210. data/dependencies/al_soft/AL/alext.h +0 -585
  211. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  212. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  213. data/dependencies/al_soft/AL/efx.h +0 -762
  214. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  215. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  216. data/lib/OpenAL32.dll +0 -0
  217. data/lib64/OpenAL32.dll +0 -0
  218. data/src/UtilityApple.cpp +0 -16
  219. data/src/UtilityWin.cpp +0 -17
data/ext/gosu/extconf.rb CHANGED
@@ -8,17 +8,17 @@ when /^darwin/
8
8
  end
9
9
 
10
10
  if not windows
11
- puts 'The Gosu gem requires some libraries to be installed system-wide.'
12
- puts 'See the following site for a list:'
11
+ puts "The Gosu gem requires some libraries to be installed system-wide."
12
+ puts "See the following site for a list:"
13
13
  if macos
14
- puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X'
14
+ puts "https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X"
15
15
  else
16
- puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux'
16
+ puts "https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux"
17
17
  end
18
18
  end
19
19
 
20
- require 'mkmf'
21
- require 'fileutils'
20
+ require "mkmf"
21
+ require "fileutils"
22
22
 
23
23
  # Silence internal deprecation warnings in Gosu.
24
24
  $CFLAGS << " -DGOSU_DEPRECATED="
@@ -33,25 +33,25 @@ $CXXFLAGS ||= ""
33
33
  $CXXFLAGS << " -std=gnu++17 -Dregister="
34
34
 
35
35
  # Make Gosu's own header files and all of its dependencies available to C++ source files.
36
- $INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound"
36
+ $INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound -I../../dependencies/mojoAL"
37
37
 
38
38
  if windows
39
39
  # We statically compile utf8proc into the Gosu binary.
40
40
  # This macro is required to avoid errors about dllexport/dllimport mismatches.
41
- $CFLAGS << " -DUTF8PROC_STATIC"
42
- $CXXFLAGS << " -DUTF8PROC_STATIC"
41
+ $CFLAGS << " -DUTF8PROC_STATIC -DAL_LIBTYPE_STATIC"
42
+ $CXXFLAGS << " -DUTF8PROC_STATIC -DAL_LIBTYPE_STATIC"
43
43
 
44
44
  # Define UNICODE to use the Unicode-aware variants of all Win32 API functions.
45
45
  $CXXFLAGS << " -DUNICODE"
46
46
 
47
47
  # Use the bundled versions of SDL 2 and open_al.
48
- $INCFLAGS << " -I../../dependencies/al_soft -I../../dependencies/SDL/include"
49
- if RbConfig::CONFIG['arch'] =~ /x64-/
50
- $LDFLAGS << " -L../../dependencies/al_soft/x64 -L../../dependencies/SDL/lib/x64"
48
+ $INCFLAGS << " -I../../dependencies/SDL/include"
49
+ if RbConfig::CONFIG["arch"] =~ /x64-/
50
+ $LDFLAGS << " -L../../dependencies/SDL/lib/x64"
51
51
  else
52
- $LDFLAGS << " -L../../dependencies/al_soft/x86 -L../../dependencies/SDL/lib/x86"
52
+ $LDFLAGS << " -L../../dependencies/SDL/lib/x86"
53
53
  end
54
- $LDFLAGS << " -lgdi32 -lwinmm -ldwmapi -lOpenGL32 -lOpenAL32 -lSDL2"
54
+ $LDFLAGS << " -lgdi32 -lwinmm -ldwmapi -lOpenGL32 -lSDL2"
55
55
  # Link libstdc++ statically to avoid having another DLL dependency when using Ocra.
56
56
  $LDFLAGS << " -static-libstdc++"
57
57
  elsif macos
@@ -66,49 +66,48 @@ elsif macos
66
66
  # Disable an error that is disabled by default and prevents Gosu from building with universal Ruby:
67
67
  # https://trac.macports.org/ticket/58255 / https://github.com/gosu/gosu/issues/424
68
68
  $CXXFLAGS << " -Wno-reserved-user-defined-literal"
69
-
69
+
70
70
  # Dependencies.
71
71
  $CFLAGS << " #{`sdl2-config --cflags`.chomp}"
72
72
  $CXXFLAGS << " #{`sdl2-config --cflags`.chomp}"
73
73
  # Prefer statically linking SDL 2.
74
- $LDFLAGS << " #{`sdl2-config --static-libs`.chomp} -framework OpenGL -framework Metal -framework OpenAL"
74
+ $LDFLAGS << " #{`sdl2-config --static-libs`.chomp} -framework OpenGL -framework Metal"
75
75
  # And yet another hack: `sdl2-config --static-libs` uses `-lSDL2` instead of linking to the static library,
76
76
  # even if it exists. -> Manually replace it. (Ugh!)
77
- $LDFLAGS.sub! " -lSDL2 ", " /usr/local/lib/libSDL2.a " if File.exist? "/usr/local/lib/libSDL2.a"
78
-
77
+ %w(/usr/local/lib/libSDL2.a /opt/homebrew/opt/sdl2/lib/libSDL2.a).each do |static_lib|
78
+ $LDFLAGS.sub! " -lSDL2 ", " #{static_lib} " if File.exist? static_lib
79
+ end
80
+
79
81
  # Disable building of 32-bit slices in Apple's Ruby.
80
82
  # (RbConfig::CONFIG['CXXFLAGS'] on 10.11: -arch x86_64 -arch i386 -g -Os -pipe)
81
83
  $CFLAGS.gsub! "-arch i386", ""
82
84
  $CXXFLAGS.gsub! "-arch i386", ""
83
85
  $LDFLAGS.gsub! "-arch i386", ""
84
86
  $ARCH_FLAG.gsub! "-arch i386", ""
85
- CONFIG['LDSHARED'].gsub! "-arch i386", ""
87
+ CONFIG["LDSHARED"].gsub! "-arch i386", ""
86
88
  else
87
89
  if /BCM2708/ =~ `cat /proc/cpuinfo`
88
90
  $INCFLAGS << " -I/opt/vc/include/GLES"
89
91
  $INCFLAGS << " -I/opt/vc/include"
90
92
  $LDFLAGS << " -L/opt/vc/lib"
91
93
  $LDFLAGS << " -lGLESv1_CM"
92
- $CFLAGS << " -DGOSU_IS_OPENGLES"
94
+ $CFLAGS << " -DGOSU_IS_OPENGLES"
93
95
  $CXXFLAGS << " -DGOSU_IS_OPENGLES"
94
96
  else
95
- pkg_config 'gl'
97
+ pkg_config "gl"
96
98
  end
97
99
 
98
- pkg_config 'sdl2'
99
- pkg_config 'vorbisfile'
100
- pkg_config 'openal'
101
- pkg_config 'sndfile'
102
- pkg_config 'libmpg123'
103
- pkg_config 'fontconfig'
104
-
105
- have_header 'AL/al.h' if have_library('openal')
100
+ pkg_config "sdl2"
101
+ pkg_config "vorbisfile"
102
+ pkg_config "sndfile"
103
+ pkg_config "libmpg123"
104
+ pkg_config "fontconfig"
106
105
  end
107
106
 
108
107
  # Because Ruby will only compile source file in the src/ folder, but our dependencies are
109
108
  # stored in dependencies/, we need to create symlinks for all the .c files. This is terrible,
110
109
  # but still seems better than putting everything into the same folder to begin with.
111
- Dir.glob('../../dependencies/**/*.c').each do |dep|
110
+ Dir.glob("../../dependencies/**/*.c").each do |dep|
112
111
  File.open("../../src/#{File.basename dep}", "w") do |shim|
113
112
  shim.puts "#include \"#{File.expand_path dep}\""
114
113
  end
@@ -1,141 +1,126 @@
1
- //! \file Audio.hpp
2
- //! Contains all the classes of Gosu's audio system.
3
-
4
1
  #pragma once
5
2
 
6
3
  #include <Gosu/Fwd.hpp>
7
4
  #include <Gosu/IO.hpp>
8
5
  #include <Gosu/Platform.hpp>
6
+ #include <Gosu/Utility.hpp>
9
7
  #include <memory>
10
8
  #include <string>
11
9
 
12
10
  namespace Gosu
13
11
  {
14
- //! Sample::play returns a Channel that represents the sound being played.
15
- //! This object can be used to stop sounds dynamically, or to check whether playback has
16
- //! finished.
12
+ /// Sample::play returns a Channel that represents the sound being played.
13
+ /// This object can be used to stop or influence sounds as they are played, or to check whether
14
+ /// playback has finished.
17
15
  class Channel
18
16
  {
19
- mutable int channel, token;
17
+ mutable int m_channel, m_token;
20
18
 
21
19
  public:
22
- //! This creates an "empty" Channel which is expired and cannot be resumed.
20
+ /// This creates an "empty" Channel which is expired and cannot be resumed.
23
21
  Channel();
24
- //! For internal use only.
22
+ /// For internal use only.
25
23
  Channel(int channel, int token);
26
-
27
- //! For internal use only.
24
+
25
+ /// For internal use only.
28
26
  int current_channel() const;
29
-
27
+
30
28
  bool playing() const;
31
29
  bool paused() const;
32
- //! Pauses this instance to be resumed afterwards.
33
- //! Avoid leaving samples paused for too long, as they will still occupy one of Gosu's
34
- //! limited channels.
30
+ /// Pauses this instance to be resumed afterwards.
31
+ /// Avoid leaving samples paused for too long, as they will still occupy one of Gosu's
32
+ /// limited channels.
35
33
  void pause();
36
34
  void resume();
37
- //! Stops this channel if the sample is still being played.
38
- //! If this method is called when playback has finished, it has no effect.
35
+ /// Stops this m_channel if the sample is still being played.
36
+ /// If this method is called when playback has finished, it has no effect.
39
37
  void stop();
40
38
 
41
- //! \param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
39
+ /// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
42
40
  void set_volume(double volume);
43
- //! \param pan Can be anything from -1.0 (left) to 1.0 (right).
41
+ /// @param pan Can be anything from -1.0 (left) to 1.0 (right).
44
42
  void set_pan(double pan);
45
- //! \param speed Use 1.0 for normal playback speed.
43
+ /// @param speed Use 1.0 for normal playback speed.
46
44
  void set_speed(double speed);
47
45
  };
48
-
49
- //! A sample is a short sound that is completely loaded in memory, can be
50
- //! played multiple times at once and offers very flexible playback
51
- //! parameters. Use samples for everything that's not music.
46
+
47
+ /// A sample is a short sound that is completely loaded in memory, can be played multiple times
48
+ /// at once, and offers very flexible playback parameters.
52
49
  class Sample
53
50
  {
54
51
  struct Impl;
55
- std::shared_ptr<Impl> pimpl;
52
+ std::shared_ptr<Impl> m_impl;
56
53
 
57
54
  public:
58
- //! Constructs an empty sample that is inaudible when played.
55
+ /// Constructs an empty sample that is inaudible when played.
59
56
  Sample();
60
-
61
- //! Constructs a sample that can be played on the specified audio
62
- //! system and loads the sample from a file.
57
+
58
+ /// Constructs a sample that can be played on the specified audio
59
+ /// system and loads the sample from a file.
63
60
  explicit Sample(const std::string& filename);
64
-
65
- //! Constructs a sample that can be played on the specified audio
66
- //! system and loads the sample data from a stream.
61
+
62
+ /// Constructs a sample that can be played on the specified audio
63
+ /// system and loads the sample data from a stream.
67
64
  explicit Sample(Reader reader);
68
-
69
- //! Plays the sample without panning.
70
- //! \param volume Can be anything from 0.0 (silence) to 1.0 (full
71
- //! volume).
72
- //! \param speed Playback speed is only limited by the underlying audio library,
73
- //! and can accept very high or low values. Use 1.0 for
74
- //! normal playback speed.
75
- Channel play(double volume = 1, double speed = 1, bool looping = false) const;
76
-
77
- //! Plays the sample with panning. Even if pan is 0.0, the sample will
78
- //! not be as loud as if it were played by calling play() due to the
79
- //! way the panning works.
80
- //! \param pan Can be anything from -1.0 (left) to 1.0 (right).
81
- //! \param volume Can be anything from 0.0 (silence) to 1.0 (full
82
- //! volume).
83
- //! \param speed Playback speed is only limited by by the underlying audio library,
84
- //! and can accept very high
85
- //! or low values. Use 1.0 for normal playback speed.
86
- Channel play_pan(double pan, double volume = 1, double speed = 1,
87
- bool looping = false) const;
65
+
66
+ /// Plays the sample without panning.
67
+ /// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
68
+ /// @param speed Playback speed is only limited by the underlying audio library,
69
+ /// and can accept very high or low values. Use 1.0 for normal playback speed.
70
+ Channel play(double volume = 1.0, double speed = 1.0, bool looping = false) const;
71
+
72
+ /// Plays the sample with panning. Even if pan is 0.0, the sample will
73
+ /// not be as loud as if it were played by calling play() due to the
74
+ /// way the panning works.
75
+ /// @param pan Can be anything from -1.0 (left) to 1.0 (right).
76
+ /// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
77
+ /// @param speed Playback speed is only limited by by the underlying audio library,
78
+ /// and can accept very high or low values. Use 1.0 for normal playback speed.
79
+ Channel play_pan(double pan, double volume = 1.0, double speed = 1.0,
80
+ bool looping = false) const;
88
81
  };
89
82
 
90
- //! Songs are less flexible than samples. Only one Song can be played at any given time,
91
- //! and there is no way to control its pan (stereo position) or speed.
92
- class Song
83
+ /// Songs are less flexible than Samples. Only one Song can be played at any given time,
84
+ /// and there is no way to control its pan (stereo position) or speed.
85
+ class Song : private Noncopyable
93
86
  {
94
87
  struct Impl;
95
- std::unique_ptr<Impl> pimpl;
96
-
97
- // Non-movable to avoid dangling internal references.
98
- Song(Song&&) = delete;
99
- // Non-movable to avoid dangling internal references.
100
- Song& operator=(Song&&) = delete;
88
+ std::unique_ptr<Impl> m_impl;
101
89
 
102
90
  public:
103
- //! Constructs a song that can be played on the provided audio system
104
- //! and loads the song from a file.
105
- //! The file type is determined by the filename.
91
+ /// Constructs a song that can be played on the provided audio system and loads the song
92
+ /// from a file. The file type is determined by the filename.
106
93
  explicit Song(const std::string& filename);
107
-
108
- //! Constructs a song of the specified type that can be played on the
109
- //! provided audio system and loads the song data from a stream.
94
+
95
+ /// Constructs a song of the specified type that can be played on the
96
+ /// provided audio system and loads the song data from a stream.
110
97
  explicit Song(Reader reader);
111
-
98
+
112
99
  ~Song();
113
-
114
- //! Returns the song currently being played or paused, or 0 if
115
- //! no song has been played yet or the last song has finished
116
- //! playing.
100
+
101
+ /// Returns the song currently being played or paused, or 0 if no song has been played yet
102
+ /// or the last song has finished playing.
117
103
  static Song* current_song();
118
104
 
119
- //! Starts or resumes playback of the song. This will stop all other
120
- //! songs and set the current song to this object.
105
+ /// Starts or resumes playback of the song. This will stop all other songs and set the
106
+ /// current song to this object.
121
107
  void play(bool looping = false);
122
- //! Pauses playback of the song. It is not considered being played.
123
- //! current_song will stay the same.
108
+ /// Pauses playback of the song. Song::current_song() will still refer to this song, but
109
+ /// playing() will return false.
124
110
  void pause();
125
- //! Returns true if the song is the current song, but in paused
126
- //! mode.
111
+ /// Returns true if the song is the current song, but in paused mode.
127
112
  bool paused() const;
128
- //! Stops playback of this song if it is currently played or paused.
129
- //! Afterwards, current_song will return nullptr.
113
+ /// Stops playback of this song if it is currently played or paused.
114
+ /// Afterwards, current_song will return nullptr.
130
115
  void stop();
131
- //! Returns true if the song is currently playing.
116
+ /// Returns true if the song is currently playing.
132
117
  bool playing() const;
133
- //! Returns the current volume of the song.
118
+ /// Returns the current volume of the song.
134
119
  double volume() const;
135
- //! \param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
120
+ /// @param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
136
121
  void set_volume(double volume);
137
-
138
- //! Called every tick by Window to feed new audio data to OpenAL.
122
+
123
+ /// Called every tick by Window to feed new audio data to OpenAL.
139
124
  static void update();
140
125
  };
141
126
  }
@@ -1,6 +1,3 @@
1
- //! \file Color.hpp
2
- //! Interface of the Color class.
3
-
4
1
  #pragma once
5
2
 
6
3
  #include <Gosu/Platform.hpp>
@@ -8,154 +5,113 @@
8
5
 
9
6
  namespace Gosu
10
7
  {
11
- //! Represents an RGBA color value with 8 bits for each channel.
12
- //! Can be implicitly constructed from literals of the form 0xaarrggbb.
13
- //! Has fast value semantics.
14
- //! The four-byte layout in memory is RGBA. On Big-Endian machines the unsigned int will look
15
- //! like 0xrrggbbaa, on Little-Endian machines it is 0xaabbggrr.
16
- class Color
8
+ /// Represents an RGBA color value with 8 bit for each channel.
9
+ /// Can be implicitly constructed from literals of the form 0xaarrggbb.
10
+ struct Color
17
11
  {
18
- std::uint32_t rep;
19
- #ifdef GOSU_IS_LITTLE_ENDIAN
20
- enum { RED_OFFSET = 0, GREEN_OFFSET = 8, BLUE_OFFSET = 16, ALPHA_OFFSET = 24 };
21
- #else
22
- enum { RED_OFFSET = 24, GREEN_OFFSET = 16, BLUE_OFFSET = 8, ALPHA_OFFSET = 0 };
23
- #endif
24
-
25
- public:
26
- typedef std::uint8_t Channel;
27
12
  static const unsigned GL_FORMAT = 0x1908; // GL_RGBA
28
-
29
- //! The default constructor does not initialize the color to any value.
30
- Color()
31
- {
32
- }
33
-
34
- //! Conversion constructor for literals of the form 0xaarrggbb.
35
- Color(unsigned argb)
36
- : Color((argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb >> 0) & 0xff)
37
- {
38
- }
39
-
40
- Color(Channel red, Channel green, Channel blue)
41
- : Color(0xff, red, green, blue)
42
- {
43
- }
44
-
45
- Color(Channel alpha, Channel red, Channel green, Channel blue)
46
- {
47
- rep = (alpha << ALPHA_OFFSET) | (red << RED_OFFSET) |
48
- (green << GREEN_OFFSET) | (blue << BLUE_OFFSET);
49
- }
50
-
51
- //! Constructs a color from the given hue/saturation/value triple.
52
- //! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
53
- static Color from_hsv(double h, double s, double v);
54
-
55
- //! Constructs a color from the given hue/saturation/value triple.
56
- //! Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
57
- static Color from_ahsv(Channel alpha, double h, double s, double v);
58
13
 
59
- Channel red() const
60
- {
61
- return static_cast<Channel>(rep >> RED_OFFSET);
62
- }
14
+ typedef std::uint8_t Channel;
63
15
 
64
- Channel green() const
65
- {
66
- return static_cast<Channel>(rep >> GREEN_OFFSET);
67
- }
16
+ Channel red, green, blue, alpha;
68
17
 
69
- Channel blue() const
18
+ constexpr Color()
19
+ : red{0},
20
+ green{0},
21
+ blue{0},
22
+ alpha{0}
70
23
  {
71
- return static_cast<Channel>(rep >> BLUE_OFFSET);
72
24
  }
73
25
 
74
- Channel alpha() const
26
+ /// Conversion constructor for literals of the form 0xaarrggbb.
27
+ // NOLINTNEXTLINE: We want to allow implicit conversions.
28
+ constexpr Color(std::uint32_t argb)
29
+ : red{static_cast<Channel>(argb >> 16)},
30
+ green{static_cast<Channel>(argb >> 8)},
31
+ blue{static_cast<Channel>(argb >> 0)},
32
+ alpha{static_cast<Channel>(argb >> 24)}
75
33
  {
76
- return static_cast<Channel>(rep >> ALPHA_OFFSET);
77
34
  }
78
35
 
79
- void set_red(Channel value)
36
+ constexpr Color(Channel red, Channel green, Channel blue)
37
+ : red{red},
38
+ green{green},
39
+ blue{blue},
40
+ alpha{255}
80
41
  {
81
- rep &= ~(0xff << RED_OFFSET);
82
- rep |= value << RED_OFFSET;
83
42
  }
84
43
 
85
- void set_green(Channel value)
44
+ Color with_alpha(Channel new_alpha)
86
45
  {
87
- rep &= ~(0xff << GREEN_OFFSET);
88
- rep |= value << GREEN_OFFSET;
46
+ Color result = *this;
47
+ result.alpha = new_alpha;
48
+ return result;
89
49
  }
90
50
 
91
- void set_blue(Channel value)
92
- {
93
- rep &= ~(0xff << BLUE_OFFSET);
94
- rep |= value << BLUE_OFFSET;
95
- }
96
-
97
- void set_alpha(Channel value)
98
- {
99
- rep &= ~(0xff << ALPHA_OFFSET);
100
- rep |= value << ALPHA_OFFSET;
101
- }
51
+ /// Constructs a color from the given hue/saturation/value triple.
52
+ /// Ranges of these values are given as 0..360, 0..1, and 0..1, respectively.
53
+ static Color from_hsv(double h, double s, double v);
102
54
 
103
- //! Returns the hue of the color, in the usual range of 0..360.
55
+ /// Returns the hue of the color, in the usual range of 0..360.
104
56
  double hue() const;
105
-
106
- //! Changes the current color so hue() will return h.
57
+
58
+ /// Changes the current color so hue() will return h.
107
59
  void set_hue(double h);
108
-
109
- //! Returns the saturation of the color, in the range of 0..1.
60
+
61
+ /// Returns the saturation of the color, in the range of 0..1.
110
62
  double saturation() const;
111
-
112
- //! Changes the current color so saturation() will return s.
63
+
64
+ /// Changes the current color so saturation() will return s.
113
65
  void set_saturation(double s);
114
-
115
- //! Returns the value (brightness) of the color, in the range of 0..1.
66
+
67
+ /// Returns the value (brightness) of the color, in the range of 0..1.
116
68
  double value() const;
117
-
118
- //! Changes the current color so value() will return v.
69
+
70
+ /// Changes the current color so value() will return v.
119
71
  void set_value(double v);
120
72
 
121
- //! Returns the color in 0xaarrggbb representation.
122
- std::uint32_t argb() const { return alpha() << 24 | red() << 16 | green() << 8 | blue(); }
73
+ /// Returns the color in 0xaarrggbb representation.
74
+ std::uint32_t argb() const { return alpha << 24 | red << 16 | green << 8 | blue; }
75
+
76
+ /// Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
77
+ std::uint32_t bgr() const { return blue << 16 | green << 8 | red; }
78
+
79
+ /// Returns the color in 0xaabbggrr representation.
80
+ std::uint32_t abgr() const { return alpha << 24 | blue << 16 | green << 8 | red; }
123
81
 
124
- //! Returns the color in 0x00bbggrr representation. Useful for Win32 programming.
125
- std::uint32_t bgr() const { return blue() << 16 | green() << 8 | red(); }
82
+ /// Returns the internal representation of the color (RGBA in memory).
83
+ std::uint32_t gl() const { return *reinterpret_cast<const std::uint32_t*>(this); }
126
84
 
127
- //! Returns the color in 0xaabbggrr representation.
128
- std::uint32_t abgr() const { return alpha() << 24 | blue() << 16 | green() << 8 | red(); }
129
-
130
- //! Returns the internal representation of the color (RGBA in memory).
131
- std::uint32_t gl() const { return rep; }
132
-
133
85
  static const Color NONE;
134
86
  static const Color BLACK;
135
87
  static const Color GRAY;
136
88
  static const Color WHITE;
137
-
89
+
90
+ /// Same as Color::CYAN.
138
91
  static const Color AQUA;
139
92
  static const Color RED;
140
93
  static const Color GREEN;
141
94
  static const Color BLUE;
142
95
  static const Color YELLOW;
143
96
  static const Color FUCHSIA;
97
+ /// Same as Color::AQUA.
144
98
  static const Color CYAN;
145
99
  };
146
-
100
+
101
+ // Ensure that we can pass vectors of Gosu::Color straight to OpenGL and back.
102
+ static_assert(sizeof(Color) == sizeof(std::uint32_t));
103
+
147
104
  #ifndef SWIG
148
105
  inline bool operator<(Color a, Color b) { return a.gl() < b.gl(); }
149
106
  inline bool operator==(Color a, Color b) { return a.gl() == b.gl(); }
150
107
  inline bool operator!=(Color a, Color b) { return a.gl() != b.gl(); }
151
108
 
152
- //! Interpolates linearly between two colors, with a given weight towards
153
- //! the second color.
154
- //! Specialization of the general function in Gosu/Math.hpp.
155
- Color interpolate(Color a, Color b, double weight = 0.5);
156
-
157
- //! Combines two colors as if their channels were mapped to the 0..1 range
158
- //! and then multiplied with each other.
109
+ /// Interpolates linearly between two colors, with a given weight towards
110
+ /// the second color.
111
+ Color lerp(Color a, Color b, double t = 0.5);
112
+
113
+ /// Combines two colors as if their channels were mapped to the 0..1 range
114
+ /// and then multiplied with each other.
159
115
  Color multiply(Color a, Color b);
160
116
  #endif
161
117
  }