gosu 0.15.1 → 1.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/COPYING +1 -1
  4. data/dependencies/SDL/include/SDL.h +138 -0
  5. data/dependencies/SDL/include/SDL_assert.h +293 -0
  6. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  7. data/dependencies/SDL/include/SDL_audio.h +859 -0
  8. data/dependencies/SDL/include/SDL_bits.h +121 -0
  9. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  10. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  11. data/dependencies/SDL/include/SDL_config.h +55 -0
  12. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  13. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  14. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  15. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  16. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  17. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  18. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  19. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  20. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  21. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  22. data/dependencies/SDL/include/SDL_copying.h +20 -0
  23. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  24. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  25. data/dependencies/SDL/include/SDL_endian.h +263 -0
  26. data/dependencies/SDL/include/SDL_error.h +112 -0
  27. data/dependencies/SDL/include/SDL_events.h +827 -0
  28. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  29. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  30. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  31. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  32. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  33. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  34. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  35. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  36. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  37. data/dependencies/SDL/include/SDL_locale.h +101 -0
  38. data/dependencies/SDL/include/SDL_log.h +211 -0
  39. data/dependencies/SDL/include/SDL_main.h +180 -0
  40. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  41. data/dependencies/SDL/include/SDL_metal.h +117 -0
  42. data/dependencies/SDL/include/SDL_misc.h +75 -0
  43. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  44. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  45. data/dependencies/SDL/include/SDL_name.h +33 -0
  46. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  47. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  48. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  49. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  51. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  52. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  53. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  54. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  55. data/dependencies/SDL/include/SDL_platform.h +198 -0
  56. data/dependencies/SDL/include/SDL_power.h +75 -0
  57. data/dependencies/SDL/include/SDL_quit.h +58 -0
  58. data/dependencies/SDL/include/SDL_rect.h +174 -0
  59. data/dependencies/SDL/include/SDL_render.h +1158 -0
  60. data/dependencies/SDL/include/SDL_revision.h +2 -0
  61. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  62. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  63. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  64. data/dependencies/SDL/include/SDL_shape.h +144 -0
  65. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  66. data/dependencies/SDL/include/SDL_surface.h +563 -0
  67. data/dependencies/SDL/include/SDL_system.h +325 -0
  68. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  69. data/dependencies/SDL/include/SDL_test.h +69 -0
  70. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  71. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  72. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  73. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  74. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  75. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  76. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  77. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  78. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  79. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  80. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  81. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  82. data/dependencies/SDL/include/SDL_thread.h +366 -0
  83. data/dependencies/SDL/include/SDL_timer.h +115 -0
  84. data/dependencies/SDL/include/SDL_touch.h +102 -0
  85. data/dependencies/SDL/include/SDL_types.h +29 -0
  86. data/dependencies/SDL/include/SDL_version.h +162 -0
  87. data/dependencies/SDL/include/SDL_video.h +1282 -0
  88. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  89. data/dependencies/SDL/include/begin_code.h +166 -0
  90. data/dependencies/SDL/include/close_code.h +40 -0
  91. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  92. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  93. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  94. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  95. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  96. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  97. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  98. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  99. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  100. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  101. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  102. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  103. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  104. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  105. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  106. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  107. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  108. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  109. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  110. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  111. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  112. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  113. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  114. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  116. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  117. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  118. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  119. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  121. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  124. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  125. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  126. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  127. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  128. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  129. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  130. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  131. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  132. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  133. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  134. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  135. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  136. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  137. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  138. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  140. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  141. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  142. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  143. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  144. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  145. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
  146. data/dependencies/al_soft/AL/al.h +655 -0
  147. data/dependencies/al_soft/AL/alc.h +270 -0
  148. data/dependencies/al_soft/AL/alext.h +585 -0
  149. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  150. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  151. data/dependencies/al_soft/AL/efx.h +762 -0
  152. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  153. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  154. data/{src → dependencies/stb}/stb_image.h +330 -127
  155. data/{src → dependencies/stb}/stb_image_write.h +156 -85
  156. data/{src → dependencies/stb}/stb_truetype.h +192 -69
  157. data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
  158. data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
  159. data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
  160. data/ext/gosu/extconf.rb +53 -39
  161. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  162. data/include/Gosu/Bitmap.hpp +100 -0
  163. data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
  164. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  165. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  166. data/{Gosu → include/Gosu}/Font.hpp +1 -1
  167. data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
  168. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  169. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  170. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  171. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  172. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  173. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  174. data/{Gosu → include/Gosu}/Input.hpp +39 -51
  175. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  176. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  177. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  178. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  179. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  180. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Utility.hpp +15 -4
  182. data/{Gosu → include/Gosu}/Version.hpp +3 -3
  183. data/{Gosu → include/Gosu}/Window.hpp +46 -34
  184. data/lib/OpenAL32.dll +0 -0
  185. data/lib/SDL2.dll +0 -0
  186. data/lib/gosu.rb +0 -3
  187. data/lib/gosu/patches.rb +0 -23
  188. data/lib/gosu/preview.rb +1 -3
  189. data/lib/gosu/swig_patches.rb +6 -8
  190. data/lib64/OpenAL32.dll +0 -0
  191. data/lib64/SDL2.dll +0 -0
  192. data/rdoc/gosu.rb +112 -23
  193. data/src/Audio.cpp +50 -224
  194. data/src/AudioFile.hpp +20 -37
  195. data/src/AudioFileAudioToolbox.cpp +237 -0
  196. data/src/AudioFileSDLSound.cpp +147 -0
  197. data/src/AudioImpl.cpp +3 -12
  198. data/src/AudioImpl.hpp +3 -1
  199. data/src/Bitmap.cpp +85 -83
  200. data/src/BitmapIO.cpp +52 -58
  201. data/src/Font.cpp +4 -1
  202. data/src/Graphics.cpp +7 -4
  203. data/src/Image.cpp +13 -16
  204. data/src/Input.cpp +412 -164
  205. data/src/LargeImageData.cpp +2 -1
  206. data/src/MarkupParser.cpp +2 -1
  207. data/src/Resolution.cpp +8 -8
  208. data/src/RubyGosu.cxx +1184 -352
  209. data/src/RubyGosu.h +3 -2
  210. data/src/TexChunk.cpp +1 -1
  211. data/src/Text.cpp +1 -0
  212. data/src/TextBuilder.cpp +3 -1
  213. data/src/Texture.cpp +1 -1
  214. data/src/TrueTypeFont.cpp +2 -1
  215. data/src/TrueTypeFontWin.cpp +3 -3
  216. data/src/Utility.cpp +11 -7
  217. data/src/Window.cpp +90 -62
  218. data/src/WindowUIKit.cpp +21 -9
  219. metadata +195 -46
  220. data/Gosu/AutoLink.hpp +0 -14
  221. data/Gosu/Bitmap.hpp +0 -113
  222. data/lib/gosu/zen.rb +0 -89
  223. data/src/AudioToolboxFile.hpp +0 -210
  224. data/src/MPEGFile.hpp +0 -90
  225. data/src/OggFile.hpp +0 -92
  226. data/src/SndFile.hpp +0 -174
  227. data/src/WinMain.cpp +0 -64
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
2
  * This file was automatically generated by SWIG (http://www.swig.org).
3
- * Version 4.0.2
3
+ * Version 4.1.0
4
4
  *
5
5
  * This file is not intended to be easily readable and contains a number of
6
6
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -28,7 +28,6 @@ public:
28
28
  class SwigDirector_Window : public Gosu::Window, public Swig::Director {
29
29
 
30
30
  public:
31
- SwigDirector_Window(VALUE self, unsigned int width, unsigned int height, bool fullscreen = false, double update_interval = 16.666666, bool resizable = false);
32
31
  virtual ~SwigDirector_Window();
33
32
  virtual void show();
34
33
  virtual bool tick();
@@ -41,6 +40,8 @@ public:
41
40
  virtual void release_memory();
42
41
  virtual void button_down(Gosu::Button arg0);
43
42
  virtual void button_up(Gosu::Button arg0);
43
+ virtual void gamepad_connected(int index);
44
+ virtual void gamepad_disconnected(int index);
44
45
  virtual void drop(std::string const &filename);
45
46
  };
46
47
 
@@ -120,7 +120,7 @@ void Gosu::TexChunk::insert(const Bitmap& original_bitmap, int x, int y)
120
120
  if (clipped_width <= 0 || clipped_height <= 0) return;
121
121
 
122
122
  clipped_bitmap.resize(clipped_width, clipped_height);
123
- clipped_bitmap.insert(original_bitmap, -clip_left, -clip_top);
123
+ clipped_bitmap.insert(-clip_left, -clip_top, original_bitmap);
124
124
  bitmap = &clipped_bitmap;
125
125
  }
