gosu 1.5.0 → 2.0.0.pre6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +233 -0
  3. data/dependencies/SDL/include/SDL_assert.h +320 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +414 -0
  5. data/dependencies/SDL/include/SDL_audio.h +1500 -0
  6. data/dependencies/SDL/include/{SDL3/SDL_bits.h → SDL_bits.h} +27 -47
  7. data/dependencies/SDL/include/{SDL3/SDL_blendmode.h → SDL_blendmode.h} +55 -59
  8. data/dependencies/SDL/include/SDL_clipboard.h +141 -0
  9. data/dependencies/SDL/include/SDL_config.h +331 -0
  10. data/dependencies/SDL/include/SDL_cpuinfo.h +594 -0
  11. data/dependencies/SDL/include/{SDL3/SDL_egl.h → SDL_egl.h} +8 -11
  12. data/dependencies/SDL/include/SDL_endian.h +348 -0
  13. data/dependencies/SDL/include/SDL_error.h +163 -0
  14. data/dependencies/SDL/include/SDL_events.h +1166 -0
  15. data/dependencies/SDL/include/SDL_filesystem.h +149 -0
  16. data/dependencies/SDL/include/SDL_gamecontroller.h +1074 -0
  17. data/dependencies/SDL/include/SDL_gesture.h +117 -0
  18. data/dependencies/SDL/include/SDL_guid.h +100 -0
  19. data/dependencies/SDL/include/SDL_haptic.h +1341 -0
  20. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  21. data/dependencies/SDL/include/SDL_hints.h +2613 -0
  22. data/dependencies/SDL/include/SDL_joystick.h +1069 -0
  23. data/dependencies/SDL/include/SDL_keyboard.h +353 -0
  24. data/dependencies/SDL/include/SDL_keycode.h +358 -0
  25. data/dependencies/SDL/include/SDL_loadso.h +115 -0
  26. data/dependencies/SDL/include/{SDL3/SDL_locale.h → SDL_locale.h} +24 -40
  27. data/dependencies/SDL/include/SDL_log.h +404 -0
  28. data/dependencies/SDL/include/SDL_main.h +282 -0
  29. data/dependencies/SDL/include/{SDL3/SDL_messagebox.h → SDL_messagebox.h} +48 -85
  30. data/dependencies/SDL/include/{SDL3/SDL_metal.h → SDL_metal.h} +29 -29
  31. data/dependencies/SDL/include/{SDL3/SDL_misc.h → SDL_misc.h} +12 -13
  32. data/dependencies/SDL/include/SDL_mouse.h +464 -0
  33. data/dependencies/SDL/include/SDL_mutex.h +545 -0
  34. data/dependencies/SDL/include/SDL_name.h +33 -0
  35. data/dependencies/SDL/include/{SDL3/SDL_opengl.h → SDL_opengl.h} +252 -1221
  36. data/dependencies/SDL/include/{SDL3/SDL_opengles.h → SDL_opengles.h} +7 -6
  37. data/dependencies/SDL/include/{SDL3/SDL_opengles2.h → SDL_opengles2.h} +11 -10
  38. data/dependencies/SDL/include/SDL_pixels.h +644 -0
  39. data/dependencies/SDL/include/SDL_platform.h +261 -0
  40. data/dependencies/SDL/include/{SDL3/SDL_power.h → SDL_power.h} +19 -40
  41. data/dependencies/SDL/include/SDL_quit.h +58 -0
  42. data/dependencies/SDL/include/SDL_rect.h +376 -0
  43. data/dependencies/SDL/include/SDL_render.h +1924 -0
  44. data/dependencies/SDL/include/SDL_revision.h +7 -0
  45. data/dependencies/SDL/include/SDL_rwops.h +841 -0
  46. data/dependencies/SDL/include/{SDL3/SDL_scancode.h → SDL_scancode.h} +68 -60
  47. data/dependencies/SDL/include/SDL_sensor.h +322 -0
  48. data/dependencies/SDL/include/SDL_shape.h +155 -0
  49. data/dependencies/SDL/include/SDL_stdinc.h +838 -0
  50. data/dependencies/SDL/include/SDL_surface.h +997 -0
  51. data/dependencies/SDL/include/SDL_system.h +623 -0
  52. data/dependencies/SDL/include/SDL_syswm.h +386 -0
  53. data/dependencies/SDL/include/{SDL3/SDL_test.h → SDL_test.h} +22 -16
  54. data/dependencies/SDL/include/{SDL3/SDL_test_assert.h → SDL_test_assert.h} +34 -27
  55. data/dependencies/SDL/include/{SDL3/SDL_test_common.h → SDL_test_common.h} +52 -109
  56. data/dependencies/SDL/include/{SDL3/SDL_test_compare.h → SDL_test_compare.h} +14 -22
  57. data/dependencies/SDL/include/{SDL3/SDL_test_crc32.h → SDL_test_crc32.h} +30 -27
  58. data/dependencies/SDL/include/{SDL3/SDL_test_font.h → SDL_test_font.h} +49 -50
  59. data/dependencies/SDL/include/{SDL3/SDL_test_fuzzer.h → SDL_test_fuzzer.h} +79 -64
  60. data/dependencies/SDL/include/{SDL3/SDL_test_harness.h → SDL_test_harness.h} +30 -47
  61. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  62. data/dependencies/SDL/include/{SDL3/SDL_platform.h → SDL_test_log.h} +26 -25
  63. data/dependencies/SDL/include/{SDL3/SDL_test_md5.h → SDL_test_md5.h} +28 -21
  64. data/dependencies/SDL/include/{SDL3/SDL_test_memory.h → SDL_test_memory.h} +16 -19
  65. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  66. data/dependencies/SDL/include/SDL_thread.h +464 -0
  67. data/dependencies/SDL/include/SDL_timer.h +222 -0
  68. data/dependencies/SDL/include/SDL_touch.h +150 -0
  69. data/dependencies/SDL/include/{SDL3/SDL_copying.h → SDL_types.h} +9 -2
  70. data/dependencies/SDL/include/SDL_version.h +204 -0
  71. data/dependencies/SDL/include/SDL_video.h +2178 -0
  72. data/dependencies/SDL/include/SDL_vulkan.h +215 -0
  73. data/dependencies/SDL/include/begin_code.h +187 -0
  74. data/dependencies/SDL/include/{SDL3/SDL_close_code.h → close_code.h} +6 -7
  75. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  76. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  77. data/dependencies/SDL_sound/SDL_sound.c +215 -136
  78. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  79. data/dependencies/SDL_sound/SDL_sound_aiff.c +54 -55
  80. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  81. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +41 -24
  82. data/dependencies/SDL_sound/SDL_sound_flac.c +12 -32
  83. data/dependencies/SDL_sound/SDL_sound_internal.h +48 -33
  84. data/dependencies/SDL_sound/SDL_sound_modplug.c +29 -21
  85. data/dependencies/SDL_sound/SDL_sound_mp3.c +13 -35
  86. data/dependencies/SDL_sound/SDL_sound_raw.c +15 -14
  87. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  88. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  89. data/dependencies/SDL_sound/SDL_sound_vorbis.c +25 -34
  90. data/dependencies/SDL_sound/SDL_sound_wav.c +82 -86
  91. data/dependencies/SDL_sound/dr_flac.h +1281 -1845
  92. data/dependencies/SDL_sound/dr_mp3.h +617 -1035
  93. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  94. data/dependencies/SDL_sound/libmodplug/libmodplug.h +4 -5
  95. data/dependencies/SDL_sound/libmodplug/load_ams.c +3 -6
  96. data/dependencies/SDL_sound/libmodplug/load_dsm.c +1 -2
  97. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  98. data/dependencies/SDL_sound/libmodplug/modplug.h +1 -2
  99. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  100. data/dependencies/SDL_sound/libmodplug/sndfile.c +0 -3
  101. data/dependencies/SDL_sound/libmodplug/sndmix.c +3 -7
  102. data/dependencies/SDL_sound/stb_vorbis.h +343 -397
  103. data/dependencies/mojoAL/AL/alc.h +2 -2
  104. data/dependencies/mojoAL/mojoal.c +1878 -2113
  105. data/dependencies/stb/stb_image.h +1381 -1192
  106. data/dependencies/stb/stb_image_write.h +129 -329
  107. data/dependencies/stb/stb_truetype.h +60 -304
  108. data/dependencies/utf8proc/utf8proc.c +75 -133
  109. data/dependencies/utf8proc/utf8proc.h +50 -131
  110. data/dependencies/utf8proc/utf8proc_data.h +15658 -16213
  111. data/ext/gosu-ffi/extconf.rb +28 -11
  112. data/ext/gosu-ffi/gosu-ffi.def +0 -3
  113. data/ffi/Gosu.cpp +29 -52
  114. data/ffi/Gosu.h +4 -4
  115. data/ffi/Gosu_Color.cpp +36 -80
  116. data/ffi/Gosu_FFI_internal.h +13 -12
  117. data/ffi/Gosu_Font.cpp +11 -16
  118. data/ffi/Gosu_Font.h +4 -4
  119. data/ffi/Gosu_Image.cpp +36 -69
  120. data/ffi/Gosu_Image.h +5 -16
  121. data/include/Gosu/Bitmap.hpp +1 -1
  122. data/include/Gosu/Color.hpp +4 -5
  123. data/include/Gosu/Graphics.hpp +0 -2
  124. data/include/Gosu/Image.hpp +1 -1
  125. data/include/Gosu/Math.hpp +5 -5
  126. data/include/Gosu/Utility.hpp +1 -27
  127. data/include/Gosu/Version.hpp +2 -2
  128. data/lib/SDL2.dll +0 -0
  129. data/lib/gosu/channel.rb +0 -1
  130. data/lib/gosu/color.rb +13 -36
  131. data/lib/gosu/compat.rb +14 -106
  132. data/lib/gosu/constants.rb +24 -24
  133. data/lib/gosu/ffi.rb +13 -24
  134. data/lib/gosu/font.rb +13 -19
  135. data/lib/gosu/gosu.rb +61 -101
  136. data/lib/gosu/image.rb +34 -72
  137. data/lib/gosu/sample.rb +0 -1
  138. data/lib/gosu/song.rb +0 -1
  139. data/lib/gosu/text_input.rb +1 -15
  140. data/lib/gosu/window.rb +10 -31
  141. data/lib64/SDL2.dll +0 -0
  142. data/rdoc/gosu.rb +0 -2
  143. data/src/Audio.cpp +16 -22
  144. data/src/AudioFileSDLSound.cpp +5 -5
  145. data/src/BinPacker.cpp +4 -5
  146. data/src/Bitmap.cpp +9 -16
  147. data/src/Buffer.cpp +14 -5
  148. data/src/ClipRectStack.hpp +83 -17
  149. data/src/Directories.cpp +1 -1
  150. data/src/DrawOp.hpp +17 -14
  151. data/src/DrawOpQueue.hpp +31 -25
  152. data/src/Font.cpp +1 -1
  153. data/src/GosuGLView.cpp +7 -1
  154. data/src/Graphics.cpp +25 -32
  155. data/src/GraphicsImpl.hpp +24 -0
  156. data/src/Image.cpp +2 -2
  157. data/src/Input.cpp +70 -66
  158. data/src/Macro.cpp +26 -43
  159. data/src/Macro.hpp +16 -22
  160. data/src/Math.cpp +7 -20
  161. data/src/OffScreenTarget.cpp +10 -3
  162. data/src/OpenGLContext.cpp +8 -7
  163. data/src/OpenGLContext.hpp +2 -2
  164. data/src/RenderState.hpp +54 -30
  165. data/src/Resolution.cpp +38 -48
  166. data/src/TexChunk.cpp +2 -2
  167. data/src/TextInput.cpp +9 -9
  168. data/src/Texture.cpp +1 -1
  169. data/src/TiledDrawable.cpp +7 -6
  170. data/src/TrueTypeFontUnix.cpp +9 -12
  171. data/src/Utility.cpp +26 -39
  172. data/src/UtilityWin.cpp +2 -6
  173. data/src/Window.cpp +34 -54
  174. metadata +93 -99
  175. data/dependencies/SDL/include/SDL3/SDL.h +0 -91
  176. data/dependencies/SDL/include/SDL3/SDL_assert.h +0 -710
  177. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +0 -550
  178. data/dependencies/SDL/include/SDL3/SDL_atomic.h +0 -692
  179. data/dependencies/SDL/include/SDL3/SDL_audio.h +0 -2382
  180. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +0 -553
  181. data/dependencies/SDL/include/SDL3/SDL_camera.h +0 -535
  182. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +0 -331
  183. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +0 -374
  184. data/dependencies/SDL/include/SDL3/SDL_dialog.h +0 -343
  185. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +0 -234
  186. data/dependencies/SDL/include/SDL3/SDL_endian.h +0 -645
  187. data/dependencies/SDL/include/SDL3/SDL_error.h +0 -226
  188. data/dependencies/SDL/include/SDL3/SDL_events.h +0 -1651
  189. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +0 -537
  190. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +0 -1657
  191. data/dependencies/SDL/include/SDL3/SDL_gpu.h +0 -4637
  192. data/dependencies/SDL/include/SDL3/SDL_guid.h +0 -106
  193. data/dependencies/SDL/include/SDL3/SDL_haptic.h +0 -1461
  194. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +0 -571
  195. data/dependencies/SDL/include/SDL3/SDL_hints.h +0 -5041
  196. data/dependencies/SDL/include/SDL3/SDL_init.h +0 -508
  197. data/dependencies/SDL/include/SDL3/SDL_intrin.h +0 -410
  198. data/dependencies/SDL/include/SDL3/SDL_iostream.h +0 -1379
  199. data/dependencies/SDL/include/SDL3/SDL_joystick.h +0 -1385
  200. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +0 -615
  201. data/dependencies/SDL/include/SDL3/SDL_keycode.h +0 -348
  202. data/dependencies/SDL/include/SDL3/SDL_loadso.h +0 -145
  203. data/dependencies/SDL/include/SDL3/SDL_log.h +0 -541
  204. data/dependencies/SDL/include/SDL3/SDL_main.h +0 -704
  205. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +0 -149
  206. data/dependencies/SDL/include/SDL3/SDL_mouse.h +0 -813
  207. data/dependencies/SDL/include/SDL3/SDL_mutex.h +0 -1117
  208. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +0 -1339
  209. data/dependencies/SDL/include/SDL3/SDL_pen.h +0 -198
  210. data/dependencies/SDL/include/SDL3/SDL_pixels.h +0 -1441
  211. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +0 -497
  212. data/dependencies/SDL/include/SDL3/SDL_process.h +0 -441
  213. data/dependencies/SDL/include/SDL3/SDL_properties.h +0 -572
  214. data/dependencies/SDL/include/SDL3/SDL_rect.h +0 -528
  215. data/dependencies/SDL/include/SDL3/SDL_render.h +0 -3034
  216. data/dependencies/SDL/include/SDL3/SDL_revision.h +0 -56
  217. data/dependencies/SDL/include/SDL3/SDL_sensor.h +0 -321
  218. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +0 -6186
  219. data/dependencies/SDL/include/SDL3/SDL_storage.h +0 -686
  220. data/dependencies/SDL/include/SDL3/SDL_surface.h +0 -1769
  221. data/dependencies/SDL/include/SDL3/SDL_system.h +0 -840
  222. data/dependencies/SDL/include/SDL3/SDL_test_log.h +0 -83
  223. data/dependencies/SDL/include/SDL3/SDL_thread.h +0 -602
  224. data/dependencies/SDL/include/SDL3/SDL_time.h +0 -249
  225. data/dependencies/SDL/include/SDL3/SDL_timer.h +0 -454
  226. data/dependencies/SDL/include/SDL3/SDL_touch.h +0 -184
  227. data/dependencies/SDL/include/SDL3/SDL_tray.h +0 -544
  228. data/dependencies/SDL/include/SDL3/SDL_version.h +0 -198
  229. data/dependencies/SDL/include/SDL3/SDL_video.h +0 -3497
  230. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +0 -287
  231. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  232. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  233. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +0 -755
  234. data/lib/SDL3.dll +0 -0
  235. data/lib64/SDL3.dll +0 -0
  236. data/src/ClipRectStack.cpp +0 -38
  237. /data/dependencies/SDL/include/{SDL3/SDL_opengl_glext.h → SDL_opengl_glext.h} +0 -0
  238. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2.h → SDL_opengles2_gl2.h} +0 -0
  239. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2ext.h → SDL_opengles2_gl2ext.h} +0 -0
  240. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2platform.h → SDL_opengles2_gl2platform.h} +0 -0
  241. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_khrplatform.h → SDL_opengles2_khrplatform.h} +0 -0
