gosu 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d1640e560328b803317616abde6c301648daffb
4
- data.tar.gz: 419425be00ae9f09d1cc74702170f55f87ff563b
3
+ metadata.gz: 0e780ad64700f539c7956253b0900d69ab828562
4
+ data.tar.gz: bf9eea3a88a216860bac22d6cb2b16dddbe363b1
5
5
  SHA512:
6
- metadata.gz: 6ba0ce007bc4fdddd98887d1594f2b106e150fb50282dc859e517f1122a4853c6d8f3ca69cb8d34cde51914e2310c53eba1ba9873dde736fbac58e6dc0bcef32
7
- data.tar.gz: 2eb57895d03d4bfcbcc31c28ef79ef35fa5f78684dde4d1f7106b0914470bf2d70b27aa87b3df23e4432f367aa1bdbbd4883bb39e2915405b9b6aba79ed83775
6
+ metadata.gz: cae8120cd63eac622abf7a59a5c8e2735dc8d35f5c20a91f4189800d577736ff5eca92e22f1b295165f833f1dc546ada16fb3979a5c5624853242841baee4d8b
7
+ data.tar.gz: fee3c74049220d40390106f33f444d739b4d614bcdc253225aa6fc2445b936c0de5650c51e9bc34e3ff2c242e0e6d5a5ba782d8558eafbccfcb9f6a7b40e9b35
@@ -39,7 +39,7 @@ namespace Gosu
39
39
 
40
40
  //! Prepares the graphics object for drawing and then runs the rendering code in f.
41
41
  //! Nothing must be drawn outside of frame() and record().
42
- void frame(const std::function<void()>& f);
42
+ void frame(const std::function<void ()>& f);
43
43
 
44
44
  //! Flushes the Z queue to the screen and starts a new one.
45
45
  //! This can be useful to separate the Z queues of two parts of the game, e.g. the two
@@ -48,27 +48,27 @@ namespace Gosu
48
48
 
49
49
  //! Finishes all pending Gosu drawing operations and executes the code in f in a clean
50
50
  //! OpenGL environment.
51
- static void gl(const std::function<void()>& f);
51
+ static void gl(const std::function<void ()>& f);
52
52
 
53
53
  //! Schedules a custom GL functor to be executed at a certain Z level.
54
54
  //! The functor f is run in a clean GL context.
55
55
  //! Note: You may not call any Gosu rendering functions from within the
56
56
  //! functor.
57
- static void gl(ZPos z, const std::function<void()>& f);
57
+ static void gl(ZPos z, const std::function<void ()>& f);
58
58
 
59
59
  //! Renders everything drawn in f clipped to a rectangle on the screen.
60
60
  static void clip_to(double x, double y, double width, double height,
61
- const std::function<void()>& f);
61
+ const std::function<void ()>& f);
62
62
 
63
63
  //! Records a macro and returns it as an ImageData instance.
64
64
  //! Usually, the return value is passed to Image::Image().
65
65
  //! Cannot be nested.
66
66
  static std::unique_ptr<Gosu::ImageData> record(int width, int height,
67
- const std::function<void()>& f);
67
+ const std::function<void ()>& f);
68
68
 
69
69
  //! Pushes one transformation onto the transformation stack.
70
70
  static void transform(const Transform& transform,
71
- const std::function<void()>& f);
71
+ const std::function<void ()>& f);
72
72
 
73
73
  //! Draws a line from one point to another (last pixel exclusive).
74
74
  //! Note: OpenGL lines are not reliable at all and may have a missing pixel at the start
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 0
6
6
  #define GOSU_MINOR_VERSION 12
7
- #define GOSU_POINT_VERSION 0
7
+ #define GOSU_POINT_VERSION 1
8
8
 
9
9
  namespace Gosu