126
126
 
@@ -7,6 +7,7 @@
7
7
  #include <cmath>
8
8
  #include <algorithm>
9
9
  #include <vector>
10
+ #include <stdexcept>
10
11
  using namespace std;
11
12
 
12
13
  double Gosu::text_width(const u32string& text,
@@ -1,8 +1,10 @@
1
1
  #include "TextBuilder.hpp"
2
2
  #include <Gosu/Text.hpp>
3
+
4
+ #include <utf8proc.h>
5
+
3
6
  #include <cassert>
4
7
  #include <cmath>
5
- #include "utf8proc.h"
6
8
  using namespace std;
7
9
 
8
10
  Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<FormattedString> parts)
@@ -124,7 +124,7 @@ Gosu::Bitmap Gosu::Texture::to_bitmap(unsigned x, unsigned y, unsigned width, un
124
124
  // TODO: There are ways to retrieve only part of a texture, which we should use sooner or later.
125
125
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, full_texture.data());
126
126
  Bitmap bitmap(width, height);
127
- bitmap.insert(full_texture, -int(x), -int(y));
127
+ bitmap.insert(-int(x), -int(y), full_texture);
128
128
 
129
129
  return bitmap;
130
130
  #endif
@@ -1,6 +1,7 @@
1
1
  #include "TrueTypeFont.hpp"
