gosu 1.4.1 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL_sound/SDL_sound.c +21 -63
  3. data/dependencies/SDL_sound/SDL_sound.h +2 -2
  4. data/dependencies/SDL_sound/SDL_sound_aiff.c +26 -23
  5. data/dependencies/SDL_sound/SDL_sound_au.c +8 -8
  6. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +4 -5
  7. data/dependencies/SDL_sound/SDL_sound_flac.c +28 -30
  8. data/dependencies/SDL_sound/SDL_sound_internal.h +4 -4
  9. data/dependencies/SDL_sound/SDL_sound_modplug.c +1 -1
  10. data/dependencies/SDL_sound/SDL_sound_mp3.c +19 -23
  11. data/dependencies/SDL_sound/SDL_sound_raw.c +5 -6
  12. data/dependencies/SDL_sound/SDL_sound_shn.c +4 -4
  13. data/dependencies/SDL_sound/SDL_sound_voc.c +15 -15
  14. data/dependencies/SDL_sound/SDL_sound_vorbis.c +14 -7
  15. data/dependencies/SDL_sound/SDL_sound_wav.c +17 -17
  16. data/dependencies/SDL_sound/dr_flac.h +10840 -4779
  17. data/dependencies/SDL_sound/dr_mp3.h +2793 -1004
  18. data/dependencies/SDL_sound/libmodplug/fastmix.c +5 -0
  19. data/dependencies/SDL_sound/libmodplug/load_669.c +1 -1
  20. data/dependencies/SDL_sound/libmodplug/load_amf.c +1 -0
  21. data/dependencies/SDL_sound/libmodplug/load_ams.c +38 -22
  22. data/dependencies/SDL_sound/libmodplug/load_it.c +18 -14
  23. data/dependencies/SDL_sound/libmodplug/load_mdl.c +18 -9
  24. data/dependencies/SDL_sound/libmodplug/load_med.c +7 -6
  25. data/dependencies/SDL_sound/libmodplug/load_mt2.c +36 -17
  26. data/dependencies/SDL_sound/libmodplug/load_okt.c +51 -24
  27. data/dependencies/SDL_sound/libmodplug/load_psm.c +4 -2
  28. data/dependencies/SDL_sound/libmodplug/load_s3m.c +4 -4
  29. data/dependencies/SDL_sound/libmodplug/load_ult.c +4 -3
  30. data/dependencies/SDL_sound/libmodplug/load_xm.c +5 -5
  31. data/dependencies/SDL_sound/libmodplug/snd_fx.c +8 -1
  32. data/dependencies/SDL_sound/libmodplug/sndfile.c +21 -4
  33. data/dependencies/SDL_sound/stb_vorbis.h +10 -18
  34. data/dependencies/mojoAL/mojoal.c +260 -6
  35. data/dependencies/stb/stb_image.h +208 -73
  36. data/dependencies/stb/stb_image_write.h +57 -23
  37. data/dependencies/stb/stb_truetype.h +345 -279
  38. data/dependencies/utf8proc/utf8proc.c +37 -18
  39. data/dependencies/utf8proc/utf8proc.h +17 -5
  40. data/dependencies/utf8proc/utf8proc_data.h +12012 -10089
  41. data/include/Gosu/Buttons.hpp +103 -103
  42. data/include/Gosu/Directories.hpp +31 -24
  43. data/include/Gosu/Font.hpp +4 -2
  44. data/include/Gosu/Gosu.hpp +5 -8
  45. data/include/Gosu/IO.hpp +0 -3
  46. data/include/Gosu/Math.hpp +0 -3
  47. data/include/Gosu/Timing.hpp +2 -8
  48. data/include/Gosu/Version.hpp +1 -1
  49. data/src/AudioImpl.cpp +0 -7
  50. data/src/AudioImpl.hpp +1 -3
  51. data/src/BitmapIO.cpp +23 -2
  52. data/src/DirectoriesApple.cpp +25 -24
  53. data/src/DirectoriesUnix.cpp +14 -12
  54. data/src/DirectoriesWin.cpp +26 -30
  55. data/src/Font.cpp +12 -2
  56. data/src/Image.cpp +10 -15
  57. data/src/RubyGosu.cxx +6 -34
  58. data/src/TimingApple.cpp +1 -7
  59. data/src/TimingUnix.cpp +0 -6
  60. data/src/TimingWin.cpp +0 -6
  61. data/src/Window.cpp +4 -3
  62. metadata +2 -2
