gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) 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 +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
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/Platform.hpp>
8
- #include <Gosu/Utility.hpp>
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
- using namespace std;
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 (!pimpl) return Channel();
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, pimpl->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
- double volume_ = 1.0;
83
- unique_ptr<AudioFile> file;
84
- ALuint buffers[2];
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 = file->read_data(audio_data, sizeof audio_data);
94
+ size_t read_bytes = m_file->read_data(audio_data, sizeof audio_data);
95
95
  if (read_bytes > 0) {
96
- alBufferData(buffer, file->format(), audio_data,
97
- static_cast<ALsizei>(read_bytes), file->sample_rate());
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, buffers);
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, buffers);
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, buffers);
124
+
125
+ alDeleteBuffers(2, m_buffers);
126
126
  }
127
-
128
- void play(bool looping)
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(buffers[0]);
138
- stream_to_buffer(buffers[1]);
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, buffers);
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
- // Unqueue all buffers for this source.
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
- file->rewind();
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() const
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(true);
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 volume_;
219
+ return m_volume;
220
220
  }
221
-
221
+
222
222
  void set_volume(double volume)
223
223
  {
224
- volume_ = clamp(volume, 0.0, 1.0);
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
- pimpl->resume();
252
+ m_impl->resume();
253
253
  }
254
-
254
+
255
255
  if (cur_song && cur_song != this) {
256
256
  cur_song->stop();
257
- assert (cur_song == nullptr);
257
+ assert(cur_song == nullptr);
258
258
  }
259
-
259
+
260
260
  if (cur_song == nullptr) {
261
- pimpl->play(looping);
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
- pimpl->pause();
271
+ m_impl->pause();
272
272
  }
273
273
  }
274
274
 
275
275
  bool Gosu::Song::paused() const
276
276
  {
277
- return cur_song == this && pimpl->paused();
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
- pimpl->stop();
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 && !pimpl->paused();
290
+ return cur_song == this && !m_impl->paused();
291
291
  }
292
292
 
293
293
  double Gosu::Song::volume() const
294
294
  {
295
- return pimpl->volume();
295
+ return m_impl->volume();
296
296
  }
297
297
 
298
298
  void Gosu::Song::set_volume(double volume)