2
2
  #include <Gosu/IO.hpp>
3
3
  #include <Gosu/Text.hpp>
4
+ #include <stdexcept>
4
5
 
5
6
  // Disable comma warnings in stb headers.
6
7
  #ifdef __GNUC__
@@ -9,7 +10,7 @@
9
10
  #endif
10
11
 
11
12
  #define STB_TRUETYPE_IMPLEMENTATION
12
- #include "stb_truetype.h"
13
+ #include <stb_truetype.h>
13
14
 
14
15
  #ifdef __GNUC__
15
16
  #pragma GCC diagnostic pop
@@ -32,9 +32,9 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
32
32
  LOGFONT logfont = {
33
33
  0, 0, 0, 0,
34
34
  (font_flags & Gosu::FF_BOLD) ? FW_BOLD : FW_NORMAL,
35
- (font_flags & Gosu::FF_ITALIC) ? TRUE : FALSE,
36
- (font_flags & Gosu::FF_UNDERLINE) ? TRUE : FALSE,
37
- FALSE /* no strikethrough */,
35
+ (font_flags & Gosu::FF_ITALIC) ? 1 : 0,
36
+ (font_flags & Gosu::FF_UNDERLINE) ? 1 : 0,
37
+ 0 /* no strikethrough */,
38
38
  ANSI_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
39
39
  DEFAULT_PITCH
40
40
  };
@@ -1,7 +1,7 @@
1
1
  #include <Gosu/Utility.hpp>
2
2
  #include <Gosu/Platform.hpp>
3
3
 
4
- #include "utf8proc.h"
4
+ #include <utf8proc.h>
5
5
 
6
6
  #include <cstring>
7
7
  #include <stdexcept>
@@ -45,17 +45,20 @@ u32string Gosu::utf8_to_composed_utc4(const string& utf8)
45
45
  return utc4;
46
46
  }
47
47
 
