rubygame 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CREDITS CHANGED
@@ -48,3 +48,13 @@
48
48
  Email:: danielneis at gmail.com
49
49
  Contribution:: Patch to add Sprite#undraw (based on UpdateGroup#undraw).
50
50
  Date:: 2007-07-29 (r460).
51
+
52
+ - <b>ippa</a>
53
+ Email:: admin at rubylicio.us
54
+ Contribution:: Patch to optimize Rect#collide_rect?
55
+ Date:: 2007-11-21 (r595)
56
+
57
+ - <b>Michael Swiger</b> / mokkan
58
+ Email:: mokkan at users.sourceforge.net
59
+ Contribution:: Patch to add Screen.icon=
60
+ Date:: 2007-11-21 (r597)
@@ -1,3 +1,41 @@
1
+ == Changes from 2.1.0 to 2.2.0
2
+
3
+ === Features
4
+
5
+ - Add: Rubygame::Color module
6
+ - ColorRGB, ColorHSV, and ColorHSL classes.
7
+ - X11 and CSS palettes of pre-defined colors.
8
+ - Surface methods can accept ColorRGB etc. for colors.
9
+ - Automatic lookup of color names when a string or symbol
10
+ is passed for a color to Surface methods.
11
+ - Add: Surface#set_at().
12
+
13
+ - Add: Screen#icon=().
14
+
15
+ === Bug Fixes
16
+
17
+ - Fix: Surface#draw_arc was incorrectly documented as Surface#draw_pie
18
+
19
+ === Improvements
20
+
21
+ - Rect#collide_rect? is now faster.
22
+ - Sprites::Group#collide_group can take a block; arguments are deprecated.
23
+
24
+ === Other Stuff
25
+
26
+ - Build system correctly recompiles if source has changed.
27
+ - Build system option syntax has changed. See the README: Advanced Install.
28
+ - Build system will correctly exit with an error status if it can't compile;
29
+ fixes Rubygems trying to install even when compile failed.
30
+
31
+ === Acknowledgements
32
+
33
+ - Michael Swiger (mokkan) for Screen#icon=.
34
+ - ippa for optimizing Rect#collide_rect?.
35
+
36
+
37
+
38
+
1
39
  == Changes from 2.0.1 to 2.1.0
2
40
 
3
41
  === Features
@@ -41,6 +79,7 @@
41
79
  - Roger Ostrander (denor) for and bug fixes and adding Rubygame.key_name.
42
80
  - Bjorn De Meyer (beoran) for numerous patches and improvements.
43
81
 
82
+
44
83
 
45
84
 
46
85
  == Changes from 2.0.0 to 2.0.1
data/README CHANGED
@@ -49,7 +49,7 @@
49
49
  If you are compiling source on a binary-based Linux ditribution,
50
50
  you will also need the "dev" packages of ruby, SDL, SDL_gfx, SDL_image,
51
51
  SDL_mixer, and SDL_ttf. (Really, you just need the header files.)
52
-
52
+
53
53
  And of course, if you are compiling the source, you will need a C compiler!
54
54
  These versions of gcc worked fine when I tried them; other compilers might
55
55
  work too:
@@ -69,18 +69,35 @@
69
69
 
70
70
  === Advanced Install
71
71
 
