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/Image.cpp CHANGED
@@ -1,81 +1,80 @@
1
- #include <Gosu/Image.hpp>
2
1
  #include <Gosu/Bitmap.hpp>
3
2
  #include <Gosu/Graphics.hpp>
4
3
  #include <Gosu/IO.hpp>
4
+ #include <Gosu/Image.hpp>
5
5
  #include <Gosu/ImageData.hpp>
6
6
  #include <Gosu/Math.hpp>
7
- #include <stdexcept>
8
7
  #include "EmptyImageData.hpp"
9
- using namespace std;
8
+ #include <stdexcept>
10
9
 
11
10
  Gosu::Image::Image()
12
- : data_(EmptyImageData::instance_ptr())
11
+ : m_data(EmptyImageData::instance_ptr())
13
12
  {
14
13
  }
15
14
 
16
- Gosu::Image::Image(const string& filename, unsigned image_flags)
15
+ Gosu::Image::Image(const std::string& filename, unsigned image_flags)
17
16
  {
18
17
  // Forward.
19
18
  Bitmap bitmap = load_image_file(filename);
20
- Image{bitmap, image_flags}.data_.swap(data_);
19
+ Image{bitmap, image_flags}.m_data.swap(m_data);
21
20
  }
22
21
 
23
- Gosu::Image::Image(const string& filename, int src_x, int src_y, int src_width, int src_height,
22
+ Gosu::Image::Image(const std::string& filename, int src_x, int src_y, int src_width, int src_height,
24
23
  unsigned image_flags)
25
24
  {
26
25
  // Forward.
27
26
  Bitmap bitmap = load_image_file(filename);
28
- Image{bitmap, src_x, src_y, src_width, src_height, image_flags}.data_.swap(data_);
27
+ Image{bitmap, src_x, src_y, src_width, src_height, image_flags}.m_data.swap(m_data);
29
28
  }
30
29
 
31
30
  Gosu::Image::Image(const Bitmap& source, unsigned image_flags)
32
31
  {
33
32
  // Forward.
34
- Image{source, 0, 0, source.width(), source.height(), image_flags}.data_.swap(data_);
33
+ Image{source, 0, 0, source.width(), source.height(), image_flags}.m_data.swap(m_data);
35
34
  }
36
35
 
37
36
  Gosu::Image::Image(const Bitmap& source, int src_x, int src_y, int src_width, int src_height,
38
37
  unsigned image_flags)
39
- : data_(Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags))
38
+ : m_data(Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags))
40
39
  {
41
40
  }
42
41
 
43
- Gosu::Image::Image(unique_ptr<ImageData>&& data)
44
- : data_(data.release())
42
+ Gosu::Image::Image(std::unique_ptr<ImageData>&& data)
43
+ : m_data(data.release())
45
44
  {
46
- if (!data_) throw invalid_argument("Gosu::Image cannot be initialized with nullptr");
45
+ if (!m_data) throw std::invalid_argument("Gosu::Image cannot be initialized with nullptr");
47
46
  }
48
47
 
49
48
  unsigned Gosu::Image::width() const
50
49
  {
51
- return data_->width();
50
+ return m_data->width();
52
51
  }
53
52
 
54
53
  unsigned Gosu::Image::height() const
55
54
  {
56
- return data_->height();
55
+ return m_data->height();
57
56
  }
58
57
 
59
58
  void Gosu::Image::draw(double x, double y, ZPos z, double scale_x, double scale_y, Color c,
60
- BlendMode mode) const
59
+ BlendMode mode) const
61
60
  {
62
61
  double x2 = x + width() * scale_x;
63
62
  double y2 = y + height() * scale_y;
64
63
 
65
- data_->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
64
+ m_data->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
66
65
  }
67
66
 
