gosu 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed0ac66341075737207ca2339bf55a0fb6d32706
4
- data.tar.gz: 1dfdefbffd3829dfe825abdd1c83e8eae9a6037e
3
+ metadata.gz: a99fd67ed15c43d6baa549fcf60a0ad00b08bd7b
4
+ data.tar.gz: 9691a5d023c9f8e3f92862eed8fddf613916c53f
5
5
  SHA512:
6
- metadata.gz: 197fba0e97d66a57276e219fcf314dd57786b008b8779e9fc4b7ec89619e8b3874157581e5e1ba14272c5fe95e51706a606dac0152ebf56fbfcb43dd097026cc
7
- data.tar.gz: 3025dd68ae612cb1450aabbc728f63d60532ec46f85bc8fe65af53a6302474d26647901666c1dbe3c9c1a50e2204c9e1ba5d960eab5d9c53511600006ca3a523
6
+ metadata.gz: 6c0952e4ebd1c1120f02f9d3f41bf173bc659784b2a08549326f41d63b860b2b6102e754c54b50dfa94268825066b2bf5da5780a0b4b037598cdd6bdf604c27c
7
+ data.tar.gz: 1aaa547b027028f1db2ee54e10bfc5e6e6ddb8ec95df921778d753e07bcbd0cf4f213b83aaee5397ce893a6b943a92c71c202fd2c3258e09d3ec57b85deae14e
@@ -21,7 +21,7 @@ namespace Gosu
21
21
  {
22
22
  // Deprecated.
23
23
  #ifndef SWIG
24
- class GOSU_DEPRECATED Audio;
24
+ class Audio;
25
25
  #endif
26
26
 
27
27
  //! An instance of a Sample playing. Can be used to stop sounds dynamically,
@@ -3,8 +3,8 @@
3
3
 
4
4
  #define GOSU_MAJOR_VERSION 0
5
5
  #define GOSU_MINOR_VERSION 8
6
- #define GOSU_POINT_VERSION 6
7
- #define GOSU_VERSION "0.8.6"
6
+ #define GOSU_POINT_VERSION 7
7
+ #define GOSU_VERSION "0.8.7"
8
8
 
9
9
  #define GOSU_COPYRIGHT_NOTICE \
10
10
  "This software uses the following third-party libraries:\n" \
@@ -131,8 +131,8 @@ namespace Gosu
131
131
  virtual void touchEnded(Touch touch) {}
132
132
  #endif
133
133
 
134
- const Audio& audio() const;
135
- Audio& audio();
134
+ GOSU_DEPRECATED const Audio& audio() const;
135
+ GOSU_DEPRECATED Audio& audio();
136
136
 
137
137
  #endif
138
138
  };
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- WINDOWS_HINTS = %w(-win32 win32- mswin mingw32)
4
-
5
- if RUBY_PLATFORM =~ /mswin|mingw32|mingw64|win32\-|\-win32/ then
6
- puts 'This gem is not meant to be installed on Windows. Instead, please use:'
7
- puts 'gem install gosu --platform=i386-mingw32'
3
+ if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/ then
4
+ platform = (RUBY_PLATFORM =~ /^x64-/ ? 'x64-mingw32' : 'i386-mingw32')
5
+
6
+ puts "This gem is not meant to be installed on Windows. Instead, please use:"
7
+ puts "gem install gosu --platform=#{platform}"
8
8
  exit 1
9
9
  end
10
10
 
@@ -10876,8 +10876,8 @@ SWIGEXPORT void Init_gosu(void) {
10876
10876
  SWIG_RubyInitializeTrackings();
10877
10877
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
10878
10878
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(8)));
10879
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(6)));
10880
- rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.8.6"));
10879
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(7)));
10880
+ rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.8.7"));
10881
10881
  rb_define_const(mGosu, "GOSU_COPYRIGHT_NOTICE", SWIG_FromCharPtr("This software uses the following third-party libraries:\n\nGosu, http://www.libgosu.org, MIT License, http://opensource.org/licenses/MIT\nSDL 2, http://www.libsdl.org, MIT License, http://opensource.org/licenses/MIT\nFreeImage, http://freeimage.sourceforge.net, FreeImage Public License\nlibogg & libvorbis, http://www.xiph.org, BSD License, 3-Clause Version, http://www.xiph.org/licenses/bsd\nlibsndfile, http://www.mega-nerd.com/libsndfile, GNU LGPL 3, http://www.gnu.org/copyleft/lesser.html\nOpenAL Soft, http://kcat.strangesoft.net/openal.html, GNU LGPL 2, http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html\n"));
