gosu 1.4.6 → 1.5.0

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 (320) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL3/SDL.h +91 -0
  4. data/dependencies/SDL/include/SDL3/SDL_assert.h +710 -0
  5. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +550 -0
  6. data/dependencies/SDL/include/SDL3/SDL_atomic.h +692 -0
  7. data/dependencies/SDL/include/SDL3/SDL_audio.h +2382 -0
  8. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +553 -0
  9. data/dependencies/SDL/include/{SDL_bits.h → SDL3/SDL_bits.h} +47 -27
  10. data/dependencies/SDL/include/{SDL_blendmode.h → SDL3/SDL_blendmode.h} +59 -55
  11. data/dependencies/SDL/include/SDL3/SDL_camera.h +535 -0
  12. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +331 -0
  13. data/dependencies/SDL/include/{close_code.h → SDL3/SDL_close_code.h} +9 -8
  14. data/dependencies/SDL/include/{SDL_types.h → SDL3/SDL_copying.h} +2 -9
  15. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +374 -0
  16. data/dependencies/SDL/include/SDL3/SDL_dialog.h +343 -0
  17. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +234 -0
  18. data/dependencies/SDL/include/{SDL_egl.h → SDL3/SDL_egl.h} +11 -8
  19. data/dependencies/SDL/include/SDL3/SDL_endian.h +645 -0
  20. data/dependencies/SDL/include/SDL3/SDL_error.h +226 -0
  21. data/dependencies/SDL/include/SDL3/SDL_events.h +1651 -0
  22. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +537 -0
  23. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +1657 -0
  24. data/dependencies/SDL/include/SDL3/SDL_gpu.h +4637 -0
  25. data/dependencies/SDL/include/SDL3/SDL_guid.h +106 -0
  26. data/dependencies/SDL/include/SDL3/SDL_haptic.h +1461 -0
  27. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +571 -0
  28. data/dependencies/SDL/include/SDL3/SDL_hints.h +5041 -0
  29. data/dependencies/SDL/include/SDL3/SDL_init.h +508 -0
  30. data/dependencies/SDL/include/SDL3/SDL_intrin.h +410 -0
  31. data/dependencies/SDL/include/SDL3/SDL_iostream.h +1379 -0
  32. data/dependencies/SDL/include/SDL3/SDL_joystick.h +1385 -0
  33. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +615 -0
  34. data/dependencies/SDL/include/SDL3/SDL_keycode.h +348 -0
  35. data/dependencies/SDL/include/SDL3/SDL_loadso.h +145 -0
  36. data/dependencies/SDL/include/{SDL_locale.h → SDL3/SDL_locale.h} +40 -24
  37. data/dependencies/SDL/include/SDL3/SDL_log.h +541 -0
  38. data/dependencies/SDL/include/SDL3/SDL_main.h +704 -0
  39. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +149 -0
  40. data/dependencies/SDL/include/{SDL_messagebox.h → SDL3/SDL_messagebox.h} +85 -48
  41. data/dependencies/SDL/include/{SDL_metal.h → SDL3/SDL_metal.h} +29 -29
  42. data/dependencies/SDL/include/{SDL_misc.h → SDL3/SDL_misc.h} +13 -12
  43. data/dependencies/SDL/include/SDL3/SDL_mouse.h +813 -0
  44. data/dependencies/SDL/include/SDL3/SDL_mutex.h +1117 -0
  45. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +1339 -0
  46. data/dependencies/SDL/include/{SDL_opengl.h → SDL3/SDL_opengl.h} +1247 -278
  47. data/dependencies/SDL/include/{SDL_opengl_glext.h → SDL3/SDL_opengl_glext.h} +5 -1
  48. data/dependencies/SDL/include/{SDL_opengles.h → SDL3/SDL_opengles.h} +6 -7
  49. data/dependencies/SDL/include/{SDL_opengles2.h → SDL3/SDL_opengles2.h} +10 -11
  50. data/dependencies/SDL/include/SDL3/SDL_pen.h +198 -0
  51. data/dependencies/SDL/include/SDL3/SDL_pixels.h +1441 -0
  52. data/dependencies/SDL/include/{SDL_test_log.h → SDL3/SDL_platform.h} +25 -26
  53. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +497 -0
  54. data/dependencies/SDL/include/{SDL_power.h → SDL3/SDL_power.h} +40 -20
  55. data/dependencies/SDL/include/SDL3/SDL_process.h +441 -0
  56. data/dependencies/SDL/include/SDL3/SDL_properties.h +572 -0
  57. data/dependencies/SDL/include/SDL3/SDL_rect.h +528 -0
  58. data/dependencies/SDL/include/SDL3/SDL_render.h +3034 -0
  59. data/dependencies/SDL/include/SDL3/SDL_revision.h +56 -0
  60. data/dependencies/SDL/include/{SDL_scancode.h → SDL3/SDL_scancode.h} +60 -68
  61. data/dependencies/SDL/include/SDL3/SDL_sensor.h +321 -0
  62. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +6186 -0
  63. data/dependencies/SDL/include/SDL3/SDL_storage.h +686 -0
  64. data/dependencies/SDL/include/SDL3/SDL_surface.h +1769 -0
  65. data/dependencies/SDL/include/SDL3/SDL_system.h +840 -0
  66. data/dependencies/SDL/include/{SDL_test.h → SDL3/SDL_test.h} +16 -22
  67. data/dependencies/SDL/include/{SDL_test_assert.h → SDL3/SDL_test_assert.h} +27 -34
  68. data/dependencies/SDL/include/{SDL_test_common.h → SDL3/SDL_test_common.h} +109 -52
  69. data/dependencies/SDL/include/{SDL_test_compare.h → SDL3/SDL_test_compare.h} +22 -14
  70. data/dependencies/SDL/include/{SDL_test_crc32.h → SDL3/SDL_test_crc32.h} +27 -30
  71. data/dependencies/SDL/include/{SDL_test_font.h → SDL3/SDL_test_font.h} +50 -49
  72. data/dependencies/SDL/include/{SDL_test_fuzzer.h → SDL3/SDL_test_fuzzer.h} +64 -79
  73. data/dependencies/SDL/include/{SDL_test_harness.h → SDL3/SDL_test_harness.h} +47 -30
  74. data/dependencies/SDL/include/SDL3/SDL_test_log.h +83 -0
  75. data/dependencies/SDL/include/{SDL_test_md5.h → SDL3/SDL_test_md5.h} +21 -28
  76. data/dependencies/SDL/include/{SDL_test_memory.h → SDL3/SDL_test_memory.h} +19 -16
  77. data/dependencies/SDL/include/SDL3/SDL_thread.h +602 -0
  78. data/dependencies/SDL/include/SDL3/SDL_time.h +249 -0
  79. data/dependencies/SDL/include/SDL3/SDL_timer.h +454 -0
  80. data/dependencies/SDL/include/SDL3/SDL_touch.h +184 -0
  81. data/dependencies/SDL/include/SDL3/SDL_tray.h +544 -0
  82. data/dependencies/SDL/include/SDL3/SDL_version.h +198 -0
  83. data/dependencies/SDL/include/SDL3/SDL_video.h +3497 -0
  84. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +287 -0
  85. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  86. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  87. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +755 -0
  88. data/dependencies/SDL_sound/SDL_sound.c +136 -215
  89. data/dependencies/SDL_sound/SDL_sound_aiff.c +55 -54
  90. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  91. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +24 -41
  92. data/dependencies/SDL_sound/SDL_sound_flac.c +32 -12
  93. data/dependencies/SDL_sound/SDL_sound_internal.h +33 -48
  94. data/dependencies/SDL_sound/SDL_sound_modplug.c +21 -29
  95. data/dependencies/SDL_sound/SDL_sound_mp3.c +35 -13
  96. data/dependencies/SDL_sound/SDL_sound_raw.c +14 -15
  97. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  98. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  99. data/dependencies/SDL_sound/SDL_sound_vorbis.c +34 -25
  100. data/dependencies/SDL_sound/SDL_sound_wav.c +86 -82
  101. data/dependencies/SDL_sound/dr_flac.h +1890 -1301
  102. data/dependencies/SDL_sound/dr_mp3.h +1098 -660
  103. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  104. data/dependencies/SDL_sound/libmodplug/libmodplug.h +5 -4
  105. data/dependencies/SDL_sound/libmodplug/load_ams.c +6 -3
  106. data/dependencies/SDL_sound/libmodplug/load_dsm.c +2 -1
  107. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  108. data/dependencies/SDL_sound/libmodplug/modplug.h +2 -1
  109. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  110. data/dependencies/SDL_sound/libmodplug/sndfile.c +3 -0
  111. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -3
  112. data/dependencies/SDL_sound/stb_vorbis.h +397 -342
  113. data/dependencies/mojoAL/AL/alc.h +2 -2
  114. data/dependencies/mojoAL/mojoal.c +2120 -1885
  115. data/dependencies/stb/stb_image.h +1190 -1379
  116. data/dependencies/stb/stb_image_write.h +329 -129
  117. data/dependencies/stb/stb_truetype.h +304 -60
  118. data/dependencies/utf8proc/utf8proc.c +133 -75
  119. data/dependencies/utf8proc/utf8proc.h +131 -50
  120. data/dependencies/utf8proc/utf8proc_data.h +16213 -15658
  121. data/ext/gosu-ffi/extconf.rb +103 -0
  122. data/ext/gosu-ffi/gosu-ffi.def +467 -0
  123. data/ffi/Gosu.cpp +330 -0
  124. data/ffi/Gosu.h +84 -0
  125. data/ffi/Gosu_Channel.cpp +62 -0
  126. data/ffi/Gosu_Channel.h +17 -0
  127. data/ffi/Gosu_Color.cpp +176 -0
  128. data/ffi/Gosu_Color.h +31 -0
  129. data/ffi/Gosu_Constants.cpp +334 -0
  130. data/ffi/Gosu_FFI.h +34 -0
  131. data/ffi/Gosu_FFI_internal.h +160 -0
  132. data/ffi/Gosu_Font.cpp +97 -0
  133. data/ffi/Gosu_Font.h +32 -0
  134. data/ffi/Gosu_Image.cpp +239 -0
  135. data/ffi/Gosu_Image.h +71 -0
  136. data/ffi/Gosu_Sample.cpp +29 -0
  137. data/ffi/Gosu_Sample.h +14 -0
  138. data/ffi/Gosu_Song.cpp +69 -0
  139. data/ffi/Gosu_Song.h +18 -0
  140. data/ffi/Gosu_TextInput.cpp +94 -0
  141. data/ffi/Gosu_TextInput.h +25 -0
  142. data/ffi/Gosu_Window.cpp +314 -0
  143. data/ffi/Gosu_Window.h +78 -0
  144. data/include/Gosu/Audio.hpp +6 -11
  145. data/include/Gosu/Bitmap.hpp +38 -53
  146. data/include/Gosu/Buffer.hpp +54 -0
  147. data/include/Gosu/Color.hpp +29 -36
  148. data/include/Gosu/Directories.hpp +25 -28
  149. data/include/Gosu/Drawable.hpp +58 -0
  150. data/include/Gosu/Font.hpp +6 -5
  151. data/include/Gosu/Fwd.hpp +4 -6
  152. data/include/Gosu/Gosu.hpp +5 -5
  153. data/include/Gosu/Graphics.hpp +53 -61
  154. data/include/Gosu/GraphicsBase.hpp +1 -11
  155. data/include/Gosu/Image.hpp +12 -15
  156. data/include/Gosu/Math.hpp +50 -72
  157. data/include/Gosu/Transform.hpp +32 -0
  158. data/include/Gosu/Utility.hpp +77 -1
  159. data/include/Gosu/Version.hpp +2 -2
  160. data/include/Gosu/Window.hpp +15 -9
  161. data/lib/SDL3.dll +0 -0
  162. data/lib/gosu/channel.rb +50 -0
  163. data/lib/gosu/color.rb +173 -0
  164. data/lib/gosu/compat.rb +130 -17
  165. data/lib/gosu/constants.rb +386 -0
  166. data/lib/gosu/ffi.rb +269 -0
  167. data/lib/gosu/font.rb +62 -0
  168. data/lib/gosu/gl_tex_info.rb +33 -0
  169. data/lib/gosu/gosu.rb +250 -0
  170. data/lib/gosu/image.rb +179 -0
  171. data/lib/gosu/numeric.rb +17 -0
  172. data/lib/gosu/preview.rb +6 -6
  173. data/lib/gosu/sample.rb +25 -0
  174. data/lib/gosu/song.rb +57 -0
  175. data/lib/gosu/text_input.rb +83 -0
  176. data/lib/gosu/window.rb +249 -0
  177. data/lib/gosu.rb +29 -8
  178. data/lib64/SDL3.dll +0 -0
  179. data/rdoc/gosu.rb +2 -2
  180. data/src/Audio.cpp +30 -24
  181. data/src/AudioFile.hpp +5 -4
  182. data/src/AudioFileAudioToolbox.cpp +8 -8
  183. data/src/AudioFileSDLSound.cpp +12 -15
  184. data/src/BinPacker.cpp +188 -0
  185. data/src/BinPacker.hpp +55 -0
  186. data/src/Bitmap.cpp +172 -143
  187. data/src/BitmapIO.cpp +60 -86
  188. data/src/Buffer.cpp +150 -0
  189. data/src/ClipRectStack.cpp +38 -0
  190. data/src/ClipRectStack.hpp +17 -83
  191. data/src/Color.cpp +75 -80
  192. data/src/Directories.cpp +47 -0
  193. data/src/DirectoriesUIKit.cpp +50 -0
  194. data/src/DrawOp.hpp +20 -18
  195. data/src/DrawOpQueue.hpp +27 -33
  196. data/src/Drawable.cpp +95 -0
  197. data/src/EmptyDrawable.hpp +38 -0
  198. data/src/FPS.cpp +31 -0
  199. data/src/Font.cpp +104 -74
  200. data/src/GosuGLView.cpp +13 -11
  201. data/src/GosuViewController.cpp +2 -10
  202. data/src/Graphics.cpp +86 -145
  203. data/src/GraphicsImpl.hpp +14 -68
  204. data/src/Image.cpp +41 -35
  205. data/src/Input.cpp +73 -78
  206. data/src/Macro.cpp +46 -29
  207. data/src/Macro.hpp +23 -17
  208. data/src/MarkupParser.cpp +5 -5
  209. data/src/Math.cpp +48 -22
  210. data/src/OffScreenTarget.cpp +47 -50
  211. data/src/OffScreenTarget.hpp +13 -11
  212. data/src/OpenGLContext.cpp +116 -0
  213. data/src/OpenGLContext.hpp +41 -0
  214. data/src/RenderState.hpp +49 -71
  215. data/src/Resolution.cpp +65 -53
  216. data/src/TexChunk.cpp +35 -80
  217. data/src/TexChunk.hpp +44 -35
  218. data/src/Text.cpp +1 -1
  219. data/src/TextBuilder.cpp +35 -21
  220. data/src/TextBuilder.hpp +6 -9
  221. data/src/TextInput.cpp +9 -9
  222. data/src/Texture.cpp +62 -80
  223. data/src/Texture.hpp +25 -23
  224. data/src/TiledDrawable.cpp +149 -0
  225. data/src/TiledDrawable.hpp +47 -0
  226. data/src/TimingApple.cpp +1 -1
  227. data/src/Transform.cpp +45 -50
  228. data/src/TransformStack.hpp +16 -16
  229. data/src/TrueTypeFont.cpp +59 -51
  230. data/src/TrueTypeFont.hpp +6 -7
  231. data/src/TrueTypeFontApple.cpp +28 -19
  232. data/src/TrueTypeFontUnix.cpp +39 -32
  233. data/src/TrueTypeFontWin.cpp +30 -30
  234. data/src/Utility.cpp +113 -37
  235. data/src/UtilityWin.cpp +49 -0
  236. data/src/Window.cpp +121 -151
  237. data/src/WindowUIKit.cpp +14 -14
  238. metadata +165 -118
  239. data/dependencies/SDL/include/SDL.h +0 -233
  240. data/dependencies/SDL/include/SDL_assert.h +0 -320
  241. data/dependencies/SDL/include/SDL_atomic.h +0 -415
  242. data/dependencies/SDL/include/SDL_audio.h +0 -1500
  243. data/dependencies/SDL/include/SDL_clipboard.h +0 -141
  244. data/dependencies/SDL/include/SDL_config.h +0 -331
  245. data/dependencies/SDL/include/SDL_cpuinfo.h +0 -594
  246. data/dependencies/SDL/include/SDL_endian.h +0 -348
  247. data/dependencies/SDL/include/SDL_error.h +0 -163
  248. data/dependencies/SDL/include/SDL_events.h +0 -1166
  249. data/dependencies/SDL/include/SDL_filesystem.h +0 -149
  250. data/dependencies/SDL/include/SDL_gamecontroller.h +0 -1074
  251. data/dependencies/SDL/include/SDL_gesture.h +0 -117
  252. data/dependencies/SDL/include/SDL_guid.h +0 -100
  253. data/dependencies/SDL/include/SDL_haptic.h +0 -1341
  254. data/dependencies/SDL/include/SDL_hidapi.h +0 -451
  255. data/dependencies/SDL/include/SDL_hints.h +0 -2569
  256. data/dependencies/SDL/include/SDL_joystick.h +0 -1066
  257. data/dependencies/SDL/include/SDL_keyboard.h +0 -353
  258. data/dependencies/SDL/include/SDL_keycode.h +0 -358
  259. data/dependencies/SDL/include/SDL_loadso.h +0 -115
  260. data/dependencies/SDL/include/SDL_log.h +0 -404
  261. data/dependencies/SDL/include/SDL_main.h +0 -275
  262. data/dependencies/SDL/include/SDL_mouse.h +0 -465
  263. data/dependencies/SDL/include/SDL_mutex.h +0 -471
  264. data/dependencies/SDL/include/SDL_name.h +0 -33
  265. data/dependencies/SDL/include/SDL_pixels.h +0 -644
  266. data/dependencies/SDL/include/SDL_platform.h +0 -261
  267. data/dependencies/SDL/include/SDL_quit.h +0 -58
  268. data/dependencies/SDL/include/SDL_rect.h +0 -376
  269. data/dependencies/SDL/include/SDL_render.h +0 -1919
  270. data/dependencies/SDL/include/SDL_revision.h +0 -7
  271. data/dependencies/SDL/include/SDL_rwops.h +0 -841
  272. data/dependencies/SDL/include/SDL_sensor.h +0 -322
  273. data/dependencies/SDL/include/SDL_shape.h +0 -155
  274. data/dependencies/SDL/include/SDL_stdinc.h +0 -830
  275. data/dependencies/SDL/include/SDL_surface.h +0 -997
  276. data/dependencies/SDL/include/SDL_system.h +0 -623
  277. data/dependencies/SDL/include/SDL_syswm.h +0 -386
  278. data/dependencies/SDL/include/SDL_test_images.h +0 -78
  279. data/dependencies/SDL/include/SDL_test_random.h +0 -115
  280. data/dependencies/SDL/include/SDL_thread.h +0 -464
  281. data/dependencies/SDL/include/SDL_timer.h +0 -222
  282. data/dependencies/SDL/include/SDL_touch.h +0 -150
  283. data/dependencies/SDL/include/SDL_version.h +0 -204
  284. data/dependencies/SDL/include/SDL_video.h +0 -2150
  285. data/dependencies/SDL/include/SDL_vulkan.h +0 -215
  286. data/dependencies/SDL/include/begin_code.h +0 -187
  287. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  288. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  289. data/dependencies/SDL_sound/SDL_sound.h +0 -725
  290. data/ext/gosu/extconf.rb +0 -119
  291. data/include/Gosu/IO.hpp +0 -254
  292. data/include/Gosu/ImageData.hpp +0 -53
  293. data/include/Gosu/Inspection.hpp +0 -7
  294. data/lib/SDL2.dll +0 -0
  295. data/lib/gosu/patches.rb +0 -66
  296. data/lib/gosu/run.rb +0 -20
  297. data/lib/gosu/swig_patches.rb +0 -110
  298. data/lib64/SDL2.dll +0 -0
  299. data/src/BlockAllocator.cpp +0 -131
  300. data/src/BlockAllocator.hpp +0 -32
  301. data/src/DirectoriesApple.cpp +0 -69
  302. data/src/DirectoriesUnix.cpp +0 -46
  303. data/src/DirectoriesWin.cpp +0 -65
  304. data/src/EmptyImageData.hpp +0 -52
  305. data/src/FileUnix.cpp +0 -99
  306. data/src/FileWin.cpp +0 -88
  307. data/src/IO.cpp +0 -60
  308. data/src/Iconv.hpp +0 -51
  309. data/src/Inspection.cpp +0 -27
  310. data/src/LargeImageData.cpp +0 -215
  311. data/src/LargeImageData.hpp +0 -39
  312. data/src/Log.hpp +0 -19
  313. data/src/RubyGosu.cxx +0 -13100
  314. data/src/RubyGosu.h +0 -49
  315. data/src/WinUtility.cpp +0 -61
  316. data/src/WinUtility.hpp +0 -27
  317. /data/dependencies/SDL/include/{SDL_opengles2_gl2.h → SDL3/SDL_opengles2_gl2.h} +0 -0
  318. /data/dependencies/SDL/include/{SDL_opengles2_gl2ext.h → SDL3/SDL_opengles2_gl2ext.h} +0 -0
  319. /data/dependencies/SDL/include/{SDL_opengles2_gl2platform.h → SDL3/SDL_opengles2_gl2platform.h} +0 -0
  320. /data/dependencies/SDL/include/{SDL_opengles2_khrplatform.h → SDL3/SDL_opengles2_khrplatform.h} +0 -0
