rubygame 2.2.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CREDITS +60 -0
  2. data/LICENSE +504 -0
  3. data/NEWS +201 -0
  4. data/README +139 -0
  5. data/ROADMAP +43 -0
  6. data/Rakefile +409 -0
  7. data/doc/extended_readme.rdoc +49 -0
  8. data/doc/getting_started.rdoc +47 -0
  9. data/doc/macosx_install.rdoc +70 -0
  10. data/doc/windows_install.rdoc +127 -0
  11. data/ext/rubygame/MANIFEST +25 -0
  12. data/ext/rubygame/rubygame_core.so +0 -0
  13. data/ext/rubygame/rubygame_event.c +644 -0
  14. data/ext/rubygame/rubygame_event.h +48 -0
  15. data/ext/rubygame/rubygame_event.obj +0 -0
  16. data/ext/rubygame/rubygame_gfx.c +942 -0
  17. data/ext/rubygame/rubygame_gfx.h +101 -0
  18. data/ext/rubygame/rubygame_gfx.obj +0 -0
  19. data/ext/rubygame/rubygame_gfx.so +0 -0
  20. data/ext/rubygame/rubygame_gl.c +154 -0
  21. data/ext/rubygame/rubygame_gl.h +32 -0
  22. data/ext/rubygame/rubygame_gl.obj +0 -0
  23. data/ext/rubygame/rubygame_image.c +108 -0
  24. data/ext/rubygame/rubygame_image.h +41 -0
  25. data/ext/rubygame/rubygame_image.obj +0 -0
  26. data/ext/rubygame/rubygame_image.so +0 -0
  27. data/ext/rubygame/rubygame_joystick.c +247 -0
  28. data/ext/rubygame/rubygame_joystick.h +41 -0
  29. data/ext/rubygame/rubygame_joystick.obj +0 -0
  30. data/ext/rubygame/rubygame_main.c +155 -0
  31. data/ext/rubygame/rubygame_main.h +33 -0
  32. data/ext/rubygame/rubygame_main.obj +0 -0
  33. data/ext/rubygame/rubygame_mixer.c +764 -0
  34. data/ext/rubygame/rubygame_mixer.h +62 -0
  35. data/ext/rubygame/rubygame_mixer.obj +0 -0
  36. data/ext/rubygame/rubygame_mixer.so +0 -0
  37. data/ext/rubygame/rubygame_screen.c +448 -0
  38. data/ext/rubygame/rubygame_screen.h +43 -0
  39. data/ext/rubygame/rubygame_screen.obj +0 -0
  40. data/ext/rubygame/rubygame_shared.c +209 -0
  41. data/ext/rubygame/rubygame_shared.h +60 -0
  42. data/ext/rubygame/rubygame_shared.obj +0 -0
  43. data/ext/rubygame/rubygame_surface.c +1147 -0
  44. data/ext/rubygame/rubygame_surface.h +62 -0
  45. data/ext/rubygame/rubygame_surface.obj +0 -0
  46. data/ext/rubygame/rubygame_time.c +183 -0
  47. data/ext/rubygame/rubygame_time.h +32 -0
  48. data/ext/rubygame/rubygame_time.obj +0 -0
  49. data/ext/rubygame/rubygame_ttf.c +599 -0
  50. data/ext/rubygame/rubygame_ttf.h +69 -0
  51. data/ext/rubygame/rubygame_ttf.obj +0 -0
  52. data/ext/rubygame/rubygame_ttf.so +0 -0
  53. data/lib/rubygame.rb +41 -0
  54. data/lib/rubygame/MANIFEST +12 -0
  55. data/lib/rubygame/clock.rb +128 -0
  56. data/lib/rubygame/color.rb +79 -0
  57. data/lib/rubygame/color/models/base.rb +106 -0
  58. data/lib/rubygame/color/models/hsl.rb +153 -0
  59. data/lib/rubygame/color/models/hsv.rb +149 -0
  60. data/lib/rubygame/color/models/rgb.rb +78 -0
  61. data/lib/rubygame/color/palettes/css.rb +49 -0
  62. data/lib/rubygame/color/palettes/palette.rb +100 -0
  63. data/lib/rubygame/color/palettes/x11.rb +177 -0
  64. data/lib/rubygame/constants.rb +238 -0
  65. data/lib/rubygame/event.rb +313 -0
  66. data/lib/rubygame/ftor.rb +370 -0
  67. data/lib/rubygame/hotspot.rb +265 -0
  68. data/lib/rubygame/keyconstants.rb +237 -0
  69. data/lib/rubygame/mediabag.rb +94 -0
  70. data/lib/rubygame/queue.rb +288 -0
  71. data/lib/rubygame/rect.rb +612 -0
  72. data/lib/rubygame/sfont.rb +223 -0
  73. data/lib/rubygame/sprite.rb +511 -0
  74. data/samples/FreeSans.ttf +0 -0
  75. data/samples/GPL.txt +340 -0
  76. data/samples/README +40 -0
  77. data/samples/chimp.bmp +0 -0
  78. data/samples/chimp.rb +313 -0
  79. data/samples/demo_gl.rb +151 -0
  80. data/samples/demo_gl_tex.rb +197 -0
  81. data/samples/demo_music.rb +75 -0
  82. data/samples/demo_rubygame.rb +284 -0
  83. data/samples/demo_sfont.rb +52 -0
  84. data/samples/demo_ttf.rb +193 -0
  85. data/samples/demo_utf8.rb +53 -0
  86. data/samples/fist.bmp +0 -0
  87. data/samples/load_and_blit.rb +22 -0
  88. data/samples/panda.png +0 -0
  89. data/samples/punch.wav +0 -0
  90. data/samples/ruby.png +0 -0
  91. data/samples/song.ogg +0 -0
  92. data/samples/term16.png +0 -0
  93. data/samples/whiff.wav +0 -0
  94. metadata +152 -0