299
299
  {
300
- pimpl->set_volume(volume);
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()->pimpl->update();
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 GOSU_IS_MAC
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;
@@ -14,7 +14,7 @@
14
14
  #include <mutex>
15
15
  #include <vector>
16
16
 
17
- struct Gosu::AudioFile::Impl
17
+ struct Gosu::AudioFile::Impl : Gosu::Noncopyable
18
18
  {
19
19
  Buffer buffer;
20
20
 
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 GOSU_IS_MAC
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();
data/src/BitmapIO.cpp CHANGED
@@ -7,18 +7,8 @@
7
7
  #define STBI_NO_STDIO
8
8
  #define STBI_NO_LINEAR
9
9
 
10
- // Disable comma warnings in stb headers.
11
- #ifdef __GNUC__
12
- #pragma GCC diagnostic push
13
- #pragma GCC diagnostic ignored "-Wcomma"
14
- #endif
15
-
16
10
  #include <stb_image.h>
17
11
 
18
- #ifdef __GNUC__
19
- #pragma GCC diagnostic pop
20
- #endif
21
-
22
12
  static int read_callback(void* user, char* data, int size)
23
13
  {
24
14
  Gosu::Reader* reader = static_cast<Gosu::Reader*>(user);
@@ -82,19 +72,9 @@ Gosu::Bitmap Gosu::load_image_file(Reader input)
82
72
  return bitmap;
83
73
  }
84
74
 
85
- // Disable comma warnings in stb headers.
86
- #ifdef __GNUC__
87
- #pragma GCC diagnostic push
88
- #pragma GCC diagnostic ignored "-Wcomma"
89
- #endif
90
-
91
75
  #define STB_IMAGE_WRITE_IMPLEMENTATION
92
76
  #include <stb_image_write.h>
93
77
 
94
- #ifdef __GNUC__
95
- #pragma GCC diagnostic pop
96
- #endif
97
-
98
78
  void Gosu::save_image_file(const Gosu::Bitmap& bitmap, const std::string& filename)
99
79
  {
100
80
  int ok;
@@ -1,9 +1,10 @@
1
+ #include <Gosu/Utility.hpp>
1
2
  #include "BlockAllocator.hpp"
2
3
  #include <stdexcept>
3
4
  #include <vector>
4
5
  using namespace std;
5
6
 
6
- struct Gosu::BlockAllocator::Impl
7
+ struct Gosu::BlockAllocator::Impl : Gosu::Noncopyable
7
8
  {
8
9
  unsigned width, height;
9
10
 
data/src/Channel.cpp CHANGED
@@ -1,8 +1,8 @@
1
1
  #include <Gosu/Audio.hpp>
2
2
  #include "AudioImpl.hpp"
3
- using namespace std;
3
+ #include <algorithm>
4
4
 
5
- // Returns the current state of a source
5
+ /// Returns the current state of a source.
6
6
  static ALint state(int& channel)
7
7
  {
8
8
  ALint state;
@@ -14,41 +14,43 @@ static ALint state(int& channel)
14
14
  }
15
15
 
16
16
  Gosu::Channel::Channel()
17
- : channel(NO_CHANNEL), token(0)
17
+ : m_channel{NO_CHANNEL},
18
+ m_token{0}
18
19
  {
19
20
  }
20
21
 
21
22
  Gosu::Channel::Channel(int channel, int token)
22
- : channel(channel), token(token)
23
+ : m_channel{channel},
24
+ m_token{token}
23
25
  {
24
26
  }
25
27
 
26
28
  int Gosu::Channel::current_channel() const
27
29
  {
28
- if (channel != NO_CHANNEL && channel_expired(channel, token)) {
29
- channel = NO_CHANNEL;
30
+ if (m_channel != NO_CHANNEL && channel_expired(m_channel, m_token)) {
31
+ m_channel = NO_CHANNEL;
30
32
  }
31
- return channel;
33
+ return m_channel;
32
34
  }
33
35
 
34
36
  bool Gosu::Channel::playing() const
35
37
  {
36
38
  if (current_channel() == NO_CHANNEL) return false;
37
-
38
- return state(channel) == AL_PLAYING;
39
+
40
+ return state(m_channel) == AL_PLAYING;
39
41
  }
40
42
 
41
43
  bool Gosu::Channel::paused() const
42
44
  {
43
45
  if (current_channel() == NO_CHANNEL) return false;
44
46
 
45
- return state(channel) == AL_PAUSED;
47
+ return state(m_channel) == AL_PAUSED;
46
48
  }
47
49
 
48
50
  void Gosu::Channel::pause()
49
51
  {
50
52
  if (playing()) {
51
- ALuint source = al_source_for_channel(channel);
53
+ ALuint source = al_source_for_channel(m_channel);
52
54
  alSourcePause(source);
53
55
  }
54
56
  }
@@ -56,7 +58,7 @@ void Gosu::Channel::pause()
56
58
  void Gosu::Channel::resume()
57
59
  {
58
60
  if (paused()) {
59
- ALuint source = al_source_for_channel(channel);
61
+ ALuint source = al_source_for_channel(m_channel);
60
62
  alSourcePlay(source);
61
63
  }
62
64
  }
@@ -65,31 +67,31 @@ void Gosu::Channel::stop()
65
67
  {
66
68
  if (current_channel() == NO_CHANNEL) return;
67
69
 
68
- ALuint source = al_source_for_channel(channel);
70
+ ALuint source = al_source_for_channel(m_channel);
69
71
  alSourceStop(source);
70
- channel = NO_CHANNEL;
72
+ m_channel = NO_CHANNEL;
71
73
  }
72
74
 
73
75
  void Gosu::Channel::set_volume(double volume)
74
76
  {
75
77
  if (current_channel() == NO_CHANNEL) return;
76
78
 
77
- ALuint source = al_source_for_channel(channel);
78
- alSourcef(source, AL_GAIN, max(volume, 0.0));
79
+ ALuint source = al_source_for_channel(m_channel);
80
+ alSourcef(source, AL_GAIN, static_cast<ALfloat>(std::max(volume, 0.0)));
79
81
  }
80
82
 
81
83
  void Gosu::Channel::set_pan(double pan)
82
84
  {
83
85
  if (current_channel() == NO_CHANNEL) return;
84
86
 
85
- ALuint source = al_source_for_channel(channel);
86
- alSource3f(source, AL_POSITION, pan * 10, 0, 0);
87
+ ALuint source = al_source_for_channel(m_channel);
88
+ alSource3f(source, AL_POSITION, static_cast<ALfloat>(pan * 10), 0, 0);
87
89
  }
88
90
 
89
91
  void Gosu::Channel::set_speed(double speed)
90
92
  {
91
93
  if (current_channel() == NO_CHANNEL) return;
92
94
 
93
- ALuint source = al_source_for_channel(channel);
94
- alSourcef(source, AL_PITCH, speed);
95
+ ALuint source = al_source_for_channel(m_channel);
96
+ alSourcef(source, AL_PITCH, static_cast<ALfloat>(speed));
95
97
  }
data/src/Color.cpp CHANGED
@@ -1,35 +1,38 @@
1
1
  #include <Gosu/Color.hpp>
2
2
  #include <Gosu/Math.hpp>
3
- #include <cmath>
4
3
  #include <algorithm>
4
+ #include <cmath>
5
5
 
6
6
  namespace
7
7
  {
8
- struct HSV { double h, s, v; };
9
-
8
+ struct HSV
9
+ {
10
+ double h, s, v;
11
+ };
12
+
10
13
  HSV color_to_hsv(const Gosu::Color& c)
11
14
  {
12
15
  double r = c.red / 255.0;
13
16
  double g = c.green / 255.0;
14
17
  double b = c.blue / 255.0;
15
-
18
+
16
19
  double min = std::min(std::min(r, g), b);
17
20
  double max = std::max(std::max(r, g), b);
18
21
  double delta = max - min;
19
22
 
20
23
  if (max == 0) {
21
- HSV hsv = { 0, 0, 0 };
24
+ HSV hsv = {0, 0, 0};
22
25
  return hsv;
23
26
  }
24
-
27
+
25
28
  HSV hsv{};
26
29
 
27
30
  // Value.
28
31
  hsv.v = max;
29
-
32
+
30
33
  // Saturation.
31
34
  hsv.s = delta / max;
32
-
35
+
33
36
  // Hue.
34
37
  if (delta == 0) {
35
38
  hsv.h = 0;
@@ -44,7 +47,7 @@ namespace
44
47
  hsv.h = (r - g) / delta + 4;
45
48
  }
46
49
  hsv.h *= 60;
47
-
50
+
48
51
  return hsv;
49
52
  }
50
53
  }