data/src/DrawOpQueue.hpp CHANGED
@@ -9,6 +9,7 @@
9
9
  #include <cmath>
10
10
  #include <functional>
11
11
  #include <map>
12
+ #include <utility>
12
13
  #include <vector>
13
14
 
14
15
  class Gosu::DrawOpQueue
@@ -22,7 +23,7 @@ class Gosu::DrawOpQueue
22
23
  std::vector<std::function<void ()>> gl_blocks;
23
24
 
24
25
  public:
25
- DrawOpQueue(QueueMode mode)
26
+ explicit DrawOpQueue(QueueMode mode)
26
27
  : queue_mode(mode)
27
28
  {
28
29
  }
@@ -34,39 +35,31 @@ public:
34
35
 
35
36
  void schedule_draw_op(DrawOp op)
36
37
  {
37
- if (clip_rect_stack.clipped_world_away()) return;
38
-
39
- #ifdef GOSU_IS_OPENGLES
38
+ #ifdef GOSU_IS_OPENGLES
40
39
  // No triangles, no lines supported
41
- assert (op.vertices_or_block_index == 4);
42
- #endif
40
+ assert(op.vertices_or_block_index == 4);
41
+ #endif
43
42
 
44
43
  op.render_state.transform = &transform_stack.current();
45
- if (const ClipRect* cr = clip_rect_stack.maybe_effective_rect()) {
46
- op.render_state.clip_rect = *cr;
47
- }
44
+ op.render_state.clip_rect = clip_rect_stack.effective_rect();
48
45
  ops.push_back(op);
49
46
  }
