lib/rubygame.rb in rubygame-2.5.3 vs lib/rubygame.rb in rubygame-2.6.0
- old
+ new
@@ -17,40 +17,78 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#++
-# This file is loaded when you "require 'rubygame'".
-# It loads up the compiled C extensions and the rest of
-# the Rubygame library modules.
+this_dir = File.expand_path( File.dirname(__FILE__) )
-# Prefer local library over global installed version.
-$:.unshift( File.join( File.dirname(__FILE__), "..", "lib" ) )
-$:.unshift( File.join( File.dirname(__FILE__), "..", "ext", "rubygame" ) )
+# Require Rubygame files. If these fail, don't rescue.
+# Note: screen.rb is intentionally loaded late.
+%w{ main
+ shared
+ audio
+ clock
+ constants
+ color
+ event
+ events
+ event_handler
+ gl
+ joystick
+ named_resource
+ queue
+ rect
+ surface
+ sprite
+}.each do |f|
+ require File.join( this_dir, "rubygame", f )
+end
-require "rbconfig"
-require "rubygame_core"
+# SDL_gfx is optional, rescue if it fails.
+begin
+ require File.join( this_dir, "rubygame", "gfx" )
+rescue LoadError => e
+ puts( "Warning: Could not load SDL_gfx! " +
+ "Continuing anyway, but some Surface methods will be missing.\n" +
+ "Error message was: #{e.message.inspect}" )
+end
-%W{ rubygame_gfx rubygame_image rubygame_ttf rubygame_mixer }.each do |mod|
- begin
- require mod
- rescue LoadError
- warn( "Warning: Unable to require optional module: #{mod}.") if $VERBOSE
- end
+
+# SDL_image is optional, rescue if it fails.
+begin
+ require File.join( this_dir, "rubygame", "image" )
+rescue LoadError => e
+ puts( "Warning: Could not load SDL_image! " +
+ "Continuing anyway, but image loading will be missing.\n" +
+ "Error message was: #{e.message.inspect}" )
end
-require "rubygame/shared"
-require "rubygame/color"
-require "rubygame/constants"
+# SDL_mixer is optional, rescue if it fails.
+begin
+ require File.join( this_dir, "rubygame", "mixer" )
+rescue LoadError => e
+ puts( "Warning: Could not load SDL_mixer! " +
+ "Continuing anyway, but audio features will be missing.\n" +
+ "Error message was: #{e.message.inspect}" )
+end
-require "rubygame/event"
-require "rubygame/events"
-require "rubygame/queue"
-require "rubygame/event_handler"
-require "rubygame/rect"
-require "rubygame/sprite"
-require "rubygame/clock"
+# SDL_ttf is optional, rescue if it fails.
+begin
+ require File.join( this_dir, "rubygame", "ttf" )
+rescue LoadError => e
+ puts( "Warning: Could not load SDL_ttf! " +
+ "Continuing anyway, but the TTF class will be missing.\n" +
+ "Error message was: #{e.message.inspect}" )
+end
+
+
+# Loaded late so Screen can undefine some inherited Surface methods.
+require File.join( this_dir, "rubygame", "screen" )
+
+
+Rubygame.init
+at_exit { Rubygame.quit }