10882
10882
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
10883
10883
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
@@ -1,16 +1,19 @@
1
1
  require 'rbconfig'
2
2
 
3
- if RUBY_PLATFORM =~ /mswin|mingw32|mingw64|win32\-|\-win32/ then
4
- # Add this gem to the PATH on Windows so that DLLs can be found
5
- ENV['PATH'] = "#{File.dirname(__FILE__)};#{ENV['PATH']}"
6
- end
7
-
8
- begin
3
+ if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/ then
4
+ binary_path = File.dirname(__FILE__)
5
+ # 64-bit builds of Windows use "x64-mingw32" as RUBY_PLATFORM
6
+ binary_path += '64' if RUBY_PLATFORM =~ /^x64-/
7
+
8
+ # Add this gem to the PATH on Windows so that bundled DLLs can be found.
9
+ ENV['PATH'] = "#{binary_path};#{ENV['PATH']}"
10
+
11
+ # Add the correct directory
9
12
  RUBY_VERSION =~ /(\d+.\d+)/
10
- require "#{$1}/gosu.#{RbConfig::CONFIG['DLEXT']}"
11
- rescue LoadError
12
- require "gosu.#{RbConfig::CONFIG['DLEXT']}"
13
+ $LOAD_PATH.unshift "#{binary_path}/#{$1}"
13
14
  end
14
15
 
16
+ require "gosu.#{RbConfig::CONFIG['DLEXT']}"
17
+
15
18
  require "gosu/swig_patches"
16
19
  require "gosu/patches"
@@ -1,25 +1,25 @@
1
1
  require 'gosu'
2
2
 
3
- # Wrapper around Gosu 0.7 that provides the work-in-progress 0.8 interface
3
+ # Wrapper around Gosu 0.4-0.8 that provides the work-in-progress 0.9 interface
4
4
 
5
5
  module Gosu
6
6
  class Font
7
- alias :initialize07 :initialize
7
+ alias :initialize_old :initialize
8
8
 
9
9
  def initialize *args
10
10
  if args.first.is_a? Gosu::Window then
11
- initialize07 *args
11
+ initialize_old *args
12
12
  else
13
13
  height = args[0]
14
14
  options = args[1] || {}
15
15
  name = options[:name] || Gosu::default_font_name
16
- initialize07 $window, name, height
16
+ initialize_old $window, name, height
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
21
  class Window
22
- alias :initialize07 :initialize
22
+ alias :initialize_old :initialize
23
23
 
24
24
  def initialize width, height, *args
25
25
  if args.empty? or args.first.is_a? Hash then
@@ -29,40 +29,40 @@ module Gosu
29
29
  else
30
30
  fullscreen, update_interval = *args
31
31
  end
32
- $window = initialize07 width, height, fullscreen, update_interval
32
+ $window = initialize_old width, height, fullscreen, update_interval
33
33
  end
34
34
  end
35
35
 
36
36
  class Image
37
- alias :initialize07 :initialize
37
+ alias :initialize_old :initialize
38
38
 
39
39
  def initialize *args
40
40
  if args.first.is_a? Gosu::Window then
41
- initialize07 *args
41
+ initialize_old *args
42
42
  else
43
43
  source = args[0]
44
44
  tileable = !args[1] || args[1][:tileable]
45
45
  rect = args[1] && args[1][:rect]
46
46
  if rect then
47
- initialize07 $window, source, !!tileable, *rect
47
+ initialize_old $window, source, !!tileable, *rect
48
48
  else
49
- initialize07 $window, source, !!tileable
49
+ initialize_old $window, source, !!tileable
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  class <<self
55
- alias load_tiles07 load_tiles
55
+ alias load_tiles_old load_tiles
56
56
  end
57
57
 
58
58
  def self.load_tiles *args
59
59
  if args.first.is_a? Gosu::Window then
60
- load_tiles07 *args
60
+ load_tiles_old *args
61
61
  else
62
62
  source = args[0]
63
63
  x, y = args[1..2]
64
64
  tileable = !args[3] || args[3][:tileable]
65
- load_tiles07 $window, source, x, y, !!tileable
65
+ load_tiles_old $window, source, x, y, !!tileable
66
66
  end