72
- You can provide flags to configure how the build and install tasks run.
73
- Flags are provided in an environmental variable, RUBYGAME_CONFIG.
74
- (Yes, I know this is an ugly hack. At least you only have to do it once.)
72
+ The build and install tasks can be configured by providing certain commands
73
+ to rake:
74
+
75
+ * no-sdl-gfx:: do not build modules which depend on SDL_gfx
76
+ * no-sdl-image:: do not build modules which depend on SDL_image
77
+ * no-sdl-mixer:: do not build modules which depend on SDL_mixer
78
+ * no-sdl-ttf:: do not build modules which depend on SDL_ttf
79
+ * no-opengl:: do not build modules which depend on OpenGL
80
+
81
+ * no-sdl-config:: do not guess compiler/linker flags using `sdl-config'
82
+
83
+ * debug:: build modules with debbugging flags enabled
84
+ * verbose:: display the build commands as they are run
75
85
 
76
- Try this command to see all the possible configuration flags:
86
+ Additionally, the build process respects certain environmental variables.
87
+ In particular, CFLAGS and LDFLAGS are important for users compiling with
88
+ the no-sdl-config command.
77
89
 
78
- $ RUBYGAME_CONFIG="--help" rake
90
+ * CC:: C compiler command
91
+ * CFLAGS:: flags passed to the C compiler
92
+ * LDSHARED:: linker command
93
+ * LDFLAGS:: flags passed to the linker
94
+ * RUBYARCHDIR:: where to install platform-specific compiled extensions
95
+ * RUBYLIBDIR:: where to install platform-independent interpreted libs
79
96
 
80
97
  IMPORTANT: if you are missing any optional SDL_* libraries, you must specify
81
- "--no-*" flags for those libraries. For example, if you don't have SDL_gfx:
98
+ "no-*" flags for those libraries. For example, if you don't have SDL_gfx:
82
99
 
83
- $ RUBYGAME_CONFIG="--no-gfx" rake build
100
+ $ rake no-gfx build
84
101
 
85
102
  If you don't disable the features, the compile will probably fail when it
86
103
  looks for the headers and libraries. (The build system is not smart enough to
@@ -1,15 +1,11 @@
1
- = TODO / ROADMAP
2
-
3
- === 2.2.0 (next minor release)
4
-
5
- - Color (representation of a color)
6
- - ColorRGB and ColorHSV classes
7
- - Mix/combine colors using various blending modes (add, multiply, etc.)
8
- - Library of common pre-defined colors. (:red, :black, :chartreuse, etc.)
9
- - Integrate with SDL/OpenGL functions (automatic conversion).
1
+ = ROADMAP
10
2
 
11
3
  === 3.0.0 (next major release)
12
4
 
5
+ - Backwards compatibility will be broken:
6
+ - Surface#get_at
7
+ - Sprites::Group#collide_group
8
+
13
9
  - New scene/camera/sprite sytem.
14
10
  - New geometric primitives classes (for collision detection, drawing).
15
11
  - New hook-based event handler system.
@@ -43,3 +39,5 @@
43
39
  - Screen#update (cannot pass object with rect attribute)
44
40
  - Screen#update_rects (same as above)
45
41
  - Why not just call the ruby function from within C?
42
+
43
+ - Generate bounding Polygon from an image automatically.
data/Rakefile CHANGED
@@ -8,24 +8,47 @@ require 'rake/rdoctask'
8
8
  require "rbconfig"
9
9
  include Config
10
10
 
11
+ require 'English'
12
+
13
+ class ShellCommandError < RuntimeError
14
+ end
15
+
16
+ # Execute the block (which is supposed to perform a shell command),
17
+ # then raise ShellCommandError if the command failed.
18
+ def try_shell( &block )
19
+ result = yield
20
+
21
+ unless $CHILD_STATUS.exitstatus == 0
22
+ raise ShellCommandError, "Command failed. Aborting."
23
+ end
24
+
25
+ return result
26
+ end
27
+
28
+ def try_sdl_config( flag )
29
+ begin
30
+ if $options[:"sdl-config"]
31
+ return try_shell { `sdl-config #{flag}`.chomp }
32
+ else
33
+ return String.new
34
+ end
35
+ rescue ShellCommandError
36
+ warn "WARNING: 'sdl-config' failed."
37
+ warn "Continuing anyway, but compile may fail."
38
+ return String.new
39
+ end
40
+ end
41
+
11
42
  # Get a variable from ENV or CONFIG, with ENV having precedence.
12
43
  # Returns "" if the variable didn't exist at all.
13
44
  def from_env_or_config(string)
14
45
  ([ENV[string], CONFIG[string]] - ["", nil])[0] or ""
15
46
  end
16
47
 
17
- def try_sdl_config( flag )
18
- if $options.sdl_config
19
- `sdl-config #{flag}`.chomp
20
- else
21
- return ""
22
- end
23
- end
24
-
25
48
  OBJEXT = from_env_or_config("OBJEXT")