50
47
 
51
48
  void gl(std::function<void ()> gl_block, ZPos z)
52
49
  {
53
- // TODO: Document this case: Clipped-away GL blocks are *not* being run.
54
- if (clip_rect_stack.clipped_world_away()) return;
55
-
56
50
  int complement_of_block_index = ~(int)gl_blocks.size();
57
- gl_blocks.push_back(gl_block);
51
+ gl_blocks.push_back(std::move(gl_block));
58
52
 
59
53
  DrawOp op;
60
54
  op.vertices_or_block_index = complement_of_block_index;
61
55
  op.render_state.transform = &transform_stack.current();
62
- if (const ClipRect* cr = clip_rect_stack.maybe_effective_rect()) {
63
- op.render_state.clip_rect = *cr;
64
- }
56
+ op.render_state.clip_rect = clip_rect_stack.effective_rect();
65
57
  op.z = z;
66
58
  ops.push_back(op);
67
59
  }
68
60
 
69
- void begin_clipping(double x, double y, double width, double height, double screen_height)
61
+ void begin_clipping(double x, double y, double width, double height,
62
+ std::optional<int> viewport_height)
70
63
  {
71
64
  if (mode() == QM_RECORD_MACRO) {
72
65
  throw std::logic_error("Clipping is not allowed while creating a macro");
@@ -77,24 +70,24 @@ public:
77
70
  double left = x, right = x + width;
78
71
  double top = y, bottom = y + height;
79
72
 
80
- apply_transform(transform_stack.current(), left, top);
81
- apply_transform(transform_stack.current(), right, bottom);
82
-
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);
73
+ transform_stack.current().apply(left, top);
74
+ transform_stack.current().apply(right, bottom);
87
75
 
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
+ };
88
82
  // Adjust for OpenGL having the wrong idea of where y=0 is.