68
67
  void Gosu::Image::draw_mod(double x, double y, ZPos z, double scale_x, double scale_y, Color c1,
69
- Color c2, Color c3, Color c4, BlendMode mode) const
68
+ Color c2, Color c3, Color c4, BlendMode mode) const
70
69
  {
71
70
  double x2 = x + width() * scale_x;
72
71
  double y2 = y + height() * scale_y;
73
72
 
74
- data_->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
73
+ m_data->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
75
74
  }
76
75
 
77
- void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle,
78
- double center_x, double center_y, double scale_x, double scale_y, Color c,
76
+ void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle, double center_x,
77
+ double center_y, double scale_x, double scale_y, Color c,
79
78
  BlendMode mode) const
80
79
  {
81
80
  double size_x = width() * scale_x;
@@ -84,33 +83,33 @@ void Gosu::Image::draw_rot(double x, double y, ZPos z, double angle,
84
83
  double offs_y = offset_y(angle, 1);
85
84
 
86
85
  // Offset to the centers of the original Image's edges after rotation.
87
- double dist_to_left_x = +offs_y * size_x * center_x;
88
- double dist_to_left_y = -offs_x * size_x * center_x;
89
- double dist_to_right_x = -offs_y * size_x * (1 - center_x);
90
- double dist_to_right_y = +offs_x * size_x * (1 - center_x);
91
- double dist_to_top_x = +offs_x * size_y * center_y;
92
- double dist_to_top_y = +offs_y * size_y * center_y;
86
+ double dist_to_left_x = +offs_y * size_x * center_x;
87
+ double dist_to_left_y = -offs_x * size_x * center_x;
88
+ double dist_to_right_x = -offs_y * size_x * (1 - center_x);
89
+ double dist_to_right_y = +offs_x * size_x * (1 - center_x);
90
+ double dist_to_top_x = +offs_x * size_y * center_y;
91
+ double dist_to_top_y = +offs_y * size_y * center_y;
93
92
  double dist_to_bottom_x = -offs_x * size_y * (1 - center_y);
94
93
  double dist_to_bottom_y = -offs_y * size_y * (1 - center_y);
95
94
 
96
- data_->draw(x + dist_to_left_x + dist_to_top_x, y + dist_to_left_y + dist_to_top_y, c,
97
- x + dist_to_right_x + dist_to_top_x, y + dist_to_right_y + dist_to_top_y, c,
98
- x + dist_to_left_x + dist_to_bottom_x, y + dist_to_left_y + dist_to_bottom_y, c,
99
- x + dist_to_right_x + dist_to_bottom_x, y + dist_to_right_y + dist_to_bottom_y, c,
100
- z, mode);
95
+ m_data->draw(x + dist_to_left_x + dist_to_top_x, y + dist_to_left_y + dist_to_top_y, c,
96
+ x + dist_to_right_x + dist_to_top_x, y + dist_to_right_y + dist_to_top_y, c,
97
+ x + dist_to_left_x + dist_to_bottom_x, y + dist_to_left_y + dist_to_bottom_y, c,
98
+ x + dist_to_right_x + dist_to_bottom_x, y + dist_to_right_y + dist_to_bottom_y, c,
99
+ z, mode);
101
100
  }
102
101
 
103
102
  Gosu::ImageData& Gosu::Image::data() const
104
103
  {
105
- return *data_;
104
+ return *m_data;
106
105
  }
107
106
 
108
- vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile_height,
109
- unsigned flags)
107
+ std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile_height,
108
+ unsigned flags)
110
109
  {
111
110
  int tiles_x, tiles_y;
112
- vector<Image> images;
113
-
111
+ std::vector<Image> images;
112
+
114
113
  if (tile_width > 0) {
115
114
  tiles_x = bmp.width() / tile_width;
116
115
  }
@@ -118,7 +117,7 @@ vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile
118
117
  tiles_x = -tile_width;
119
118
  tile_width = bmp.width() / tiles_x;
120
119
  }
121
-
120
+
122
121
  if (tile_height > 0) {
123
122
  tiles_y = bmp.height() / tile_height;
124
123
  }