26
49
  DLEXT = from_env_or_config("DLEXT")
27
50
 
28
- RUBYGAME_VERSION = "2.1.0"
51
+ RUBYGAME_VERSION = "2.2.0"
29
52
 
30
53
  spec = Gem::Specification.new do |s|
31
54
  s.name = "rubygame"
@@ -36,21 +59,20 @@ spec = Gem::Specification.new do |s|
36
59
  s.summary = "Clean and powerful library for game programming"
37
60
  s.has_rdoc = true
38
61
 
39
- candidates = Dir.glob("{lib,ext,samples,doc}/**/*")
40
- s.files = candidates.delete_if do |item|
41
- item.include?("svn") or item =~ /\.#{OBJEXT}/
62
+ s.files = FileList.new do |fl|
63
+ fl.include("{lib,ext,samples,doc}/**/*")
64
+ fl.exclude(/svn/)
65
+ #fl.exclude(/\.#{OBJEXT}/)
42
66
  end
43
67
 
44
68
  s.require_paths = ["lib", "lib/rubygame/", "ext/rubygame/"]
45
69
  s.autorequire = "rubygame.rb"
46
70
  s.extensions = ["Rakefile"]
47
71
 
48
- s.extra_rdoc_files = Dir.glob("doc/*.rdoc")
49
- s.extra_rdoc_files += ["README",
50
- "LICENSE",
51
- "CREDITS",
52
- "TODO",
53
- "Changelog"]
72
+ s.extra_rdoc_files = FileList.new do |fl|
73
+ fl.include "doc/*.rdoc"
74
+ fl.include "README", "LICENSE", "CREDITS", "ROADMAP", "NEWS"
75
+ end
54
76
  end
55
77
 
56
78
  task :linux do
@@ -73,13 +95,13 @@ Rake::RDocTask.new do |rd|
73
95
  rd.main = "README"
74
96
  rd.title = "Rubygame #{RUBYGAME_VERSION} Docs"
75
97
  rd.rdoc_files.include("ext/rubygame/*.c",
76
- "lib/rubygame/*.rb",
98
+ "lib/rubygame/**/*.rb",
77
99
  "doc/*.rdoc",
78
100
  "README",
79
101
  "LICENSE",
80
102
  "CREDITS",
81
- "TODO",
82
- "Changelog")
103
+ "ROADMAP",
104
+ "NEWS")
83
105
  end
84
106
 
85
107
  task :default => [:build]
@@ -90,101 +112,106 @@ require 'rake/clean'
90
112
  task(:clean) { puts "Cleaning out temporary generated files" }
91
113
  task(:clobber) { puts "Cleaning out final generated files" }
92
114
 
93
- # Options
94
-
95
- require 'ostruct'
96
- $options = OpenStruct.new(:gfx => true,
97
- :image => true,
98
- :ttf => true,
99
- :mixer => true,
100
- :opengl => true,
101
- :sdl_config => true,
102
- :debug => false,
103
- :verbose => false,
104
- :sitearchdir => CONFIG["sitearchdir"],
105
- :sitelibdir => CONFIG["sitelibdir"]
106
- )
107
-
108
- # Default behavior for win32 is to skip sdl-config,
115
+ ##############################
116
+ ## BUILD OPTIONS ##
117
+ ##############################
118
+
119
+ $options = {
120
+ :"sdl-gfx" => true,
121
+ :"sdl-image" => true,
122
+ :"sdl-ttf" => true,
123
+ :"sdl-mixer" => true,
124
+ :opengl => true,
125
+ :"sdl-config" => true,
126
+ :debug => false,
127
+ :verbose => false,
128
+ :sitearchdir => CONFIG["sitearchdir"],
129
+ :sitelibdir => CONFIG["sitelibdir"]
130
+ }
131
+
132
+ # Default behavior for win32 is to skip sdl_config,
109
133
  # since it's usually not available. It can still be
110
134
  # enabled through the options, though.
111
135
  if PLATFORM =~ /win32/
112
- $options.sdl_config = false
136
+ $options[:"sdl-config"] = false
113
137
  end