@@ -1,21 +1,19 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_WIN)
3
3
 
4
- #include "WinUtility.hpp"
5
4
  #include <Gosu/Directories.hpp>
6
5
  #include <Gosu/Utility.hpp>
6
+ #include "WinUtility.hpp"
7
7
  #include <cwchar>
8
- #include <stdexcept>
9
8
  #include <shlobj.h>
10
- using namespace std;
9
+ #include <stdexcept>
11
10
 
12
- static string special_folder_path(int csidl)
11
+ static std::string special_folder_path(int csidl)
13
12
  {
14
13
  WCHAR buf[MAX_PATH + 2];
15
- if (FAILED(SHGetFolderPathW(nullptr, csidl | CSIDL_FLAG_CREATE, nullptr, 0, buf))) {
16
- throw runtime_error("Error getting special folder path");
17
- }
18
- size_t len = wcslen(buf);
14
+ if (FAILED(SHGetFolderPathW(nullptr, csidl | CSIDL_FLAG_CREATE, nullptr, 0, buf)))
15
+ throw std::runtime_error{"Error getting special folder path"};
16
+ size_t len = std::wcslen(buf);
19
17
  if (buf[len - 1] != L'\\') {
20
18
  buf[len] = L'\\';
21
19
  buf[len + 1] = 0;
@@ -23,16 +21,12 @@ static string special_folder_path(int csidl)
23
21
  return Gosu::utf16_to_utf8(buf);
24
22
  }
25
23
 
26
- static string exe_filename()
24
+ std::string exe_filename()
27
25
  {
28
- static string result;
29
- if (result.empty()) {
30
- WCHAR buffer[MAX_PATH * 2];
31
- Gosu::winapi_check(GetModuleFileNameW(nullptr, buffer, MAX_PATH * 2),
32
- "getting the module filename");
33
- result = Gosu::utf16_to_utf8(buffer);
34
- }
35
- return result;
26
+ WCHAR buffer[MAX_PATH * 2];
27
+ Gosu::winapi_check(GetModuleFileNameW(nullptr, buffer, MAX_PATH * 2),
28
+ "getting the module filename");
29
+ return Gosu::utf16_to_utf8(buffer);
36
30
  }
37
31
 
38
32
  void Gosu::use_resource_directory()
@@ -40,30 +34,32 @@ void Gosu::use_resource_directory()
40
34
  SetCurrentDirectory(utf8_to_utf16(resource_prefix()).c_str());
41
35
  }
42
36
 
43
- string Gosu::resource_prefix()
37
+ const std::string& Gosu::resource_prefix()
44
38
  {
45
- static string result;
46
- if (result.empty()) {
47
- result = exe_filename();
48
- auto last_delim = result.find_last_of("\\/");
49
- result.resize(last_delim == string::npos ? 0 : last_delim + 1);
50
- }
51
- return result;
39
+ static const std::string resource_prefix = [] {
40
+ std::string result = exe_filename();
41
+ const auto last_delim = result.find_last_of("\\/");
42
+ result.resize(last_delim == std::string::npos ? 0 : last_delim + 1);
43
+ return result;
44
+ }();
45
+ return resource_prefix;
52
46
  }
53
47
 
54
- string Gosu::shared_resource_prefix()
48
+ const std::string& Gosu::shared_resource_prefix()
55
49
  {
56
50
  return resource_prefix();
57
51
  }
58
52
 
59
- string Gosu::user_settings_prefix()
53
+ const std::string& Gosu::user_settings_prefix()
60
54
  {
61
- return special_folder_path(CSIDL_APPDATA);
55
+ static const std::string user_settings_prefix = special_folder_path(CSIDL_APPDATA);
56
+ return user_settings_prefix;
62
57
  }
63
58
 
64
- string Gosu::user_documents_prefix()
59
+ const std::string& Gosu::user_documents_prefix()
65
60
  {
66
- return special_folder_path(CSIDL_PERSONAL);
61
+ static const std::string user_documents_prefix = special_folder_path(CSIDL_PERSONAL);
62
+ return user_documents_prefix;
67
63
  }
68
64
 
69
65
  #endif
data/src/Font.cpp CHANGED
@@ -18,6 +18,7 @@ struct Gosu::Font::Impl : Gosu::Noncopyable
18
18
  std::string name;