10
10
  {
@@ -1,14 +1,22 @@
1
- require "rbconfig"
1
+ require 'rbconfig'
2
2
 
3
3
  if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/
4
4
  binary_path = File.dirname(__FILE__)
5
5
  # 64-bit builds of Windows use "x64-mingw32" as RUBY_PLATFORM
6
6
  binary_path += "64" if RUBY_PLATFORM =~ /^x64-/
7
7
 
8
- # Add this gem to the PATH on Windows so that bundled DLLs can be found.
9
- # When running through Ocra on Windows, we need to be careful to preserve the ENV["PATH"]
10
- # encoding (see #385).
11
- ENV["PATH"] = "#{binary_path.encode ENV["PATH"].encoding};#{ENV["PATH"]}"
8
+ begin
9
+ # Make DLLs available as shown here:
10
+ # https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers
11
+ require 'ruby_installer'
12
+ RubyInstaller::Runtime.add_dll_directory(binary_path)
13
+ rescue LoadError
14
+ # Add this gem to the PATH on Windows so that bundled DLLs can be found.
15
+ # When running through Ocra on Windows, we need to be careful to preserve the ENV["PATH"]
16
+ # encoding (see #385).
17
+ path_encoding = ENV["PATH"].encoding
18
+ ENV["PATH"] = "#{binary_path.encode(path_encoding)};#{ENV["PATH"]}"
19
+ end
12
20
 
13
21
  # Add the correct lib directory for the current version of Ruby (major.minor).
14
22
  $LOAD_PATH.unshift File.join(binary_path, RUBY_VERSION[/^\d+.\d+/])
@@ -506,12 +506,10 @@ module Gosu
506
506
  ##
507
507
  # Plays the sample without panning.
508
508
  #
509
- # Playback speed is limited only by the underlying audio library, and both very large and very small values should work just fine.
510
- #
511
509
  # @return [SampleInstance]
512
- # @param volume [Float] the playback volume, in the range [0.0; 1.0], where 0 is completely silent and 1 is full volume.
513
- # @param speed [Float] the playback speed.
514
- # @param looping [true, false] whether the sample should play in a loop.
510
+ # @param volume [Float] see {SampleInstance#volume=}
511
+ # @param speed [Float] see {SampleInstance#speed=}
512
+ # @param looping [true, false] whether the sample should play in a loop. If you pass true, be sure to store the return value of this method so that you can later stop the looping sound.
515
513
  #
516
514
  # @see #play_pan
517
515
  def play(volume=1, speed=1, looping=false); end
@@ -519,11 +517,11 @@ module Gosu
519
517
  ##
520
518
  # Plays the sample with panning.
521
519
  #
522
- # @note Samples played with this method will not be as loud as those played with {#play}, even if `pan` is 0. This is due to a limitation in the way panning works.
523
- #
524
520
  # @return [SampleInstance]
525
- # @param pan [Float] the amount of panning. 0.0 is centered.
526
- # @param (see #play)
521
+ # @param pan [Float] see {SampleInstance#pan=}
522
+ # @param volume [Float] see {SampleInstance#volume=}
523
+ # @param speed [Float] see {SampleInstance#speed=}
524
+ # @param looping [true, false] whether the sample should play in a loop. If you pass true, be sure to store the return value of this method so that you can later stop the looping sound.
527
525
  #
528
526
  # @see #play
529
527
  def play_pan(pan=0, volume=1, speed=1, looping=false); end
@@ -534,8 +532,22 @@ module Gosu
534
532
  #
535
533
  # It is recommended to throw away sample instances as soon as possible, as holding onto them for a long time can prevent unneeded samples being properly disposed.
536
534
  class SampleInstance
535
+ ##
536
+ # Sets the playback volume, in the range [0.0; 1.0], where 0 is completely silent and 1 is full volume. Values outside of this range will be clamped to [0.0; 1.0].
537
+ # @param [Float]
538
+ # @return [Float]
537
539
  attr_writer :volume
540
+
541
+ ##
542
+ # Sets the playback speed. A value of 2.0 will play the sample at 200% speed and one octave higher. A value of 0.5 will play the sample at 50% speed and one octave lower. The valid range of this property depends on the operating system, but values up to 8.0 should work.
543
+ # @param [Float]
544
+ # @return [Float]
538
545
  attr_writer :speed
546
+
547
+ ##
548
+ # Set the amount of panning, i.e. the position of the sound when using stereo speakers. 0.0 is the centre, negative values are to the left, positive values are to the right. If something happens on the edge of the screen, a good value for pan would be ±0.1.
549
+ # @param [Float]
550
+ # @return [Float]
539
551
  attr_writer :pan
540
552
 
541
553
  ##
@@ -124,7 +124,7 @@ void Gosu::SampleInstance::change_volume(double volume)
124
124
  ALuint source = al_channel_management->source_if_still_playing(handle, extra);
125
125
  if (source == ALChannelManagement::NO_SOURCE) return;
126
126
 
127
- alSourcef(source, AL_GAIN, volume);
127
+ alSourcef(source, AL_GAIN, max(volume, 0.0));
128
128
  }