114
138
 
115
- require 'optparse'
116
- optparse = OptionParser.new
117
-
118
- optparse.banner = "Configure the rubygame build/install tasks."
119
-
120
- optparse.on("-g", "--debug",
121
- "Compile extensions with debug symbols.") do |val|
122
- $options.debug = val
123
- end
124
- optparse.on("-v", "--verbose", "Show commands while compiling.") do |val|
125
- $options.verbose = val
139
+ # Define tasks to enable and disable bool options.
140
+ #
141
+ # rake option
142
+ # rake no-option
143
+ #
144
+ # task_name:: the task name to use
145
+ # option_name:: the option name (if different from
146
+ # the task name)
147
+ # desc:: a longer description, to fill
148
+ # "Enable ________.", if different
149
+ # from the task name.
150
+ #
151
+ def bool_option( task_name, option_name=nil, desc=nil )
152
+ option_name = task_name unless option_name
153
+ option_name = option_name.intern if option_name.kind_of? String
154
+
155
+ desc = task_name.to_s unless desc
156
+
157
+ notask_name = "no-#{task_name.to_s}".intern
158
+
159
+ is_true = $options[option_name]
160
+
161
+ desc "Enable #{desc} #{'(default)' if is_true}"
162
+ task(task_name) { $options[option_name] = true }
163
+
164
+ desc "Disable #{desc} #{'(default)' unless is_true}"
165
+ task(notask_name) { $options[option_name] = false }
126
166
  end
127
- optparse.on("--[no-]gfx", "Compile rubygame_gfx or not.") do |val|
128
- $options.gfx = val
129
- end
130
- optparse.on("--[no-]image", "Compile rubygame_image or not.") do |val|
131
- $options.image = val
132
- end
133
- optparse.on("--[no-]ttf", "Compile rubygame_ttf or not.") do |val|
134
- $options.ttf = val
135
- end
136
- optparse.on("--[no-]mixer", "Compile rubygame_mixer or not.") do |val|
137
- $options.mixer = val
138
- end
139
- optparse.on("--[no-]opengl", "Enable OpenGL support.") do |val|
140
- $options.opengl = val
141
- end
142
- optparse.on("--[no-]sdl-config",
143
- "Feed results from `sdl-config' to \\",
144
- "\tthe compiler and linker or not.") do |val|
145
- $options.sdl_config = val
146
- end
147
- optparse.on("--sitearchdir PATH",
148
- "Install extensions into this PATH \\",
149
- "\tinstead of the usual sitearchdir.") do |val|
150
- $options.sitearchdir = val
151
- end
152
- optparse.on("--sitelibdir PATH",
153
- "Install library into this PATH \\",
154
- "\tinstead of the usual sitelibdir.") do |val|
155
- $options.sitelibdir = val
167
+
168
+ # Gather a string option from an environment variable:
169
+ #
170
+ # rake option="the value of the option"
171
+ #
172
+ # task_name:: the task name to use
173
+ # option_name:: the option name (if different from
174
+ # the task name)
175
+ #
176
+ def string_option( task_name, option_name=nil )
177
+ option_name = task_name unless option_name
178
+ option_name = option_name.intern if option_name.kind_of? String
179
+
180
+ $options[option_name] = ENV["#{task_name}"] if ENV["#{task_name}"]
156
181
  end
157
182
 
158
- # Rake is not very nice about letting us specify custom flags, so
159
- # we'll go around it in this way.
160
- optparse.parse( (ENV["RUBYGAME_CONFIG"] or "").split(" ") )
183
+ bool_option :"sdl-gfx", nil, "SDL_gfx support"
184
+ bool_option :"sdl-image", nil, "SDL_image support"
185
+ bool_option :"sdl-mixer", nil, "SDL_mixer support"
186
+ bool_option :"sdl-ttf", nil, "SDL_ttf support"
187
+ bool_option :"sdl-config", nil, "guess compiler flags for SDL"
188
+ bool_option :opengl, nil, "OpenGL support"
189
+ bool_option :debug, nil, "compil with debug symbols"
190
+ bool_option :verbose, nil, "show compiler commands"
161
191
 
