gosu 0.10.9.pre1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +35 -66
  3. data/Gosu/AutoLink.hpp +14 -16
  4. data/Gosu/Bitmap.hpp +50 -37
  5. data/Gosu/Buttons.hpp +246 -265
  6. data/Gosu/Color.hpp +32 -76
  7. data/Gosu/Directories.hpp +14 -17
  8. data/Gosu/Font.hpp +28 -34
  9. data/Gosu/Fwd.hpp +27 -31
  10. data/Gosu/Gosu.hpp +2 -5
  11. data/Gosu/Graphics.hpp +31 -48
  12. data/Gosu/GraphicsBase.hpp +27 -58
  13. data/Gosu/IO.hpp +44 -56
  14. data/Gosu/Image.hpp +29 -73
  15. data/Gosu/ImageData.hpp +13 -17
  16. data/Gosu/Input.hpp +42 -57
  17. data/Gosu/Inspection.hpp +2 -6
  18. data/Gosu/Math.hpp +32 -38
  19. data/Gosu/Platform.hpp +10 -29
  20. data/Gosu/Text.hpp +30 -39
  21. data/Gosu/TextInput.hpp +29 -36
  22. data/Gosu/Timing.hpp +14 -16
  23. data/Gosu/Utility.hpp +10 -15
  24. data/Gosu/Version.hpp +13 -14
  25. data/Gosu/Window.hpp +53 -68
  26. data/README.md +23 -11
  27. data/ext/gosu/extconf.rb +31 -81
  28. data/lib/gosu/patches.rb +35 -19
  29. data/lib/gosu/run.rb +13 -4
  30. data/rdoc/gosu.rb +24 -20
  31. data/src/ALChannelManagement.hpp +119 -0
  32. data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
  33. data/src/AudioFile.hpp +57 -0
  34. data/src/AudioToolboxFile.hpp +214 -0
  35. data/src/Bitmap.cpp +159 -0
  36. data/src/BitmapIO.cpp +141 -0
  37. data/src/BlockAllocator.cpp +133 -0
  38. data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
  39. data/src/ClipRectStack.hpp +87 -0
  40. data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
  41. data/src/DirectoriesApple.cpp +68 -0
  42. data/src/DirectoriesUnix.cpp +20 -18
  43. data/src/DirectoriesWin.cpp +40 -41
  44. data/src/DrawOp.hpp +168 -0
  45. data/src/DrawOpQueue.hpp +190 -0
  46. data/src/FileUnix.cpp +40 -46
  47. data/src/FileWin.cpp +42 -38
  48. data/src/Font.cpp +165 -0
  49. data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
  50. data/src/GosuAppDelegate.cpp +30 -0
  51. data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
  52. data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
  53. data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
  54. data/src/GosuViewController.cpp +231 -0
  55. data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
  56. data/src/Graphics.cpp +464 -0
  57. data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
  58. data/src/IO.cpp +17 -16
  59. data/src/Iconv.hpp +13 -22
  60. data/src/Image.cpp +142 -0
  61. data/src/Input.cpp +459 -0
  62. data/src/InputUIKit.cpp +197 -0
  63. data/src/Inspection.cpp +4 -5
  64. data/src/LargeImageData.cpp +151 -0
  65. data/src/LargeImageData.hpp +43 -0
  66. data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
  67. data/src/Macro.hpp +30 -0
  68. data/src/Math.cpp +17 -29
  69. data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
  70. data/src/RenderState.hpp +205 -0
  71. data/src/Resolution.cpp +86 -0
  72. data/src/ResolutionApple.cpp +25 -0
  73. data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
  74. data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
  75. data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
  76. data/src/TexChunk.cpp +117 -0
  77. data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
  78. data/src/Text.cpp +371 -0
  79. data/src/TextApple.cpp +209 -0
  80. data/src/TextInput.cpp +278 -0
  81. data/src/TextTTFWin.cpp +251 -0
  82. data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
  83. data/src/TextWin.cpp +194 -0
  84. data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
  85. data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
  86. data/src/TimingApple.cpp +11 -7
  87. data/src/TimingUnix.cpp +13 -7
  88. data/src/TimingWin.cpp +6 -1
  89. data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
  90. data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
  91. data/src/Utility.cpp +29 -70
  92. data/src/UtilityApple.cpp +52 -0
  93. data/src/UtilityWin.cpp +7 -4
  94. data/src/Version.cpp +22 -0
  95. data/src/WinMain.cpp +30 -33
  96. data/src/WinUtility.cpp +24 -22
  97. data/src/WinUtility.hpp +11 -20
  98. data/src/Window.cpp +142 -112
  99. data/src/WindowUIKit.cpp +155 -0
  100. data/src/stb_image.h +384 -173
  101. data/src/stb_vorbis.c +20 -18
  102. metadata +60 -62
  103. data/Gosu/TR1.hpp +0 -56
  104. data/src/AppleUtility.hpp +0 -66
  105. data/src/Audio/ALChannelManagement.hpp +0 -114
  106. data/src/Audio/Audio.mm +0 -1
  107. data/src/Audio/AudioFile.hpp +0 -53
  108. data/src/Audio/AudioToolboxFile.hpp +0 -207
  109. data/src/Bitmap/Bitmap.cpp +0 -183
  110. data/src/Bitmap/BitmapIO.cpp +0 -176
  111. data/src/DirectoriesApple.mm +0 -71
  112. data/src/Graphics/BlockAllocator.cpp +0 -142
  113. data/src/Graphics/ClipRectStack.hpp +0 -93
  114. data/src/Graphics/DrawOp.hpp +0 -175
  115. data/src/Graphics/DrawOpQueue.hpp +0 -188
  116. data/src/Graphics/Graphics.cpp +0 -478
  117. data/src/Graphics/Image.cpp +0 -193
  118. data/src/Graphics/LargeImageData.cpp +0 -133
  119. data/src/Graphics/LargeImageData.hpp +0 -46
  120. data/src/Graphics/Macro.hpp +0 -36
  121. data/src/Graphics/RenderState.hpp +0 -211
  122. data/src/Graphics/Resolution.cpp +0 -91
  123. data/src/Graphics/ResolutionApple.mm +0 -19
  124. data/src/Graphics/TexChunk.cpp +0 -112
  125. data/src/Input/Input.cpp +0 -463
  126. data/src/Input/InputUIKit.mm +0 -190
  127. data/src/Input/TextInput.cpp +0 -261
  128. data/src/Text/Font.cpp +0 -175
  129. data/src/Text/Text.cpp +0 -391
  130. data/src/Text/TextApple.mm +0 -227
  131. data/src/Text/TextTTFWin.cpp +0 -249
  132. data/src/Text/TextWin.cpp +0 -186
  133. data/src/UIKit/GosuAppDelegate.mm +0 -24
  134. data/src/UIKit/GosuViewController.mm +0 -211
  135. data/src/UtilityApple.mm +0 -63
  136. data/src/WindowUIKit.mm +0 -139