@@ -126,19 +125,19 @@ vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile
126
125
  tiles_y = -tile_height;
127
126
  tile_height = bmp.height() / tiles_y;
128
127
  }
129
-
128
+
130
129
  for (int y = 0; y < tiles_y; ++y) {
131
130
  for (int x = 0; x < tiles_x; ++x) {
132
131
  images.emplace_back(bmp, x * tile_width, y * tile_height, tile_width, tile_height,
133
132
  flags);
134
133
  }
135
134
  }
136
-
135
+
137
136
  return images;
138
137
  }
139
138
 
140
- vector<Gosu::Image> Gosu::load_tiles(const string& filename, int tile_width, int tile_height,
141
- unsigned flags)
139
+ std::vector<Gosu::Image> Gosu::load_tiles(const std::string& filename, int tile_width,
140
+ int tile_height, unsigned flags)
142
141
  {
143
142
  Bitmap bmp = load_image_file(filename);
144
143
  return load_tiles(bmp, tile_width, tile_height, flags);
data/src/Input.cpp CHANGED
@@ -36,7 +36,7 @@ static vector<shared_ptr<SDL_GameController>> open_game_controllers;
36
36
  // Stores joystick instance id or -1 if empty
37
37
  static array<int, Gosu::NUM_GAMEPADS> gamepad_slots = {-1, -1, -1, -1};
38
38
 
39
- struct Gosu::Input::Impl
39
+ struct Gosu::Input::Impl : Gosu::Noncopyable
40
40
  {
41
41
  struct InputEvent
42
42
  {
data/src/InputUIKit.cpp CHANGED
@@ -7,7 +7,7 @@
7
7
  #import <UIKit/UIKit.h>
8
8
  using namespace std;
9
9
 
10
- struct Gosu::Input::Impl
10
+ struct Gosu::Input::Impl : Gosu::Noncopyable
11
11
  {
12
12
  UIView* view = nil;
13
13
  TextInput* text_input = nullptr;
@@ -4,46 +4,51 @@
4
4
  #include <Gosu/Math.hpp>
5
5
  #include <cmath>
6
6
  #include <stdexcept>
7
- using namespace std;
7
+
8
+ const Gosu::ImageData& Gosu::LargeImageData::tile(int x, int y) const
9
+ {
10
+ return *m_tiles.at(static_cast<std::size_t>(y * m_tiles_x + x));
11
+ }
8
12
 
9
13
  Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int tile_height,
10
14
  unsigned image_flags)
11
15
  {
12
- w = source.width();
13
- h = source.height();
14
- tiles_x = static_cast<int>(ceil(1.0 * w / tile_width));
15
- tiles_y = static_cast<int>(ceil(1.0 * h / tile_height));
16
+ m_w = source.width();
17
+ m_h = source.height();
18
+ // Manual ceil() for integer division.
19
+ m_tiles_x = (m_w + tile_width - 1) / tile_width;
20
+ m_tiles_y = (m_h + tile_height - 1) / tile_height;
16
21
 
17
22
  // When there are no tiles, set both fields to 0 to avoid entering any for () loop in this class.
18
- if (tiles_x == 0 || tiles_y == 0) {
19
- tiles_x = tiles_y = 0;
23
+ if (m_tiles_x == 0 || m_tiles_y == 0) {
24
+ m_tiles_x = m_tiles_y = 0;
20
25
  }
21
26
 
22
- tiles.reserve(tiles_x * tiles_y);
27
+ m_tiles.reserve(m_tiles_x * m_tiles_y);
23
28
 
24
- for (int y = 0; y < tiles_y; ++y) {
25
- for (int x = 0; x < tiles_x; ++x) {
29
+ for (int y = 0; y < m_tiles_y; ++y) {
30
+ for (int x = 0; x < m_tiles_x; ++x) {
26
31
  int src_width = tile_width;
27
- if (x == tiles_x - 1 && w % tile_width != 0) {
32
+ if (x == m_tiles_x - 1 && m_w % tile_width != 0) {
28
33
  // The right-most parts don't necessarily have the full width.
29
- src_width = w % tile_width;
34
+ src_width = m_w % tile_width;
30
35
  }
31
36
 
32
37
  int src_height = tile_height;
33
- if (y == tiles_y - 1 && h % tile_height != 0) {
38
+ if (y == m_tiles_y - 1 && m_h % tile_height != 0) {
34
39
  // Same for the parts on the bottom.
35
- src_height = h % tile_height;
40
+ src_height = m_h % tile_height;
36
41
  }
37
42
 
38
43
  unsigned local_flags = IF_TILEABLE | image_flags;
39
-
44
+
40
45
  // Left edge, only tileable if requested in image_flags.
41
46
  if (x == 0) {
42
47
  local_flags &= ~IF_TILEABLE_LEFT;
43
48
  local_flags |= (image_flags & IF_TILEABLE_LEFT);
44
49
  }
45
50
  // Right edge, only tileable if requested in image_flags.
46
- if (x == tiles_x - 1) {
51
+ if (x == m_tiles_x - 1) {
47
52
  local_flags &= ~IF_TILEABLE_RIGHT;
48
53
  local_flags |= (image_flags & IF_TILEABLE_RIGHT);
49
54
  }
@@ -53,41 +58,37 @@ Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int t
53
58
  local_flags |= (image_flags & IF_TILEABLE_TOP);
54
59
  }
55
60
  // Bottom edge, only tileable if requested in image_flags.
56
- if (y == tiles_y - 1) {
61
+ if (y == m_tiles_y - 1) {
57
62
  local_flags &= ~IF_TILEABLE_BOTTOM;
58
63
  local_flags |= (image_flags & IF_TILEABLE_BOTTOM);
59
64
  }
60
-
61
- tiles.emplace_back(Graphics::create_image(source,
62
- x * tile_width, y * tile_height,
63
- src_width, src_height, local_flags));
65
+
66
+ m_tiles.emplace_back(Graphics::create_image(source, x * tile_width, y * tile_height,
67
+ src_width, src_height, local_flags));
64
68
  }
65
69
  }
66
70
  }
67
71
 
68
- void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
69
- double x2, double y2, Color c2,
70
- double x3, double y3, Color c3,
71
- double x4, double y4, Color c4,
72
+ void Gosu::LargeImageData::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
73
+ double x3, double y3, Color c3, double x4, double y4, Color c4,
72
74
  ZPos z, BlendMode mode) const
73
75
  {
74
76
  normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
75
-
77
+
76
78
  double y = 0;
77
- for (int ty = 0; ty < tiles_y; ++ty) {
79
+ for (int ty = 0; ty < m_tiles_y; ++ty) {
78
80
  double x = 0;
79
- for (int tx = 0; tx < tiles_x; ++tx) {
80
- ImageData& tile = *tiles[ty * tiles_x + tx];
81
-
82
- double rel_x_l = x / w;
83
- double rel_x_r = (x + tile.width()) / w;
84
- double rel_y_t = y / h;
85
- double rel_y_b = (y + tile.height()) / h;
86
-
87
- #define LERP2D(what, x_weight, y_weight) \
88
- lerp(lerp(what##1, what##3, y_weight), \
89
- lerp(what##2, what##4, y_weight), \
90
- x_weight);
81
+ for (int tx = 0; tx < m_tiles_x; ++tx) {
82
+ const ImageData& image = tile(tx, ty);
83
+
84
+ double rel_x_l = x / m_w;
85
+ double rel_x_r = (x + image.width()) / m_w;
86
+ double rel_y_t = y / m_h;
87
+ double rel_y_b = (y + image.height()) / m_h;
88
+
89
+ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
90
+ #define LERP2D(what, x_weight, y_weight) \
91
+ lerp(lerp(what##1, what##3, y_weight), lerp(what##2, what##4, y_weight), x_weight);
91
92
 
92
93
  double x_t_l = LERP2D(x, rel_x_l, rel_y_t);
93
94
  double x_t_r = LERP2D(x, rel_x_r, rel_y_t);
@@ -99,80 +100,86 @@ void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
99
100
  double y_b_l = LERP2D(y, rel_x_l, rel_y_b);
100
101
  double y_b_r = LERP2D(y, rel_x_r, rel_y_b);
101
102
 
102
- Color c_t_l = LERP2D(c, rel_x_l, rel_y_t);
103
- Color c_t_r = LERP2D(c, rel_x_r, rel_y_t);
104
- Color c_b_l = LERP2D(c, rel_x_l, rel_y_b);
105
- Color c_b_r = LERP2D(c, rel_x_r, rel_y_b);
106
-
107
- tile.draw(x_t_l, y_t_l, c_t_l,
108
- x_t_r, y_t_r, c_t_r,
109
- x_b_l, y_b_l, c_b_l,
110
- x_b_r, y_b_r, c_b_r,
111
- z, mode);
112
-
113
- x += tile.width();
103
+ Color c_t_l = LERP2D(c, rel_x_l, rel_y_t);
104
+ Color c_t_r = LERP2D(c, rel_x_r, rel_y_t);
105
+ Color c_b_l = LERP2D(c, rel_x_l, rel_y_b);
106
+ Color c_b_r = LERP2D(c, rel_x_r, rel_y_b);
107
+
108
+ image.draw(x_t_l, y_t_l, c_t_l, x_t_r, y_t_r, c_t_r, x_b_l, y_b_l, c_b_l, x_b_r, y_b_r,
109
+ c_b_r, z, mode);
110
+
111
+ x += image.width();
114
112
  }
115
- y += tiles[ty * tiles_x]->height();
113
+ y += tile(0, ty).height();
116
114
  }
117
115
  }
118
116
 
119
- unique_ptr<Gosu::ImageData>
120
- Gosu::LargeImageData::subimage(int left, int top, int width, int height) const
117
+ std::unique_ptr<Gosu::ImageData> Gosu::LargeImageData::subimage(int left, int top, int width,
118
+ int height) const
121
119
  {
122
- if (left < 0 || top < 0 || left + width > w || top + height > h) {
123
- throw invalid_argument("subimage bounds exceed those of its parent");
120
+ if (left < 0 || top < 0 || left + width > m_w || top + height > m_h) {
121
+ throw std::invalid_argument{"subimage bounds exceed those of its parent"};
124
122
  }
125
123
  if (width <= 0 || height <= 0) {
126
- throw invalid_argument("cannot create empty image");
124
+ throw std::invalid_argument{"cannot create empty subimage"};
127
125
  }
128
-
126
+
129
127
  int sub_tiles_y = 0;
130
- vector<unique_ptr<ImageData>> sub_tiles;
131
-
128
+ std::vector<std::unique_ptr<ImageData>> sub_tiles;
129
+
132
130
  int y = 0;
133
- for (int ty = 0; ty < tiles_y; ++ty) {
134
- int row_height = tiles[ty * tiles_x]->height();
135
-
131
+ for (int ty = 0; ty < m_tiles_y; ++ty) {
132
+ int row_height = tile(0, ty).height();
133
+
136
134
  if (y + row_height <= top) {
137
- y += tiles[ty * tiles_x]->height();
135
+ // Skip rows until we are at the requested Y coordinate.
136
+ y += row_height;
138
137
  continue;
139
138
  }
140
- if (y >= top + height) break;
141
-
139
+ if (y >= top + height) {
140
+ // Also skip all rows after reaching the bottom requested Y coordinate.
141
+ break;
142
+ }
143
+
142
144
  sub_tiles_y += 1;
143
145
 
144
146
  int x = 0;
145
- for (int tx = 0; tx < tiles_x; ++tx) {
146
- ImageData& tile = *tiles[ty * tiles_x + tx];
147
-
148
- if (x + tile.width() <= left) {
149
- x += tile.width();
147
+ for (int tx = 0; tx < m_tiles_x; ++tx) {
148
+ const ImageData& image = tile(tx, ty);
149
+
150
+ if (x + image.width() <= left) {
151
+ // Skip columns until we are at the requested X coordinate.
152
+ x += image.width();
150
153
  continue;
151
154
  }
152
- if (x >= left + width) break;
153
-
154
- int sub_left = max(0, left - x);
155
- int sub_top = max(0, top - y);
156
- int sub_right = min(tile.width(), left + width - x);
157
- int sub_bottom = min(tile.height(), top + height - y);
158
-
159
- sub_tiles.emplace_back(tile.subimage(sub_left, sub_top, sub_right - sub_left, sub_bottom - sub_top));
160
-
161
- x += tile.width();
155
+ if (x >= left + width) {
156
+ // Also skip all columns after reaching the right-most requested Y coordinate.
157
+ break;
158
+ }
159
+
160
+ int sub_left = std::max(0, left - x);
161
+ int sub_top = std::max(0, top - y);
162
+ int sub_right = std::min(image.width(), left + width - x);
163
+ int sub_bottom = std::min(image.height(), top + height - y);
164
+
165
+ sub_tiles.emplace_back(
166
+ image.subimage(sub_left, sub_top, sub_right - sub_left, sub_bottom - sub_top));
167
+
168
+ x += image.width();
162
169
  }
163
- y += tiles[ty * tiles_x]->height();
170
+ y += tile(0, ty).height();
164
171
  }
165
-
172
+
166
173
  if (sub_tiles.size() == 1) {
167
174
  return move(sub_tiles[0]);
168
175
  }
169
176
  else {
170
- unique_ptr<LargeImageData> result(new LargeImageData());
171
- result->w = width;
172
- result->h = height;
173
- result->tiles_x = static_cast<int>(sub_tiles.size()) / sub_tiles_y;
174
- result->tiles_y = sub_tiles_y;
175
- result->tiles.swap(sub_tiles);
177
+ std::unique_ptr<LargeImageData> result(new LargeImageData());
178
+ result->m_w = width;
179
+ result->m_h = height;
180
+ result->m_tiles_x = static_cast<int>(sub_tiles.size()) / sub_tiles_y;
181
+ result->m_tiles_y = sub_tiles_y;
182
+ result->m_tiles.swap(sub_tiles);
176
183
  return move(result);
177
184
  }
178
185
  }
@@ -181,14 +188,14 @@ Gosu::Bitmap Gosu::LargeImageData::to_bitmap() const
181
188
  {
182
189
  Bitmap bitmap(width(), height());
183
190
  int y = 0;
184
- for (int ty = 0; ty < tiles_y; ++ty) {
191
+ for (int ty = 0; ty < m_tiles_y; ++ty) {
185
192
  int x = 0;
186
- for (int tx = 0; tx < tiles_x; ++tx) {
187
- ImageData& tile = *tiles[ty * tiles_x + tx];
188
- bitmap.insert(x, y, tile.to_bitmap());
189
- x += tile.width();
193
+ for (int tx = 0; tx < m_tiles_x; ++tx) {
194
+ const ImageData& image = tile(tx, ty);
195
+ bitmap.insert(x, y, image.to_bitmap());
196
+ x += image.width();
190
197
  }
191
- y += tiles[ty * tiles_x]->height();
198
+ y += tile(0, ty).height();
192
199
  }
193
200
  return bitmap;
194
201
  }
@@ -196,13 +203,13 @@ Gosu::Bitmap Gosu::LargeImageData::to_bitmap() const
196
203
  void Gosu::LargeImageData::insert(const Bitmap& bitmap, int at_x, int at_y)
197
204
  {
198
205
  int y = 0;
199
- for (int ty = 0; ty < tiles_y; ++ty) {
206
+ for (int ty = 0; ty < m_tiles_y; ++ty) {
200
207
  int x = 0;
201
- for (int tx = 0; tx < tiles_x; ++tx) {
202
- ImageData& tile = *tiles[ty * tiles_x + tx];
203
- tile.insert(bitmap, at_x - x, at_y - y);
204
- x += tile.width();
208
+ for (int tx = 0; tx < m_tiles_x; ++tx) {
209
+ ImageData& image = *m_tiles[static_cast<std::size_t>(ty * m_tiles_x + tx)];
210
+ image.insert(bitmap, at_x - x, at_y - y);
211
+ x += image.width();
205
212
  }
206
- y += tiles[ty * tiles_x]->height();
213
+ y += tile(0, ty).height();
207
214
  }
208
215
  }
@@ -1,37 +1,39 @@
1
1
  #pragma once
2
2
 
3
- #include "GraphicsImpl.hpp"
4
3
  #include <Gosu/Fwd.hpp>
5
4
  #include <Gosu/ImageData.hpp>
6
5
  #include <Gosu/Platform.hpp>
6
+ #include "GraphicsImpl.hpp"
7
7
  #include <memory>
8
8
  #include <vector>
9
9
 
10
10
  class Gosu::LargeImageData : public Gosu::ImageData
11
11
  {
12
- int w, h;
13
- int tiles_x, tiles_y;
14
- std::vector<std::unique_ptr<ImageData>> tiles;
15
-
16
- LargeImageData() {}
12
+ int m_w, m_h;
13
+ int m_tiles_x, m_tiles_y;
14
+ std::vector<std::unique_ptr<ImageData>> m_tiles;
15
+
16
+ LargeImageData() = default;
17
+
18
+ const ImageData& tile(int x, int y) const;
17
19
 
18
20
  public:
19
21
  LargeImageData(const Bitmap& source, int tile_width, int tile_height, unsigned image_flags);
20
22
 
21
- int width() const override { return w; }
22
- int height() const override { return h; }
23
+ int width() const override { return m_w; }
24
+ int height() const override { return m_h; }
23
25
 
24
- void draw(double x1, double y1, Color c1,
25
- double x2, double y2, Color c2,
26
- double x3, double y3, Color c3,
27
- double x4, double y4, Color c4,
26
+ void draw(double x1, double y1, Color c1, //
27
+ double x2, double y2, Color c2, //
28
+ double x3, double y3, Color c3, //
29
+ double x4, double y4, Color c4, //
28
30
  ZPos z, BlendMode mode) const override;
29
31
 
30
32
  const GLTexInfo* gl_tex_info() const override { return nullptr; }
31
-
33
+
32
34
  std::unique_ptr<ImageData> subimage(int x, int y, int width, int height) const override;
33
-
35
+
34
36
  Bitmap to_bitmap() const override;
35
-
37
+
36
38
  void insert(const Bitmap& bitmap, int x, int y) override;
37
39
  };
data/src/Log.hpp CHANGED
@@ -1,5 +1,6 @@
1
1
  #pragma once
2
2
 
3
+ #include <cstdio>
3
4
  #include <cstdlib>
4
5
  #include <utility>
5
6
 
@@ -8,12 +9,11 @@ namespace Gosu
8
9
  template<class... Args>
9
10
  void log(const char* format, Args&&... args)
10
11
  {
11
- using namespace std;
12
-
13
- if (getenv("GOSU_DEBUG")) {
14
- fprintf(stderr, format, std::forward<Args>(args)...);
15
- fprintf(stderr, "\n");
12
+ // NOLINTNEXTLINE(concurrency-mt-unsafe) - we don't even follow the pointer
13
+ static bool enable_log = (std::getenv("GOSU_DEBUG") != nullptr);
14
+ if (enable_log) {
15
+ std::fprintf(stderr, format, std::forward<Args>(args)...);
16
+ std::fprintf(stderr, "\n");
16
17
  }
17
18
  }
18
19
  }
19
-