162
- # rubygem passes RUBYARCHDIR=/path/to/some/directory when building extension
163
- rule( /RUBYARCHDIR/ ) do |t|
164
- $options.sitearchdir = t.name.split("=")[1]
165
- end
192
+ string_option "RUBYARCHDIR", :sitearchdir
193
+ string_option :sitearchdir
194
+
195
+ string_option "RUBYLIBDIR", :sitelibdir
196
+ string_option :sitelibdir
166
197
 
167
- # rubygem passes RUBYLIBDIR=/path/to/another/directory when building extension
168
- rule( /RUBYLIBDIR/ ) do |t|
169
- $options.sitelibdir = t.name.split("=")[1]
170
- end
171
198
 
172
199
  CFLAGS = [from_env_or_config("CFLAGS"),
173
200
  try_sdl_config("--cflags"),
174
201
  "-I. -I#{CONFIG['topdir']}",
175
- ("-g" if $options.debug) ].join(" ")
202
+ ("-g" if $options[:debug]) ].join(" ")
176
203
 
177
204
  LINK_FLAGS = [from_env_or_config("LIBRUBYARG_SHARED"),
178
205
  from_env_or_config("LDFLAGS"),
179
206
  try_sdl_config("--libs")].join(" ")
180
207
 
181
- DEFALUT_EXTDIR = File.join('ext','rubygame','')
208
+ DEFAULT_EXTDIR = File.join('ext','rubygame','')
182
209
 
183
210
  class ExtensionModule
184
211
  @@libflag = " -l%s " # compiler flag for giving linked libraries
185
212
  attr_accessor :dynlib, :objs, :libs, :cflags, :lflags, :directory
186
213
  def initialize(&block)
187
- @directory = DEFALUT_EXTDIR
214
+ @directory = DEFAULT_EXTDIR
188
215
  @dynlib = ""
189
216
  @objs = []
190
217
  @libs = []
@@ -221,20 +248,14 @@ class ExtensionModule
221
248
  File.join( @directory, "#{obj}.#{OBJEXT}" )
222
249
  }
223
250
 
224
- taskname = @dynlib.gsub('rubygame_','')
225
-
226
- file dynlib_full do
227
- Rake::Task[taskname].invoke
228
- end
229
-
230
251
  desc "Compile the #{@dynlib} extension"
231
- task taskname => objs_full do |task|
252
+ file dynlib_full => objs_full do |task|
232
253
  link_command = "#{from_env_or_config('LDSHARED')} #{LINK_FLAGS} #{@lflags} -o #{dynlib_full} #{task.prerequisites.join(' ')}"
233
- if( $options.verbose )
234
- sh link_command
254
+ if( $options[:verbose] )
255
+ try_shell { sh link_command }
235
256
  else
236
257
  puts "Linking compiled files to create #{File.basename(@directory)}/#{File.basename(dynlib_full)}"
237
- `#{link_command}`
258
+ try_shell { `#{link_command}` }
238
259
  end
239
260
  end
240
261
 
@@ -256,11 +277,11 @@ class ExtensionModule
256
277
  ])\
257
278
  do |t|
258
279
  compile_command = "#{from_env_or_config('CC')} -c #{CFLAGS} #{t.source} -o #{t.name}"
259
- if( $options.verbose )
260
- sh compile_command
280
+ if( $options[:verbose] )
281
+ try_shell { sh compile_command }
261
282
  else
262
283
  puts "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}"
263
- `#{compile_command}`
284
+ try_shell { `#{compile_command}` }
264
285
  end
265
286
  end
266
287
  rescue
@@ -269,11 +290,11 @@ class ExtensionModule
269
290
  object = source.sub(".c", ".#{OBJEXT}")
270
291
  file object => ([source] + depends_headers( source )) do |t|
271
292
  compile_command = "#{CONFIG['CC']} -c #{CFLAGS} #{source} -o #{t.name}"
272
- if( $options.verbose )
273
- sh compile_command
293
+ if( $options[:verbose] )
294
+ try_shell { sh compile_command }
274
295
  else
