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
data/README.md CHANGED
@@ -1,20 +1,32 @@
1
1
  Welcome to Gosu!
2
2
  ================
3
3
 
4
- Gosu's main website is [libgosu.org](https://www.libgosu.org/).
5
- The source code, wiki, issue tracker and change log are all hosted on [GitHub](https://github.com/gosu/gosu)
4
+ Gosu is a 2D game development library for Ruby and C++.
5
+
6
+ The main website is [www.libgosu.org](https://www.libgosu.org/).
7
+ The source code, wiki, issue tracker and change log are all hosted on [GitHub](https://github.com/gosu/gosu).
8
+
9
+ Gosu is released under the MIT license.
10
+
11
+ Getting Started
12
+ ---------------
6
13
 
7
14
  The best entry point into Gosu's documentation is the [wiki home page](https://github.com/gosu/gosu/wiki).
8
- Try doing the tutorial there if you don't know how to get started,
9
- or look at one of the games in the [Gosu Showcase](https://www.libgosu.org/cgi-bin/mwf/board_show.pl?bid=2) board.
15
+ Try doing the tutorials there if you don't know how to get started,
16
+ or look at existing projects in the [Gosu Showcase](https://www.libgosu.org/cgi-bin/mwf/board_show.pl?bid=2).
10
17
 
11
- Gosu is licensed under the MIT license. Feel invited to fork, port and transmogrify all parts of it!
18
+ Community
19
+ ---------
12
20
 
13
- Complaints, questions, feedback?
14
- - Visit the [boards](https://www.libgosu.org/)
15
- - Try your luck in the (mostly idle) [IRC channel](https://webchat.freenode.net/?channels=gosu)
16
- - Or [email me](mailto:julian@raschke.de) :)
21
+ - Visit our [message board](https://www.libgosu.org/cgi-bin/mwf/forum.pl) or the [r/gosu subreddit](https://reddit.com/r/gosu).
22
+ - There’s also an IRC room, [#gosu on freenode](https://webchat.freenode.net/?channels=gosu). The regulars are spread across many timezones, so you’ll need some patience.
23
+ - You can file bugs and feature requests as [issues on GitHub](https://github.com/gosu/gosu/issues).
24
+ - Or [simply email me](mailto:julian@raschke.de) :)
17
25
 
18
- [![Build Status](https://travis-ci.org/gosu/gosu.svg?branch=master)](https://travis-ci.org/gosu/gosu) Linux, OS X and iOS builds
26
+ Build Status
27
+ ------------
19
28
 
20
- [![Build status](https://ci.appveyor.com/api/projects/status/v0liohs47jono1eq?svg=true)](https://ci.appveyor.com/project/gosu-ci/gosu) Windows builds
29
+ Platforms| 
30
+ ---|---:
31
+ Linux, macOS and iOS|[![Travis build status](https://travis-ci.org/gosu/gosu.svg?branch=master)](https://travis-ci.org/gosu/gosu)
32
+ Windows|[![Appveyor build status](https://ci.appveyor.com/api/projects/status/v0liohs47jono1eq?svg=true)](https://ci.appveyor.com/project/gosu-ci/gosu)
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/ then
3
+ if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/
4
4
  platform = (RUBY_PLATFORM =~ /^x64-/ ? 'x64-mingw32' : 'i386-mingw32')
5
5
 
6
6
  puts "This gem is not meant to be installed on Windows. Instead, please use:"
@@ -10,77 +10,34 @@ end
10
10
 
11
11
  puts 'The Gosu gem requires some libraries to be installed system-wide.'
12
12
  puts 'See the following site for a list:'
13
- if `uname`.chomp == 'Darwin' then
13
+ if `uname`.chomp == 'Darwin'
14
14
  puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X'
15
15
  else
16
16
  puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux'
17
17
  end
18
18
 
19
- BASE_FILES = %w(
20
- Bitmap/Bitmap.cpp
21
- Bitmap/BitmapIO.cpp
22
- DirectoriesUnix.cpp
23
- FileUnix.cpp
24
- Graphics/BlockAllocator.cpp
25
- Graphics/Color.cpp
26
- Graphics/Graphics.cpp
27
- Graphics/Image.cpp
28
- Graphics/LargeImageData.cpp
29
- Graphics/Macro.cpp
30
- Graphics/Resolution.cpp
31
- Graphics/TexChunk.cpp
32
- Graphics/Texture.cpp
33
- Graphics/Transform.cpp
34
- Input/Input.cpp
35
- Input/TextInput.cpp
36
- Inspection.cpp
37
- IO.cpp
38
- Math.cpp
39
- Text/Font.cpp
40
- Text/Text.cpp
41
- Utility.cpp
42
- Window.cpp
43
-
44
- stb_vorbis.c
45
- )
46
-
47
- MAC_FILES = %w(
48
- Audio/Audio.mm
49
- Graphics/ResolutionApple.mm
50
- Text/TextApple.mm
51
- TimingApple.cpp
52
- UtilityApple.mm
53
- )
54
-
55
- LINUX_FILES = %w(
56
- Audio/Audio.cpp
57
- Text/TextUnix.cpp
58
- TimingUnix.cpp
59
- )
60
-
61
19
  require 'mkmf'
62
20
  require 'fileutils'
63
21
 
64
22
  # Silence internal deprecation warnings in Gosu
65
23
  $CFLAGS << " -DGOSU_DEPRECATED="
66
24
 
67
- $CXXFLAGS ||= ''
25
+ $CXXFLAGS ||= ""
26
+ $CXXFLAGS << " -std=gnu++11"
68
27
 
69
- $INCFLAGS << " -I../.. -I../../src"
28
+ # For #include <Gosu/...>
29
+ $INCFLAGS << " -I../.."
70
30
 
71
- if `uname`.chomp == 'Darwin' then
72
- SOURCE_FILES = BASE_FILES + MAC_FILES
73
-
31
+ if `uname`.chomp == 'Darwin'
74
32
  # To make everything work with the Objective C runtime
75
33
  $CFLAGS << " -x objective-c -fobjc-arc -DNDEBUG"
76
- # Compile all C++ files as Objective C++ on OS X since mkmf does not support .mm
77
- # files.
34
+ # Compile all C++ files as Objective C++ on macOS since mkmf does not support .mm files.
78
35
  $CXXFLAGS << " -x objective-c++ -fobjc-arc -DNDEBUG"
79
36
 
80
- # Enable C++ 11, and explicitly specify libc++ as the standard library.
37
+ # Explicitly specify libc++ as the standard library.
81
38
  # rvm will sometimes try to override this:
82
39
  # https://github.com/shawn42/gamebox/issues/96
83
- $CXXFLAGS << " -std=gnu++11 -stdlib=libc++"
40
+ $CXXFLAGS << " -stdlib=libc++"
84
41
 
85
42
  # Dependencies.
86
43
  $CXXFLAGS << " #{`sdl2-config --cflags`.chomp}"
@@ -95,13 +52,11 @@ if `uname`.chomp == 'Darwin' then
95
52
  $ARCH_FLAG.gsub! "-arch i386", ""
96
53
  CONFIG['LDSHARED'].gsub! "-arch i386", ""
97
54
  else
98
- SOURCE_FILES = BASE_FILES + LINUX_FILES
99
-
100
- if /Raspbian/ =~ `cat /etc/issue` or /BCM2708/ =~ `cat /proc/cpuinfo` then
55
+ if /Raspbian/ =~ `cat /etc/issue` or /BCM2708/ =~ `cat /proc/cpuinfo`
101
56
  $INCFLAGS << " -I/opt/vc/include/GLES"
102
57
  $INCFLAGS << " -I/opt/vc/include"
103
- $LDFLAGS << " -L/opt/vc/lib"
104
- $LDFLAGS << " -lGLESv1_CM"
58
+ $LDFLAGS << " -L/opt/vc/lib"
59
+ $LDFLAGS << " -lGLESv1_CM"
105
60
  else
106
61
  pkg_config 'gl'
107
62
  end
@@ -112,33 +67,28 @@ else
112
67
  pkg_config 'openal'
113
68
  pkg_config 'sndfile'
114
69
 
115
- have_header 'SDL_ttf.h' if have_library('SDL2_ttf', 'TTF_RenderUTF8_Blended')
116
- have_header 'AL/al.h' if have_library('openal')
70
+ have_header 'SDL_ttf.h' if have_library('SDL2_ttf', 'TTF_RenderUTF8_Blended')
71
+ have_header 'AL/al.h' if have_library('openal')
117
72
  end
118
73
 
119
- # And now it gets ridiculous (or I am overcomplicating things...):
120
- # mkmf will compile all .c/.cpp files in this directory, but if they are nested
121
- # inside folders, it will not find the resulting .o files during linking.
122
- # So we create a shim .c/.cpp file for each file that we want to compile, ensuring
123
- # that all .o files are built into the current directory, without any nesting.
124
- # TODO: Just move all of Gosu's source files back into a flat hierarchy again.
125
- # The nested directory structure has really not been worth it.
126
- SOURCE_FILES.each do |file|
127
- shim_name = file.gsub('/', '-').sub(/\.mm$/, '.cpp')
128
- File.open(shim_name, "w") do |shim|
129
- shim.puts "#include \"../../src/#{file}\""
130
- end
131
- end
132
-
133
- # This is necessary to build on stock Ruby on OS X 10.7.
74
+ # This is necessary to build with stock Ruby on OS X 10.7.
134
75
  CONFIG['CXXFLAGS'] ||= $CXXFLAGS
135
76
 
136
- if RUBY_VERSION >= '1.9.3' and RUBY_VERSION < '2.2.0' then
137
- # In some versions of Ruby and mkmf, the $CXXFLAGS variable is badly broken.
138
- # We can modify CONFIG instead, and our changes will end up in the Makefile.
139
- # See http://bugs.ruby-lang.org/issues/8315
140
- # The lower bound was reduced to 1.9.3 here: https://github.com/gosu/gosu/issues/321
77
+ # Gem::Version#initialize is apparently broken in some versions of Ruby, so use a local helper.
78
+ def ruby_newer_than?(want_version)
79
+ have_parts = RUBY_VERSION.split('.').map { |part| part.to_i }
80
+ want_parts = want_version.split('.').map { |part| part.to_i }
81
+ have_parts << 0 while have_parts.size < want_parts.size
82
+ want_parts << 0 while want_parts.size < have_parts.size
83
+ (have_parts <=> want_parts) == 1
84
+ end
85
+
86
+ # In some versions of Ruby/mkmf, the $CXXFLAGS variable does not work.
87
+ # We can modify CONFIG instead, and our changes will end up in the Makefile.
88
+ # See: http://bugs.ruby-lang.org/issues/8315
89
+ # The lower bound was reduced to 1.9.3 here: https://github.com/gosu/gosu/issues/321
90
+ if ruby_newer_than?("1.9.2") and not ruby_newer_than?("2.2.0")
141
91
  CONFIG['CXXFLAGS'] = "#$CFLAGS #$CXXFLAGS"
142
92
  end
143
93
 
144
- create_makefile 'gosu'
94
+ create_makefile "gosu", "../../src"
@@ -4,31 +4,43 @@ class ::Numeric
4
4
  def degrees_to_radians
5
5
  self * Math::PI / 180.0
6
6
  end
7
-
7
+
8
8
  def radians_to_degrees
9
9
  self * 180.0 / Math::PI
10
10
  end
11
-
11
+
12
12
  def gosu_to_radians
13
13
  (self - 90) * Math::PI / 180.0
14
14
  end
15
-
15
+
16
16
  def radians_to_gosu
17
17
  self * 180.0 / Math::PI + 90
18
18
  end
19
19
  end
20
20
 
21
21
  # Backwards compatibility:
22
- # Import constants into Gosu::Button.
23
- module Gosu::Button
24
- Gosu.constants.each { |c| const_set(c, Gosu.const_get(c)) }
22
+ # Support for KbLeft instead of KB_LEFT and Gp3Button2 instead of GP_3_BUTTON_2.
23
+ # Also import old-style constants into Gosu::Button.
24
+ module Gosu::Button; end
25
+ Gosu.constants.grep(/^KB_|MS_|GP_/).each do |c|
26
+ old_name = case c
27
+ when :KB_ISO then "KbISO"
28
+ when :KB_NUMPAD_PLUS then "KbNumpadAdd"
29
+ when :KB_NUMPAD_MINUS then "KbNumpadSubtract"
30
+ when :KB_EQUALS then "KbEqual"
31
+ when :KB_LEFT_BRACKET then "KbBracketLeft"
32
+ when :KB_RIGHT_BRACKET then "KbBracketRight"
33
+ else c.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
34
+ end
35
+ Gosu.const_set old_name, Gosu.const_get(c)
36
+ Gosu::Button.const_set old_name, Gosu.const_get(c)
25
37
  end
26
38
 
27
39
  # Backwards compatibility:
28
40
  # Passing a Window to initialize and from_text has been deprecated in Gosu 0.9.
29
41
  class Gosu::Image
30
42
  alias initialize_without_window initialize
31
-
43
+
32
44
  def initialize(*args)
33
45
  if args[0].is_a? Gosu::Window then
34
46
  if args.size == 7 then
@@ -40,11 +52,11 @@ class Gosu::Image
40
52
  initialize_without_window(*args)
41
53
  end
42
54
  end
43
-
55
+
44
56
  class << self
45
57
  alias from_text_without_window from_text
46
58
  end
47
-
59
+
48
60
  def self.from_text(*args)
49
61
  if args.size == 4
50
62
  from_text_without_window(args[1], args[3], :font => args[2])
@@ -61,7 +73,7 @@ end
61
73
  # Passing a Window to Sample#initialize has been deprecated in Gosu 0.7.17.
62
74
  class Gosu::Sample
63
75
  alias initialize_without_window initialize
64
-
76
+
65
77
  def initialize(*args)
66
78
  args.shift if args.first.is_a? Gosu::Window
67
79
  initialize_without_window(*args)
@@ -72,7 +84,7 @@ end
72
84
  # Passing a Window to Song#initialize has been deprecated in Gosu 0.7.17.
73
85
  class Gosu::Song
74
86
  alias initialize_without_window initialize
75
-
87
+
76
88
  def initialize(*args)
77
89
  args.shift if args.first.is_a? Gosu::Window
78
90
  initialize_without_window(*args)
@@ -85,7 +97,7 @@ module Gosu
85
97
  class ImmutableColor < Color
86
98
  private :alpha=, :red=, :green=, :blue=, :hue=, :saturation=, :value=
87
99
  end
88
-
100
+
89
101
  class Color
90
102
  NONE = Gosu::ImmutableColor.new(0x00_000000)
91
103
  BLACK = Gosu::ImmutableColor.new(0xff_000000)
@@ -109,18 +121,18 @@ end
109
121
  class Gosu::Window
110
122
  # Backwards compatibility:
111
123
  # Class methods that have been turned into module methods.
112
-
124
+
113
125
  def self.button_id_to_char(id)
114
126
  Gosu.button_id_to_char(id)
115
127
  end
116
-
128
+
117
129
  def self.char_to_button_id(ch)
118
130
  Gosu.char_to_button_id(ch)
119
131
  end
120
-
132
+
121
133
  # Backwards compatibility:
122
134
  # Instance methods that have been turned into module methods.
123
-
135
+
124
136
  %w(draw_line draw_triangle draw_quad
125
137
  flush gl clip_to record
126
138
  transform translate rotate scale
@@ -129,18 +141,22 @@ class Gosu::Window
129
141
  Gosu.send method, *args, &block
130
142
  end
131
143
  end
132
-
144
+
133
145
  # Call Thread.pass every tick, which may or may not be necessary for friendly co-existence with
134
146
  # Ruby's Thread class.
135
-
147
+
136
148
  alias _tick tick
137
-
149
+
138
150
  def tick
139
151
  Thread.pass
140
152
  _tick
141
153
  end
142
154
  end
143
155
 
156
+ # Backwards compatibility:
157
+ # This was renamed, because it's not actually a "copyright notice" (Wikipedia: https://en.wikipedia.org/wiki/Copyright_notice).
158
+ Gosu::GOSU_COPYRIGHT_NOTICE = Gosu::LICENSES
159
+
144
160
  # Release OpenAL resources during Ruby's shutdown, not Gosu's.
145
161
  at_exit do
146
162
  Gosu::Song.current_song.stop if Gosu::Song.current_song
@@ -1,11 +1,20 @@
1
- # Replace the load path
1
+ # This script is used by Ruby.app: https://github.com/gosu/ruby_app
2
+
3
+ # Replace the load path.
2
4
  $LOAD_PATH.clear
3
5
  $LOAD_PATH << File.dirname(__FILE__)[0..-6]
4
6
  $LOAD_PATH << $LOAD_PATH[0] + '/lib'
5
- # Ruby portions of Gosu
7
+
8
+ # Ruby portions of Gosu.
6
9
  require 'gosu/patches'
7
10
  require 'gosu/swig_patches'
11
+
8
12
  # Let the application know it is being run from the Mac app wrapper.
9
13
  OSX_EXECUTABLE = true
10
- # Main application
11
- require 'Main'
14
+
15
+ # Main application.
16
+ begin
17
+ require 'Main'
18
+ rescue LoadError
19
+ require 'main'
20
+ end
@@ -1,24 +1,28 @@
1
- ##
2
- # The first component of the version.
3
- GOSU_MAJOR_VERSION = :a_fixnum
1
+ module Gosu
2
+ ##
3
+ # The first component of the version.
4
+ MAJOR_VERSION = :a_fixnum
4
5
 
5
- ##
6
- # The second component of the version.
7
- GOSU_MINOR_VERSION = :a_fixnum
6
+ ##
7
+ # The second component of the version.
8
+ MINOR_VERSION = :a_fixnum
8
9
 
9
- ##
10
- # The third component of the version.
11
- GOSU_POINT_VERSION = :a_fixnum
10
+ ##
11
+ # The third component of the version.
12
+ POINT_VERSION = :a_fixnum
12
13
 
13
- ##
14
- # A version string of the form "0.1.2", "0.1.2.3" or "0.1.2pre4".
15
- GOSU_VERSION = :a_string
14
+ ##
15
+ # A version string of the form "0.1.2", "0.1.2.3" or "0.1.2pre4".
16
+ VERSION = :a_string
16
17
 
17
- ##
18
- # A long block of legal copy that your game is obliged to display somewhere.
19
- GOSU_COPYRIGHT_NOTICE = :a_string
18
+ ##
19
+ # @deprecated Use LICENSES instead as it's a more appropriate name
20
+ GOSU_COPYRIGHT_NOTICE = :a_string
21
+
22
+ ##
23
+ # A block of legal copy that your game is obliged to display somewhere.
24
+ LICENSES = :a_string
20
25
 
21
- module Gosu
22
26
  Kb0 Kb1 Kb2 Kb3 Kb4 Kb5 Kb6 Kb7 Kb8 Kb9 = :implementation_defined
23
27
  KbA KbB KbC KbD KbE KbF KbG KbH KbI KbJ KbK KbL KbM KbN KbO KbP KbQ KbR KbS KbT KbU KbV KbW KbX KbY KbZ = :implementation_defined
24
28
  KbBackspace = :implementation_defined
@@ -736,21 +740,21 @@ module Gosu
736
740
  # The window's width, in pixels. This only counts the drawable area and does not include any borders or decorations added by the window manager.
737
741
  #
738
742
  # @return [Fixnum] the window's width, in pixels.
739
- attr_reader :width
743
+ attr_accessor :width
740
744
 
741
745
  ##
742
746
  # The window's height, in pixels. This only counts the drawable area and does not include any borders or decorations added by the window manager.
743
747
  #
744
748
  # @return [Fixnum] the window's height, in pixels.
745
- attr_reader :height
749
+ attr_accessor :height
746
750
 
747
751
  ##
748
752
  # @return [true, false] whether this is a full-screen window.
749
- attr_reader :fullscreen?
753
+ attr_accessor :fullscreen?
750
754
 
751
755
  ##
752
756
  # @return [Float] the interval between calls to {#update}, in milliseconds.
753
- attr_reader :update_interval
757
+ attr_accessor :update_interval
754
758
 
755
759
  ##
756
760
  # Creates a new window with the requested size.
@@ -0,0 +1,119 @@
1
+ #include <Gosu/Platform.hpp>
2
+ #include <cstdlib>
3
+ #include <algorithm>
4
+ #include <memory>
5
+ #ifdef GOSU_IS_MAC
6
+ #include <OpenAL/al.h>
7
+ #include <OpenAL/alc.h>
8
+ #else
9
+ #include <AL/al.h>
10
+ #include <AL/alc.h>
11
+ #endif
12
+
13
+ namespace Gosu
14
+ {
15
+ class ALChannelManagement
16
+ {
17
+ ALChannelManagement(const ALChannelManagement&) = delete;
18
+ ALChannelManagement& operator=(const ALChannelManagement&) = delete;
19
+ ALChannelManagement(ALChannelManagement&&) = delete;
20
+ ALChannelManagement& operator=(ALChannelManagement&&) = delete;
21
+
22
+ static ALCdevice* al_device;
23
+ static ALCcontext* al_context;
24
+
25
+ #ifdef GOSU_IS_IPHONE
26
+ // iOS system limit.
27
+ enum { NUM_SOURCES = 32 };
28
+ #else
29
+ enum { NUM_SOURCES = 255 };
30
+ #endif
31
+ static ALuint al_sources[NUM_SOURCES];
32
+ static ALuint current_token;
33
+ static ALuint current_tokens[NUM_SOURCES];
34
+
35
+ public:
36
+ enum { NO_TOKEN = -1, NO_SOURCE = -1, NO_FREE_CHANNEL = -1 };
37
+
38
+ static ALCdevice* device()
39
+ {
40
+ return al_device;
41
+ }
42
+
43
+ static ALCcontext* context()
44
+ {
45
+ return al_context;
46
+ }
47
+
48
+ ALChannelManagement()
49
+ {
50
+ // Open preferred device
51
+ al_device = alcOpenDevice(0);
52
+ al_context = alcCreateContext(al_device, 0);
53
+ alcMakeContextCurrent(al_context);
54
+ alGenSources(NUM_SOURCES, al_sources);
55
+ std::fill(current_tokens, current_tokens + NUM_SOURCES, static_cast<ALuint>(NO_TOKEN));
56
+ }
57
+
58
+ ~ALChannelManagement()
59
+ {
60
+ alDeleteSources(NUM_SOURCES, al_sources);
61
+ alcMakeContextCurrent(0);
62
+ alcDestroyContext(al_context);
63
+ alcCloseDevice(al_device);
64
+ }
65
+
66
+ std::pair<int, int> reserve_channel()
67
+ {
68
+ int i;
69
+ for (i = 1; i <= NUM_SOURCES; ++i) {
70
+ if (i == NUM_SOURCES) {
71
+ return std::make_pair<int, int>(NO_FREE_CHANNEL, NO_TOKEN);
72
+ }
73
+ if (current_tokens[i] == NO_TOKEN) {
74
+ break;
75
+ }
76
+ ALint state;
77
+ alGetSourcei(al_sources[i], AL_SOURCE_STATE, &state);
78
+ if (state != AL_PLAYING && state != AL_PAUSED) {
79
+ break;
80
+ }
81
+ }
82
+ ++current_token;
83
+ current_tokens[i] = current_token;
84
+ return std::make_pair(i, int(current_token));
85
+ }
86
+
87
+ int source_if_still_playing(int channel, int token) const
88
+ {
89
+ if (channel != NO_FREE_CHANNEL && current_tokens[channel] == token) {
90
+ return al_sources[channel];
91
+ }
92
+ else {
93
+ return NO_SOURCE;
94
+ }
95
+ }
96
+
97
+ int source_for_songs() const
98
+ {
99
+ return al_sources[0];
100
+ }
101
+ };
102
+ ALCdevice* ALChannelManagement::al_device = 0;
103
+ ALCcontext* ALChannelManagement::al_context = 0;
104
+ ALuint ALChannelManagement::al_sources[NUM_SOURCES];
105
+ ALuint ALChannelManagement::current_token = 0;
106
+ ALuint ALChannelManagement::current_tokens[NUM_SOURCES];
107
+
108
+ std::unique_ptr<ALChannelManagement> al_channel_management;
109
+
110
+ void release_all_openal_resources()
111
+ {
112
+ al_channel_management.reset();
113
+ }
114
+
115
+ ALCcontext *shared_openal_context()
116
+ {
117
+ return ALChannelManagement::context();
118
+ }
119
+ }