48
- bool Gosu::has_extension(const string& filename, const char* extension)
48
+ bool Gosu::has_extension(string_view filename, string_view extension)
49
49
  {
50
- size_t ext_len = strlen(extension);
50
+ size_t ext_len = extension.length();
51
51
  if (ext_len > filename.length()) {
52
52
  return false;
53
53
  }
54
54
 
55
- const char* str = filename.c_str() + filename.length();
56
- const char* ext = extension + ext_len;
55
+ string_view::iterator filename_iter = filename.end();
56
+ string_view::iterator ext_iter = extension.end();
57
57
  while (ext_len--) {
58
- if (tolower((int) *--str) != *--ext) {
58
+ --filename_iter;
59
+ --ext_iter;
60
+
61
+ if (tolower((int) *filename_iter) != tolower((int) *ext_iter)) {
59
62
  return false;
60
63
  }
61
64
  }
@@ -66,6 +69,7 @@ bool Gosu::has_extension(const string& filename, const char* extension)
66
69
  #if defined(GOSU_IS_UNIX) && !defined(GOSU_IS_MAC)
67
70
  string Gosu::language()
68
71
  {
69
- return getenv("LANG");
72
+ const char* env = getenv("LANG");
73
+ return env ? env : "en_US";
70
74
  }
71
75
  #endif
@@ -1,6 +1,10 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if !defined(GOSU_IS_IPHONE)
3
3
 
4
+ #if defined(GOSU_IS_WIN)
5
+ #include <windows.h>
6
+ #endif
7
+
4
8
  #include <Gosu/Gosu.hpp>
5
9
  #include "GraphicsImpl.hpp"
6
10
  #include <SDL.h>
@@ -22,8 +26,6 @@ namespace Gosu
22
26
  throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
23
27
  }
24
28
 
25
- static void cleanup();
26
-
27
29
  SDL_Window* shared_window()
28
30
  {
29
31
  static SDL_Window* window = nullptr;
@@ -32,14 +34,12 @@ namespace Gosu
32
34
  throw_sdl_error("Could not initialize SDL Video");
33
35
  }
34
36
 
35
- atexit(cleanup);
36
-
37
37
  Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
38
-
38
+
39
39
  #if SDL_VERSION_ATLEAST(2, 0, 1)
40
40
  flags |= SDL_WINDOW_ALLOW_HIGHDPI;
41
41
  #endif
42
-
42
+
43
43
  window =
44
44
  SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
45
45
  if (window == nullptr) {
@@ -58,27 +58,20 @@ namespace Gosu
58
58
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
59
59
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
60
60
  #endif
61
-
61
+
62
62
  context = SDL_GL_CreateContext(shared_window());
63
-
63
+
64
64
  if (context == nullptr) {
65
65
  throw_sdl_error("Could not create OpenGL context");
66
66
  }
67
67
  }
68
68
  return context;
69
69
  }
70
-
70
+
71
71
  void ensure_current_context()
72
72
  {
73
73
  SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
74
74
  }
75
-
76
- static void cleanup()
77
- {
78
- SDL_GL_DeleteContext(shared_gl_context());
79
- SDL_DestroyWindow(shared_window());
80
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
81
- }
82
75
  }
83
76
 
84
77
  struct Gosu::Window::Impl
@@ -98,13 +91,11 @@ struct Gosu::Window::Impl
98
91
  unique_ptr<Input> input;
99
92
  };
100
93
 
101
- Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double update_interval,
102
- bool resizable)
94
+ Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
103
95
  : pimpl(new Impl)
104
96
  {
105
- #if SDL_VERSION_ATLEAST(2, 0, 5)
106
- SDL_SetWindowResizable(shared_window(), (SDL_bool)resizable);
107
- #endif
97
+ set_borderless(window_flags & WF_BORDERLESS);
98
+ set_resizable(window_flags & WF_RESIZABLE);
108
99
 
109
100
  // Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
110
101
  // This ensures that the window will be centered correctly when exiting fullscreen mode.
@@ -114,15 +105,16 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
114
105
  SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
115
106
 
116
107
  // Really enable fullscreen if desired.
117
- resize(width, height, fullscreen);
108
+ resize(width, height, (window_flags & WF_FULLSCREEN));
118
109
 
119
110
  SDL_GL_SetSwapInterval(1);
120
111
 
121
112
  pimpl->update_interval = update_interval;
122
- pimpl->resizable = resizable;
123
113
 
124
114
  input().on_button_down = [this](Button button) { button_down(button); };
125
115
  input().on_button_up = [this](Button button) { button_up(button); };
116
+ input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
117
+ input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
126
118
  }
