rubygame 2.5.3 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/CREDITS +6 -4
  2. data/NEWS +79 -0
  3. data/README +55 -72
  4. data/ROADMAP +20 -13
  5. data/doc/custom_sdl_load_paths.rdoc +79 -0
  6. data/doc/getting_started.rdoc +65 -36
  7. data/doc/keyboard_symbols.rdoc +243 -0
  8. data/doc/macosx_install.rdoc +49 -35
  9. data/doc/windows_install.rdoc +36 -108
  10. data/lib/rubygame.rb +62 -24
  11. data/lib/rubygame/audio.rb +147 -0
  12. data/lib/rubygame/clock.rb +164 -1
  13. data/lib/rubygame/color.rb +40 -7
  14. data/lib/rubygame/color/models/hsl.rb +1 -1
  15. data/lib/rubygame/color/models/hsv.rb +1 -1
  16. data/lib/rubygame/color/models/rgb.rb +1 -1
  17. data/lib/rubygame/color/palettes/css.rb +1 -3
  18. data/lib/rubygame/color/palettes/x11.rb +1 -2
  19. data/lib/rubygame/constants.rb +297 -0
  20. data/lib/rubygame/deprecated_mixer.rb +555 -0
  21. data/lib/rubygame/event.rb +122 -6
  22. data/lib/rubygame/event_handler.rb +3 -1
  23. data/lib/rubygame/event_hook.rb +6 -2
  24. data/lib/rubygame/event_triggers.rb +1 -1
  25. data/lib/rubygame/events.rb +416 -1
  26. data/lib/rubygame/ftor.rb +1 -7
  27. data/lib/rubygame/gfx.rb +583 -0
  28. data/lib/rubygame/gl.rb +107 -0
  29. data/lib/rubygame/image.rb +140 -0
  30. data/lib/rubygame/joystick.rb +184 -0
  31. data/lib/rubygame/main.rb +82 -0
  32. data/lib/rubygame/mediabag.rb +1 -1
  33. data/lib/rubygame/mixer.rb +30 -0
  34. data/lib/rubygame/music.rb +493 -0
  35. data/lib/rubygame/queue.rb +3 -1
  36. data/lib/rubygame/rect.rb +9 -9
  37. data/lib/rubygame/screen.rb +357 -0
  38. data/lib/rubygame/shared.rb +40 -4
  39. data/lib/rubygame/sound.rb +428 -0
  40. data/lib/rubygame/surface.rb +626 -0
  41. data/lib/rubygame/ttf.rb +311 -0
  42. data/samples/FreeSans.ttf +0 -0
  43. data/samples/README +6 -5
  44. data/samples/demo_draw.rb +1 -1
  45. data/samples/demo_gl.rb +3 -1
  46. data/samples/demo_gl_tex.rb +4 -2
  47. data/samples/demo_rubygame.rb +114 -105
  48. data/samples/demo_sfont.rb +1 -1
  49. data/samples/demo_ttf.rb +3 -1
  50. data/samples/demo_utf8.rb +1 -1
  51. data/samples/image_viewer.rb +118 -0
  52. data/samples/load_and_blit.rb +1 -1
  53. data/samples/rubygame.png +0 -0
  54. metadata +34 -40
  55. data/Rakefile +0 -537
  56. data/doc/extended_readme.rdoc +0 -49
  57. data/ext/body/rubygame_body.so +0 -0
  58. data/ext/rubygame/rubygame_clock.c +0 -301
  59. data/ext/rubygame/rubygame_clock.h +0 -32
  60. data/ext/rubygame/rubygame_event.c +0 -760
  61. data/ext/rubygame/rubygame_event.h +0 -48
  62. data/ext/rubygame/rubygame_event2.c +0 -661
  63. data/ext/rubygame/rubygame_event2.h +0 -29
  64. data/ext/rubygame/rubygame_gfx.c +0 -942
  65. data/ext/rubygame/rubygame_gfx.h +0 -101
  66. data/ext/rubygame/rubygame_gl.c +0 -154
  67. data/ext/rubygame/rubygame_gl.h +0 -32
  68. data/ext/rubygame/rubygame_image.c +0 -252
  69. data/ext/rubygame/rubygame_image.h +0 -41
  70. data/ext/rubygame/rubygame_joystick.c +0 -336
  71. data/ext/rubygame/rubygame_joystick.h +0 -41
  72. data/ext/rubygame/rubygame_main.c +0 -158
  73. data/ext/rubygame/rubygame_main.h +0 -36
  74. data/ext/rubygame/rubygame_mixer.c +0 -1024
  75. data/ext/rubygame/rubygame_mixer.h +0 -36
  76. data/ext/rubygame/rubygame_music.c +0 -1017
  77. data/ext/rubygame/rubygame_music.h +0 -29
  78. data/ext/rubygame/rubygame_screen.c +0 -572
  79. data/ext/rubygame/rubygame_screen.h +0 -45
  80. data/ext/rubygame/rubygame_shared.c +0 -269
  81. data/ext/rubygame/rubygame_shared.h +0 -69
  82. data/ext/rubygame/rubygame_sound.c +0 -863
  83. data/ext/rubygame/rubygame_sound.h +0 -29
  84. data/ext/rubygame/rubygame_surface.c +0 -1153
  85. data/ext/rubygame/rubygame_surface.h +0 -62
  86. data/ext/rubygame/rubygame_ttf.c +0 -599
  87. data/ext/rubygame/rubygame_ttf.h +0 -69
  88. data/samples/keys.rb +0 -52