129
129
 
130
130
  void Gosu::SampleInstance::change_pan(double pan)
@@ -171,7 +171,7 @@ private:
171
171
  SampleData& operator=(const SampleData&);
172
172
  };
173
173
 
174
- Gosu::Sample::Sample(const std::string& filename)
174
+ Gosu::Sample::Sample(const string& filename)
175
175
  {
176
176
  CONSTRUCTOR_BEGIN;
177
177
 
@@ -201,12 +201,13 @@ Gosu::Sample::Sample(Reader reader)
201
201
  WAVE_FILE audio_file(reader);
202
202
  data.reset(new SampleData(audio_file));
203
203
  }
204
- catch (const std::runtime_error& ex) {
204
+ catch (const runtime_error& ex) {
205
205
  #ifndef GOSU_IS_MAC
206
- if (std::string(ex.what()).find("unknown format") != std::string::npos) {
206
+ if (string(ex.what()).find("unknown format") != string::npos) {
207
207
  MPEGFile mpeg_file(reader);
208
208
  data.reset(new SampleData(mpeg_file));
209
- } else
209
+ }
210
+ else
210
211
  #endif
211
212
  throw ex;
212
213
  }
@@ -223,7 +224,7 @@ Gosu::SampleInstance Gosu::Sample::play(double volume, double speed, bool loopin
223
224
  Gosu::SampleInstance Gosu::Sample::play_pan(double pan, double volume, double speed,
224
225
  bool looping) const
225
226
  {
226
- std::pair<int, int> channel_and_token = al_channel_management->reserve_channel();
227
+ pair<int, int> channel_and_token = al_channel_management->reserve_channel();
227
228
  if (channel_and_token.first == ALChannelManagement::NO_FREE_CHANNEL) {
228
229
  return Gosu::SampleInstance(channel_and_token.first, channel_and_token.second);
229
230
  }
@@ -233,7 +234,7 @@ Gosu::SampleInstance Gosu::Sample::play_pan(double pan, double volume, double sp
233
234
  assert (source != ALChannelManagement::NO_SOURCE);
234
235
  alSourcei(source, AL_BUFFER, data->buffer);
235
236
  alSource3f(source, AL_POSITION, pan * 10, 0, 0);
236
- alSourcef(source, AL_GAIN, volume);
237
+ alSourcef(source, AL_GAIN, max(volume, 0.0));
237
238
  alSourcef(source, AL_PITCH, speed);
238
239
  alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
239
240
  alSourcePlay(source);
@@ -285,7 +286,7 @@ class Gosu::Song::ModuleData : public BaseData
285
286
  }
286
287
 
287
288
  public:
288
- ModuleData(const std::string& filename)
289
+ ModuleData(const string& filename)
289
290
  {
290
291
  NSURL* URL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filename.c_str()]];
291
292
  player = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:nil];
@@ -330,14 +331,14 @@ public:
330
331
  // AudioFile impl
331
332
  class Gosu::Song::StreamData : public BaseData
332
333
  {
333
- std::unique_ptr<AudioFile> file;
334
+ unique_ptr<AudioFile> file;
334
335
  ALuint buffers[2];
335
336
 
336
337
  void apply_volume() override
337
338
  {
338
339
  int source = lookup_source();
339
340
  if (source != ALChannelManagement::NO_SOURCE) {
340
- alSourcef(source, AL_GAIN, volume());
341
+ alSourcef(source, AL_GAIN, max(volume(), 0.0));
341
342
  }
342
343
  }
343
344
 
@@ -354,7 +355,7 @@ class Gosu::Song::StreamData : public BaseData
354
355
  static const unsigned BUFFER_SIZE = 4096 * 8;
355
356
  #endif
356
357
  char audio_data[BUFFER_SIZE];
357
- std::size_t read_bytes = file->read_data(audio_data, BUFFER_SIZE);
358
+ size_t read_bytes = file->read_data(audio_data, BUFFER_SIZE);
358
359
  if (read_bytes > 0) {
359
360
  alBufferData(buffer, file->format(), audio_data,
360
361
  static_cast<ALsizei>(read_bytes), file->sample_rate());
@@ -363,7 +364,7 @@ class Gosu::Song::StreamData : public BaseData
363
364
  }
364
365
 
365
366
  public:
366
- StreamData(const std::string& filename)
367
+ StreamData(const string& filename)
367
368
  {
368
369
  if (is_ogg_file(filename)) {
369
370
  Gosu::File source_file(filename);
@@ -373,9 +374,9 @@ public:
373
374
  try {
374
375
  file.reset(new WAVE_FILE(filename));
375
376
  }
376
- catch (const std::runtime_error& ex) {
377
+ catch (const runtime_error& ex) {
377
378
  #ifndef GOSU_IS_MAC
378
- if (std::string(ex.what()).find("unknown format") != std::string::npos) {
379
+ if (string(ex.what()).find("unknown format") != string::npos) {
379
380
  Gosu::File source_file(filename);
380
381
  file.reset(new MPEGFile(source_file.front_reader()));
381
382
  }
@@ -396,9 +397,9 @@ public:
396
397
  try {
397
398
  file.reset(new WAVE_FILE(reader));
398
399
  }
399
- catch (const std::runtime_error& ex) {
400
+ catch (const runtime_error& ex) {
400
401
  #ifndef GOSU_IS_MAC
401
- if (std::string(ex.what()).find("unknown format") != std::string::npos) {
402
+ if (string(ex.what()).find("unknown format") != string::npos) {
402
403
  file.reset(new MPEGFile(reader));
403
404
  }
404
405
  else
@@ -421,7 +422,7 @@ public:
421
422
  int source = lookup_source();
422
423
  if (source != ALChannelManagement::NO_SOURCE) {
423
424
  alSource3f(source, AL_POSITION, 0, 0, 0);
424
- alSourcef(source, AL_GAIN, volume());
425
+ alSourcef(source, AL_GAIN, max(volume(), 0.0));
425
426
  alSourcef(source, AL_PITCH, 1);
426
427
  alSourcei(source, AL_LOOPING, AL_FALSE); // need to implement this manually...
427
428
 
@@ -521,7 +522,7 @@ public:
521
522
  }
522
523
  };
523
524
 
524
- Gosu::Song::Song(const std::string& filename)
525
+ Gosu::Song::Song(const string& filename)
525
526
  {
526
527
  #ifdef GOSU_IS_IPHONE
527
528
  if (has_extension(filename, ".mp3") ||
@@ -32,7 +32,8 @@ namespace
32
32
  // Hue.
33
33
  if (delta == 0) {
34
34
  hsv.h = 0;
35
- } else if (r == max) {
35
+ }
36
+ else if (r == max) {
36
37
  hsv.h = (g - b) / delta + (g < b ? 6 : 0);
37
38
  }
38
39
  else if (g == max) {
@@ -141,7 +141,7 @@ void Gosu::Graphics::set_resolution(unsigned virtual_width, unsigned virtual_hei
141
141
  pimpl->update_base_transform();
142
142
  }
143
143
 
144
- void Gosu::Graphics::frame(const std::function<void()>& f)
144
+ void Gosu::Graphics::frame(const std::function<void ()>& f)
145
145
  {
146
146
  if (current_graphics_pointer != nullptr) {
147
147
  throw std::logic_error("Cannot nest calls to Gosu::Graphics::begin()");
@@ -222,7 +222,7 @@ void Gosu::Graphics::flush()
222
222
  current_queue().clear_queue();
223
223
  }
224
224
 
225
- void Gosu::Graphics::gl(const std::function<void()>& f)
225
+ void Gosu::Graphics::gl(const std::function<void ()>& f)
226
226
  {
227
227
  if (current_queue().recording()) {
228
228
  throw std::logic_error("Custom OpenGL is not allowed while creating a macro");
@@ -258,7 +258,7 @@ void Gosu::Graphics::gl(Gosu::ZPos z, const std::function<void ()>& f)
258
258
  }
259
259
 
260
260
  void Gosu::Graphics::clip_to(double x, double y, double width, double height,
261
- const std::function<void()>& f)
261
+ const std::function<void ()>& f)
262
262
  {
263
263
  double screen_height = current_graphics().pimpl->phys_height;
264
264
  current_queue().begin_clipping(x, y, width, height, screen_height);
@@ -267,7 +267,7 @@ void Gosu::Graphics::clip_to(double x, double y, double width, double height,
267
267
  }
268
268
 
269
269
  std::unique_ptr<Gosu::ImageData> Gosu::Graphics::record(int width, int height,
270
- const std::function<void()>& f)
270
+ const std::function<void ()>& f)
271
271
  {
272
272
  queues.resize(queues.size() + 1);
273
273
  current_queue().set_recording();
@@ -280,7 +280,7 @@ std::unique_ptr<Gosu::ImageData> Gosu::Graphics::record(int width, int height,
280
280
  }
281
281
 
282
282
  void Gosu::Graphics::transform(const Gosu::Transform& transform,
283
- const std::function<void()>& f)
283
+ const std::function<void ()>& f)
284
284
  {
285
285
  current_queue().push_transform(transform);
286
286
  f();
@@ -19,7 +19,7 @@ static void require_sdl_video()
19
19
  std::atexit([] { SDL_QuitSubSystem(SDL_INIT_VIDEO); });
20
20
  }
21
21
  }
22
-
22
+
23
23
  static std::array<bool, Gosu::NUM_BUTTONS> button_states = { { false } };
24
24
 
25
25
  struct Gosu::Input::Impl
@@ -13,7 +13,7 @@ Gosu::LargeImageData::LargeImageData(const Bitmap& source, int tile_width, int t
13
13
  tiles_x = static_cast<int>(ceil(1.0 * w / tile_width));
14
14
  tiles_y = static_cast<int>(ceil(1.0 * h / tile_height));
15
15
 
16
- // When there are no tiles, set both fields to 0 to avoid entering any for() loop in this class.
16
+ // When there are no tiles, set both fields to 0 to avoid entering any for () loop in this class.
17
17
  if (tiles_x == 0 || tiles_y == 0) {
18
18
  tiles_x = tiles_y = 0;
19
19
  }
@@ -11627,7 +11627,7 @@ SWIGEXPORT void Init_gosu(void) {
11627
11627
  rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
11628
11628
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11629
11629
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(12)));
11630
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(0)));
11630
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(1)));
11631
11631
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11632
11632
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11633
11633
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -260,7 +260,7 @@ bool Gosu::Window::tick()
260
260
  break;
261
261
  }
262
262
  case (SDL_DROPFILE): {
263
- char* dropped_filedir = e.drop.file;
263
+ char* dropped_filedir = e.drop.file;
264
264
  if (dropped_filedir == nullptr) break;
265
265
  drop(std::string(dropped_filedir));
266
266
  SDL_free(dropped_filedir);
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: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2017-06-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.