67
67
  end
68
68
 
@@ -109,6 +109,10 @@ module Gosu
109
109
  $window.draw_quad *args
110
110
  end
111
111
 
112
+ def self.draw_rect x, y, width, height, color = 0xffffffff, z, mode = :default
113
+ $window.draw_quad x, y, color, x + width, y, color, x, y + height, color, x + width, y + height, color, z, mode
114
+ end
115
+
112
116
  def self.clip_to *args, &draw
113
117
  $window.clip_to *args, &draw
114
118
  end
@@ -55,9 +55,9 @@ namespace
55
55
  bool curSongLooping;
56
56
  }
57
57
 
58
- // TODO: What is the NSAutoreleasePool good for?
58
+ // TODO: What is this NSAutoreleasePool good for?
59
59
  #ifdef GOSU_IS_MAC
60
- #include "MacUtility.hpp"
60
+ #include "../MacUtility.hpp"
61
61
  #define CONSTRUCTOR_COMMON \
62
62
  ObjRef<NSAutoreleasePool> pool([[NSAutoreleasePool alloc] init]); \
63
63
  if (!alChannelManagement.get()) \
@@ -7,9 +7,9 @@
7
7
  #include <AudioToolbox/ExtendedAudioFile.h>
8
8
  #include <OpenAL/al.h>
9
9
  #include <Gosu/IO.hpp>
10
- #include "MacUtility.hpp"
11
10
  #include <Gosu/Utility.hpp>
12
11
  #include <Gosu/Platform.hpp>
12
+ #include "../MacUtility.hpp"
13
13
  #include <algorithm>
14
14
  #include <vector>
15
15
  #include <arpa/inet.h>
@@ -15,7 +15,7 @@ namespace Gosu
15
15
  Reader reader;
16
16
  Buffer buffer;
17
17
 
18
- // Cannot use /DELAYLOAD with libsndfile-1.dll because it was compiled
18
+ // Cannot use /DELAYLOAD with libsndfile.dll because it was compiled
19
19
  // using arcane GNU tools of dark magic (or maybe it's the filename).
20
20
  #ifdef GOSU_IS_WIN
21
21
  static HMODULE dll()
@@ -23,6 +23,7 @@ namespace Gosu
23
23
  static HMODULE dll = LoadLibrary(L"libsndfile.dll");
24
24
  if (!dll)
25
25
  throw std::runtime_error("Cannot find libsndfile.dll");
26
+
26
27
  return dll;
27
28
  }
28
29
 
@@ -4,7 +4,7 @@
4
4
  #include <Gosu/Platform.hpp>
5
5
  #include <Gosu/Utility.hpp>
6
6
 
7
- #include "MacUtility.hpp"
7
+ #include "../MacUtility.hpp"
8
8
  #include <stdexcept>
9
9
 
10
10
  #ifdef GOSU_IS_IPHONE
@@ -59,6 +59,15 @@ struct Gosu::Input::Impl
59
59
  int numGamepads = std::min<int>(Gosu::numGamepads, SDL_NumJoysticks());
60
60
 
61
61
  for (int i = 0; i < numGamepads; ++i) {
62
+ // Prefer the SDL_GameController API...
63
+ if (SDL_IsGameController(i)) {
64
+ SDL_GameController *gameController = SDL_GameControllerOpen(i);
65
+ if (gameController) {
66
+ gameControllers.push_back(gameController);
67
+ continue;
68
+ }
69
+ }
70
+ // ...but fall back on the good, old SDL_Joystick API :)
62
71
  SDL_Joystick *joystick = SDL_JoystickOpen(i);
63
72
  if (joystick) {
64
73
  joysticks.push_back(joystick);
@@ -66,55 +75,41 @@ struct Gosu::Input::Impl
66
75
  }
67
76
  }
68
77
 
78
+ void releaseGamepads()
79
+ {
80
+ std::for_each(joysticks.begin(), joysticks.end(), &SDL_JoystickClose);
81
+ joysticks.clear();
82
+ std::for_each(gameControllers.begin(), gameControllers.end(), &SDL_GameControllerClose);
83
+ gameControllers.clear();
84
+ }
85
+
86
+ typedef std::tr1::array<bool, gpNumPerGamepad> GamepadBuffer;
87
+
69
88
  void pollGamepads()
