rubygame 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/CREDITS +50 -0
  2. data/Changelog +162 -0
  3. data/LICENSE +504 -0
  4. data/README +122 -0
  5. data/Rakefile +380 -0
  6. data/TODO +45 -0
  7. data/doc/extended_readme.rdoc +49 -0
  8. data/doc/getting_started.rdoc +47 -0
  9. data/doc/macosx_install.rdoc +74 -0
  10. data/doc/windows_install.rdoc +124 -0
  11. data/ext/rubygame/MANIFEST +25 -0
  12. data/ext/rubygame/rubygame_event.c +644 -0
  13. data/ext/rubygame/rubygame_event.h +48 -0
  14. data/ext/rubygame/rubygame_gfx.c +951 -0
  15. data/ext/rubygame/rubygame_gfx.h +102 -0
  16. data/ext/rubygame/rubygame_gl.c +154 -0
  17. data/ext/rubygame/rubygame_gl.h +32 -0
  18. data/ext/rubygame/rubygame_image.c +108 -0
  19. data/ext/rubygame/rubygame_image.h +41 -0
  20. data/ext/rubygame/rubygame_joystick.c +247 -0
  21. data/ext/rubygame/rubygame_joystick.h +41 -0
  22. data/ext/rubygame/rubygame_main.c +155 -0
  23. data/ext/rubygame/rubygame_main.h +33 -0
  24. data/ext/rubygame/rubygame_mixer.c +764 -0
  25. data/ext/rubygame/rubygame_mixer.h +62 -0
  26. data/ext/rubygame/rubygame_screen.c +420 -0
  27. data/ext/rubygame/rubygame_screen.h +41 -0
  28. data/ext/rubygame/rubygame_shared.c +152 -0
  29. data/ext/rubygame/rubygame_shared.h +54 -0
  30. data/ext/rubygame/rubygame_surface.c +1107 -0
  31. data/ext/rubygame/rubygame_surface.h +62 -0
  32. data/ext/rubygame/rubygame_time.c +183 -0
  33. data/ext/rubygame/rubygame_time.h +32 -0
  34. data/ext/rubygame/rubygame_ttf.c +600 -0
  35. data/ext/rubygame/rubygame_ttf.h +69 -0
  36. data/lib/rubygame.rb +40 -0
  37. data/lib/rubygame/MANIFEST +12 -0
  38. data/lib/rubygame/clock.rb +128 -0
  39. data/lib/rubygame/constants.rb +238 -0
  40. data/lib/rubygame/event.rb +313 -0
  41. data/lib/rubygame/ftor.rb +370 -0
  42. data/lib/rubygame/hotspot.rb +265 -0
  43. data/lib/rubygame/keyconstants.rb +237 -0
  44. data/lib/rubygame/mediabag.rb +94 -0
  45. data/lib/rubygame/queue.rb +288 -0
  46. data/lib/rubygame/rect.rb +614 -0
  47. data/lib/rubygame/sfont.rb +223 -0
  48. data/lib/rubygame/sprite.rb +477 -0
  49. data/samples/FreeSans.ttf +0 -0
  50. data/samples/GPL.txt +340 -0
  51. data/samples/README +40 -0
  52. data/samples/chimp.bmp +0 -0
  53. data/samples/chimp.rb +313 -0
  54. data/samples/demo_gl.rb +151 -0
  55. data/samples/demo_gl_tex.rb +197 -0
  56. data/samples/demo_music.rb +75 -0
  57. data/samples/demo_rubygame.rb +279 -0
  58. data/samples/demo_sfont.rb +52 -0
  59. data/samples/demo_ttf.rb +193 -0
  60. data/samples/demo_utf8.rb +53 -0
  61. data/samples/fist.bmp +0 -0
  62. data/samples/load_and_blit.rb +22 -0
  63. data/samples/panda.png +0 -0
  64. data/samples/punch.wav +0 -0
  65. data/samples/ruby.png +0 -0
  66. data/samples/term16.png +0 -0
  67. data/samples/whiff.wav +0 -0
  68. metadata +123 -0