19
19
  int height;
20
20
  unsigned base_flags;
21
+ unsigned image_flags;
21
22
 
22
23
  // The most common characters are stored directly in an array for maximum performance.
23
24
  // (This is the start of the Basic Multilingual Plane, up until the part where right-to-left
@@ -39,6 +40,9 @@ struct Gosu::Font::Impl : Gosu::Noncopyable
39
40
  // If this codepoint has not been rendered before, do it now.
40
41
  if (image->width() == 0 && image->height() == 0) {
41
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;
42
46
 
43
47
  std::u32string string(1, codepoint);
44
48
  Bitmap bitmap(scaled_height, scaled_height);
@@ -51,19 +55,20 @@ struct Gosu::Font::Impl : Gosu::Noncopyable
51
55
  font_flags);
52
56
  }
53
57
 
54
- *image = Image(bitmap, 0, 0, required_width, scaled_height);
58
+ *image = Image(bitmap, 0, 0, required_width, scaled_height, image_flags);
55
59
  }
56
60
 
57
61
  return *image;
58
62
  }
59
63
  };
60
64
 
61
- Gosu::Font::Font(int font_height, const std::string& font_name, unsigned font_flags)
65
+ Gosu::Font::Font(int font_height, const std::string& font_name, unsigned font_flags, unsigned image_flags)
62
66
  : m_impl{new Impl}
63
67
  {
64
68
  m_impl->name = font_name;
65
69
  m_impl->height = font_height;
66
70
  m_impl->base_flags = font_flags;
71
+ m_impl->image_flags = image_flags;
67
72
  }
68
73
 
69
74
  const std::string& Gosu::Font::name() const
@@ -81,6 +86,11 @@ unsigned Gosu::Font::flags() const
81
86
  return m_impl->base_flags;
82
87
  }
83
88
 
89
+ unsigned Gosu::Font::image_flags() const
90
+ {
91
+ return m_impl->image_flags;
92
+ }
93
+
84
94
  double Gosu::Font::text_width(const std::string& text) const
85
95
  {
86
96
  return markup_width(escape_markup(text));
data/src/Image.cpp CHANGED
@@ -8,39 +8,34 @@
8
8
  #include <stdexcept>
9
9
 
10
10
  Gosu::Image::Image()
11
- : m_data(EmptyImageData::instance_ptr())
11
+ : m_data{EmptyImageData::instance_ptr()}
12
12
  {
13
13
  }
14
14
 
15
15
  Gosu::Image::Image(const std::string& filename, unsigned image_flags)
16
+ : Image(load_image_file(filename), image_flags)
16
17
  {
17
- // Forward.
18
- Bitmap bitmap = load_image_file(filename);
19
- Image{bitmap, image_flags}.m_data.swap(m_data);
20
18
  }
21
19
 
22
20
  Gosu::Image::Image(const std::string& filename, int src_x, int src_y, int src_width, int src_height,
23
21
  unsigned image_flags)
22
+ : Image(load_image_file(filename), src_x, src_y, src_width, src_height, image_flags)
24
23
  {
25
- // Forward.
26
- Bitmap bitmap = load_image_file(filename);
27
- Image{bitmap, src_x, src_y, src_width, src_height, image_flags}.m_data.swap(m_data);
28
24
  }
29
25
 
30
26
  Gosu::Image::Image(const Bitmap& source, unsigned image_flags)
27
+ : Image(source, 0, 0, source.width(), source.height(), image_flags)
31
28
  {
32
- // Forward.
33
- Image{source, 0, 0, source.width(), source.height(), image_flags}.m_data.swap(m_data);
34
29
  }
35
30
 
36
31
  Gosu::Image::Image(const Bitmap& source, int src_x, int src_y, int src_width, int src_height,
37
32
  unsigned image_flags)
38
- : m_data(Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags))
33
+ : m_data{Graphics::create_image(source, src_x, src_y, src_width, src_height, image_flags)}
39
34
  {
40
35
  }
41
36
 
42
37
  Gosu::Image::Image(std::unique_ptr<ImageData>&& data)
43
- : m_data(data.release())
38
+ : m_data{data.release()}
44
39
  {
45
40
  if (!m_data) throw std::invalid_argument("Gosu::Image cannot be initialized with nullptr");
46
41
  }