89
- phys_y = screen_height - phys_y - phys_height;
83
+ if (viewport_height && mode() == QM_RENDER_TO_SCREEN) {
84
+ clip_rect.y = *viewport_height - clip_rect.y - clip_rect.height;
85
+ }
90
86
 
91
- clip_rect_stack.begin_clipping(phys_x, phys_y, phys_width, phys_height);
87
+ clip_rect_stack.push(clip_rect);
92
88
  }
93
89
 
94
- void end_clipping()
95
- {
96
- clip_rect_stack.end_clipping();
97
- }
90
+ void end_clipping() { clip_rect_stack.pop(); }
98
91
 
99
92
  void set_base_transform(const Transform& base_transform)
100
93
  {
@@ -118,7 +111,8 @@ public:
118
111
  }
119
112
 
120
113
  // Apply Z-Ordering.
121
- std::stable_sort(ops.begin(), ops.end());
114
+ std::stable_sort(ops.begin(), ops.end(),
115
+ [](const DrawOp& lhs, const DrawOp& rhs) { return lhs.z < rhs.z; });
122
116
 
123
117
  RenderStateManager manager;
124
118
 
@@ -144,7 +138,7 @@ public:
144
138
  assert (block_index >= 0);
145
139
  assert (block_index < gl_blocks.size());