@@ -25,7 +25,7 @@ EOF
25
25
  font_name = args[0]
26
26
  end
27
27
 
28
- screen = Screen.set_mode([700,400])
28
+ screen = Screen.open([700,400])
29
29
  queue = EventQueue.new()
30
30
  queue.ignore = [ActiveEvent,MouseMotionEvent,MouseUpEvent,MouseDownEvent]
31
31
 
@@ -142,7 +142,7 @@ def test_iu_aa(font,screen,y)
142
142
  end
143
143
 
144
144
  def main
145
- screen = Screen.set_mode([300,300])
145
+ screen = Screen.open([300,300])
146
146
  queue = EventQueue.new()
147
147
  queue.ignore = SDL_EVENTS - [QuitEvent, KeyDownEvent]
148
148
 
@@ -191,3 +191,5 @@ def main
191
191
  end
192
192
 
193
193
  main()
194
+
195
+ Rubygame.quit
@@ -7,7 +7,7 @@ require 'rubygame'
7
7
 
8
8
  # Initialize Rubygame
9
9
  Rubygame.init
10
- screen = Rubygame::Screen.set_mode([320,200])
10
+ screen = Rubygame::Screen.open([320,200])
11
11
  queue = Rubygame::EventQueue.new
12
12
 
13
13
  # Initialize fonts
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A basic image viewer demo for Rubygame.
4
+ #
5
+ # Usage: Pass an image file to this script to display it. To quit,
6
+ # press Q or Escape, right click, or close the window.
7
+ #
8
+ # Author: John Croisant
9
+ # Date: 2009-10-18
10
+ # License: You may use this code however you want. No warranty.
11
+ #
12
+
13
+
14
+ # Load Rubygame and include Rubygame and Rubygame::Events
15
+ # in the current namespace, for convenience.
16
+ #
17
+ require "rubygame"
18
+ include Rubygame
19
+ include Rubygame::Events
20
+
21
+
22
+ # Initialize Rubygame, and clean up when script exits.
23
+ Rubygame.init
24
+ at_exit { Rubygame.quit }
25
+
26
+
27
+ # Decide which image file to load.
28
+ this_dir = File.dirname( __FILE__ )
29
+ file = File.expand_path( "rubygame.png", this_dir ) # default file
30
+ if ARGV[0]
31
+ file = File.expand_path( ARGV[0], this_dir )
32
+ else
33
+ puts "You can pass an script to this file to load it."
34
+ end
35
+
36
+
37
+ # Wrap this code in a "begin/rescue" block to recover from errors if
38
+ # the image cannot be loaded.
39
+ #
40
+ begin
41
+
42
+ # Load the image
43
+ image = Surface.load( file )
44
+
45
+ # Open a new Rubygame window to fit the image.
46
+ screen = Screen.open( image.size )
47
+ screen.title = File.basename(file)
48
+
49
+ # Blit ("paste") the image onto the screen.
50
+ image.blit( screen, [0,0] )
51
+
52
+ rescue SDLError, NoMethodError
53
+
54
+ # Oops, load failed.
55
+ puts "#{File.basename($0)}: Could not load image: #{file}"
56
+
57
+ # Open a new Rubygame window
58
+ screen = Screen.open( [200,200] )
59
+ screen.title = "Load Error"
60
+
61
+ # Fill with white
62
+ screen.fill( :white )
63
+
64
+ # Thick red line from top left to bottom right.
65
+ # Point [0,0] is the top left corner of the screen,
66
+ # [200,200] is bottom right.
67
+ #
68
+ screen.draw_polygon_s( [[ -5, 5], [ 5, -5],
69
+ [205, 195], [195, 205]], :red )
70
+
71
+ # Now from top right to bottom left.
72
+ screen.draw_polygon_s( [[195, -5], [205, 5],
73
+ [ 5, 205], [ -5, 195]], :red )
74
+
75
+ end
76
+
77
+
78
+ # Set up an event handler to listen for events:
79
+ #
80
+ # - Q or Escape keys press
81
+ # - Right mouse click inside the window
82
+ # - Window close button press
83
+ #
84
+ # When any of these events occurs, the "exit_script" method is called.
85
+ #
86
+ class MyHandler
87
+ include Rubygame::EventHandler::HasEventHandler
88
+ end
89
+
90
+ handler = MyHandler.new
91
+ handler.make_magic_hooks( :q => :exit_script,
92
+ :escape => :exit_script,
93
+ :mouse_right => :exit_script,
94
+ QuitRequested => :exit_script )
95
+
96
+ def exit_script
97
+ exit
98
+ end
99
+
100
+
101
+ # Repeat this code until the user quits.
102
+ loop do
103
+
104
+ # Fetch the user input events from SDL.
105
+ events = Rubygame::Events.fetch_sdl_events
106
+
107
+ # Pass each input to the event handler to check.
108
+ events.each do |event|
109
+ handler.handle( event )
110
+ end
111
+
112
+ # Refresh the screen
113
+ screen.update
114
+
115
+ # Pause for a while before checking for more events.
116
+ sleep 0.1
117
+
118
+ end
@@ -7,7 +7,7 @@ include Rubygame
7
7
 