@@ -1,12 +1,10 @@
1
1
  #include "ALChannelManagement.hpp"
2
2
  #include "OggFile.hpp"
3
-
4
3
  #include <Gosu/Audio.hpp>
5
4
  #include <Gosu/Math.hpp>
6
5
  #include <Gosu/IO.hpp>
7
- #include <Gosu/Utility.hpp>
8
6
  #include <Gosu/Platform.hpp>
9
-
7
+ #include <Gosu/Utility.hpp>
10
8
  #include <cassert>
11
9
  #include <cstdlib>
12
10
  #include <algorithm>
@@ -35,39 +33,35 @@ using namespace std;
35
33
 
36
34
  namespace
37
35
  {
38
- using namespace Gosu;
39
-
40
- bool isOggFile(Gosu::Reader reader)
36
+ bool is_ogg_file(Gosu::Reader reader)
41
37
  {
42
- char magicBytes[4];
43
- reader.read(magicBytes, 4);
44
- return magicBytes[0] == 'O' && magicBytes[1] == 'g' &&
45
- magicBytes[2] == 'g' && magicBytes[3] == 'S';
38
+ char magic_bytes[4];
39
+ reader.read(magic_bytes, 4);
40
+ return magic_bytes[0] == 'O' && magic_bytes[1] == 'g' &&
41
+ magic_bytes[2] == 'g' && magic_bytes[3] == 'S';
46
42
  }
47
43
 
48
- bool isOggFile(const wstring& filename)
44
+ bool is_ogg_file(const string& filename)
49
45
  {
50
46
  Gosu::File file(filename);
51
- return isOggFile(file.frontReader());
47
+ return is_ogg_file(file.front_reader());
52
48
  }
53
49
 
54
- Song* curSong = 0;
55
- bool curSongLooping;
50
+ Gosu::Song* cur_song = nullptr;
51
+ bool cur_song_looping;
56
52
  }