146
140
  gl_blocks[block_index]();
147
- manager.enforce_after_untrusted_gL();
141
+ manager.enforce_after_untrusted_gl();
148
142
  }
149
143
  }
150
144
  #endif
@@ -156,7 +150,7 @@ public:
156
150
  throw std::logic_error("Custom OpenGL code cannot be recorded as a macro");
157
151
  }
158
152
 
159
- std::stable_sort(ops.begin(), ops.end());
153
+ std::stable_sort(ops.begin(), ops.end(), [](const DrawOp& lhs, const DrawOp& rhs) { return lhs.z < rhs.z; });
160
154
  for (const auto& op : ops) {
161
155
  op.compile_to(vas);
162
156
  }
data/src/Drawable.cpp ADDED
@@ -0,0 +1,95 @@
1
+ #include <Gosu/Drawable.hpp>
2
+ #include <Gosu/Utility.hpp>
3
+ #include "EmptyDrawable.hpp"
4
+ #include "Texture.hpp"
5
+ #include "TiledDrawable.hpp"
6
+ #include <list>
7
+ #include <mutex>
8
+
9
+ namespace Gosu
10
+ {
11
+ // This variable has been declared in multiple places. Define it here, where it will be used.
12
+ // This is a compatibility hack for old versions of Ruby/Gosu that didn't yet support :retro.
13
+ bool undocumented_retrofication = false; // NOLINT(*-avoid-non-const-global-variables)
14
+ }
15
+
16
+ std::unique_ptr<Gosu::Drawable> Gosu::create_drawable(const Bitmap& source, const Rect& source_rect,
17
+ unsigned image_flags)
18
+ {
19
+ if (!Rect::covering(source).contains(source_rect)) {
20
+ throw std::invalid_argument("Source rectangle exceeds bitmap");
21
+ }
22
+
23
+ if (source_rect.empty()) {
24
+ // It can happen that Gosu::Font wants us to create an empty drawable when rendering
25
+ // invisible characters (e.g. '\r'). In this case, return an empty drawable that is not
26
+ // backed by any kind of OpenGL texture.
27
+ return std::make_unique<EmptyDrawable>(source_rect.width, source_rect.height);
28
+ }
29
+
30
+ // Backward compatibility: This used to be 'bool tileable', help users that still pass 'true'.
31
+ if (image_flags == 1) {
32
+ image_flags = IF_TILEABLE;
33
+ }
34
+
35
+ bool wants_retro = (image_flags & IF_RETRO) || undocumented_retrofication;
36
+
37
+ // Special case: If the texture is supposed to be tileable, is quadratic, has a size that is at
38
+ // least 64 pixels but no more than MAX_TEXTURE_SIZE pixels and a power of two, create a single
39
+ // texture just for this image.
40
+ // This is not just an optimization, but a feature of Gosu so that one can use Gosu for loading
41
+ // textures for use in 3D scenes, where it is important that the full u/v range is dedicated to
42
+ // a single image so that texture repetition works as expected.
43
+ if ((image_flags & IF_TILEABLE) == IF_TILEABLE && source_rect.width == source_rect.height
44
+ && (source_rect.width & (source_rect.width - 1)) == 0 && source_rect.width >= 64
45
+ && source_rect.width <= MAX_TEXTURE_SIZE) {
46
+
47
+ const std::shared_ptr<Texture> texture
48
+ = std::make_shared<Texture>(source_rect.width, source_rect.height, wants_retro);
49
+
50
+ // Use the source bitmap directly if the source area completely covers it.
51
+ if (source_rect == Rect::covering(source)) {
52
+ return texture->try_alloc(source, 0);
53
+ }
54
+ else {
55
+ Bitmap trimmed_source(source_rect.width, source_rect.height);
56
+ trimmed_source.insert(source, 0, 0, source_rect);
57
+ return texture->try_alloc(trimmed_source, 0);
58
+ }
59
+ }
60
+
61
+ const int max_size = MAX_TEXTURE_SIZE;
62
+
63
+ // Too large to fit on a single texture? -> Create a tiled representation.
64
+ if (source_rect.width > max_size - 2 || source_rect.height > max_size - 2) {
65
+ return std::make_unique<TiledDrawable>(source, source_rect, max_size - 2, image_flags);
66
+ }
67
+
68
+ Bitmap source_with_borders = apply_border_flags(image_flags, source, source_rect);
69
+
70
+ // Try to put the bitmap into one of the already allocated textures.
71
+ static std::list<std::weak_ptr<Texture>> texture_pool;
72
+ static std::mutex mutex;
73
+ std::scoped_lock lock(mutex);
74
+
75
+ texture_pool.remove_if([](const auto& weak_ptr) { return weak_ptr.expired(); });
76
+
77
+ for (const std::weak_ptr<Texture>& weak_texture : texture_pool) {
78
+ const auto texture = weak_texture.lock();
79
+ if (!texture || texture->retro() != wants_retro) {
80
+ continue;
81
+ }
82
+
83
+ std::unique_ptr<Drawable> data = texture->try_alloc(source_with_borders, 1);
84
+ if (data) {
85
+ return data;
86
+ }
87
+ }
88
+
89
+ // All textures are full: Create a new one.
90
+
91
+ std::shared_ptr<Texture> texture
92
+ = std::make_shared<Texture>(MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE, wants_retro);
93
+ texture_pool.push_back(texture);
94
+ return texture->try_alloc(source_with_borders, 1);
95
+ }
@@ -0,0 +1,38 @@
1
+ #pragma once
2
+
3
+ #include <Gosu/Bitmap.hpp>
4
+ #include <Gosu/Drawable.hpp>
5
+ #include <memory>
6
+
7
+ namespace Gosu
8
+ {
9
+ class EmptyDrawable : public Drawable
10
+ {
11
+ int m_width, m_height;
12
+
13
+ public:
14
+ EmptyDrawable(int width, int height)
15
+ : m_width(width),
16
+ m_height(height)
17
+ {
18
+ }
19
+
20
+ int width() const override { return m_width; }
21
+
22
+ int height() const override { return m_height; }
23
+
24
+ void draw(double, double, Color, double, double, Color, //
25
+ double, double, Color, double, double, Color, //
26
+ ZPos, BlendMode) const override
27
+ {
28
+ }
29
+
30
+ GLTexInfo* gl_tex_info() const override { return nullptr; }
31
+
32
+ Bitmap to_bitmap() const override { return Bitmap(m_width, m_height); }
33
+
34
+ std::unique_ptr<Drawable> subimage(const Rect&) const override { return nullptr; }
35
+
36
+ void insert(const Bitmap&, int, int) override { }
37
+ };
38
+ }
data/src/FPS.cpp ADDED
@@ -0,0 +1,31 @@
1
+ #include <Gosu/Timing.hpp>
2
+ #include "GraphicsImpl.hpp"
3
+
4
+ namespace Gosu
5
+ {
6
+ namespace
7
+ {
8
+ int current_fps = 0;
9
+ }
10
+
11
+ void register_frame()
12
+ {
13
+ static unsigned long current_second = Gosu::milliseconds() / 1000;
14
+ static int frames_in_current_second = 0;
15
+
16
+ unsigned long new_sec = Gosu::milliseconds() / 1000;
17
+ if (current_second != new_sec) {
18
+ current_second = new_sec;
19
+ current_fps = frames_in_current_second;
20
+ frames_in_current_second = 0;
21
+ }
22
+ else {
23
+ ++frames_in_current_second;
24
+ }
25
+ }
26
+
27
+ int fps()
28
+ {
29
+ return current_fps;
30
+ }
31
+ }
data/src/Font.cpp CHANGED
@@ -1,74 +1,94 @@
1
1
  #include <Gosu/Font.hpp>