@@ -104,8 +99,8 @@ Gosu::ImageData& Gosu::Image::data() const
104
99
  return *m_data;
105
100
  }
106
101
 
107
- std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int tile_height,
108
- unsigned flags)
102
+ std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, //
103
+ int tile_width, int tile_height, unsigned flags)
109
104
  {
110
105
  int tiles_x, tiles_y;
111
106
  std::vector<Image> images;
@@ -136,8 +131,8 @@ std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bmp, int tile_width, int
136
131
  return images;
137
132
  }
138
133
 
139
- std::vector<Gosu::Image> Gosu::load_tiles(const std::string& filename, int tile_width,
140
- int tile_height, unsigned flags)
134
+ std::vector<Gosu::Image> Gosu::load_tiles(const std::string& filename, //
135
+ int tile_width, int tile_height, unsigned flags)
141
136
  {
142
137
  Bitmap bmp = load_image_file(filename);
143
138
  return load_tiles(bmp, tile_width, tile_height, flags);
data/src/RubyGosu.cxx CHANGED
@@ -2806,6 +2806,7 @@ SWIGINTERN Gosu::Font *new_Gosu_Font__SWIG_0(Gosu::Window &window,std::string co
2806
2806
  SWIGINTERN Gosu::Font *new_Gosu_Font__SWIG_1(int height,VALUE options=0){
2807
2807
  std::string font_name = Gosu::default_font_name();
2808
2808
  unsigned font_flags = 0;
2809
+ unsigned image_flags = 0;
2809
2810
 
2810
2811
  if (options) {
2811
2812
  Check_Type(options, T_HASH);
@@ -2831,6 +2832,9 @@ SWIGINTERN Gosu::Font *new_Gosu_Font__SWIG_1(int height,VALUE options=0){
2831
2832
  else if (!strcmp(key_string, "underline")) {
2832
2833
  if (RTEST(value)) font_flags |= Gosu::FF_UNDERLINE;
2833
2834
  }
2835
+ else if (!strcmp(key_string, "retro")) {
2836
+ if (RTEST(value)) image_flags |= Gosu::IF_RETRO;
2837
+ }
2834
2838
  else {
2835
2839
  static bool issued_warning = false;
2836
2840
  if (!issued_warning) {
@@ -2841,7 +2845,7 @@ SWIGINTERN Gosu::Font *new_Gosu_Font__SWIG_1(int height,VALUE options=0){
2841
2845
  }
2842
2846
  }
2843
2847
 
2844
- return new Gosu::Font(height, font_name, font_flags);
2848
+ return new Gosu::Font(height, font_name, font_flags, image_flags);
2845
2849
  }
2846
2850
  SWIGINTERN double Gosu_Font_text_width(Gosu::Font *self,std::string const &markup,double scale_x=1.0){
2847
2851
  static bool issued_warning = false;
@@ -5258,37 +5262,6 @@ fail:
5258
5262
  }
5259
5263
 
5260
5264
 
5261
- SWIGINTERN VALUE
5262
- _wrap_Font_flags(int argc, VALUE *argv, VALUE self) {
5263
- Gosu::Font *arg1 = (Gosu::Font *) 0 ;
5264
- void *argp1 = 0 ;
5265
- int res1 = 0 ;
5266
- unsigned int result;
5267
- VALUE vresult = Qnil;
5268
-
5269
- if ((argc < 0) || (argc > 0)) {
5270
- rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
5271
- }
5272
- res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Font, 0 | 0 );
5273
- if (!SWIG_IsOK(res1)) {
5274
- SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Font const *","flags", 1, self ));
5275
- }
5276
- arg1 = reinterpret_cast< Gosu::Font * >(argp1);
5277
- {
5278
- try {
5279
- result = (unsigned int)((Gosu::Font const *)arg1)->flags();
5280
- }
5281
- catch (const std::exception& e) {
5282
- SWIG_exception(SWIG_RuntimeError, e.what());
5283
- }
5284
- }
5285
- vresult = SWIG_From_unsigned_SS_int(static_cast< unsigned int >(result));
5286
- return vresult;
5287
- fail:
5288
- return Qnil;
5289
- }
5290
-
5291
-
5292
5265
  SWIGINTERN VALUE
5293
5266
  _wrap_Font_draw_text(int argc, VALUE *argv, VALUE self) {
5294
5267
  Gosu::Font *arg1 = (Gosu::Font *) 0 ;
@@ -12486,7 +12459,7 @@ SWIGEXPORT void Init_gosu(void) {
12486
12459
  rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
12487
12460
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(1)));
12488
12461
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(4)));
12489
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(1)));
12462
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(3)));
12490
12463
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
12491
12464
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
12492
12465
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -12544,7 +12517,6 @@ SWIGEXPORT void Init_gosu(void) {
12544
12517
  rb_define_method(SwigClassFont.klass, "initialize", VALUEFUNC(_wrap_new_Font), -1);
12545
12518
  rb_define_method(SwigClassFont.klass, "name", VALUEFUNC(_wrap_Font_name), -1);
12546
12519
  rb_define_method(SwigClassFont.klass, "height", VALUEFUNC(_wrap_Font_height), -1);
12547
- rb_define_method(SwigClassFont.klass, "flags", VALUEFUNC(_wrap_Font_flags), -1);
12548
12520
  rb_define_method(SwigClassFont.klass, "draw_text", VALUEFUNC(_wrap_Font_draw_text), -1);
12549
12521
  rb_define_method(SwigClassFont.klass, "draw_markup", VALUEFUNC(_wrap_Font_draw_markup), -1);
12550
12522
  rb_define_method(SwigClassFont.klass, "draw_text_rel", VALUEFUNC(_wrap_Font_draw_text_rel), -1);
data/src/TimingApple.cpp CHANGED
@@ -2,12 +2,6 @@
2
2
  #if defined(GOSU_IS_MAC)
3
3
 
4
4
  #include <Gosu/Timing.hpp>
5
- #include <unistd.h>
6
-
7
- void Gosu::sleep(unsigned milliseconds)
8
- {
9
- usleep(milliseconds * 1000);
10
- }
11
5
 
12
6
  // Thanks to this blog for the unconvoluted code example:
13
7
  // http://shiftedbits.org/2008/10/01/mach_absolute_time-on-the-iphone/
@@ -21,7 +15,7 @@ unsigned long Gosu::milliseconds()
21
15
  mach_timebase_info(&info);
22
16
  return mach_absolute_time();
23
17
  }();