57
53
 
58
- // TODO: What is this NSAutoreleasePool good for?
59
54
  #ifdef GOSU_IS_MAC
60
- #include "../AppleUtility.hpp"
61
55
  #define CONSTRUCTOR_BEGIN \
62
56
  @autoreleasepool { \
63
- if (!alChannelManagement.get()) \
64
- alChannelManagement.reset(new ALChannelManagement)
57
+ if (!al_channel_management.get()) \
58
+ al_channel_management.reset(new ALChannelManagement)
65
59
  #define CONSTRUCTOR_END \
66
60
  }
67
61
  #else
68
62
  #define CONSTRUCTOR_BEGIN \
69
- if (!alChannelManagement.get()) \
70
- alChannelManagement.reset(new ALChannelManagement)
63
+ if (!al_channel_management.get()) \
64
+ al_channel_management.reset(new ALChannelManagement)
71
65
  #define CONSTRUCTOR_END
72
66
  #endif
73
67
 
@@ -78,9 +72,9 @@ Gosu::SampleInstance::SampleInstance(int handle, int extra)
78
72
 
79
73
  bool Gosu::SampleInstance::playing() const
80
74
  {
81
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
82
- if (source == ALChannelManagement::NO_SOURCE)
83
- return false;
75
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
76
+ if (source == ALChannelManagement::NO_SOURCE) return false;
77
+
84
78
  ALint state;
85
79
  alGetSourcei(source, AL_SOURCE_STATE, &state);
86
80
  return state == AL_PLAYING;
@@ -88,9 +82,9 @@ bool Gosu::SampleInstance::playing() const
88
82
 
89
83
  bool Gosu::SampleInstance::paused() const
90
84
  {
91
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
92
- if (source == ALChannelManagement::NO_SOURCE)
93
- return false;
85
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
86
+ if (source == ALChannelManagement::NO_SOURCE) return false;
87
+
94
88
  ALint state;
95
89
  alGetSourcei(source, AL_SOURCE_STATE, &state);
96
90
  return state == AL_PAUSED;
@@ -98,52 +92,53 @@ bool Gosu::SampleInstance::paused() const
98
92
 
99
93
  void Gosu::SampleInstance::pause()
100
94
  {
101
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
102
- if (source == ALChannelManagement::NO_SOURCE)
103
- return;
95
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
96
+ if (source == ALChannelManagement::NO_SOURCE) return;
97
+
104
98
  alSourcePause(source);
105
99
  }
106
100
 
107
101
  void Gosu::SampleInstance::resume()
108
102
  {
109
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
110
- if (source == ALChannelManagement::NO_SOURCE)
111
- return;
103
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
104
+ if (source == ALChannelManagement::NO_SOURCE) return;
105
+
112
106
  ALint state;
113
107
  alGetSourcei(source, AL_SOURCE_STATE, &state);
114
- if (state == AL_PAUSED)
108
+ if (state == AL_PAUSED) {
115
109
  alSourcePlay(source);
110
+ }
116
111
  }
117
112
 
118
113
  void Gosu::SampleInstance::stop()
119
114
  {
120
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
121
- if (source == ALChannelManagement::NO_SOURCE)
122
- return;
115
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
116
+ if (source == ALChannelManagement::NO_SOURCE) return;
117
+
123
118
  alSourceStop(source);
124
119
  }
125
120
 
126
- void Gosu::SampleInstance::changeVolume(double volume)
121
+ void Gosu::SampleInstance::change_volume(double volume)
127
122
  {
128
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
129
- if (source == ALChannelManagement::NO_SOURCE)
130
- return;
123
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
124
+ if (source == ALChannelManagement::NO_SOURCE) return;
125
+
131
126
  alSourcef(source, AL_GAIN, volume);
132
127
  }
133
128
 
134
- void Gosu::SampleInstance::changePan(double pan)
129
+ void Gosu::SampleInstance::change_pan(double pan)
135
130
  {
136
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
137
- if (source == ALChannelManagement::NO_SOURCE)
138
- return;
131
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
132
+ if (source == ALChannelManagement::NO_SOURCE) return;
133
+
139
134
  alSource3f(source, AL_POSITION, pan * 10, 0, 0);
140
135
  }
141
136
 
142
- void Gosu::SampleInstance::changeSpeed(double speed)
137
+ void Gosu::SampleInstance::change_speed(double speed)
143
138
  {
144
- ALuint source = alChannelManagement->sourceIfStillPlaying(handle, extra);
145
- if (source == ALChannelManagement::NO_SOURCE)
146
- return;
139
+ ALuint source = al_channel_management->source_if_still_playing(handle, extra);
140
+ if (source == ALChannelManagement::NO_SOURCE) return;
141
+
147
142
  alSourcef(source, AL_PITCH, speed);
148
143
  }
149
144
 
@@ -151,23 +146,22 @@ struct Gosu::Sample::SampleData
151
146
  {
152
147
  ALuint buffer, source;
153
148
 
154
- SampleData(AudioFile& audioFile)
149
+ SampleData(AudioFile& audio_file)
155
150
  {
156
151
  alGenBuffers(1, &buffer);
157
- alBufferData(buffer,
158
- audioFile.format(),
159
- &audioFile.decodedData().front(),
160
- (ALsizei)audioFile.decodedData().size(),
161
- audioFile.sampleRate());
152
+ alBufferData(buffer, audio_file.format(), &audio_file.decoded_data().front(),
153
+ static_cast<ALsizei>(audio_file.decoded_data().size()),
154
+ audio_file.sample_rate());
162
155
  }
163
156
 
164
157
  ~SampleData()
165
158
  {
166
159
  // It's hard to free things in the right order in Ruby/Gosu.
167
160
  // Make sure buffer isn't deleted after the context/device are shut down.
168
- if (!alChannelManagement.get())
161
+ if (!al_channel_management.get()) {
169
162
  return;
170
-
163
+ }
164
+
171
165
  alDeleteBuffers(1, &buffer);
172
166
  }
173
167
 
@@ -176,60 +170,56 @@ private:
176
170
  SampleData& operator=(const SampleData&);
177
171
  };
178
172
 
179
- Gosu::Sample::Sample(const std::wstring& filename)
173
+ Gosu::Sample::Sample(const std::string& filename)
180
174
  {
181
175
  CONSTRUCTOR_BEGIN;
182
176
 
183
- if (isOggFile(filename))
184
- {
177
+ if (is_ogg_file(filename)) {
185
178
  Gosu::Buffer buffer;
186
- Gosu::loadFile(buffer, filename);
187
- OggFile oggFile(buffer.frontReader());
188
- data.reset(new SampleData(oggFile));
179
+ Gosu::load_file(buffer, filename);
180
+ OggFile ogg_file(buffer.front_reader());
181
+ data.reset(new SampleData(ogg_file));
189
182
  }
190
- else
191
- {
192
- WAVE_FILE audioFile(filename);
193
- data.reset(new SampleData(audioFile));
183
+ else {
184
+ WAVE_FILE audio_file(filename);
185
+ data.reset(new SampleData(audio_file));
194
186
  }
195
187
 
196
- CONSTRUCTOR_END
188
+ CONSTRUCTOR_END;
197
189
  }
198
190
 
199
191
  Gosu::Sample::Sample(Reader reader)
200
192
  {
201
193
  CONSTRUCTOR_BEGIN;
202
194
 
203
- if (isOggFile(reader))
204
- {
205
- OggFile oggFile(reader);
206
- data.reset(new SampleData(oggFile));
195
+ if (is_ogg_file(reader)) {
196
+ OggFile ogg_file(reader);
197
+ data.reset(new SampleData(ogg_file));
207
198
  }
208
- else
209
- {
210
- WAVE_FILE audioFile(reader);
211
- data.reset(new SampleData(audioFile));
199
+ else {
200
+ WAVE_FILE audio_file(reader);
201
+ data.reset(new SampleData(audio_file));
212
202
  }
213
203
 
214
- CONSTRUCTOR_END
204
+ CONSTRUCTOR_END;
215
205
  }
216
206
 
217
- Gosu::SampleInstance Gosu::Sample::play(double volume, double speed,
218
- bool looping) const
207
+ Gosu::SampleInstance Gosu::Sample::play(double volume, double speed, bool looping) const
219
208
  {
220
- return playPan(0, volume, speed, looping);
209
+ return play_pan(0, volume, speed, looping);
221
210
  }
222
211
 
223
- Gosu::SampleInstance Gosu::Sample::playPan(double pan, double volume,
224
- double speed, bool looping) const
212
+ Gosu::SampleInstance Gosu::Sample::play_pan(double pan, double volume, double speed,
213
+ bool looping) const
225
214
  {
226
- std::pair<int, int> channelAndToken = alChannelManagement->reserveChannel();
227
- if (channelAndToken.first == ALChannelManagement::NO_FREE_CHANNEL)
228
- return Gosu::SampleInstance(channelAndToken.first, channelAndToken.second);
215
+ std::pair<int, int> channel_and_token = al_channel_management->reserve_channel();
216
+ if (channel_and_token.first == ALChannelManagement::NO_FREE_CHANNEL) {
217
+ return Gosu::SampleInstance(channel_and_token.first, channel_and_token.second);
218
+ }
229
219
 
230
- ALuint source = alChannelManagement->sourceIfStillPlaying(channelAndToken.first,
231
- channelAndToken.second);
232
- assert(source != ALChannelManagement::NO_SOURCE);
220
+ ALuint source = al_channel_management->source_if_still_playing(channel_and_token.first,
221
+ channel_and_token.second);
222
+ assert (source != ALChannelManagement::NO_SOURCE);
233
223
  alSourcei(source, AL_BUFFER, data->buffer);
234
224
  // TODO: This is not the old panning behavior!
235
225
  alSource3f(source, AL_POSITION, pan * 10, 0, 0);
@@ -238,7 +228,7 @@ Gosu::SampleInstance Gosu::Sample::playPan(double pan, double volume,
238
228
  alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
239
229
  alSourcePlay(source);
240
230
 
241
- return Gosu::SampleInstance(channelAndToken.first, channelAndToken.second);
231
+ return Gosu::SampleInstance(channel_and_token.first, channel_and_token.second);
242
232
  }
243
233
 
244
234
  class Gosu::Song::BaseData
@@ -250,17 +240,15 @@ class Gosu::Song::BaseData
250
240
 
251
241
  protected:
252
242
  BaseData() : volume_(1) {}
253
- virtual void applyVolume() = 0;
243
+ virtual void apply_volume() = 0;
254
244
 
255
245
  public:
256
246
  virtual ~BaseData() {}
257
-
258
247
  virtual void play(bool looping) = 0;
259
248
  virtual void pause() = 0;
260
249
  virtual void resume() = 0;
261
250
  virtual bool paused() const = 0;
262
251
  virtual void stop() = 0;
263
-
264
252
  virtual void update() = 0;
265
253
 
266
254
  double volume() const
@@ -268,10 +256,10 @@ public:
268
256
  return volume_;
269
257
  }
270
258
 
271
- void changeVolume(double volume)
259
+ void change_volume(double volume)
272
260
  {
273
261
  volume_ = clamp(volume, 0.0, 1.0);
274
- applyVolume();
262
+ apply_volume();
275
263
  }
276
264
  };
277
265
 
@@ -279,19 +267,18 @@ public:
279
267
  // AVAudioPlayer impl
280
268
  class Gosu::Song::ModuleData : public BaseData
281
269
  {
282
- AVAudioPlayer *player;
270
+ AVAudioPlayer* player;
283
271
 
284
- void applyVolume()
272
+ void apply_volume()
285
273
  {
286
274
  player.volume = volume();
287
275
  }
288
276
 
289
277
  public:
290
- ModuleData(const std::wstring& filename)
278
+ ModuleData(const std::string& filename)
291
279
  {
292
- std::string utf8Filename = Gosu::wstringToUTF8(filename);
293
- NSURL *URL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:utf8Filename.c_str()]];
294
- player = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:NULL];
280
+ NSURL* URL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filename.c_str()]];
281
+ player = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:nil];
295
282
  }