127
119
 
128
120
  Gosu::Window::~Window()
@@ -130,12 +122,12 @@ Gosu::Window::~Window()
130
122
  SDL_HideWindow(shared_window());
131
123
  }
132
124
 
133
- unsigned Gosu::Window::width() const
125
+ int Gosu::Window::width() const
134
126
  {
135
127
  return graphics().width();
136
128
  }
137
129
 
138
- unsigned Gosu::Window::height() const
130
+ int Gosu::Window::height() const
139
131
  {
140
132
  return graphics().height();
141
133
  }
@@ -145,25 +137,20 @@ bool Gosu::Window::fullscreen() const
145
137
  return pimpl->fullscreen;
146
138
  }
147
139
 
148
- bool Gosu::Window::resizable() const
149
- {
150
- return pimpl->resizable;
151
- }
152
-
153
- void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
140
+ void Gosu::Window::resize(int width, int height, bool fullscreen)
154
141
  {
155
142
  pimpl->fullscreen = fullscreen;
156
-
143
+
157
144
  int actual_width = width;
158
145
  int actual_height = height;
159
146
  double scale_factor = 1.0;
160
147
  double black_bar_width = 0;
161
148
  double black_bar_height = 0;
162
-
149
+
163
150
  if (fullscreen) {
164
151
  actual_width = Gosu::screen_width(this);
165
152
  actual_height = Gosu::screen_height(this);
166
-
153
+
167
154
  if (resizable()) {
168
155
  // Resizable fullscreen windows stubbornly follow the desktop resolution.
169
156
  width = actual_width;
@@ -184,9 +171,9 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
184
171
  }
185
172
  }
186
173
  else {
187
- unsigned max_width = Gosu::available_width(this);
188
- unsigned max_height = Gosu::available_height(this);
189
-
174
+ int max_width = Gosu::available_width(this);
175
+ int max_height = Gosu::available_height(this);
176
+
190
177
  if (resizable()) {
191
178
  // If the window is resizable, limit its size, without preserving the aspect ratio.
192
179
  width = actual_width = min(width, max_width);
@@ -199,18 +186,18 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
199
186
  actual_height = height * scale_factor;
200
187
  }
201
188
  }
202
-
189
+
203
190
  SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
204
191
  if (!pimpl->resizing) {
205
192
  SDL_SetWindowSize(shared_window(), actual_width, actual_height);
206
193
  }
207
-
194
+
208
195
  #if SDL_VERSION_ATLEAST(2, 0, 1)
209
196
  SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
210
197
  #endif
211
-
198
+
212
199
  ensure_current_context();
213
-
200
+
214
201
  if (!pimpl->graphics) {
215
202
  pimpl->graphics.reset(new Graphics(actual_width, actual_height));
216
203
  }
@@ -218,7 +205,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
218
205
  pimpl->graphics->set_physical_resolution(actual_width, actual_height);
219
206
  }
220
207
  pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
221
-
208
+
222
209
  if (!pimpl->input) {
223
210
  pimpl->input.reset(new Input(shared_window()));
224
211
  }
@@ -226,6 +213,29 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
226
213
  black_bar_width, black_bar_height);
227
214
  }
228
215
 
216
+ bool Gosu::Window::resizable() const
217
+ {
218
+ return pimpl->resizable;
219
+ }
220
+
221
+ void Gosu::Window::set_resizable(bool resizable)
222
+ {
223
+ pimpl->resizable = resizable;
224
+ #if SDL_VERSION_ATLEAST(2, 0, 5)
225
+ SDL_SetWindowResizable(shared_window(), resizable ? SDL_TRUE : SDL_FALSE);
226
+ #endif
227
+ }
228
+
229
+ bool Gosu::Window::borderless() const
230
+ {
231
+ return SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_BORDERLESS;
232
+ }
233
+
234
+ void Gosu::Window::set_borderless(bool borderless)
235
+ {
236
+ SDL_SetWindowBordered(shared_window(), borderless ? SDL_FALSE : SDL_TRUE);
237
+ }
238
+
229
239
  double Gosu::Window::update_interval() const