data/src/Audio.cpp CHANGED
@@ -1,5 +1,6 @@
1
1
  #include <Gosu/Audio.hpp>
2
2
  #include <Gosu/Buffer.hpp>
3
+ #include <Gosu/Math.hpp>
3
4
  #include "AudioFile.hpp"
4
5
  #include "AudioImpl.hpp"
5
6
  #include <algorithm>
@@ -17,11 +18,11 @@ struct Gosu::Sample::Impl : private Gosu::Noncopyable
17
18
  ALuint buffer;
18
19
 
19
20
  explicit Impl(AudioFile&& audio_file)
20
- : buffer()
21
+ : buffer{}
21
22
  {
22
23
  al_initialize();
23
24
  alGenBuffers(1, &buffer);
24
- alBufferData(buffer, audio_file.format(), audio_file.decoded_data().data(),
25
+ alBufferData(buffer, audio_file.format(), &audio_file.decoded_data().front(),
25
26
  static_cast<ALsizei>(audio_file.decoded_data().size()),
26
27
  static_cast<ALsizei>(audio_file.sample_rate()));
27
28
  }
@@ -30,9 +31,7 @@ struct Gosu::Sample::Impl : private Gosu::Noncopyable
30
31
  {
31
32
  // It's hard to free things in the right order in Ruby/Gosu.
32
33
  // Make sure buffer isn't deleted after the context/device are shut down.
33
- if (!al_initialized()) {
34
- return;
35
- }
34
+ if (!al_initialized()) return;
36
35
 
37
36
  alDeleteBuffers(1, &buffer);
38
37
  }
@@ -59,16 +58,12 @@ Gosu::Channel Gosu::Sample::play(double volume, double speed, bool looping) cons
59
58
 
60
59
  Gosu::Channel Gosu::Sample::play_pan(double pan, double volume, double speed, bool looping) const
61
60
  {
62
- if (!m_impl) {
63
- return Channel();
64
- }
61
+ if (!m_impl) return Channel{};
65
62
 
66
63
  Channel channel = allocate_channel();
67
64
 
68
65
  // Couldn't allocate a free channel.
69
- if (channel.current_channel() == NO_CHANNEL) {
70
- return channel;
71
- }
66
+ if (channel.current_channel() == NO_CHANNEL) return channel;
72
67
 
73
68
  ALuint source = al_source_for_channel(channel.current_channel());
74
69
  alSourcei(source, AL_BUFFER, static_cast<ALint>(m_impl->buffer));
@@ -106,7 +101,7 @@ private:
106
101
 
107
102
  public:
108
103
  explicit Impl(const std::string& filename)
109
- : m_buffers(),
104
+ : m_buffers {},
110
105
  m_file(new AudioFile(filename))
111
106
  {
112
107
  al_initialize();
@@ -114,7 +109,7 @@ public:
114
109
  }
115
110
 
116
111
  explicit Impl(Buffer buffer)
117
- : m_buffers(),
112
+ : m_buffers {},
118
113
  m_file(new AudioFile(std::move(buffer)))
119
114
  {
120
115
  al_initialize();
@@ -125,9 +120,7 @@ public:
125
120
  {
126
121
  // It's hard to free things in the right order in Ruby/Gosu.
127
122
  // Make sure buffers aren't deleted after the context/device are shut down.
128
- if (!al_initialized()) {
129
- return;
130
- }
123
+ if (!al_initialized()) return;
131
124
 
132
125
  alDeleteBuffers(2, m_buffers);
133
126
  }
@@ -199,9 +192,7 @@ public:
199
192
  for (int i = 0; i < processed; ++i) {
200
193
  alSourceUnqueueBuffers(source, 1, &buffer);
201
194
  active = stream_to_buffer(buffer);
202
- if (active) {
203
- alSourceQueueBuffers(source, 1, &buffer);
204
- }
195
+ if (active) alSourceQueueBuffers(source, 1, &buffer);
205
196
  }
206
197
 
207
198
  ALint state;
@@ -225,7 +216,10 @@ public:
225
216
  }
226
217
  }
227
218
 
228
- double volume() const { return m_volume; }
219
+ double volume() const
220
+ {
221
+ return m_volume;
222
+ }
229
223
 
230
224
  void set_volume(double volume)
231
225
  {
@@ -235,12 +229,12 @@ public:
235
229
  };
236
230
 
237
231
  Gosu::Song::Song(const std::string& filename)
238
- : m_impl(new Impl(filename))
232
+ : m_impl(new Impl(filename))
239
233
  {
240
234
  }
241
235
 
242
236
  Gosu::Song::Song(Buffer buffer)
243
- : m_impl(new Impl(std::move(buffer)))
237
+ : m_impl(new Impl(std::move(buffer)))
244
238
  {
245
239
  }
246
240
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  #include "AudioFile.hpp"
7
7
  #include "AudioImpl.hpp"
8
- #include <SDL3_sound/SDL_sound.h>
8
+ #include <SDL_sound.h>
9
9
  #include <algorithm>
10
10
  #include <cstdlib>
11
11
  #include <cstring>
@@ -36,12 +36,12 @@ Gosu::AudioFile::AudioFile(const std::string& filename)
36
36
  {
37
37
  // We need to set a "desired" audio format, otherwise we may encounter data formats such as
38
38
  // floating-point samples that Apple's OpenAL implementation does not support.
39
- SDL_AudioSpec desired;
39
+ Sound_AudioInfo desired;
40
40
  // Prefer 16-bit signed data which is supported by all versions of OpenAL.
41
- desired.format = SDL_AUDIO_S16;
41
+ desired.format = AUDIO_S16;
42
42
  // 0 means "use whatever we have" (see SDL_sound.c, init_sample).
43
43
  desired.channels = 0;
44
- desired.freq = 0;
44
+ desired.rate = 0;
45
45
 
46
46
  pimpl->sample.reset(Sound_NewSampleFromFile(filename.c_str(), &desired, 4096),
47
47
  Sound_FreeSample);
@@ -97,7 +97,7 @@ ALenum Gosu::AudioFile::format() const
97
97
 
98
98
  ALuint Gosu::AudioFile::sample_rate() const
99
99
  {
100
- return pimpl->sample->actual.freq;
100
+ return pimpl->sample->actual.rate;
101
101
  }
102
102
 
103
103
  void Gosu::AudioFile::rewind()
data/src/BinPacker.cpp CHANGED
@@ -9,7 +9,7 @@
9
9
  Gosu::BinPacker::BinPacker(int width, int height)
10
10
  : m_width(width),
11
11
  m_height(height),
12
- m_free_rects { Rect::xywh(0, 0, width, height) }
12
+ m_free_rects { Rect { 0, 0, width, height } }
13
13
  {
14
14
  }
15
15
 
@@ -27,9 +27,8 @@ std::shared_ptr<const Gosu::Rect> Gosu::BinPacker::alloc(int width, int height)
27
27
  // We found a free area, place the result in the top left corner of it.
28
28
  // (Also make sure that the pointer's deleter returns the rectangle. Note: Even though
29
29
  // shared_ptr may call its deleter with a nullptr in general, it will not do so here.)
30
- std::shared_ptr<const Rect> result(
31
- new Rect(Rect::xywh(best_rect->x, best_rect->y, width, height)),
32
- [this](const Rect* p) { add_free_rect(*p); });
30
+ std::shared_ptr<const Rect> result(new Rect { best_rect->x, best_rect->y, width, height },
31
+ [this](const Rect* p) { add_free_rect(*p); });
33
32
 
34
33
  // We need to split the remaining rectangle into two. We use the axis with the longer side.
35
34
  // (Called "Longer Axis Split Rule", "-LAS" in the paper.)
@@ -137,7 +136,7 @@ void Gosu::BinPacker::merge_neighbors(int index)
137
136
  // ┃ ┣━━┻━┫
138
137
  // ┗━┻━━━━┛
139
138
  // In this case, the texture gets stuck in this fragmented state. We assume that this is not an
140
- // issue in practice, just like RAM fragmentation has never been problematic for us.
139
+ // issue in practice, just like memory
141
140
 
142
141
  // Merge any of the other rectangles in the list into the one with the given index if they share
143
142
  // any of their four sides.
data/src/Bitmap.cpp CHANGED
@@ -6,7 +6,9 @@
6
6
  #include <stdexcept> // for std::invalid_argument
7
7
  #include <utility> // for std::move, std::swap
8
8
 
9
- static void check_bitmap_size(int width, int height)
9
+ Gosu::Bitmap::Bitmap(int width, int height, Color c)
10
+ : m_width(width),
11
+ m_height(height)
10
12
  {
11
13
  if (width < 0 || height < 0) {
12
14
  throw std::invalid_argument("Negative Gosu::Bitmap size");
@@ -16,30 +18,21 @@ static void check_bitmap_size(int width, int height)
16
18
  if (height != 0 && width > std::numeric_limits<int>::max() / height) {
17
19
  throw std::invalid_argument("Gosu::Bitmap size out of bounds");
18
20
  }
19
- }
20
-
21
- Gosu::Bitmap::Bitmap(int width, int height, Color c)
22
- : m_width(width),
23
- m_height(height)
24
- {
25
- check_bitmap_size(width, height);
26
21
 
27
22
  const int size = width * height;
28
23
  m_pixels = Buffer(size * sizeof(Color));
29
24
  std::fill_n(data(), size, c);
30
25
  }
31
26
 
32
- Gosu::Bitmap::Bitmap(int width, int height, Buffer&& buffer)
27
+ Gosu::Bitmap::Bitmap(int width, int height, Gosu::Buffer&& buffer)
33
28
  : m_width(width),
34
29
  m_height(height),
35
30
  m_pixels(std::move(buffer))
36
31
  {
37
- check_bitmap_size(width, height);
38
-
39
- const int size = width * height;
40
- if (static_cast<std::size_t>(size) * sizeof(Color) != m_pixels.size()) {
32
+ int pixels = width * height;
33
+ if (static_cast<std::size_t>(pixels) * sizeof(Color) != m_pixels.size()) {
41
34
  throw std::length_error("Gosu::Bitmap given Gosu::Buffer of wrong size, expected "
42
- + std::to_string(size * sizeof(Color)) + ", given "
35
+ + std::to_string(pixels * sizeof(Color)) + ", given "
43
36
  + std::to_string(m_pixels.size()));
44
37
  }
45
38
  }
@@ -89,7 +82,7 @@ void Gosu::Bitmap::insert(const Bitmap& source, int x, int y, Rect source_rect)
89
82
  source_rect.clip_to(Rect::covering(source), &x, &y);
90
83
 
91
84
  // Set up the target area and make sure that it does not exceed this image.
92
- Rect target_rect = Rect::xywh(x, y, source_rect.width, source_rect.height);
85
+ Rect target_rect { .x = x, .y = y, .width = source_rect.width, .height = source_rect.height };
93
86
  // If we need to move the target_rect origin, then also move the source_rect origin.
94
87
  target_rect.clip_to(Rect::covering(*this), &source_rect.x, &source_rect.y);
95
88
 
@@ -116,7 +109,7 @@ void Gosu::Bitmap::insert(const Bitmap& source, int x, int y, Rect source_rect)
116
109
  }
117
110
  }
118
111
 
119
- bool Gosu::Bitmap::operator==(const Bitmap& other) const
112
+ bool Gosu::Bitmap::operator==(const Gosu::Bitmap& other) const
120
113
  {
121
114
  int pixels = width() * height();
122
115
  return pixels == other.width() * other.height()
data/src/Buffer.cpp CHANGED
@@ -8,7 +8,7 @@
8
8
  #include <filesystem>
9
9
  #include <fstream>
10
10
  #else
11
- #include <SDL3/SDL.h>
11
+ #include <SDL.h>
12
12
  #endif
13
13
 
14
14
  Gosu::Buffer::Buffer(void* buffer, std::size_t size, std::function<void(void*)> deleter)
@@ -135,12 +135,21 @@ Gosu::Buffer Gosu::load_file(const std::string& filename)
135
135
 
136
136
  void Gosu::save_file(const Buffer& buffer, const std::string& filename)
137
137
  {
138
- std::unique_ptr<SDL_IOStream, decltype(&SDL_CloseIO)> io(
139
- SDL_IOFromFile(filename.c_str(), "w"), &SDL_CloseIO);
140
- if (io == nullptr) {
138
+ struct RWopsDeleter
139
+ {
140
+ void operator()(SDL_RWops* p) const
141
+ {
142
+ // SDL_RWclose will crash if given nullptr.
143
+ if (p) {
144
+ SDL_RWclose(p);
145
+ }
146
+ }
147
+ };
148
+ std::unique_ptr<SDL_RWops, RWopsDeleter> rwops(SDL_RWFromFile(filename.c_str(), "w"));
149
+ if (rwops == nullptr) {
141
150
  throw std::runtime_error("Could not open '" + filename + "', error: " + SDL_GetError());
142
151
  }
143
- std::size_t written = SDL_WriteIO(io.get(), buffer.data(), buffer.size());
152
+ std::size_t written = SDL_RWwrite(rwops.get(), buffer.data(), buffer.size(), 1);
144
153
  // GCOV_EXCL_START: It is hard to set up a file where opening works but writing doesn't.
145
154
  if (written == 0) {
146
155
  throw std::runtime_error("Could not write to '" + filename + "', error: " + SDL_GetError());
@@ -1,24 +1,90 @@
1
1
  #pragma once
2
2
 
3
- #include <Gosu/Utility.hpp>
4
3
  #include "GraphicsImpl.hpp"
5
- #include <limits>
6
- #include <optional>
7
- #include <stdexcept>
4
+ #include <cassert>
8
5
  #include <vector>
9
6
 
10
- namespace Gosu
7
+ class Gosu::ClipRectStack
11
8
  {
12
- class ClipRectStack
9
+ std::vector<ClipRect> stack;
10
+ bool has_effective_rect; // is effective_rect valid?
11
+ ClipRect effective_rect;
12
+
13
+ void update_effective_rect()
13
14
  {
14
- std::vector<Rect> m_stack;
15
- std::optional<Rect> m_effective_rect;
16
-
17
- public:
18
- void clear();
19
- void push(const Rect& rect);
20
- void pop();
21
-
22
- const std::optional<Rect>& effective_rect() const { return m_effective_rect; }
23
- };
24
- }
15
+ // Nothing to do, no clipping in place.
16
+ if (stack.empty()) {
17
+ has_effective_rect = false;
18
+ return;
19
+ }
20
+
21
+ ClipRect result = { 0.0, 0.0, 1e10, 1e10 };
22
+ for (std::size_t i = 0, end = stack.size(); i < end; ++i) {
23
+ const ClipRect& rect = stack[i];
24
+ int result_right = std::min(result.x + result.width, rect.x + rect.width);
25
+ int result_bottom = std::min(result.y + result.height, rect.y + rect.height);
26
+ result.x = std::max(result.x, rect.x);
27
+ result.y = std::max(result.y, rect.y);
28
+
29
+ if (result.x >= result_right || result.y >= result_bottom) {
30
+ // We have clipped the world away!
31
+ has_effective_rect = false;
32
+ return;
33
+ }
34
+
35
+ result.width = result_right - result.x;
36
+ result.height = result_bottom - result.y;
37
+ }
38
+
39
+ // On the iPhone, we may have to multiply everything by 2 for Retina displays.
40
+ // TODO: Doesn't this affect Retina Macs as well?
41
+ // TODO: This should be handled by a global transform.
42
+ int fac = clip_rect_base_factor();
43
+ result.x *= fac;
44
+ result.y *= fac;
45
+ result.width *= fac;
46
+ result.height *= fac;
47
+
48
+ // Normal clipping.
49
+ effective_rect = result;
50
+ has_effective_rect = true;
51
+ }
52
+
53
+ public:
54
+ ClipRectStack()
55
+ : has_effective_rect(false)
56
+ {
57
+ }
58
+
59
+ void clear()
60
+ {
61
+ stack.clear();
62
+ has_effective_rect = false;
63
+ }
64
+
65
+ void begin_clipping(double x, double y, double width, double height)
66
+ {
67
+ ClipRect rect = { x, y, width, height };
68
+ stack.push_back(rect);
69
+ update_effective_rect();
70
+ }
71
+
72
+ void end_clipping()
73
+ {
74
+ assert (!stack.empty());
75
+ stack.pop_back();
76
+ update_effective_rect();
77
+ }
78
+
79
+ const ClipRect* maybe_effective_rect() const
80
+ {
81
+ return has_effective_rect ? &effective_rect : 0;
82
+ }
83
+
84
+ bool clipped_world_away() const
85
+ {
86
+ // When we have no effective rect but the stack is not empty, we have clipped
87
+ // the whole world away and don't need to render things.
88
+ return !has_effective_rect && !stack.empty();
89
+ }
90
+ };
data/src/Directories.cpp CHANGED
@@ -18,7 +18,7 @@ void Gosu::use_resource_directory()
18
18
  }
19
19
 
20
20
  #ifndef GOSU_IS_IPHONE
21
- #include <SDL3/SDL.h>
21
+ #include <SDL.h>
22
22
  #include <memory>
23
23
  #include <stdexcept>
24
24
  #endif
data/src/DrawOp.hpp CHANGED
@@ -5,7 +5,6 @@
5
5
  #include "TexChunk.hpp"
6
6
  #include <Gosu/Color.hpp>
7
7
  #include <Gosu/GraphicsBase.hpp>
8
- #include <algorithm>
9
8
  #include <cassert>
10
9
 
11
10
  namespace Gosu
@@ -16,15 +15,15 @@ namespace Gosu
16
15
  ZPos z;
17
16
 
18
17
  RenderState render_state;
19
- // Only set if render_state.tex_name != NO_TEXTURE
20
- GLfloat top = 0, left = 0, bottom = 0, right = 0;
18
+ // Only valid if render_state.tex_name != NO_TEXTURE
19
+ GLfloat top, left, bottom, right;
21
20
  // Used to keep TexChunk rectangles on shared textures alive until the end of the frame.
22
21
  std::shared_ptr<const Rect> rect_handle;
23
22
 
24
23
  // TODO: Merge with Gosu::ArrayVertex.
25
24
  struct Vertex
26
25
  {
27
- float x = 0, y = 0;
26
+ float x, y;
28
27
  Color c;
29
28
  Vertex() {}
30
29
  Vertex(float x, float y, Color c) : x(x), y(y), c(c) {}
@@ -140,17 +139,15 @@ namespace Gosu
140
139
  // frame anyway.
141
140
  ArrayVertex result[4];
142
141
  for (int i = 0; i < 4; ++i) {
143
- // Triangles are turned into quads by repeating the last vertex.
144
- // This allows us to use the same array for both triangles and quads.
145
- // (This is also why draw_line does not work inside macros right now.)
146
- const Vertex& vertex = vertices[std::min(i, vertices_or_block_index - 1)];
147
- double x = vertex.x;
148
- double y = vertex.y;
142
+ result[i].vertices[0] = vertices[i].x;
143
+ result[i].vertices[1] = vertices[i].y;
144
+ result[i].vertices[2] = 0;
145
+ result[i].color = vertices[i].c.abgr();
146
+ double x = result[i].vertices[0];
147
+ double y = result[i].vertices[1];
149
148
  render_state.transform->apply(x, y);
150
149
  result[i].vertices[0] = static_cast<float>(x);
151
150
  result[i].vertices[1] = static_cast<float>(y);
152
- result[i].vertices[2] = 0;
153
- result[i].color = vertex.c.abgr();
154
151
  }
155
152
  RenderState va_render_state = render_state;
156
153
  va_render_state.transform = 0;
@@ -164,11 +161,17 @@ namespace Gosu
164
161
  result[3].tex_coords[0] = left;
165
162
  result[3].tex_coords[1] = bottom;
166
163
 
167
- if (vas.empty() || vas.back().render_state != va_render_state) {
168
- vas.emplace_back().render_state = va_render_state;
164
+ if (vas.empty() || !(vas.back().render_state == va_render_state)) {
165
+ vas.push_back(VertexArray());
166
+ vas.back().render_state = va_render_state;
169
167
  }
170
168
 
171
169
  vas.back().vertices.insert(vas.back().vertices.end(), result, result + 4);
172
170
  }
171
+
172
+ bool operator<(const DrawOp& other) const
173
+ {
174
+ return z < other.z;
175
+ }
173
176
  };
174
177
  }
data/src/DrawOpQueue.hpp CHANGED
@@ -9,7 +9,6 @@
9
9
  #include <cmath>
10
10
  #include <functional>
11
11
  #include <map>
12
- #include <utility>
13
12
  #include <vector>
14
13
 
15
14
  class Gosu::DrawOpQueue
@@ -23,7 +22,7 @@ class Gosu::DrawOpQueue
23
22
  std::vector<std::function<void ()>> gl_blocks;
24
23
 
25
24
  public:
26
- explicit DrawOpQueue(QueueMode mode)
25
+ DrawOpQueue(QueueMode mode)
27
26
  : queue_mode(mode)
28
27
  {
29
28
  }
@@ -35,31 +34,39 @@ public:
35
34
 
36
35
  void schedule_draw_op(DrawOp op)
37
36
  {
38
- #ifdef GOSU_IS_OPENGLES
37
+ if (clip_rect_stack.clipped_world_away()) return;
38
+
39
+ #ifdef GOSU_IS_OPENGLES
39
40
  // No triangles, no lines supported
40
- assert(op.vertices_or_block_index == 4);
41
- #endif
41
+ assert (op.vertices_or_block_index == 4);
42
+ #endif
42
43
 
43
44
  op.render_state.transform = &transform_stack.current();
44
- op.render_state.clip_rect = clip_rect_stack.effective_rect();
45
+ if (const ClipRect* cr = clip_rect_stack.maybe_effective_rect()) {
46
+ op.render_state.clip_rect = *cr;
47
+ }
45
48
  ops.push_back(op);
46
49
  }
47
50
 
48
51
  void gl(std::function<void ()> gl_block, ZPos z)
49
52
  {
53
+ // TODO: Document this case: Clipped-away GL blocks are *not* being run.
54
+ if (clip_rect_stack.clipped_world_away()) return;
55
+
50
56
  int complement_of_block_index = ~(int)gl_blocks.size();
51
- gl_blocks.push_back(std::move(gl_block));
57
+ gl_blocks.push_back(gl_block);
52
58
 
53
59
  DrawOp op;
54
60
  op.vertices_or_block_index = complement_of_block_index;
55
61
  op.render_state.transform = &transform_stack.current();
56
- op.render_state.clip_rect = clip_rect_stack.effective_rect();
62
+ if (const ClipRect* cr = clip_rect_stack.maybe_effective_rect()) {
63
+ op.render_state.clip_rect = *cr;
64
+ }
57
65
  op.z = z;
58
66
  ops.push_back(op);
59
67
  }
60
68
 
61
- void begin_clipping(double x, double y, double width, double height,
62
- std::optional<int> viewport_height)
69
+ void begin_clipping(double x, double y, double width, double height, double screen_height)
63
70
  {
64
71
  if (mode() == QM_RECORD_MACRO) {
65
72
  throw std::logic_error("Clipping is not allowed while creating a macro");
@@ -73,21 +80,21 @@ public:
73
80
  transform_stack.current().apply(left, top);
74
81
  transform_stack.current().apply(right, bottom);
75
82
 
76
- Rect clip_rect {
77
- .x = static_cast<int>(std::min(left, right)),
78
- .y = static_cast<int>(std::min(top, bottom)),
79
- .width = static_cast<int>(std::abs(left - right)),
80
- .height = static_cast<int>(std::abs(top - bottom)),
81
- };
83
+ double phys_x = std::min(left, right);
84
+ double phys_y = std::min(top, bottom);
85
+ double phys_width = std::abs(left - right);
86
+ double phys_height = std::abs(top - bottom);
87
+
82
88
  // Adjust for OpenGL having the wrong idea of where y=0 is.
83
- if (viewport_height && mode() == QM_RENDER_TO_SCREEN) {
84
- clip_rect.y = *viewport_height - clip_rect.y - clip_rect.height;
85
- }
89
+ phys_y = screen_height - phys_y - phys_height;
86
90
 
87
- clip_rect_stack.push(clip_rect);
91
+ clip_rect_stack.begin_clipping(phys_x, phys_y, phys_width, phys_height);
88
92
  }
89
93
 
90
- void end_clipping() { clip_rect_stack.pop(); }
94
+ void end_clipping()
95
+ {
96
+ clip_rect_stack.end_clipping();
97
+ }
91
98
 
92
99
  void set_base_transform(const Transform& base_transform)
93
100
  {
@@ -111,8 +118,7 @@ public:
111
118
  }
112
119
 
113
120
  // Apply Z-Ordering.
114
- std::stable_sort(ops.begin(), ops.end(),
115
- [](const DrawOp& lhs, const DrawOp& rhs) { return lhs.z < rhs.z; });
121
+ std::stable_sort(ops.begin(), ops.end());
116
122
 
117
123
  RenderStateManager manager;
118
124
 
@@ -138,7 +144,7 @@ public:
138
144
  assert (block_index >= 0);
139
145
  assert (block_index < gl_blocks.size());
140
146
  gl_blocks[block_index]();
141
- manager.enforce_after_untrusted_gl();
147
+ manager.enforce_after_untrusted_gL();
142
148
  }
143
149
  }
144
150
  #endif
@@ -150,7 +156,7 @@ public:
150
156
  throw std::logic_error("Custom OpenGL code cannot be recorded as a macro");
151
157
  }