24
-
18
+
25
19
  uint64_t runtime = mach_absolute_time() - first_tick;
26
20
  return runtime * info.numer / info.denom / 1000000;
27
21
  }
data/src/TimingUnix.cpp CHANGED
@@ -3,12 +3,6 @@
3
3
 
4
4
  #include <Gosu/Timing.hpp>
5
5
  #include <sys/time.h>
6
- #include <unistd.h>
7
-
8
- void Gosu::sleep(unsigned milliseconds)
9
- {
10
- usleep(milliseconds * 1000);
11
- }
12
6
 
13
7
  unsigned long Gosu::milliseconds()
14
8
  {
data/src/TimingWin.cpp CHANGED
@@ -2,14 +2,8 @@
2
2
  #if defined(GOSU_IS_WIN)
3
3
 
4
4
  #include <Gosu/Timing.hpp>
5
- #include <cstdlib>
6
5
  #include <windows.h>
7
6
 
8
- void Gosu::sleep(unsigned milliseconds)
9
- {
10
- Sleep(milliseconds);
11
- }
12
-
13
7
  unsigned long Gosu::milliseconds()
14
8
  {
15
9
  static unsigned long start = [] {
data/src/Window.cpp CHANGED
@@ -11,6 +11,7 @@
11
11
  #include <SDL.h>
12
12
  #include <algorithm>
13
13
  #include <stdexcept>
14
+ #include <thread>
14
15
 
15
16
  namespace Gosu
16
17
  {
@@ -272,10 +273,10 @@ void Gosu::Window::show()
272
273
  try {
273
274
  while (tick()) {
274
275
  // Sleep to keep this loop from eating 100% CPU.
275
- unsigned long tick_time = milliseconds() - time_before_tick;
276
- double sleep_time = update_interval() - tick_time;
276
+ long tick_time = milliseconds() - time_before_tick;
277
+ long sleep_time = static_cast<long>(update_interval() - tick_time);
277
278
  if (sleep_time >= 1) {
278
- sleep(static_cast<unsigned long>(sleep_time));
279
+ std::this_thread::sleep_for(std::chrono::milliseconds{sleep_time});
279
280
  }
280
281
 
281
282
  time_before_tick = milliseconds();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.