230
240
  {
231
241
  return pimpl->update_interval;
@@ -250,17 +260,35 @@ void Gosu::Window::set_caption(const string& caption)
250
260
  void Gosu::Window::show()
251
261
  {
252
262
  unsigned long time_before_tick = milliseconds();
253
-
254
- while (tick()) {
255
- // Sleep to keep this loop from eating 100% CPU.
256
- unsigned long tick_time = milliseconds() - time_before_tick;
257
- if (tick_time < update_interval()) {
258
- sleep(update_interval() - tick_time);
263
+
264
+ #ifdef GOSU_IS_WIN
265
+ // Try to convince Windows to only run this thread on the first core, to avoid timing glitches.
266
+ // (If we ever run into a situation where the first core is not available, we should start to
267
+ // use GetProcessAffinityMask to retrieve the allowed cores as a bitmask.)
268
+ DWORD_PTR previous_affinity = SetThreadAffinityMask(GetCurrentThread(), 1);
269
+ #endif
270
+
271
+ try {
272
+ while (tick()) {
273
+ // Sleep to keep this loop from eating 100% CPU.
274
+ unsigned long tick_time = milliseconds() - time_before_tick;
275
+ if (tick_time < update_interval()) {
276
+ sleep(update_interval() - tick_time);
277
+ }
278
+
279
+ time_before_tick = milliseconds();
259
280
  }
260
-
261
- time_before_tick = milliseconds();
281
+ } catch (...) {
282
+ #ifdef GOSU_IS_WIN
283
+ if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
284
+ #endif
285
+ throw;
262
286
  }
263
-
287
+
288
+ #ifdef GOSU_IS_WIN
289
+ if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
290
+ #endif
291
+
264
292
  pimpl->state = Impl::CLOSED;
265
293
  }
266
294
 
@@ -270,7 +298,7 @@ bool Gosu::Window::tick()
270
298
  pimpl->state = Impl::CLOSED;
271
299
  return false;
272
300
  }
273
-
301
+
274
302
  if (pimpl->state == Impl::CLOSED) {
275
303
  SDL_ShowWindow(shared_window());
276
304
  pimpl->state = Impl::OPEN;
@@ -282,7 +310,7 @@ bool Gosu::Window::tick()
282
310
  SDL_GL_GetDrawableSize(shared_window(), &width, &height);
283
311
  graphics().set_physical_resolution(width, height);
284
312
  }
285
-
313
+
286
314
  SDL_Event e;
287
315
  while (SDL_PollEvent(&e)) {
288
316
 
@@ -320,29 +348,29 @@ bool Gosu::Window::tick()
320
348
  }
321
349
  }
322
350
  }
323
-
351
+
324
352
  Song::update();
325
-
353
+
326
354
  input().update();
327
-
355
+
328
356
  update();
329
-
357
+
330
358
  SDL_ShowCursor(needs_cursor());
331
-
359
+
332
360
  if (needs_redraw()) {
333
361
  ensure_current_context();
334
362
  graphics().frame([&] {
335
363
  draw();
336
364
  FPS::register_frame();
337
365
  });
338
-
366
+
339
367
  SDL_GL_SwapWindow(shared_window());
340
368
  }
341
-
369
+
342
370
  if (pimpl->state == Impl::CLOSING) {
343
371
  pimpl->state = Impl::CLOSED;
344
372
  }
345
-
373
+
346
374
  return pimpl->state == Impl::OPEN;
347
375
  }
348
376
 
@@ -357,7 +385,7 @@ void Gosu::Window::button_down(Button button)
357
385
  bool toggle_fullscreen;
358
386
 
359
387
  // Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
360
-
388
+
361
389
  #ifdef GOSU_IS_MAC
362
390
  // cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
363
391
  toggle_fullscreen = button == KB_F &&