275
296
  puts "Compiling #{File.basename(@directory)}/#{File.basename(source)}"
276
- `#{compile_command}`
297
+ try_shell { `#{compile_command}` }
277
298
  end
278
299
  end
279
300
  end
@@ -316,7 +337,7 @@ rubygame_gfx = ExtensionModule.new do |gfx|
316
337
  gfx.add_lib( 'SDL_gfx' )
317
338
  gfx.add_header( 'SDL_gfxPrimitives.h')
318
339
  gfx.add_header( 'SDL_rotozoom.h' )
319
- gfx.create_all_tasks() if $options.gfx
340
+ gfx.create_all_tasks() if $options[:"sdl-gfx"]
320
341
  end
321
342
 
322
343
  rubygame_image = ExtensionModule.new do |image|
@@ -324,7 +345,7 @@ rubygame_image = ExtensionModule.new do |image|
324
345
  image.objs = ['rubygame_shared', 'rubygame_image']
325
346
  image.add_lib('SDL_image')
326
347
  image.add_header('SDL_image.h')
327
- image.create_all_tasks() if $options.image
348
+ image.create_all_tasks() if $options[:"sdl-image"]
328
349
  end
329
350
 
330
351
  rubygame_mixer = ExtensionModule.new do |mixer|
@@ -332,7 +353,7 @@ rubygame_mixer = ExtensionModule.new do |mixer|
332
353
  mixer.objs = ['rubygame_shared', 'rubygame_mixer']
333
354
  mixer.add_lib('SDL_mixer')
334
355
  mixer.add_header('SDL_mixer.h')
335
- mixer.create_all_tasks() if $options.mixer
356
+ mixer.create_all_tasks() if $options[:"sdl-mixer"]
336
357
  end
337
358
 
338
359
  rubygame_ttf = ExtensionModule.new do |ttf|
@@ -340,10 +361,10 @@ rubygame_ttf = ExtensionModule.new do |ttf|
340
361
  ttf.add_lib('SDL_ttf')
341
362
  ttf.objs = ['rubygame_shared', 'rubygame_ttf']
342
363
  ttf.add_header('SDL_ttf.h')
343
- ttf.create_all_tasks() if $options.ttf
364
+ ttf.create_all_tasks() if $options[:"sdl-ttf"]
344
365
  end
345
366
 
346
- if $options.opengl
367
+ if $options[:opengl]
347
368
  CFLAGS << " -DHAVE_OPENGL "
348
369
  end
349
370
 
@@ -361,19 +382,27 @@ task :fix_filenames do
361
382
  end
362
383
  end
363
384
 
364
- desc "Install only the extensions"
385
+ desc "Install just the extensions"
365
386
  task :install_ext do |task|
366
- puts "Installing extensions to #{$options.sitearchdir}"
367
- mkdir_p $options.sitearchdir
368
- cp task.prerequisites.to_a, $options.sitearchdir
387
+ puts "Installing extensions to #{$options[:sitearchdir]}"
388
+ mkdir_p $options[:sitearchdir]
389
+ cp task.prerequisites.to_a, $options[:sitearchdir]
369
390
  end
370
391
 
371
- desc "Install only the library"
392
+ desc "Install just the library"
372
393
  task :install_lib do |task|
373
- puts "Installing library to #{$options.sitelibdir}"
374
- mkdir_p $options.sitelibdir + "/rubygame/"
375
- cp "./lib/rubygame.rb", $options.sitelibdir
376
- cp FileList.new("./lib/rubygame/*.rb").to_a, $options.sitelibdir+"/rubygame/"
394
+ puts "Installing library to #{$options[:sitelibdir]}"
395
+
396
+ files = FileList.new do |fl|
397
+ fl.include("lib/**/*.rb")
398
+ fl.exclude(/svn/)
399
+ end
400
+
401
+ files.each do |f|
402
+ dir = File.join($options[:sitelibdir], File.dirname(f).sub('lib',''), "")
403
+ mkdir_p dir
404
+ cp f, dir
405
+ end
377
406
  end
378
407
 
379
408
  desc "Install both the extensions and the library"