152
158
 
153
- std::stable_sort(ops.begin(), ops.end(), [](const DrawOp& lhs, const DrawOp& rhs) { return lhs.z < rhs.z; });
159
+ std::stable_sort(ops.begin(), ops.end());
154
160
  for (const auto& op : ops) {
155
161
  op.compile_to(vas);
156
162
  }
data/src/Font.cpp CHANGED
@@ -79,7 +79,7 @@ struct Gosu::Font::Impl : private Gosu::Noncopyable
79
79
  std::swap(resized_bitmap, bitmap);
80
80
  Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name, scaled_height, font_flags);
81
81
  }
82
- const Rect source_rect = Rect::xywh(0, 0, required_width, bitmap.height());
82
+ const Rect source_rect { 0, 0, required_width, bitmap.height() };
83
83
 
84
84
  return glyphs[key] = Image(bitmap, source_rect, image_flags);
85
85
  }
data/src/GosuGLView.cpp CHANGED
@@ -28,6 +28,12 @@ namespace Gosu
28
28
  {
29
29
  // Don't bother unsetting anything.
30
30
  }
31
+
32
+ int clip_rect_base_factor()
33
+ {
34
+ static int result = [UIScreen mainScreen].scale;
35
+ return result;
36
+ }
31
37
  }
32
38
 
33
39
  @implementation GosuGLView
@@ -91,7 +97,7 @@ namespace Gosu
91
97
  [EAGLContext setCurrentContext:_context];
92
98
  [self destroyFramebuffer];
93
99
  [self createFramebuffer];
94
- self.contentScaleFactor = [UIScreen mainScreen].scale;
100
+ self.contentScaleFactor = Gosu::clip_rect_base_factor();
95
101
  }
96
102
 
97
103
  - (BOOL)createFramebuffer