8
8
  Rubygame.init
9
9
 
10
- screen = Screen.set_mode([320,240])
10
+ screen = Screen.open([320,240])
11
11
 
12
12
  queue = EventQueue.new() {
13
13
  |q| q.ignore = [MouseMotionEvent, ActiveEvent]
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygame
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Croisant
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-23 00:00:00 -05:00
12
+ date: 2009-10-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,18 +22,29 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.7.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-sdl-ffi
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ version:
25
35
  description:
26
36
  email: jacius@gmail.com
27
37
  executables: []
28
38
 
29
- extensions:
30
- - Rakefile
39
+ extensions: []
40
+
31
41
  extra_rdoc_files:
32
42
  - doc/windows_install.rdoc
43
+ - doc/custom_sdl_load_paths.rdoc
44
+ - doc/keyboard_symbols.rdoc
33
45
  - doc/macosx_install.rdoc
34
46
  - doc/managing_framerate.rdoc
35
47
  - doc/getting_started.rdoc
36
- - doc/extended_readme.rdoc
37
48
  - README
38
49
  - LICENSE
39
50
  - CREDITS
@@ -41,9 +52,13 @@ extra_rdoc_files:
41
52
  - NEWS
42
53
  files:
43
54
  - lib/rubygame.rb
55
+ - lib/rubygame/main.rb
44
56
  - lib/rubygame/ftor.rb
57
+ - lib/rubygame/sound.rb
58
+ - lib/rubygame/screen.rb
45
59
  - lib/rubygame/clock.rb
46
60
  - lib/rubygame/constants.rb
61
+ - lib/rubygame/mixer.rb
47
62
  - lib/rubygame/color/models/rgb.rb
48
63
  - lib/rubygame/color/models/hsl.rb
49
64
  - lib/rubygame/color/models/hsv.rb
@@ -53,18 +68,25 @@ files:
53
68
  - lib/rubygame/color/palettes/x11.rb
54
69
  - lib/rubygame/event.rb
55
70
  - lib/rubygame/event_actions.rb
71
+ - lib/rubygame/joystick.rb
56
72
  - lib/rubygame/events.rb
57
73
  - lib/rubygame/rect.rb
58
74
  - lib/rubygame/mediabag.rb
59
75
  - lib/rubygame/color.rb
60
76
  - lib/rubygame/sprite.rb
61
77
  - lib/rubygame/event_triggers.rb
78
+ - lib/rubygame/music.rb
79
+ - lib/rubygame/surface.rb
62
80
  - lib/rubygame/named_resource.rb
63
81
  - lib/rubygame/keyconstants.rb
64
82
  - lib/rubygame/hotspot.rb
83
+ - lib/rubygame/ttf.rb
65
84
  - lib/rubygame/sfont.rb
85
+ - lib/rubygame/gl.rb
66
86
  - lib/rubygame/queue.rb
87
+ - lib/rubygame/image.rb
67
88
  - lib/rubygame/shared.rb
89
+ - lib/rubygame/audio.rb
68
90
  - lib/rubygame/event_hook.rb
69
91
  - lib/rubygame/event_handler.rb
70
92
  - lib/rubygame/events/keyboard_events.rb
@@ -72,37 +94,8 @@ files:
72
94
  - lib/rubygame/events/misc_events.rb
73
95
  - lib/rubygame/events/mouse_events.rb
74
96
  - lib/rubygame/events/clock_events.rb
75
- - ext/rubygame/rubygame_event.h
76
- - ext/rubygame/rubygame_mixer.c
77
- - ext/rubygame/rubygame_ttf.h
78
- - ext/rubygame/rubygame_main.c
79
- - ext/rubygame/rubygame_joystick.h
80
- - ext/rubygame/rubygame_clock.h
81
- - ext/rubygame/rubygame_music.h
82
- - ext/rubygame/rubygame_gfx.h
83
- - ext/rubygame/rubygame_shared.c
84
- - ext/rubygame/rubygame_music.c
85
- - ext/rubygame/rubygame_gl.h
86
- - ext/rubygame/rubygame_screen.c
87
- - ext/rubygame/rubygame_event2.c
88
- - ext/rubygame/rubygame_sound.c
89
- - ext/rubygame/rubygame_shared.h
90
- - ext/rubygame/rubygame_image.h
91
- - ext/rubygame/rubygame_surface.h
92
- - ext/rubygame/rubygame_screen.h
93
- - ext/rubygame/rubygame_event2.h
94
- - ext/rubygame/rubygame_joystick.c
95
- - ext/rubygame/rubygame_sound.h
96
- - ext/rubygame/rubygame_clock.c
97
- - ext/rubygame/rubygame_surface.c
98
- - ext/rubygame/rubygame_main.h
99
- - ext/rubygame/rubygame_gfx.c
100
- - ext/rubygame/rubygame_event.c
101
- - ext/rubygame/rubygame_ttf.c
102
- - ext/rubygame/rubygame_gl.c
103
- - ext/rubygame/rubygame_mixer.h
104
- - ext/rubygame/rubygame_image.c
105
- - ext/body/rubygame_body.so
97
+ - lib/rubygame/gfx.rb
98
+ - lib/rubygame/deprecated_mixer.rb
106
99
  - samples/demo_utf8.rb
107
100
  - samples/README
108
101
  - samples/song.ogg
@@ -111,26 +104,28 @@ files:
111
104
  - samples/whiff.wav
112
105
  - samples/framerate.rb
113
106
  - samples/demo_rubygame.rb
107
+ - samples/rubygame.png
114
108
  - samples/demo_gl.rb
115
109
  - samples/chimp.bmp
116
110
  - samples/term16.png
117
111
  - samples/demo_draw.rb
118
112
  - samples/chimp.rb
119
113
  - samples/demo_ttf.rb
120
- - samples/keys.rb
121
114
  - samples/panda.png
122
115
  - samples/punch.wav
123
116
  - samples/FreeSans.ttf
124
117
  - samples/demo_sfont.rb
118
+ - samples/image_viewer.rb
125
119
  - samples/demo_gl_tex.rb
126
120
  - samples/ruby.png
127
121
  - samples/load_and_blit.rb
128
122
  - samples/fist.bmp
129
123
  - doc/windows_install.rdoc
124
+ - doc/custom_sdl_load_paths.rdoc
125
+ - doc/keyboard_symbols.rdoc
130
126
  - doc/macosx_install.rdoc
131
127
  - doc/managing_framerate.rdoc
132
128
  - doc/getting_started.rdoc
133
- - doc/extended_readme.rdoc
134
129
  - README
135
130
  - LICENSE
136
131
  - CREDITS
@@ -146,7 +141,6 @@ rdoc_options: []
146
141
  require_paths:
147
142
  - lib
148
143
  - lib/rubygame/
149
- - ext/rubygame/
150
144
  required_ruby_version: !ruby/object:Gem::Requirement
151
145
  requirements:
152
146
  - - ">="
@@ -166,7 +160,7 @@ requirements:
166
160
  - SDL_mixer >= 1.2.7 (optional)
167
161
  - SDL_ttf >= 2.0.6 (optional)
168
162
  rubyforge_project: rubygame
169
- rubygems_version: 1.3.4
163
+ rubygems_version: 1.3.5
170
164
  signing_key:
171
165
  specification_version: 3
172
166
  summary: Clean and powerful library for game programming
data/Rakefile DELETED
@@ -1,537 +0,0 @@
1
- #
2
- # This is the Rakefile for Rubygame. It's used for
3
- # compiling, packaging, installing generating the
4
- # documentation, and running specs.
5
- #
6
-
7
-
8
- # The version number for Rubygame.
9
- RUBYGAME_VERSION = [2,5,3]
10
-
11
-
12
- #
13
- # The following terms (the MIT license) apply to this Rakefile:
14
- #
15
- # Copyright (c) 2008 John Croisant
16
- #
17
- # Permission is hereby granted, free of charge, to any person
18
- # obtaining a copy of this software and associated documentation files
19
- # (the "Software"), to deal in the Software without restriction,
20
- # including without limitation the rights to use, copy, modify, merge,
21
- # publish, distribute, sublicense, and/or sell copies of the Software,
22
- # and to permit persons to whom the Software is furnished to do so,
23
- # subject to the following conditions:
24
- #
25
- # The above copyright notice and this permission notice shall be
26
- # included in all copies or substantial portions of the Software.
27
- #
28
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32
- # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33
- # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
- # SOFTWARE.
36
- #
37
-
38
-
39
- require 'rubygems'
40
-
41
- require 'rake'
42
- require 'rake/gempackagetask'
43
- require 'rake/rdoctask'
44
-
45
- require "rbconfig"
46
- include Config
47
-
48
- require 'English'
49
-
50
- class ShellCommandError < RuntimeError
51
- end
52
-
53
- # Execute the shell command and raise ShellCommandError if
54
- # the command failed.
55
- #
56
- # If verbose is true, outputs the command string to the console.
57
- # If it's false, it outputs the pretty string to the console instead.
58
- #
59
- def try_shell( command, pretty="", verbose=false )
60
- if verbose
61
- puts command
62
- else
63
- puts pretty unless pretty.empty?
64
- end
65
-
66
- result = `#{command}`
67
-
68
- unless $CHILD_STATUS.exitstatus == 0
69
- raise ShellCommandError, "Command failed. Aborting."
70
- end
71
-
72
- return result
73
- end
74
-
75
- def try_sdl_config( flag )
76
- begin
77
- if $options[:"sdl-config"]
78
- return try_shell("sdl-config #{flag}").chomp
79
- else
80
- return String.new
81
- end
82
- rescue ShellCommandError
83
- warn "WARNING: 'sdl-config' failed."
84
- warn "Continuing anyway, but compile may fail."
85
- return String.new
86
- end
87
- end
88
-
89
- # Get a variable from ENV or CONFIG, with ENV having precedence.
90
- # Returns "" if the variable didn't exist at all.
91
- def from_env_or_config(string)
92
- ([ENV[string], CONFIG[string]] - ["", nil])[0] or ""
93
- end
94
-
95
- OBJEXT = from_env_or_config("OBJEXT")
96
- DLEXT = from_env_or_config("DLEXT")
97
-
98
- gem_spec = Gem::Specification.new do |s|
99
- s.name = "rubygame"
100
- s.version = RUBYGAME_VERSION.join(".")
101
- s.author = "John Croisant"
102
- s.email = "jacius@gmail.com"
103
- s.homepage = "http://rubygame.org/"
104
- s.summary = "Clean and powerful library for game programming"
105
- s.has_rdoc = true
106
- s.rubyforge_project = "rubygame"
107
-
108
- s.files = FileList.new do |fl|
109
- fl.include("{lib,ext,samples,doc}/**/*")
110
- fl.exclude(/svn/)
111
- #fl.exclude(/\.#{OBJEXT}/)
112
- end
113
-
114
- s.require_paths = ["lib", "lib/rubygame/", "ext/rubygame/"]
115
- s.extensions = ["Rakefile"]
116
-
117
- s.extra_rdoc_files = FileList.new do |fl|
118
- fl.include "doc/*.rdoc"
119
- fl.include "README", "LICENSE", "CREDITS", "ROADMAP", "NEWS"
120
- end
121
-
122
- s.required_ruby_version = ">= 1.8"
123
- s.add_dependency( "rake", ">=0.7.0" )
124
- s.requirements = ["SDL >= 1.2.7",
125
- "SDL_gfx >= 2.0.10 (optional)",
126
- "SDL_image >= 1.2.3 (optional)",
127
- "SDL_mixer >= 1.2.7 (optional)",
128
- "SDL_ttf >= 2.0.6 (optional)"]
129
-
130
- end
131
-
132
- task :binary do
133
- gem_spec.platform = Gem::Platform::CURRENT
134
- end
135
-
136
- Rake::GemPackageTask.new(gem_spec) do |pkg|
137
- pkg.need_tar_bz2 = true
138
- end
139
-
140
- Rake::RDocTask.new do |rd|
141
- rd.main = "README"
142
- rd.title = "Rubygame #{RUBYGAME_VERSION.join(".")} Docs"
143
- rd.rdoc_files.include("ext/rubygame/*.c",
144
- "lib/rubygame/**/*.rb",
145
- "doc/*.rdoc",
146
- "README",
147
- "LICENSE",
148
- "CREDITS",
149
- "ROADMAP",
150
- "NEWS")
151
- end
152
-
153
- task :default => [:build]
154
- desc "Compile all of the extensions"
155
- task :build
156
-
157
- require 'rake/clean'
158
- task(:clean) { puts "Cleaning out temporary generated files" }
159
- task(:clobber) { puts "Cleaning out final generated files" }
160
-
161
- ##############################
162
- ## BUILD OPTIONS ##
163
- ##############################
164
-
165
- $options = {
166
- :"sdl-gfx" => true,
167
- :"sdl-image" => true,
168
- :"sdl-ttf" => true,
169
- :"sdl-mixer" => true,
170
- :opengl => true,
171
- :"sdl-config" => true,
172
- :universal => false,
173
- :debug => false,
174
- :verbose => false,
175
- :sitearchdir => CONFIG["sitearchdir"],
176
- :sitelibdir => CONFIG["sitelibdir"]
177
- }
178
-
179
- # Default behavior for win32 is to skip sdl_config,
180
- # since it's usually not available. It can still be
181
- # enabled through the options, though.
182
- if RUBY_PLATFORM =~ /win32/
183
- $options[:"sdl-config"] = false
184
- end
185
-
186
- # Define tasks to enable and disable bool options.
187
- #
188
- # rake option
189
- # rake no-option
190
- #
191
- # task_name:: the task name to use
192
- # option_name:: the option name (if different from
193
- # the task name)
194
- # desc:: a longer description, to fill
195
- # "Enable ________.", if different
196
- # from the task name.
197
- #
198
- def bool_option( task_name, option_name=nil, desc=nil )
199
- option_name = task_name unless option_name
200
- option_name = option_name.intern if option_name.kind_of? String
201
-
202
- desc = task_name.to_s unless desc
203
-
204
- notask_name = "no-#{task_name.to_s}".intern
205
-
206
- is_true = $options[option_name]
207
-
208
- desc "Enable #{desc} #{'(default)' if is_true}"
209
- task(task_name) { $options[option_name] = true }
210
-
211
- desc "Disable #{desc} #{'(default)' unless is_true}"
212
- task(notask_name) { $options[option_name] = false }
213
- end
214
-
215
- # Gather a string option from an environment variable:
216
- #
217
- # rake option="the value of the option"
218
- #
219
- # task_name:: the task name to use
220
- # option_name:: the option name (if different from
221
- # the task name)
222
- #
223
- def string_option( task_name, option_name=nil )
224
- option_name = task_name unless option_name
225
- option_name = option_name.intern if option_name.kind_of? String
226
-
227
- $options[option_name] = ENV["#{task_name}"] if ENV["#{task_name}"]
228
- end
229
-
230
- bool_option :"sdl-gfx", nil, "SDL_gfx support"
231
- bool_option :"sdl-image", nil, "SDL_image support"
232
- bool_option :"sdl-mixer", nil, "SDL_mixer support"
233
- bool_option :"sdl-ttf", nil, "SDL_ttf support"
234
- bool_option :"sdl-config", nil, "guess compiler flags for SDL"
235
- bool_option :opengl, nil, "OpenGL support"
236
- bool_option :debug, nil, "compile with debug symbols"
237
- bool_option :verbose, nil, "show compiler commands"
238
- bool_option :universal, nil, "universal binary (MacOS X Intel)"
239
-
240
- string_option "RUBYARCHDIR", :sitearchdir
241
- string_option :sitearchdir
242
-
243
- string_option "RUBYLIBDIR", :sitelibdir
244
- string_option :sitelibdir
245
-
246
-
247
- CFLAGS = [from_env_or_config("CFLAGS"),
248
- try_sdl_config("--cflags"),
249
- "-I. -I#{CONFIG['topdir']}",
250
- (if CONFIG['rubyhdrdir']
251
- "-I#{CONFIG['rubyhdrdir']} " +\
252
- "-I#{File.join(CONFIG['rubyhdrdir'], CONFIG['arch'])}"
253
- end),
254
- "-DRUBYGAME_MAJOR_VERSION=#{RUBYGAME_VERSION[0]}",
255
- "-DRUBYGAME_MINOR_VERSION=#{RUBYGAME_VERSION[1]}",
256
- "-DRUBYGAME_PATCHLEVEL=#{RUBYGAME_VERSION[2]}"
257
- ].join(" ")
258
-
259
- LINK_FLAGS = [from_env_or_config("LIBRUBYARG_SHARED"),
260
- from_env_or_config("LDFLAGS"),
261
- try_sdl_config("--libs")].join(" ")
262
-
263
- DEFAULT_EXTDIR = File.join('ext','rubygame','')
264
-
265
- class ExtensionModule
266
- @@libflag = " -l%s " # compiler flag for giving linked libraries
267
- attr_accessor :dynlib, :objs, :libs, :cflags, :lflags, :directory
268
- def initialize(&block)
269
- @directory = DEFAULT_EXTDIR
270
- @dynlib = ""
271
- @objs = []
272
- @libs = []
273
- @lflags = ""
274
- yield self if block_given?
275
- end
276
-
277
- def add_lib( lib )
278
- @lflags << @@libflag%lib
279
- end
280
-
281
- def add_header( header )
282
- #CFLAGS << " -DHAVE_#{header.upcase.gsub('.','_')} "
283
- end
284
-
285
- def create_all_tasks()
286
- create_obj_task
287
- create_dl_task
288
- CLEAN.include("#{@directory}/*.#{OBJEXT}")
289
- CLOBBER.include("#{@directory}/*.#{DLEXT}")
290
- end
291
-
292
- # Create a file task for each dynamic library (.so) we want to generate.
293
- #
294
- # The file task invokes another task which does the actual compiling, and
295
- # has the true prerequisites.
296
- #
297
- # This is done so that the prerequisites don't have to be compiled when
298
- # the final product already exists (such as in the precompiled win32 gem).
299
- #
300
- def create_dl_task
301
- dynlib_full = File.join( @directory, "#{dynlib}.#{DLEXT}" )
302
- objs_full = @objs.collect { |obj|
303
- File.join( @directory, "#{obj}.#{OBJEXT}" )
304
- }
305
-
306
- desc "Compile the #{@dynlib} extension"
307
- file dynlib_full => objs_full do |task|
308
-
309
- link_command = "#{from_env_or_config('LDSHARED')} #{LINK_FLAGS} #{@lflags} -o #{dynlib_full} #{task.prerequisites.join(' ')}"
310
-
311
-
312
- # If link command includes i386 arch, and we're not allowing universal
313
- if( /-arch i386/ === link_command and not $options[:universal] )
314
- # Strip "-arch ppc" to prevent building a universal binary.
315
- link_command.gsub!("-arch ppc","")
316
- end
317
-
318
- try_shell( link_command,
319
- "Linking compiled files to create #{File.basename(@directory)}/#{File.basename(dynlib_full)}",
320
- $options[:verbose] )
321
- end
322
-
323
- task :build => [dynlib_full] # Add this as a prereq of the build
324
- task :install_ext => [dynlib_full] # ...and install_ext tasks
325
- end
326
-
327
- def create_obj_task
328
- # A rule for object files (".o" on linux).
329
- # This won't work for rake < 0.7.2, because the proc returns an Array.
330
- # If it raises an exception, we'll try a more compatible way.
331
- rule(/#{@directory}.+\.#{OBJEXT}$/ =>
332
- [
333
- # Generate dependencies for this .o file
334
- proc do |objfile|
335
- source = objfile.sub(".#{OBJEXT}", ".c") # the .c file
336
- [source] + depends_headers( source ) # Array of .c + .h dependencies
337
- end
338
- ])\
339
- do |t|
340
-
341
- compile_command = "#{from_env_or_config('CC')} -c #{CFLAGS} #{"-g " if $options[:debug]} #{t.source} -o #{t.name}"
342
-
343
- # If compile command includes i386 arch, and we're not allowing universal
344
- if( /-arch i386/ === compile_command and not $options[:universal] )
345
- # Strip "-arch ppc" to prevent building a universal binary.
346
- compile_command.gsub!("-arch ppc","")
347
- end
348
-
349
- try_shell( compile_command,
350
- "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}",
351
- $options[:verbose] )
352
- end
353
- rescue
354
- # Generate a .o rule for each .c file in the directory.
355
- FileList.new("#{@directory}*.c").each do |source|
356
- object = source.sub(".c", ".#{OBJEXT}")
357
- file object => ([source] + depends_headers( source )) do |t|
358
- compile_command = "#{CONFIG['CC']} -c #{CFLAGS} #{"-g " if $options[:debug]} #{source} -o #{t.name}"
359
-
360
- try_shell( compile_command,
361
- "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}",
362
- $options[:verbose] )
363
- end
364
- end
365
- end
366
-
367
- # Extracts the names of all the headers that the C file depends on.
368
- def depends_headers( filename )
369
- return [] # workaround for a bug
370
- depends = []
371
- File.open(filename, "r") do |file|
372
- file.each_line do |line|
373
- if /#include\s+"(\w+\.h)"/ =~ line
374
- depends << @directory+$1
375
- end
376
- end
377
- end
378
- return depends
379
- end
380
- end
381
-
382
- rubygame_core = ExtensionModule.new do |core|
383
- core.dynlib = 'rubygame_core'
384
- core.objs = ['rubygame_main',
385
- 'rubygame_shared',
386
- 'rubygame_event',
387
- 'rubygame_event2',
388
- 'rubygame_gl',
389
- 'rubygame_joystick',
390
- 'rubygame_screen',
391
- 'rubygame_surface',
392
- 'rubygame_clock',
393
- ]
394
- core.create_all_tasks()
395
- end
396
-
397
- # TODO: We should check if the libraries exist?
398
-
399
- rubygame_gfx = ExtensionModule.new do |gfx|
400
- gfx.dynlib = 'rubygame_gfx'
401
- gfx.objs = ['rubygame_shared', 'rubygame_gfx']
402
- gfx.add_lib( 'SDL_gfx' )
403
- gfx.add_header( 'SDL_gfxPrimitives.h')
404
- gfx.add_header( 'SDL_rotozoom.h' )
405
- gfx.create_all_tasks() if $options[:"sdl-gfx"]
406
- end
407
-
408
- rubygame_image = ExtensionModule.new do |image|
409
- image.dynlib = 'rubygame_image'
410
- image.objs = ['rubygame_shared', 'rubygame_image']
411
- image.add_lib('SDL_image')
412
- image.add_header('SDL_image.h')
413
- image.create_all_tasks() if $options[:"sdl-image"]
414
- end
415
-
416
- rubygame_mixer = ExtensionModule.new do |mixer|
417
- mixer.dynlib = 'rubygame_mixer'
418
- mixer.objs = ['rubygame_shared', 'rubygame_mixer', 'rubygame_sound', 'rubygame_music']
419
- mixer.add_lib('SDL_mixer')
420
- mixer.add_header('SDL_mixer.h')
421
- mixer.create_all_tasks() if $options[:"sdl-mixer"]
422
- end
423
-
424
- rubygame_ttf = ExtensionModule.new do |ttf|
425
- ttf.dynlib = 'rubygame_ttf'
426
- ttf.add_lib('SDL_ttf')
427
- ttf.objs = ['rubygame_shared', 'rubygame_ttf']
428
- ttf.add_header('SDL_ttf.h')
429
- ttf.create_all_tasks() if $options[:"sdl-ttf"]
430
- end
431
-
432
- if $options[:opengl]
433
- CFLAGS << " -DHAVE_OPENGL "
434
- end
435
-
436
- desc "(Called when installing via Rubygems)"
437
- task :extension => [:fix_filenames, :build]
438
-
439
- task :fix_filenames do
440
- unless DLEXT == 'so'
441
- Rake::Task[:install_ext].prerequisites.each do |prereq|
442
- prereq = prereq.ext('so')
443
- if File.exist? prereq
444
- mv prereq, prereq.ext(DLEXT)
445
- end
446
- end
447
- end
448
- end
449
-
450
- desc "Install just the extensions"
451
- task :install_ext do |task|
452
- puts "Installing extensions to #{$options[:sitearchdir]}"
453
- mkdir_p $options[:sitearchdir]
454
- cp task.prerequisites.to_a, $options[:sitearchdir]
455
- end
456
-
457
- desc "Install just the library"
458
- task :install_lib do |task|
459
- puts "Installing library to #{$options[:sitelibdir]}"
460
-
461
- files = FileList.new do |fl|
462
- fl.include("lib/**/*.rb")
463
- fl.exclude(/svn/)
464
- end
465
-
466
- files.each do |f|
467
- dir = File.join($options[:sitelibdir], File.dirname(f).sub('lib',''), "")
468
- mkdir_p dir
469
- cp f, dir
470
- end
471
- end
472
-
473
- desc "Install both the extensions and the library"
474
- task :install => [:install_ext, :install_lib]
475
-
476
-
477
-
478
- #########
479
- # SPECS #
480
- #########
481
-
482
- begin
483
- require 'spec/rake/spectask'
484
-
485
-
486
- desc "Run all specs"
487
- Spec::Rake::SpecTask.new do |t|
488
- t.spec_files = FileList['spec/*_spec.rb']
489
- end
490
-
491
-
492
- namespace :spec do
493
- desc "Run all specs"
494
- Spec::Rake::SpecTask.new(:all) do |t|
495
- t.spec_files = FileList['spec/*_spec.rb']
496
- end
497
-
498
- desc "Run spec/[name]_spec.rb (e.g. 'color')"
499
- task :name do
500
- puts( "This is just a stand-in spec.",
501
- "Run rake spec:[name] where [name] is e.g. 'color', 'music'." )
502
- end
503
- end
504
-
505
-
506
- rule(/spec:.+/) do |t|
507
- name = t.name.gsub("spec:","")
508
-
509
- path = File.join( File.dirname(__FILE__),'spec','%s_spec.rb'%name )
510
-
511
- if File.exist? path
512
- Spec::Rake::SpecTask.new(name) do |t|
513
- t.spec_files = [path]
514
- end
515
-
516
- puts "\nRunning spec/%s_spec.rb"%name
517
-
518
- Rake::Task[name].invoke
519
- else
520
- puts "File does not exist: %s"%path
521
- end
522
-
523
- end
524
-
525
- rescue LoadError
526
-
527
- error = "ERROR: RSpec is not installed?"
528
-
529
- task :spec do
530
- puts error
531
- end
532
-
533
- rule( /spec:.*/ ) do
534
- puts error
535
- end
536
-
537
- end