data/README ADDED
@@ -0,0 +1,122 @@
1
+ = Rubygame README
2
+
3
+ == What is Rubygame?
4
+
5
+ Rubygame is a cross-platform game-development extension and library for Ruby,
6
+ inspired by Pygame. The purpose of Rubygame is to empower game developers by
7
+ providing them with powerful and flexible high-level concepts. Instead of
8
+ worrying about low-level technical details, you can focus your energy on
9
+ more interesting things (like making a fun game).
10
+
11
+ Rubygame's core is written in C to bind low-level SDL functions in ruby.
12
+ On top of that is a pure ruby library for higher-level behavior like
13
+ event and game object management.
14
+
15
+ There are two other Ruby-SDL bindings which are worth mentioning: Ruby/SDL
16
+ and RUDL. Ruby/SDL is a simple wrapper which closely mirrors SDL's C API,
17
+ while RUDL tries to provide some high-level concepts.
18
+ The main differences with Rubygame come down to a matter of priorities:
19
+ a great deal of care and effort goes into making Rubygame especially clean,
20
+ well-documented, powerful, and easy to use.
21
+
22
+ === Relevant Links
23
+ 1. Rubygame: http://rubygame.sourceforge.net
24
+ 2. Ruby: http://www.ruby-lang.org
25
+ 3. Pygame: http://www.pygame.org
26
+ 4. SDL: http://www.libsdl.org
27
+ 5. Ruby/SDL: http://www.kmc.gr.jp/~ohai/rubysdl.en.html
28
+ 6. RUDL: http://rudl.sourceforge.net
29
+
30
+ == Requirements
31
+
32
+ You will definitely need these software packages to compile Rubygame:
33
+
34
+ * ruby >= 1.8
35
+ * SDL >= 1.2.7
36
+ * rake >= 0.7.0 (for build/install system)
37
+
38
+ It's highly recommended that you have these packages as well, or some
39
+ cool features won't be available!
40
+
41
+ * SDL_gfx >= 2.0.10
42
+ * SDL_image >= 1.2.3
43
+ * SDL_mixer >= 1.2.7
44
+ * SDL_ttf >= 2.0.6
45
+
46
+ (If you don't have some of those, you have to disable those features
47
+ by passing some flags to the build process. See "Advanced Install", below.)
48
+
49
+ If you are compiling source on a binary-based Linux ditribution,
50
+ you will also need the "dev" packages of ruby, SDL, SDL_gfx, SDL_image,
51
+ SDL_mixer, and SDL_ttf. (Really, you just need the header files.)
52
+
53
+ And of course, if you are compiling the source, you will need a C compiler!
54
+ These versions of gcc worked fine when I tried them; other compilers might
55
+ work too:
56
+
57
+ * gcc 3.3, 3.4, 4.0, 4.1
58
+
59
+
60
+ == Install
61
+
62
+ === Basic Install
63
+
64
+ Extract the archive and enter its top directory.
65
+ Then run ($ indicates as user, # as root):
66
+
67
+ $ rake build
68
+ # rake install
69
+
70
+ === Advanced Install
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.)
75
+
76
+ Try this command to see all the possible configuration flags:
77
+
78
+ $ RUBYGAME_CONFIG="--help" rake
79
+
80
+ 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:
82
+
83
+ $ RUBYGAME_CONFIG="--no-gfx" rake build
84
+
85
+ If you don't disable the features, the compile will probably fail when it
86
+ looks for the headers and libraries. (The build system is not smart enough to
87
+ automatically disable missing features.)
88
+
89
+ === Generating documentation
90
+
91
+ You can generate documentation for Rubygame's API by running:
92
+
93
+ # rake rdoc
94
+
95
+ Documentation will be generated as HTML in the 'html' directory.
96
+ Open 'html/index.html' in a web browser to get started.
97
+
98
+ == Usage
99
+
100
+ To use Rubygame in an application, do:
101
+
102
+ require 'rubygame'
103
+
104
+ You will probably also want a display window and event queue:
105
+
106
+ screen = Rubygame::Screen.new( [640,480] )
107
+ queue = Rubygame::EventQueue.new()
108
+
109
+ For more information, see the documentation (online at
110
+ http://rubygame.sourceforge.net, or generated locally with the
111
+ 'rake rdoc' command). You should also take a peek at the demo applications
112
+ in the 'samples' directory.
113
+
114
+ == License
115
+
116
+ Rubygame is distributed under the terms of the GNU Lesser GPL.
117
+ See LICENSE for more details.
118
+
119
+ Some of the sample files are distributed under other licenses than the
120
+ GNU Lesser GPL. See 'samples/README' and 'samples/GPL' for more details.
121
+
122
+ John Croisant (jacius at users.sourceforge.net)
data/Rakefile ADDED
@@ -0,0 +1,380 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+
4
+ require 'rake'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/rdoctask'
7
+
8
+ require "rbconfig"
9
+ include Config
10
+
11
+ # Get a variable from ENV or CONFIG, with ENV having precedence.
12
+ # Returns "" if the variable didn't exist at all.
13
+ def from_env_or_config(string)
14
+ ([ENV[string], CONFIG[string]] - ["", nil])[0] or ""
15
+ end
16
+
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
+ OBJEXT = from_env_or_config("OBJEXT")
26
+ DLEXT = from_env_or_config("DLEXT")
27
+
28
+ RUBYGAME_VERSION = "2.1.0"
29
+
30
+ spec = Gem::Specification.new do |s|
31
+ s.name = "rubygame"
32
+ s.version = RUBYGAME_VERSION
33
+ s.author = "John Croisant"
34
+ s.email = "jacius@users.sourceforge.net"
35
+ s.homepage = "http://rubygame.sourceforge.net/"
36
+ s.summary = "Clean and powerful library for game programming"
37
+ s.has_rdoc = true
38
+
39
+ candidates = Dir.glob("{lib,ext,samples,doc}/**/*")
40
+ s.files = candidates.delete_if do |item|
41
+ item.include?("svn") or item =~ /\.#{OBJEXT}/
42
+ end
43
+
44
+ s.require_paths = ["lib", "lib/rubygame/", "ext/rubygame/"]
45
+ s.autorequire = "rubygame.rb"
46
+ s.extensions = ["Rakefile"]
47
+
48
+ s.extra_rdoc_files = Dir.glob("doc/*.rdoc")
49
+ s.extra_rdoc_files += ["README",
50
+ "LICENSE",
51
+ "CREDITS",
52
+ "TODO",
53
+ "Changelog"]
54
+ end
55
+
56
+ task :linux do
57
+ spec.platform = Gem::Platform::LINUX_586
58
+ end
59
+
60
+ task :macosx do
61
+ spec.platform = Gem::Platform::DARWIN
62
+ end
63
+
64
+ task :win32 do
65
+ spec.platform = Gem::Platform::WIN32
66
+ end
67
+
68
+ Rake::GemPackageTask.new(spec) do |pkg|
69
+ pkg.need_tar_bz2 = true
70
+ end
71
+
72
+ Rake::RDocTask.new do |rd|
73
+ rd.main = "README"
74
+ rd.title = "Rubygame #{RUBYGAME_VERSION} Docs"
75
+ rd.rdoc_files.include("ext/rubygame/*.c",
76
+ "lib/rubygame/*.rb",
77
+ "doc/*.rdoc",
78
+ "README",
79
+ "LICENSE",
80
+ "CREDITS",
81
+ "TODO",
82
+ "Changelog")
83
+ end
84
+
85
+ task :default => [:build]
86
+ desc "Compile all of the extensions"
87
+ task :build
88
+
89
+ require 'rake/clean'
90
+ task(:clean) { puts "Cleaning out temporary generated files" }
91
+ task(:clobber) { puts "Cleaning out final generated files" }
92
+
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,
109
+ # since it's usually not available. It can still be
110
+ # enabled through the options, though.
111
+ if PLATFORM =~ /win32/
112
+ $options.sdl_config = false
113
+ end
114
+
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
126
+ 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
156
+ end
157
+
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(" ") )
161
+
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
166
+
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
+
172
+ CFLAGS = [from_env_or_config("CFLAGS"),
173
+ try_sdl_config("--cflags"),
174
+ "-I. -I#{CONFIG['topdir']}",
175
+ ("-g" if $options.debug) ].join(" ")
176
+
177
+ LINK_FLAGS = [from_env_or_config("LIBRUBYARG_SHARED"),
178
+ from_env_or_config("LDFLAGS"),
179
+ try_sdl_config("--libs")].join(" ")
180
+
181
+ DEFALUT_EXTDIR = File.join('ext','rubygame','')
182
+
183
+ class ExtensionModule
184
+ @@libflag = " -l%s " # compiler flag for giving linked libraries
185
+ attr_accessor :dynlib, :objs, :libs, :cflags, :lflags, :directory
186
+ def initialize(&block)
187
+ @directory = DEFALUT_EXTDIR
188
+ @dynlib = ""
189
+ @objs = []
190
+ @libs = []
191
+ @lflags = ""
192
+ yield self if block_given?
193
+ end
194
+
195
+ def add_lib( lib )
196
+ @lflags << @@libflag%lib
197
+ end
198
+
199
+ def add_header( header )
200
+ #CFLAGS << " -DHAVE_#{header.upcase.gsub('.','_')} "
201
+ end
202
+
203
+ def create_all_tasks()
204
+ create_obj_task
205
+ create_dl_task
206
+ CLEAN.include("#{@directory}/*.#{OBJEXT}")
207
+ CLOBBER.include("#{@directory}/*.#{DLEXT}")
208
+ end
209
+
210
+ # Create a file task for each dynamic library (.so) we want to generate.
211
+ #
212
+ # The file task invokes another task which does the actual compiling, and
213
+ # has the true prerequisites.
214
+ #
215
+ # This is done so that the prerequisites don't have to be compiled when
216
+ # the final product already exists (such as in the precompiled win32 gem).
217
+ #
218
+ def create_dl_task
219
+ dynlib_full = File.join( @directory, "#{dynlib}.#{DLEXT}" )
220
+ objs_full = @objs.collect { |obj|
221
+ File.join( @directory, "#{obj}.#{OBJEXT}" )
222
+ }
223
+
224
+ taskname = @dynlib.gsub('rubygame_','')
225
+
226
+ file dynlib_full do
227
+ Rake::Task[taskname].invoke
228
+ end
229
+
230
+ desc "Compile the #{@dynlib} extension"
231
+ task taskname => objs_full do |task|
232
+ link_command = "#{from_env_or_config('LDSHARED')} #{LINK_FLAGS} #{@lflags} -o #{dynlib_full} #{task.prerequisites.join(' ')}"
233
+ if( $options.verbose )
234
+ sh link_command
235
+ else
236
+ puts "Linking compiled files to create #{File.basename(@directory)}/#{File.basename(dynlib_full)}"
237
+ `#{link_command}`
238
+ end
239
+ end
240
+
241
+ task :build => [dynlib_full] # Add this as a prereq of the build
242
+ task :install_ext => [dynlib_full] # ...and install_ext tasks
243
+ end
244
+
245
+ def create_obj_task
246
+ # A rule for object files (".o" on linux).
247
+ # This won't work for rake < 0.7.2, because the proc returns an Array.
248
+ # If it raises an exception, we'll try a more compatible way.
249
+ rule(/#{@directory}.+\.#{OBJEXT}$/ =>
250
+ [
251
+ # Generate dependencies for this .o file
252
+ proc do |objfile|
253
+ source = objfile.sub(".#{OBJEXT}", ".c") # the .c file
254
+ [source] + depends_headers( source ) # Array of .c + .h dependencies
255
+ end
256
+ ])\
257
+ do |t|
258
+ compile_command = "#{from_env_or_config('CC')} -c #{CFLAGS} #{t.source} -o #{t.name}"
259
+ if( $options.verbose )
260
+ sh compile_command
261
+ else
262
+ puts "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}"
263
+ `#{compile_command}`
264
+ end
265
+ end
266
+ rescue
267
+ # Generate a .o rule for each .c file in the directory.
268
+ FileList.new("#{@directory}*.c").each do |source|
269
+ object = source.sub(".c", ".#{OBJEXT}")
270
+ file object => ([source] + depends_headers( source )) do |t|
271
+ compile_command = "#{CONFIG['CC']} -c #{CFLAGS} #{source} -o #{t.name}"
272
+ if( $options.verbose )
273
+ sh compile_command
274
+ else
275
+ puts "Compiling #{File.basename(@directory)}/#{File.basename(source)}"
276
+ `#{compile_command}`
277
+ end
278
+ end
279
+ end
280
+ end
281
+
282
+ # Extracts the names of all the headers that the C file depends on.
283
+ def depends_headers( filename )
284
+ return [] # workaround for a bug
285
+ depends = []
286
+ File.open(filename, "r") do |file|
287
+ file.each_line do |line|
288
+ if /#include\s+"(\w+\.h)"/ =~ line
289
+ depends << @directory+$1
290
+ end
291
+ end
292
+ end
293
+ return depends
294
+ end
295
+ end
296
+
297
+ rubygame_core = ExtensionModule.new do |core|
298
+ core.dynlib = 'rubygame_core'
299
+ core.objs = ['rubygame_main',
300
+ 'rubygame_shared',
301
+ 'rubygame_event',
302
+ 'rubygame_gl',
303
+ 'rubygame_joystick',
304
+ 'rubygame_screen',
305
+ 'rubygame_surface',
306
+ 'rubygame_time',
307
+ ]
308
+ core.create_all_tasks()
309
+ end
310
+
311
+ # TODO: We should check if the libraries exist?
312
+
313
+ rubygame_gfx = ExtensionModule.new do |gfx|
314
+ gfx.dynlib = 'rubygame_gfx'
315
+ gfx.objs = ['rubygame_shared', 'rubygame_gfx']
316
+ gfx.add_lib( 'SDL_gfx' )
317
+ gfx.add_header( 'SDL_gfxPrimitives.h')
318
+ gfx.add_header( 'SDL_rotozoom.h' )
319
+ gfx.create_all_tasks() if $options.gfx
320
+ end
321
+
322
+ rubygame_image = ExtensionModule.new do |image|
323
+ image.dynlib = 'rubygame_image'
324
+ image.objs = ['rubygame_shared', 'rubygame_image']
325
+ image.add_lib('SDL_image')
326
+ image.add_header('SDL_image.h')
327
+ image.create_all_tasks() if $options.image
328
+ end
329
+
330
+ rubygame_mixer = ExtensionModule.new do |mixer|
331
+ mixer.dynlib = 'rubygame_mixer'
332
+ mixer.objs = ['rubygame_shared', 'rubygame_mixer']
333
+ mixer.add_lib('SDL_mixer')
334
+ mixer.add_header('SDL_mixer.h')
335
+ mixer.create_all_tasks() if $options.mixer
336
+ end
337
+
338
+ rubygame_ttf = ExtensionModule.new do |ttf|
339
+ ttf.dynlib = 'rubygame_ttf'
340
+ ttf.add_lib('SDL_ttf')
341
+ ttf.objs = ['rubygame_shared', 'rubygame_ttf']
342
+ ttf.add_header('SDL_ttf.h')
343
+ ttf.create_all_tasks() if $options.ttf
344
+ end
345
+
346
+ if $options.opengl
347
+ CFLAGS << " -DHAVE_OPENGL "
348
+ end
349
+
350
+ desc "(Called when installing via Rubygems)"
351
+ task :extension => [:fix_filenames, :build]
352
+
353
+ task :fix_filenames do
354
+ unless DLEXT == 'so'
355
+ Rake::Task[:install_ext].prerequisites.each do |prereq|
356
+ prereq = prereq.ext('so')
357
+ if File.exist? prereq
358
+ mv prereq, prereq.ext(DLEXT)
359
+ end
360
+ end
361
+ end
362
+ end
363
+
364
+ desc "Install only the extensions"
365
+ 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
369
+ end
370
+
371
+ desc "Install only the library"
372
+ 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/"
377
+ end
378
+
379
+ desc "Install both the extensions and the library"
380
+ task :install => [:install_ext, :install_lib]