296
283
 
297
284
  void play(bool looping)
@@ -333,77 +320,80 @@ public:
333
320
  // AudioFile impl
334
321
  class Gosu::Song::StreamData : public BaseData
335
322
  {
336
- GOSU_UNIQUE_PTR<AudioFile> file;
323
+ std::unique_ptr<AudioFile> file;
337
324
  ALuint buffers[2];
338
325
 
339
- void applyVolume()
326
+ void apply_volume()
340
327
  {
341
- int source = lookupSource();
342
- if (source != ALChannelManagement::NO_SOURCE)
328
+ int source = lookup_source();
329
+ if (source != ALChannelManagement::NO_SOURCE) {
343
330
  alSourcef(source, AL_GAIN, volume());
331
+ }
344
332
  }
345
333
 
346
- int lookupSource() const
334
+ int lookup_source() const
347
335
  {
348
- return alChannelManagement->sourceForSongs();
336
+ return al_channel_management->source_for_songs();
349
337
  }
350
338
 
351
- bool streamToBuffer(ALuint buffer)
339
+ bool stream_to_buffer(ALuint buffer)
352
340
  {
353
341
  #ifdef GOSU_IS_IPHONE
354
342
  static const unsigned BUFFER_SIZE = 4096 * 4;
355
343
  #else
356
344
  static const unsigned BUFFER_SIZE = 4096 * 8;
357
345
  #endif
358
- char audioData[BUFFER_SIZE];
359
- std::size_t readBytes = file->readData(audioData, BUFFER_SIZE);
360
- if (readBytes > 0)
361
- alBufferData(buffer, file->format(), audioData, (ALsizei)readBytes, file->sampleRate());
362
- return readBytes > 0;
346
+ char audio_data[BUFFER_SIZE];
347
+ std::size_t read_bytes = file->read_data(audio_data, BUFFER_SIZE);
348
+ if (read_bytes > 0) {
349
+ alBufferData(buffer, file->format(), audio_data,
350
+ static_cast<ALsizei>(read_bytes), file->sample_rate());
351
+ }
352
+ return read_bytes > 0;
363
353
  }
364
354
 
365
355
  public:
366
- StreamData(const std::wstring& filename)
356
+ StreamData(const std::string& filename)
367
357
  {
368
- if (isOggFile(filename))
369
- {
370
- Gosu::File sourceFile(filename);
371
- file.reset(new OggFile(sourceFile.frontReader()));
358
+ if (is_ogg_file(filename)) {
359
+ Gosu::File source_file(filename);
360
+ file.reset(new OggFile(source_file.front_reader()));
372
361
  }
373
- else
362
+ else {
374
363
  file.reset(new WAVE_FILE(filename));
364
+ }
375
365
  alGenBuffers(2, buffers);
376
366
  }
377
367
 
378
368
  StreamData(Reader reader)
379
369
  {
380
- if (isOggFile(reader))
370
+ if (is_ogg_file(reader)) {
381
371
  file.reset(new OggFile(reader));
382
- else
372
+ }
373
+ else {
383
374
  file.reset(new WAVE_FILE(reader));
375
+ }
384
376
  alGenBuffers(2, buffers);
385
377
  }
386
378
 
387
379
  ~StreamData()
388
380
  {
389
- if (alChannelManagement.get())
390
- {
381
+ if (al_channel_management.get()) {
391
382
  alDeleteBuffers(2, buffers);
392
383
  }
393
384
  }
394
385
 
395
386
  void play(bool looping)
396
387
  {
397
- int source = lookupSource();
398
- if (source != ALChannelManagement::NO_SOURCE)
399
- {
388
+ int source = lookup_source();
389
+ if (source != ALChannelManagement::NO_SOURCE) {
400
390
  alSource3f(source, AL_POSITION, 0, 0, 0);
401
391
  alSourcef(source, AL_GAIN, volume());
402
392
  alSourcef(source, AL_PITCH, 1);
403
393
  alSourcei(source, AL_LOOPING, AL_FALSE); // need to implement this manually...
404
394
 
405
- streamToBuffer(buffers[0]);
406
- streamToBuffer(buffers[1]);
395
+ stream_to_buffer(buffers[0]);
396
+ stream_to_buffer(buffers[1]);
407
397
 
408
398
  // TODO: Not good for songs with less than two buffers full of data.
409
399
 
@@ -414,9 +404,8 @@ public:
414
404
 
415
405
  void stop()
416
406
  {
417
- int source = lookupSource();
418
- if (source != ALChannelManagement::NO_SOURCE)
419
- {
407
+ int source = lookup_source();
408
+ if (source != ALChannelManagement::NO_SOURCE) {
420
409
  alSourceStop(source);
421
410
 
422
411
  ALuint buffer;
@@ -426,36 +415,35 @@ public:
426
415
 
427
416
  int queued;
428
417
  alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
429
- while (queued--)
418
+ while (queued--) {
430
419
  alSourceUnqueueBuffers(source, 1, &buffer);
431
-
432
- //int processed;
433
- //alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
434
- //while (processed--)
435
- // alSourceUnqueueBuffers(source, 1, &buffer);
420
+ }
436
421
  }
437
422
  file->rewind();
438
423
  }
439
424
 
440
425
  void pause()
441
426
  {
442
- int source = lookupSource();
443
- if (source != ALChannelManagement::NO_SOURCE)
427
+ int source = lookup_source();
428
+ if (source != ALChannelManagement::NO_SOURCE) {
444
429
  alSourcePause(source);
430
+ }
445
431
  }
446
432
 
447
433
  void resume()
448
434
  {
449
- int source = lookupSource();
450
- if (source != ALChannelManagement::NO_SOURCE)
435
+ int source = lookup_source();
436
+ if (source != ALChannelManagement::NO_SOURCE) {
451
437
  alSourcePlay(source);
438
+ }
452
439
  }
453
440
 
454
441
  bool paused() const
455
442
  {
456
- int source = lookupSource();
457
- if (source == ALChannelManagement::NO_SOURCE)
443
+ int source = lookup_source();
444
+ if (source == ALChannelManagement::NO_SOURCE) {
458
445
  return false;
446
+ }
459
447
  ALint state;
460
448
  alGetSourcei(source, AL_SOURCE_STATE, &state);
461
449
  return state == AL_PAUSED;
@@ -463,68 +451,66 @@ public:
463
451
 
464
452
  void update()
465
453
  {
466
- int source = lookupSource();
454
+ int source = lookup_source();
467
455
 
468
456
  ALuint buffer;
469
457
  int processed;
470
458
  bool active = true;
471
459
 
472
460
  alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
473
- for (int i = 0; i < processed; ++i)
474
- {
461
+ for (int i = 0; i < processed; ++i) {
475
462
  alSourceUnqueueBuffers(source, 1, &buffer);
476
- active = streamToBuffer(buffer);
477
- if (active)
463
+ active = stream_to_buffer(buffer);
464
+ if (active) {
478
465
  alSourceQueueBuffers(source, 1, &buffer);
466
+ }
479
467
  }
480
468
 
481
469
  ALint state;
482
470
  alGetSourcei(source, AL_SOURCE_STATE, &state);
483
- if (active && state != AL_PLAYING && state != AL_PAUSED)
484
- {
471
+ if (active && state != AL_PLAYING && state != AL_PAUSED) {
485
472
  // We seemingly got starved.
486
473
  alSourcePlay(source);
487
474
  }
488
- else if (!active)
489
- {
490
- // We got starved and there is nothing to play left.
491
- // In any case, shut down the playback logic for a moment.
475
+ else if (!active) {
476
+ // We got starved and there is nothing left to play.
492
477
  stop();
493
478
 
494
- if (curSongLooping)
479
+ if (cur_song_looping) {
495
480
  // Start anew.
496
481
  play(true);
497
- else
482
+ }
483
+ else {
498
484
  // Let the world know we're finished.
499
- curSong = 0;
485
+ cur_song = nullptr;
486
+ }
500
487
  }
501
488
  }
502
489
  };
503
490
 
504
- // TODO: Move into proper internal header
505
- namespace Gosu { bool isExtension(const wchar_t* str, const wchar_t* ext); }
506
-
507
- Gosu::Song::Song(const std::wstring& filename)
491
+ Gosu::Song::Song(const std::string& filename)
508
492
  {
509
493
  #ifdef GOSU_IS_IPHONE
510
- if (isExtension(filename.c_str(), L".mp3") ||
511
- isExtension(filename.c_str(), L".aac") ||
512
- isExtension(filename.c_str(), L".m4a"))
513
- data.reset(new ModuleData(filename));
514
- else
515
- #endif
516
- {
494
+ if (has_extension(filename, ".mp3") ||
495
+ has_extension(filename, ".aac") ||
496
+ has_extension(filename, ".m4a")) {
517
497
  CONSTRUCTOR_BEGIN;
518
- data.reset(new StreamData(filename));
519
- CONSTRUCTOR_END
498
+ data.reset(new ModuleData(filename));
499
+ CONSTRUCTOR_END;
500
+ return;
520
501
  }
502
+ #endif
503
+
504
+ CONSTRUCTOR_BEGIN;
505
+ data.reset(new StreamData(filename));
506
+ CONSTRUCTOR_END;
521
507
  }
522
508
 
523
509
  Gosu::Song::Song(Reader reader)
524
510
  {
525
511
  CONSTRUCTOR_BEGIN;
526
512
  data.reset(new StreamData(reader));
527
- CONSTRUCTOR_END
513
+ CONSTRUCTOR_END;
528
514
  }
529
515
 
530
516
  Gosu::Song::~Song()
@@ -532,52 +518,53 @@ Gosu::Song::~Song()
532
518
  stop();
533
519
  }
534
520
 
535
- Gosu::Song* Gosu::Song::currentSong()
521
+ Gosu::Song* Gosu::Song::current_song()
536
522
  {
537
- return curSong;
523
+ return cur_song;
538
524
  }
539
525
 
540
526
  void Gosu::Song::play(bool looping)
541
527
  {
542
- if (paused())
528
+ if (paused()) {
543
529
  data->resume();
530
+ }
544
531
 
545
- if (curSong && curSong != this)
546
- {
547
- curSong->stop();
548
- assert(curSong == 0);
532
+ if (cur_song && cur_song != this) {
533
+ cur_song->stop();
534
+ assert (cur_song == nullptr);
549
535
  }
550
536
 
551
- if (curSong == 0)
537
+ if (cur_song == nullptr) {
552
538
  data->play(looping);
539
+ }
553
540
 
554
- curSong = this;
555
- curSongLooping = looping;
541
+ cur_song = this;
542
+ cur_song_looping = looping;
556
543
  }
557
544
 
558
545
  void Gosu::Song::pause()
559
546
  {
560
- if (curSong == this)
547
+ if (cur_song == this) {
561
548
  data->pause(); // may be redundant
549
+ }
562
550
  }
563
551
 
564
552
  bool Gosu::Song::paused() const
565
553
  {
566
- return curSong == this && data->paused();
554
+ return cur_song == this && data->paused();
567
555
  }
568
556
 
569
557
  void Gosu::Song::stop()
570
558
  {
571
- if (curSong == this)
572
- {
559
+ if (cur_song == this) {
573
560
  data->stop();
574
- curSong = 0;
561
+ cur_song = nullptr;
575
562
  }
576
563
  }
577
564
 
578
565
  bool Gosu::Song::playing() const
579
566
  {
580
- return curSong == this && !data->paused();
567
+ return cur_song == this && !data->paused();
581
568
  }
582
569
 
583
570
  double Gosu::Song::volume() const
@@ -585,35 +572,14 @@ double Gosu::Song::volume() const
585
572
  return data->volume();
586
573
  }
587
574
 
588
- void Gosu::Song::changeVolume(double volume)
575
+ void Gosu::Song::change_volume(double volume)
589
576
  {
590
- data->changeVolume(volume);
577
+ data->change_volume(volume);
591
578
  }
592
579
 
593
580
  void Gosu::Song::update()
594
581
  {
595
- if (currentSong())
596
- currentSong()->data->update();
597
- }
598
-
599
- // Deprecated constructors.
600
-
601
- Gosu::Sample::Sample(Audio& audio, const std::wstring& filename)
602
- {
603
- Sample(filename).data.swap(data);
604
- }
605
-
606
- Gosu::Sample::Sample(Audio& audio, Reader reader)
607
- {
608
- Sample(reader).data.swap(data);
609
- }
610
-
611
- Gosu::Song::Song(Audio& audio, const std::wstring& filename)
612
- {
613
- data = Song(filename).data;
614
- }
615
-
616
- Gosu::Song::Song(Audio& audio, Type type, Reader reader)
617
- {
618
- data = Song(reader).data;
582
+ if (current_song()) {
583
+ current_song()->data->update();
584
+ }
619
585
  }