data/NEWS ADDED
@@ -0,0 +1,201 @@
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
+
39
+ == Changes from 2.0.1 to 2.1.0
40
+
41
+ === Features
42
+
43
+ - Add: Mixer::Music module.
44
+ - Add: Mixer.driver_name method.
45
+ - Add: Depth sorting for sprites.
46
+ - Add: Sprite#undraw.
47
+ - Add: TTF#size_utf8 and TTF#size_unicode.
48
+ - Add: Rubygame.key_name.
49
+
50
+ === Bug Fixes
51
+
52
+ - Fix: Bug with dirty rectangles in UpdateGroup.
53
+ - Fix: Incorrect docs for joy-hat direction value.
54
+ - Fix: Segfaults when Joysticks are garbage-collected after Rubygame has quit.
55
+ - Fix: Segfaults when using Surface#convert, #to_display, or #to_display_alpha
56
+ when no video mode has been set.
57
+ - Fix: Surface#get_at returning [0,0,0,0] when it shouldn't.
58
+ - Fix: Sprites::Group#collide_group behaving incorrectly (again).
59
+ - Fix: Build system doesn't correctly handle quoted spaces in --cflags/--lflags.
60
+ (NOTE: Use CFLAGS/LDFLAGS environment variables now, instead.)
61
+
62
+ === Known Issues
63
+
64
+ - Build system won't detect changed source files and recompile as necessary;
65
+ you must "rake clobber build" after a change.
66
+
67
+ === Other Stuff
68
+
69
+ - Added argument checks to several Rect methods.
70
+ - Surfaces can be created with no Screen mode set.
71
+ - Mixer.open_audio has default values.
72
+ - TTF style getting/setting refactored under the hood.
73
+ - Added demo_music.rb and a sample song.ogg to try out music.
74
+
75
+ === Acknowledgements
76
+
77
+ - Johan Berntsson for adding Mixer::Music.
78
+ - Daniel Neis Araujo for adding Sprite#undraw.
79
+ - Roger Ostrander (denor) for and bug fixes and adding Rubygame.key_name.
80
+ - Bjorn De Meyer (beoran) for numerous patches and improvements.
81
+
82
+
83
+
84
+
85
+ == Changes from 2.0.0 to 2.0.1
86
+
87
+ === Bug Fixes
88
+
89
+ - Fix: Segfaults in several C methods when passed an unexpected argument type.
90
+ - Fix: Segfaults in Screen#update and Screen#update_rects when the Rect(s)
91
+ extended out of the Screen bounds.
92
+ - Fix: Ftor#magnitude= behaving incorrectly.
93
+ - Fix: Rect#clip! behaving incorrectly.
94
+ - Fix: Sprites::Group#collide_group behaving incorrectly.
95
+ - Fix: Surface#savebmp wanting too many arguments.
96
+
97
+ === Other Stuff
98
+
99
+ - Argument handling for C methods is now more robust under the hood.
100
+ - C methods which expect Array arguments will now also work with objects
101
+ that can be converted to an Array (with #to_ary), such as Ftor.
102
+
103
+
104
+
105
+
106
+ == Changes from 1.1.0 to 2.0.0:
107
+
108
+ *NOTICE*: version 2.0.0 is not totally backward-compatible with 1.1.0.
109
+ You may have to update existing applications to the new syntax.
110
+ (Hence the major version number going up.)
111
+
112
+ === API Changes
113
+
114
+ ==== Basic audio playback with SDL_mixer
115
+
116
+ - Add: Rubygame::Mixer module (basic SDL_mixer audio playback).
117
+ - Add: Rubygame::Mixer::Sample class (load audio samples).
118
+
119
+ ==== Event management system revamped
120
+
121
+ - Add: Rubygame.fetch_sdl_events()
122
+ - Add: Rubygame::EventQueue class.
123
+ - Add: Rubygame::MailQueue mixin.
124
+ - Retire: Rubygame::Queue class.
125
+
126
+ ==== Surface swallows Draw, Transform, and Image methods
127
+
128
+ - Updated: Rubygame::Surface class
129
+ - Add: Surface.load_image() (migrated from Image).
130
+ - Add: ##savebmp (migrated from Image).
131
+ - Add: ##draw_* (migrated from Draw).
132
+ - Add: ##rotozoom, ##zoom (migrated from Transform).
133
+ - Add: ##zoom_to method.
134
+
135
+ - Retire: Draw module (methods merged into Surface).
136
+ - Retire: Transform module (methods merged into Surface).
137
+ - Retire: Image module (methods merged into Surface).
138
+
139
+ ==== Clock class improved
140
+
141
+ - Updated: Rubygame::Clock class
142
+ - Clock is now directly under Rubygame (not Rubygame::Time).
143
+ - Clock.new() takes no arguments, but yields self if a block is given.
144
+ - framerate limiting with ##tick is now much more accurate.
145
+ - Add: Clock.runtime(), Clock.wait(), Clock.delay() (migrated from Time)
146
+ - Rename: ##fps to ##framerate.
147
+ - Rename: ##desired_fps to ##target_framerate.
148
+ - Rename: ##desired_mspf to ##target_frametime.
149
+ - Rename: ##time to ##lifetime.
150
+
151
+ - Retire: Time module (methods merged into Clock).
152
+
153
+ ==== Experimental classes/modules
154
+
155
+ - Add: Rubygame::MediaBag class.
156
+ - Add: Rubygame::Ftor class.
157
+ - Add: Rubygame::Hotspot mixin.
158
+ - Change: Rubygame::SFont class must be explicitly imported
159
+ (require 'rubygame/sfont').
160
+
161
+ ==== New system for version and capability detection
162
+
163
+ - Rubygame::VERSIONS: a hash table with the version numbers of rubygame,
164
+ SDL, and any SDL_* libraries that were compiled in.
165
+ - Methods which are not supported will no be defined in the namespace;
166
+ formerly, they would be defined but nonfunctional (issued a warning and
167
+ returned nil).
168
+
169
+ ==== Miscellaneous other changes and additions
170
+
171
+ - Add: Rubygame.quit (cleanly exit SDL; resets resolution after fullscreen).
172
+
173
+ - Updated: Rubygame::Surface class
174
+ - Argument list for Surface.new() has changed.
175
+ - Add: ##clip and ##clip=.
176
+ - Add: ##convert, ##to_display, and ##to_display_alpha.
177
+
178
+ - Updated: Rubygame::Screen class
179
+ - Rename: Screen.set_mode() to Screen.new().
180
+ - Add: Screen.set_mode() and Screen.instance() (aliases for Screen.new()).
181
+ - Add: ##title, ##title= (replaces ##caption and ##set_caption)
182
+
183
+ - Updated: Rubygame::TTF class
184
+ - Add: ##render_utf8 and ##render_unicode methods.
185
+ - Add: ##size_text method.
186
+
187
+ === Bug Fixes
188
+
189
+ - Fix several erroneous Rect methods.
190
+ - Fix "bignum out of range of unsigned long (RangeError)" when using
191
+ Rubygame::FULLSCREEN.
192
+
193
+ === Other Stuff
194
+
195
+ - New build/install system with Rake.
196
+ - Split the monolithic rubygame extension into modules:
197
+ rubygame_core:: main SDL interface.
198
+ rubygame_gfx:: SDL_gfx interface.
199
+ rubygame_image:: SDL_image interface.
200
+ rubygame_mixer:: SDL_mixer interface.
201
+ rubygame_ttf:: SDL_ttf interface.
data/README ADDED
@@ -0,0 +1,139 @@
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
+ 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
85
+
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.
89
+
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
96
+
97
+ IMPORTANT: if you are missing any optional SDL_* libraries, you must specify
98
+ "no-*" flags for those libraries. For example, if you don't have SDL_gfx:
99
+
100
+ $ rake no-gfx build
101
+
102
+ If you don't disable the features, the compile will probably fail when it
103
+ looks for the headers and libraries. (The build system is not smart enough to
104
+ automatically disable missing features.)
105
+
106
+ === Generating documentation
107
+
108
+ You can generate documentation for Rubygame's API by running:
109
+
110
+ # rake rdoc
111
+
112
+ Documentation will be generated as HTML in the 'html' directory.
113
+ Open 'html/index.html' in a web browser to get started.
114
+
115
+ == Usage
116
+
117
+ To use Rubygame in an application, do:
118
+
119
+ require 'rubygame'
120
+
121
+ You will probably also want a display window and event queue:
122
+
123
+ screen = Rubygame::Screen.new( [640,480] )
124
+ queue = Rubygame::EventQueue.new()
125
+
126
+ For more information, see the documentation (online at
127
+ http://rubygame.sourceforge.net, or generated locally with the
128
+ 'rake rdoc' command). You should also take a peek at the demo applications
129
+ in the 'samples' directory.
130
+
131
+ == License
132
+
133
+ Rubygame is distributed under the terms of the GNU Lesser GPL.
134
+ See LICENSE for more details.
135
+
136
+ Some of the sample files are distributed under other licenses than the
137
+ GNU Lesser GPL. See 'samples/README' and 'samples/GPL' for more details.
138
+
139
+ John Croisant (jacius at users.sourceforge.net)
data/ROADMAP ADDED
@@ -0,0 +1,43 @@
1
+ = ROADMAP
2
+
3
+ === 3.0.0 (next major release)
4
+
5
+ - Backwards compatibility will be broken:
6
+ - Surface#get_at
7
+ - Sprites::Group#collide_group
8
+
9
+ - New scene/camera/sprite sytem.
10
+ - New geometric primitives classes (for collision detection, drawing).
11
+ - New hook-based event handler system.
12
+
13
+ - Keyboard events to be :symbols (e.g. :uparrow, :a, :spacebar)
14
+
15
+ - Clock class to be based on Ruby's timer (allows multi-threading).
16
+ - New TickEvent returned from Clock#tick.
17
+
18
+ - Change Sprites::Group#collide_group to scrap the 'killa/killb' stuff,
19
+ take a block instead.
20
+
21
+ === On the horizon...
22
+
23
+ - Path (Curve?) (graphs/plots for tracing position and other uses)
24
+ - Can find the position N units along the path.
25
+ - Can draw a line showing the path.
26
+ - LinearPath (connect the dots, linear interpolation)
27
+ - BezierPath (chain of continuous cubic Bézier curves)
28
+ - CodePath (calculated from a code block)
29
+
30
+ - Better support for non-US keyboards, particularly generating strings for
31
+ keypresses: (EURO, WORLD*). Will need someone with a non-US keyboard to
32
+ test this.
33
+
34
+ - Flesh out Mixer API.
35
+
36
+ - Flesh out Rect unit tests.
37
+
38
+ - C equivalent of Rect.new_from_object (see rect.rb)
39
+ - Screen#update (cannot pass object with rect attribute)
40
+ - Screen#update_rects (same as above)
41
+ - Why not just call the ruby function from within C?
42
+
43
+ - Generate bounding Polygon from an image automatically.
data/Rakefile ADDED
@@ -0,0 +1,409 @@
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
+ 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
+
42
+ # Get a variable from ENV or CONFIG, with ENV having precedence.
43
+ # Returns "" if the variable didn't exist at all.
44
+ def from_env_or_config(string)
45
+ ([ENV[string], CONFIG[string]] - ["", nil])[0] or ""
46
+ end
47
+
48
+ OBJEXT = from_env_or_config("OBJEXT")
49
+ DLEXT = from_env_or_config("DLEXT")
50
+
51
+ RUBYGAME_VERSION = "2.2.0"
52
+
53
+ spec = Gem::Specification.new do |s|
54
+ s.name = "rubygame"
55
+ s.version = RUBYGAME_VERSION
56
+ s.author = "John Croisant"
57
+ s.email = "jacius@users.sourceforge.net"
58
+ s.homepage = "http://rubygame.sourceforge.net/"
59
+ s.summary = "Clean and powerful library for game programming"
60
+ s.has_rdoc = true
61
+
62
+ s.files = FileList.new do |fl|
63
+ fl.include("{lib,ext,samples,doc}/**/*")
64
+ fl.exclude(/svn/)
65
+ #fl.exclude(/\.#{OBJEXT}/)
66
+ end
67
+
68
+ s.require_paths = ["lib", "lib/rubygame/", "ext/rubygame/"]
69
+ s.autorequire = "rubygame.rb"
70
+ s.extensions = ["Rakefile"]
71
+
72
+ s.extra_rdoc_files = FileList.new do |fl|
73
+ fl.include "doc/*.rdoc"
74
+ fl.include "README", "LICENSE", "CREDITS", "ROADMAP", "NEWS"
75
+ end
76
+ end
77
+
78
+ task :linux do
79
+ spec.platform = Gem::Platform::LINUX_586
80
+ end
81
+
82
+ task :macosx do
83
+ spec.platform = Gem::Platform::DARWIN
84
+ end
85
+
86
+ task :win32 do
87
+ spec.platform = Gem::Platform::WIN32
88
+ end
89
+
90
+ Rake::GemPackageTask.new(spec) do |pkg|
91
+ pkg.need_tar_bz2 = true
92
+ end
93
+
94
+ Rake::RDocTask.new do |rd|
95
+ rd.main = "README"
96
+ rd.title = "Rubygame #{RUBYGAME_VERSION} Docs"
97
+ rd.rdoc_files.include("ext/rubygame/*.c",
98
+ "lib/rubygame/**/*.rb",
99
+ "doc/*.rdoc",
100
+ "README",
101
+ "LICENSE",
102
+ "CREDITS",
103
+ "ROADMAP",
104
+ "NEWS")
105
+ end
106
+
107
+ task :default => [:build]
108
+ desc "Compile all of the extensions"
109
+ task :build
110
+
111
+ require 'rake/clean'
112
+ task(:clean) { puts "Cleaning out temporary generated files" }
113
+ task(:clobber) { puts "Cleaning out final generated files" }
114
+
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,
133
+ # since it's usually not available. It can still be
134
+ # enabled through the options, though.
135
+ if PLATFORM =~ /win32/
136
+ $options[:"sdl-config"] = false
137
+ end
138
+
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 }
166
+ end
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}"]
181
+ end
182
+
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"
191
+
192
+ string_option "RUBYARCHDIR", :sitearchdir
193
+ string_option :sitearchdir
194
+
195
+ string_option "RUBYLIBDIR", :sitelibdir
196
+ string_option :sitelibdir
197
+
198
+
199
+ CFLAGS = [from_env_or_config("CFLAGS"),
200
+ try_sdl_config("--cflags"),
201
+ "-I. -I#{CONFIG['topdir']}",
202
+ ("-g" if $options[:debug]) ].join(" ")
203
+
204
+ LINK_FLAGS = [from_env_or_config("LIBRUBYARG_SHARED"),
205
+ from_env_or_config("LDFLAGS"),
206
+ try_sdl_config("--libs")].join(" ")
207
+
208
+ DEFAULT_EXTDIR = File.join('ext','rubygame','')
209
+
210
+ class ExtensionModule
211
+ @@libflag = " -l%s " # compiler flag for giving linked libraries
212
+ attr_accessor :dynlib, :objs, :libs, :cflags, :lflags, :directory
213
+ def initialize(&block)
214
+ @directory = DEFAULT_EXTDIR
215
+ @dynlib = ""
216
+ @objs = []
217
+ @libs = []
218
+ @lflags = ""
219
+ yield self if block_given?
220
+ end
221
+
222
+ def add_lib( lib )
223
+ @lflags << @@libflag%lib
224
+ end
225
+
226
+ def add_header( header )
227
+ #CFLAGS << " -DHAVE_#{header.upcase.gsub('.','_')} "
228
+ end
229
+
230
+ def create_all_tasks()
231
+ create_obj_task
232
+ create_dl_task
233
+ CLEAN.include("#{@directory}/*.#{OBJEXT}")
234
+ CLOBBER.include("#{@directory}/*.#{DLEXT}")
235
+ end
236
+
237
+ # Create a file task for each dynamic library (.so) we want to generate.
238
+ #
239
+ # The file task invokes another task which does the actual compiling, and
240
+ # has the true prerequisites.
241
+ #
242
+ # This is done so that the prerequisites don't have to be compiled when
243
+ # the final product already exists (such as in the precompiled win32 gem).
244
+ #
245
+ def create_dl_task
246
+ dynlib_full = File.join( @directory, "#{dynlib}.#{DLEXT}" )
247
+ objs_full = @objs.collect { |obj|
248
+ File.join( @directory, "#{obj}.#{OBJEXT}" )
249
+ }
250
+
251
+ desc "Compile the #{@dynlib} extension"
252
+ file dynlib_full => objs_full do |task|
253
+ link_command = "#{from_env_or_config('LDSHARED')} #{LINK_FLAGS} #{@lflags} -o #{dynlib_full} #{task.prerequisites.join(' ')}"
254
+ if( $options[:verbose] )
255
+ try_shell { sh link_command }
256
+ else
257
+ puts "Linking compiled files to create #{File.basename(@directory)}/#{File.basename(dynlib_full)}"
258
+ try_shell { `#{link_command}` }
259
+ end
260
+ end
261
+
262
+ task :build => [dynlib_full] # Add this as a prereq of the build
263
+ task :install_ext => [dynlib_full] # ...and install_ext tasks
264
+ end
265
+
266
+ def create_obj_task
267
+ # A rule for object files (".o" on linux).
268
+ # This won't work for rake < 0.7.2, because the proc returns an Array.
269
+ # If it raises an exception, we'll try a more compatible way.
270
+ rule(/#{@directory}.+\.#{OBJEXT}$/ =>
271
+ [
272
+ # Generate dependencies for this .o file
273
+ proc do |objfile|
274
+ source = objfile.sub(".#{OBJEXT}", ".c") # the .c file
275
+ [source] + depends_headers( source ) # Array of .c + .h dependencies
276
+ end
277
+ ])\
278
+ do |t|
279
+ compile_command = "#{from_env_or_config('CC')} -c #{CFLAGS} #{t.source} -o #{t.name}"
280
+ if( $options[:verbose] )
281
+ try_shell { sh compile_command }
282
+ else
283
+ puts "Compiling #{File.basename(@directory)}/#{File.basename(t.source)}"
284
+ try_shell { `#{compile_command}` }
285
+ end
286
+ end
287
+ rescue
288
+ # Generate a .o rule for each .c file in the directory.
289
+ FileList.new("#{@directory}*.c").each do |source|
290
+ object = source.sub(".c", ".#{OBJEXT}")
291
+ file object => ([source] + depends_headers( source )) do |t|
292
+ compile_command = "#{CONFIG['CC']} -c #{CFLAGS} #{source} -o #{t.name}"
293
+ if( $options[:verbose] )
294
+ try_shell { sh compile_command }
295
+ else
296
+ puts "Compiling #{File.basename(@directory)}/#{File.basename(source)}"
297
+ try_shell { `#{compile_command}` }
298
+ end
299
+ end
300
+ end
301
+ end
302
+
303
+ # Extracts the names of all the headers that the C file depends on.
304
+ def depends_headers( filename )
305
+ return [] # workaround for a bug
306
+ depends = []
307
+ File.open(filename, "r") do |file|
308
+ file.each_line do |line|
309
+ if /#include\s+"(\w+\.h)"/ =~ line
310
+ depends << @directory+$1
311
+ end
312
+ end
313
+ end
314
+ return depends
315
+ end
316
+ end
317
+
318
+ rubygame_core = ExtensionModule.new do |core|
319
+ core.dynlib = 'rubygame_core'
320
+ core.objs = ['rubygame_main',
321
+ 'rubygame_shared',
322
+ 'rubygame_event',
323
+ 'rubygame_gl',
324
+ 'rubygame_joystick',
325
+ 'rubygame_screen',
326
+ 'rubygame_surface',
327
+ 'rubygame_time',
328
+ ]
329
+ core.create_all_tasks()
330
+ end
331
+
332
+ # TODO: We should check if the libraries exist?
333
+
334
+ rubygame_gfx = ExtensionModule.new do |gfx|
335
+ gfx.dynlib = 'rubygame_gfx'
336
+ gfx.objs = ['rubygame_shared', 'rubygame_gfx']
337
+ gfx.add_lib( 'SDL_gfx' )
338
+ gfx.add_header( 'SDL_gfxPrimitives.h')
339
+ gfx.add_header( 'SDL_rotozoom.h' )
340
+ gfx.create_all_tasks() if $options[:"sdl-gfx"]
341
+ end
342
+
343
+ rubygame_image = ExtensionModule.new do |image|
344
+ image.dynlib = 'rubygame_image'
345
+ image.objs = ['rubygame_shared', 'rubygame_image']
346
+ image.add_lib('SDL_image')
347
+ image.add_header('SDL_image.h')
348
+ image.create_all_tasks() if $options[:"sdl-image"]
349
+ end
350
+
351
+ rubygame_mixer = ExtensionModule.new do |mixer|
352
+ mixer.dynlib = 'rubygame_mixer'
353
+ mixer.objs = ['rubygame_shared', 'rubygame_mixer']
354
+ mixer.add_lib('SDL_mixer')
355
+ mixer.add_header('SDL_mixer.h')
356
+ mixer.create_all_tasks() if $options[:"sdl-mixer"]
357
+ end
358
+
359
+ rubygame_ttf = ExtensionModule.new do |ttf|
360
+ ttf.dynlib = 'rubygame_ttf'
361
+ ttf.add_lib('SDL_ttf')
362
+ ttf.objs = ['rubygame_shared', 'rubygame_ttf']
363
+ ttf.add_header('SDL_ttf.h')
364
+ ttf.create_all_tasks() if $options[:"sdl-ttf"]
365
+ end
366
+
367
+ if $options[:opengl]
368
+ CFLAGS << " -DHAVE_OPENGL "
369
+ end
370
+
371
+ desc "(Called when installing via Rubygems)"
372
+ task :extension => [:fix_filenames, :build]
373
+
374
+ task :fix_filenames do
375
+ unless DLEXT == 'so'
376
+ Rake::Task[:install_ext].prerequisites.each do |prereq|
377
+ prereq = prereq.ext('so')
378
+ if File.exist? prereq
379
+ mv prereq, prereq.ext(DLEXT)
380
+ end
381
+ end
382
+ end
383
+ end
384
+
385
+ desc "Install just the extensions"
386
+ task :install_ext do |task|
387
+ puts "Installing extensions to #{$options[:sitearchdir]}"
388
+ mkdir_p $options[:sitearchdir]
389
+ cp task.prerequisites.to_a, $options[:sitearchdir]
390
+ end
391
+
392
+ desc "Install just the library"
393
+ task :install_lib do |task|
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
406
+ end
407
+
408
+ desc "Install both the extensions and the library"
409
+ task :install => [:install_ext, :install_lib]