2
- #include <Gosu/Graphics.hpp>
3
2
  #include <Gosu/Image.hpp>
4
- #include <Gosu/Math.hpp>
5
3
  #include <Gosu/Text.hpp>
6
4
  #include <Gosu/Utility.hpp>
7
5
  #include "GraphicsImpl.hpp"
8
6
  #include "MarkupParser.hpp"
9
- #include <array>
10
- #include <map>
7
+ #include <cmath> // for std::ceil
8
+ #include <mutex>
11
9
  #include <stdexcept>
12
- #include <utf8proc.h>
13
-
14
- static const int FONT_RENDER_SCALE = 2;
10
+ #include <unordered_map>
15
11
 
16
12
  struct Gosu::Font::Impl : private Gosu::Noncopyable
17
13
  {
18
- std::string name;
19
- int height;
20
- unsigned base_flags;
21
- unsigned image_flags;
22
-
23
- // The most common characters are stored directly in an array for maximum performance.
24
- // (This is the start of the Basic Multilingual Plane, up until the part where right-to-left
25
- // languages begin, which don't really work with Gosu yet.)
26
- std::array<std::array<Image, 0x58f>, FF_COMBINATIONS> fast_glyphs;
27
- // Everything else is looked up through a map...
28
- std::array<std::map<utf8proc_int32_t, Image>, FF_COMBINATIONS> other_glyphs;
29
-
30
- Image& image(char32_t codepoint, unsigned font_flags)
14
+ const int height;
15
+ const std::string name;
16
+ const unsigned base_flags;
17
+ const unsigned image_flags;
18
+
19
+ Impl(int height, std::string_view name, unsigned base_flags, unsigned image_flags)
20
+ : height(height),
21
+ name(name),
22
+ base_flags(base_flags),
23
+ image_flags(image_flags)
31
24
  {
32
- Image* image;
33
- if (codepoint < fast_glyphs[font_flags].size()) {
34
- image = &fast_glyphs[font_flags][codepoint];
25
+ }
26
+
27
+ struct GlyphKey
28
+ {
29
+ char32_t codepoint;
30
+ unsigned font_flags;
31
+ bool operator==(const GlyphKey&) const = default;
32
+ };
33
+
34
+ struct GlyphKeyHasher
35
+ {
36
+ std::size_t operator()(const GlyphKey& key) const noexcept
37
+ {
38
+ // The highest legal Unicode code point is 0x10FFFF, which is a 21-bit value, so we do
39
+ // not have to worry about overwriting any of the higher bits.
40
+ // This only works if unordered_map uses prime table sizes (which it should):
41
+ // https://www.reddit.com/r/cpp_questions/comments/us3nyb/comment/i937ulb/
42
+ return key.codepoint | (key.font_flags << 24);
35
43
  }
36
- else {
37
- image = &other_glyphs[font_flags][codepoint];
44
+ };
45
+
46
+ // Font implements copying through its shared_ptr, not by making a true copy. However, Fonts are
47
+ // not immutable: Glyphs are created and cashed on demand, and set_image() enables modifications
48
+ // to the shared data of a font. Having multiple references to the same object, but not being
49
+ // able to use it from two threads, seems counterintuitive, so introduce a mutex here, even
50
+ // though most Gosu games/programs will never really require it.
51
+ // (Could be a shared_mutex, but doesn't seem to be worth the trouble.)
52
+ std::mutex glyphs_mutex;
53
+ std::unordered_map<GlyphKey, Image, GlyphKeyHasher> glyphs;
54
+
55
+ const Image& image(char32_t codepoint, unsigned font_flags)
56
+ {
57
+ const GlyphKey key { codepoint, font_flags };
58
+ if (const auto iterator = glyphs.find(key); iterator != glyphs.end()) {
59
+ return iterator->second;
38
60
  }
39
61
 
40
62
  // If this codepoint has not been rendered before, do it now.
41
- if (image->width() == 0 && image->height() == 0) {
42
- auto scaled_height = height * FONT_RENDER_SCALE;
43
- // Optimization: Don't render higher-resolution versions if we use
44
- // next neighbor interpolation anyway.
45
- if (image_flags & IF_RETRO) scaled_height = height;
46
-
47
- std::u32string string(1, codepoint);
48
- Bitmap bitmap(scaled_height, scaled_height);
49
- auto required_width = ceil(Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name,
50
- scaled_height, font_flags));
51
- if (required_width > bitmap.width()) {
52
- // If the character was wider than high, we need to render it again.
53
- Bitmap(required_width, scaled_height).swap(bitmap);
54
- Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name, scaled_height,
55
- font_flags);
56
- }
63
+ // By default, render each glyph at 200% its size so that we have some wiggle room for
64
+ // changing the font size dynamically without it appearing too blurry.
65
+ auto scaled_height = height * 2;
66
+ // Optimization: Don't render higher-resolution versions if we use
67
+ // next neighbor interpolation anyway.
68
+ if (image_flags & IF_RETRO) {
69
+ scaled_height = height;
70
+ }
57
71
 
58
- *image = Image(bitmap, 0, 0, required_width, scaled_height, image_flags);
72
+ std::u32string string(1, codepoint);
73
+ Bitmap bitmap(scaled_height, scaled_height);
74
+ const int required_width = static_cast<int>(std::ceil(
75
+ Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name, scaled_height, font_flags)));
76
+ if (required_width > bitmap.width()) {
77
+ // If the character was wider than high, we need to render it again.
78
+ Bitmap resized_bitmap(required_width, scaled_height);
79
+ std::swap(resized_bitmap, bitmap);
80
+ Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name, scaled_height, font_flags);
59
81
  }
82
+ const Rect source_rect = Rect::xywh(0, 0, required_width, bitmap.height());
60
83
 
61
- return *image;
84
+ return glyphs[key] = Image(bitmap, source_rect, image_flags);
62
85
  }