70
89
  {
71
- std::tr1::array<bool, gpNumPerGamepad> anyGamepad = { false };
90
+ // This gamepad is an OR-ed version of all the other gamepads. If button
91
+ // 3 is pressed on any attached gamepad, down(gpButton3) will return
92
+ // true. This is handy for singleplayer games.
93
+ GamepadBuffer anyGamepad = { false };
72
94
 
73
- for (int i = 0; i < joysticks.size(); ++i) {
74
- std::tr1::array<bool, gpNumPerGamepad> currentGamepad = { false };
75
-
76
- int axes = SDL_JoystickNumAxes(joysticks[i]),
77
- hats = SDL_JoystickNumHats(joysticks[i]),
78
- buttons = std::min<int>(gpNumPerGamepad - 4, SDL_JoystickNumButtons(joysticks[i]));
79
-
80
- for (int axis = 0; axis < axes; ++axis) {
81
- Sint16 value = SDL_JoystickGetAxis(joysticks[i], axis);
82
-
83
- if (value < -(1 << 14)) {
84
- if (axis % 2 == 0)
85
- currentGamepad[gpLeft - gpRangeBegin] = true;
86
- else
87
- currentGamepad[gpUp - gpRangeBegin] = true;
88
- }
89
- else if (value > +(1 << 14)) {
90
- if (axis % 2 == 0)
91
- currentGamepad[gpRight - gpRangeBegin] = true;
92
- else
93
- currentGamepad[gpDown - gpRangeBegin] = true;
94
- }
95
- }
95
+ std::size_t availableGamepads = gameControllers.size() + joysticks.size();
96
+
97
+ for (int i = 0; i < availableGamepads; ++i) {
98
+ GamepadBuffer currentGamepad = { false };
96
99
 
97
- for (int hat = 0; hat < hats; ++hat) {
98
- Uint8 value = SDL_JoystickGetHat(joysticks[i], hat);
99
-
100
- if (value == SDL_HAT_LEFT || value == SDL_HAT_LEFTUP || value == SDL_HAT_LEFTDOWN)
101
- currentGamepad[gpLeft - gpRangeBegin] = true;
102
- if (value == SDL_HAT_RIGHT || value == SDL_HAT_RIGHTUP || value == SDL_HAT_RIGHTDOWN)
103
- currentGamepad[gpRight - gpRangeBegin] = true;
104
- if (value == SDL_HAT_UP || value == SDL_HAT_LEFTUP || value == SDL_HAT_RIGHTUP)
105
- currentGamepad[gpUp - gpRangeBegin] = true;
106
- if (value == SDL_HAT_DOWN || value == SDL_HAT_LEFTDOWN || value == SDL_HAT_RIGHTDOWN)
107
- currentGamepad[gpDown - gpRangeBegin] = true;
100
+ // Poll data from SDL, using either of two API interfaces.
101
+ if (i < gameControllers.size()) {
102
+ SDL_GameController *gameController = gameControllers[i];
103
+ pollGameController(gameController, currentGamepad);
108
104
  }
109
-
110
- for (int button = 0; button < buttons; ++button) {
111
- if (SDL_JoystickGetButton(joysticks[i], button)) {
112
- currentGamepad[gpButton0 + button - gpRangeBegin] = true;
113
- }
105
+ else {
106
+ SDL_Joystick *joystick = joysticks[i];
107
+ pollJoystick(joystick, currentGamepad);
114
108
  }
115
109
 
110
+ // Now at the same time, enqueue all events for this particular
111
+ // gamepad, and OR the keyboard state into anyGamepad.
116
112
  int offset = gpRangeBegin + gpNumPerGamepad * (i + 1);
117
-
118
113
  for (int j = 0; j < currentGamepad.size(); ++j) {
119
114
  anyGamepad[j] = anyGamepad[j] || currentGamepad[j];
120
115
 
@@ -129,6 +124,7 @@ struct Gosu::Input::Impl
129
124
  }
130
125
  }
131
126
 
127
+ // And lastly, enqueue events for the virtual "any" gamepad.
132
128
  for (int j = 0; j < anyGamepad.size(); ++j) {
133
129
  if (anyGamepad[j] && !buttonStates[j + gpRangeBegin]) {
134
130
  buttonStates[j + gpRangeBegin] = true;
@@ -147,19 +143,98 @@ private:
147
143
  std::vector<int> eventQueue;
148
144
 
149
145
  std::vector<SDL_Joystick*> joysticks;
146
+ std::vector<SDL_GameController*> gameControllers;
147
+
148
+ // SDL returns axis values in the range -2^15 through 2^15-1, so we consider
149
+ // -2^14 through 2^14 the dead zone.
150
+
151
+ enum { DEAD_ZONE = (1 << 14) };
152
+
153
+ void pollGameController(SDL_GameController *gameController, GamepadBuffer& gamepad)
154
+ {
155
+ gamepad[gpLeft - gpRangeBegin] =
156
+ SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_DPAD_LEFT) ||
157
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTX) < -DEAD_ZONE ||
158
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTX) < -DEAD_ZONE;
159
+
160
+ gamepad[gpRight - gpRangeBegin] =
161
+ SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT) ||
162
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTX) > +DEAD_ZONE ||
163
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTX) > +DEAD_ZONE;
164
+
165
+ gamepad[gpUp - gpRangeBegin] =
166
+ SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_DPAD_UP) ||
167
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTY) < -DEAD_ZONE ||
168
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTY) < -DEAD_ZONE;
169
+
170
+ gamepad[gpDown - gpRangeBegin] =
171
+ SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_DPAD_DOWN) ||
172
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTY) > +DEAD_ZONE ||
173
+ SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_RIGHTY) > +DEAD_ZONE;
174
+
175
+ for (int button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_DPAD_UP; ++button) {
176
+ gamepad[gpButton0 - gpRangeBegin + button - SDL_CONTROLLER_BUTTON_A] =
177
+ SDL_GameControllerGetButton(gameController, (SDL_GameControllerButton)button);
178
+ }
179
+ }
180
+
181
+ void pollJoystick(SDL_Joystick *joystick, GamepadBuffer& gamepad)
182
+ {
183
+ int axes = SDL_JoystickNumAxes(joystick),
184
+ hats = SDL_JoystickNumHats(joystick),
185
+ buttons = std::min<int>(gpNumPerGamepad - 4, SDL_JoystickNumButtons(joystick));
186
+
187
+ for (int axis = 0; axis < axes; ++axis) {
188
+ Sint16 value = SDL_JoystickGetAxis(joystick, axis);
189
+
190
+ if (value < -DEAD_ZONE) {
191
+ if (axis % 2 == 0)
192
+ gamepad[gpLeft - gpRangeBegin] = true;
193
+ else
194
+ gamepad[gpUp - gpRangeBegin] = true;
195
+ }
196
+ else if (value > +DEAD_ZONE) {
197
+ if (axis % 2 == 0)
198
+ gamepad[gpRight - gpRangeBegin] = true;
199
+ else
200
+ gamepad[gpDown - gpRangeBegin] = true;
201
+ }
202
+ }
203
+
204
+ for (int hat = 0; hat < hats; ++hat) {
205
+ Uint8 value = SDL_JoystickGetHat(joystick, hat);
206
+
207
+ if (value & SDL_HAT_LEFT)
208
+ gamepad[gpLeft - gpRangeBegin] = true;
209
+ if (value & SDL_HAT_RIGHT)
210
+ gamepad[gpRight - gpRangeBegin] = true;
211
+ if (value & SDL_HAT_UP)
212
+ gamepad[gpUp - gpRangeBegin] = true;
213
+ if (value & SDL_HAT_DOWN)
214
+ gamepad[gpDown - gpRangeBegin] = true;
215
+ }
216
+
217
+ for (int button = 0; button < buttons; ++button) {
218
+ if (SDL_JoystickGetButton(joystick, button)) {
219
+ gamepad[gpButton0 + button - gpRangeBegin] = true;
220
+ }
221
+ }
222
+ }
150
223
  };
151
224
 
152
225
  Gosu::Input::Input()
153
226
  : pimpl(new Impl(*this))
154
227
  {
155
- SDL_InitSubSystem(SDL_INIT_JOYSTICK);
228
+ SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
156
229
 
157
230
  pimpl->initializeGamepads();
158
231
  }
159
232
 
160
233
  Gosu::Input::~Input()
161
234
  {
162
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
235
+ pimpl->releaseGamepads();
236
+
237
+ SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
163
238
  }
164
239
 
165
240
  bool Gosu::Input::feedSDLEvent(void* event)
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.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2015-01-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.