63
86
  };
64
87
 
65
- Gosu::Font::Font(int font_height, const std::string& font_name, unsigned font_flags, unsigned image_flags)
66
- : m_impl{new Impl}
88
+ Gosu::Font::Font(int font_height, std::string_view font_name, unsigned font_flags,
89
+ unsigned image_flags)
90
+ : m_impl(new Impl(font_height, font_name, font_flags, image_flags))
67
91
  {
68
- m_impl->name = font_name;
69
- m_impl->height = font_height;
70
- m_impl->base_flags = font_flags;
71
- m_impl->image_flags = image_flags;
72
92
  }
73
93
 
74
94
  const std::string& Gosu::Font::name() const
@@ -98,15 +118,17 @@ double Gosu::Font::text_width(const std::string& text) const
98
118
 
99
119
  double Gosu::Font::markup_width(const std::string& markup) const
100
120
  {
121
+ const std::unique_lock lock(m_impl->glyphs_mutex);
122
+
101
123
  double width = 0;
102
124
 
103
125
  // Split the text into lines (split_words = false) because Font doesn't implement word-wrapping.
104
- MarkupParser parser(m_impl->base_flags, false, [&](std::vector<FormattedString>&& line) {
126
+ MarkupParser parser(m_impl->base_flags, false, [&](const std::vector<FormattedString>& line) {
105
127
  double line_width = 0;
106
- for (auto& part : line) {
107
- for (auto codepoint : part.text) {
108
- auto& image = m_impl->image(codepoint, part.flags);
109
- double image_scale = 1.0 * height() / image.height();
128
+ for (const auto& part : line) {
129
+ for (const auto codepoint : part.text) {
130
+ const auto& image = m_impl->image(codepoint, part.flags);
131
+ double image_scale = image.height() ? 1.0 * height() / image.height() : 1.0;
110
132
  line_width += image_scale * image.width();
111
133
  }
112
134
  }
@@ -126,15 +148,17 @@ void Gosu::Font::draw_text(const std::string& text, double x, double y, ZPos z,
126
148
  void Gosu::Font::draw_markup(const std::string& markup, double x, double y, ZPos z, //
127
149
  double scale_x, double scale_y, Color c, BlendMode mode) const
128
150
  {
151
+ const std::unique_lock lock(m_impl->glyphs_mutex);
152
+
129
153
  double current_y = y;
130
154
 
131
155
  // Split the text into lines (split_words = false) because Font doesn't implement word-wrapping.
132
- MarkupParser parser(m_impl->base_flags, false, [&](std::vector<FormattedString>&& line) {
156
+ MarkupParser parser(m_impl->base_flags, false, [&](const std::vector<FormattedString>& line) {
133
157
  double current_x = x;
134
- for (auto& part : line) {
135
- for (auto codepoint : part.text) {
136
- auto& image = m_impl->image(codepoint, part.flags);
137
- double image_scale = 1.0 * height() / image.height();
158
+ for (const auto& part : line) {
159
+ for (const auto codepoint : part.text) {
160
+ const auto& image = m_impl->image(codepoint, part.flags);
161
+ double image_scale = image.height() ? 1.0 * height() / image.height() : 1.0;
138
162
  image.draw(current_x, current_y, z, image_scale * scale_x, image_scale * scale_y,
139
163
  multiply(c, part.color), mode);
140
164
  current_x += image_scale * scale_x * image.width();
@@ -145,12 +169,16 @@ void Gosu::Font::draw_markup(const std::string& markup, double x, double y, ZPos
145
169
  parser.parse(markup);
146
170
  }
147
171
 
148
- void Gosu::Font::draw_text_rel(const std::string& text, double x, double y, ZPos z, //
172
+ void Gosu::Font::draw_text_rel(const std::string& text, double x, double y, ZPos z, //
149
173
  double rel_x, double rel_y, double scale_x, double scale_y, //
150
174
  Color c, BlendMode mode) const
151
175
  {
152
- if (rel_x) x -= text_width(text) * scale_x * rel_x;
153
- if (rel_y) y -= height() * scale_y * rel_y;
176
+ if (rel_x != 0) {
177
+ x -= text_width(text) * scale_x * rel_x;
178
+ }
179
+ if (rel_y != 0) {
180
+ y -= height() * scale_y * rel_y;
181
+ }
154
182
 
155
183
  draw_text(text, x, y, z, scale_x, scale_y, c, mode);
156
184
  }
@@ -159,28 +187,30 @@ void Gosu::Font::draw_markup_rel(const std::string& markup, double x, double y,
159
187
  double rel_x, double rel_y, double scale_x, double scale_y,
160
188
  Color c, BlendMode mode) const
161
189
  {
162
- if (rel_x) x -= markup_width(markup) * scale_x * rel_x;
163
- if (rel_y) y -= height() * scale_y * rel_y;
190
+ if (rel_x != 0) {
191
+ x -= markup_width(markup) * scale_x * rel_x;
192
+ }
193
+ if (rel_y != 0) {
194
+ y -= height() * scale_y * rel_y;
195
+ }
164
196
 
165
197
  draw_markup(markup, x, y, z, scale_x, scale_y, c, mode);
166
198
  }
167
199
 
168
- void Gosu::Font::set_image(std::string codepoint, unsigned font_flags, const Gosu::Image& image)
200
+ void Gosu::Font::set_image(std::string_view codepoint, unsigned font_flags,
201
+ const Gosu::Image& image)
169
202
  {
170
- auto utc4 = utf8_to_composed_utc4(codepoint);
203
+ const std::u32string utc4 = utf8_to_composed_utc4(codepoint);
171
204
  if (utc4.length() != 1) {
172
- throw std::invalid_argument{"Could not compose '" + codepoint + "' into single codepoint"};
205
+ throw std::invalid_argument("Could not compose '" + std::string(codepoint)
206
+ + "' into single codepoint");
173
207
  }
174
208
 
175
- if (utc4[0] < m_impl->fast_glyphs[font_flags].size()) {
176
- m_impl->fast_glyphs[font_flags][utc4[0]] = image;
177
- }
178
- else {
179
- m_impl->other_glyphs[font_flags][utc4[0]] = image;
180
- }
209
+ const std::unique_lock lock(m_impl->glyphs_mutex);
210
+ m_impl->glyphs.insert_or_assign({ .codepoint = utc4[0], .font_flags = font_flags }, image);
181
211
  }
182
212
 
183
- void Gosu::Font::set_image(std::string codepoint, const Gosu::Image& image)
213
+ void Gosu::Font::set_image(std::string_view codepoint, const Gosu::Image& image)
184
214
  {
185
215
  for (unsigned font_flags = 0; font_flags < FF_COMBINATIONS; ++font_flags) {
186
216
  set_image(codepoint, font_flags, image);
data/src/GosuGLView.cpp CHANGED
@@ -1,30 +1,32 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_IPHONE)
3
3
 
4
- #import "GosuGLView.hpp"
5
4
  #import <Gosu/Input.hpp>
6
5
  #import <Gosu/TextInput.hpp>
7
-
6
+ #import "GosuGLView.hpp"
7
+ #import "GraphicsImpl.hpp"
8
+ #import "OpenGLContext.hpp"
8
9
  #import <OpenGLES/EAGL.h>
9
10
  #import <OpenGLES/EAGLDrawable.h>
10
- #import <OpenGLES/ES1/gl.h>
11
- #import <OpenGLES/ES1/glext.h>
12
11
  #import <QuartzCore/QuartzCore.h>
13
12
 
14
-
15
13
  static EAGLContext __weak* globalContext;
16
14
 
17
15
  namespace Gosu
18
16
  {
19
- void ensure_current_context()
17
+ OpenGLContext::OpenGLContext(bool)
20
18
  {
19
+ // Gosu does not support multithreading on iOS.
20
+ if (![NSThread isMainThread]) {
21
+ throw std::logic_error("Multi-threaded OpenGL access is not supported on iOS");
22
+ }
23
+
21
24
  [EAGLContext setCurrentContext:globalContext];
22
25
  }
23
-
24
- int clip_rect_base_factor()
26
+
27
+ OpenGLContext::~OpenGLContext()
25
28
  {
26
- static int result = [UIScreen mainScreen].scale;
27
- return result;
29
+ // Don't bother unsetting anything.
28
30
  }
29
31
  }
30
32
 
@@ -89,7 +91,7 @@ namespace Gosu
89
91
  [EAGLContext setCurrentContext:_context];
90
92
  [self destroyFramebuffer];
91
93
  [self createFramebuffer];
92
- self.contentScaleFactor = Gosu::clip_rect_base_factor();
94
+ self.contentScaleFactor = [UIScreen mainScreen].scale;
93
95
  }
94
96
 
95
97
  - (BOOL)createFramebuffer
@@ -10,14 +10,6 @@
10
10
  #import <AudioToolbox/AudioSession.h>
11
11
  #import <OpenAL/alc.h>
12
12
 
13
- namespace Gosu
14
- {
15
- namespace FPS
16
- {
17
- void register_frame();
18
- }
19
- }
20
-
21
13
  static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
22
14
  {
23
15
  if (inInterruptionState == kAudioSessionBeginInterruption) {
@@ -180,9 +172,9 @@ static void handle_audio_interruption(void* unused, UInt32 inInterruptionState)
180
172
 
181
173
  if (window.needs_redraw()) {
182
174
  [(GosuGLView*)self.view redrawGL:^{
183
- window.graphics().frame([&window] {
175
+ window.viewport().frame([&window] {
184
176
  window.draw();
185
- Gosu::FPS::register_frame();
177
+ Gosu::register_frame();
186
178
  });
187
179
  }];
188
180
  }