summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.travis.yml9
-rw-r--r--Rakefile7
-rw-r--r--appveyor.yml2
m---------assets0
-rw-r--r--ext/ruby2d/extconf.rb109
-rw-r--r--lib/ruby2d.rb8
-rw-r--r--lib/ruby2d/font.rb39
-rw-r--r--test/image_spec.rb6
-rw-r--r--test/music_spec.rb7
-rw-r--r--test/sound_spec.rb9
10 files changed, 114 insertions, 82 deletions
diff --git a/.travis.yml b/.travis.yml
index ec0f2d6..1347c81 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,5 @@
os: osx
-osx_image: xcode10.1
+osx_image: xcode10.2
language: ruby
-before_install:
- - brew update
- - brew tap simple2d/tap
- - brew install simple2d mruby
script:
- rake
- - ruby2d build --native test/ci-build.rb
- - ./build/app
- # - ruby2d build --web test/ci-build.rb
diff --git a/Rakefile b/Rakefile
index 16911c1..6dc53f3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,13 +2,6 @@ require 'rspec/core/rake_task'
require_relative 'lib/ruby2d/colorize'
require_relative 'lib/ruby2d/version'
-# Simple 2D is required for these tasks
-if `which simple2d`.empty?
- puts "Simple 2D not found!".error
- puts "Install before running Rake tasks."
- exit
-end
-
def get_args
ARGV.each { |a| task a.to_sym do ; end }
end
diff --git a/appveyor.yml b/appveyor.yml
index 2cf2028..06a28e7 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -2,8 +2,6 @@ install:
- set PATH=C:\ruby25-x64\bin;C:\msys64\usr\bin;C:\msys64\usr\local\bin;%PATH%
- set MSYSTEM=MINGW64
- bash --version
- - wget https://raw.githubusercontent.com/simple2d/simple2d/master/bin/simple2d.sh
- - bash simple2d.sh install -y
- git submodule update --init --recursive
build: off
before_test:
diff --git a/assets b/assets
-Subproject 367ca2757f66e90e967d24f605c1f995d0a8854
+Subproject 14cc1a1c1c52e4560ca130b05c93783572ccffb
diff --git a/ext/ruby2d/extconf.rb b/ext/ruby2d/extconf.rb
index a079241..46f42df 100644
--- a/ext/ruby2d/extconf.rb
+++ b/ext/ruby2d/extconf.rb
@@ -2,78 +2,87 @@ require 'mkmf'
require_relative '../../lib/ruby2d/colorize'
S2D_VERSION = '1.1.0' # Simple 2D minimum version required
-$errors = []
+$errors = [] # Array to capture errors
+# Print installation errors
def print_errors
puts "
#{"== #{"Ruby 2D Installation Errors".error} =======================================\n"}
#{$errors.join("\n ")}\n
-#{"======================================================================="}"
+#{"======================================================================"}"
end
-def check_s2d_version
- unless Gem::Version.new(`bash simple2d --version`) >= Gem::Version.new(S2D_VERSION)
- $errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
- "Run the following, then try reinstalling this gem:\n" <<
- " simple2d update".bold
- print_errors
- exit
- end
-end
-
-
-# Install Simple 2D on supported platforms
-case RUBY_PLATFORM
-
-# macOS
-when /darwin/
+# Check that Simple 2D is installed and meets minimum version requirements
+def check_s2d
# Simple 2D not installed
if `which simple2d`.empty?
+ $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
+ "To install, follow the instructions at #{"ruby2d.com/learn".bold}"
+ print_errors
+ exit
- # Homebrew not installed
- if `which brew`.empty?
- $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
- "On macOS, it can be installed using Homebrew.\n" <<
- "First, install #{"Homebrew".bold}. See instructions at #{"http://brew.sh".bold}" <<
- "Then, run the following:\n" <<
- " brew tap simple2d/tap".bold <<
- " brew install simple2d".bold
- print_errors
- exit
-
- # Homebrew installed, instruct to install Simple 2D
- else
- $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
- "Install it with Homebrew using:\n" <<
- " brew tap simple2d/tap".bold <<
- " brew install simple2d".bold
+ # Simple 2D installed, checking version
+ else
+ unless Gem::Version.new(`bash simple2d --version`) >= Gem::Version.new(S2D_VERSION)
+ $errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
+ "Run the following, then try reinstalling this gem:\n" <<
+ " simple2d update".bold
print_errors
exit
end
end
+end
-# Linux and Windows / MinGW
-when /linux|mingw/
+# Use the Simple 2D, SDL, and other libraries installed by the user (not those bundled with the gem)
+def use_usr_libs
+ check_s2d
- # Simple 2D not installed
- if `which simple2d`.empty?
- $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
- "To install, follow the instructions at #{"ruby2d.com/learn".bold}"
- print_errors
- exit
+ # Add flags
+ $CFLAGS << ' -std=c11 -I/usr/local/include'
+ if `cat /etc/os-release` =~ /raspbian/ # Raspberry Pi
+ $CFLAGS << ' -I/opt/vc/include'
end
+ $LDFLAGS << ' ' << `bash simple2d --libs`
+ $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems
end
-check_s2d_version
+# Build Ruby 2D native extention using libraries installed by user
+# To use install flag: `gem install ruby2d -- libs`
+if ARGV.include? 'libs'
+ use_usr_libs
-# Add flags
-$CFLAGS << ' -std=c11 -I/usr/local/include'
-if `cat /etc/os-release` =~ /raspbian/ # Raspberry Pi
- $CFLAGS << ' -I/opt/vc/include'
+# Use libraries provided by the gem (default)
+else
+ $CFLAGS << ' -std=c11 -I../../assets/include'
+ case RUBY_PLATFORM
+
+ # macOS
+ when /darwin/
+ # $LDFLAGS << " -L../../assets/macos/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -ljpeg -lpng16 -ltiff -lwebp -lmpg123 -logg -lflac -lvorbis -lvorbisfile -lfreetype -Wl,-framework,Cocoa -Wl,-framework,ForceFeedback"
+
+ ldir = "#{Dir.pwd}/../../assets/macos/lib"
+ $LDFLAGS << " #{ldir}/libsimple2d.a #{ldir}/libSDL2.a #{ldir}/libSDL2_image.a #{ldir}/libSDL2_mixer.a #{ldir}/libSDL2_ttf.a \
+ #{ldir}/libjpeg.a #{ldir}/libpng16.a #{ldir}/libtiff.a #{ldir}/libwebp.a \
+ #{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libflac.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a \
+ #{ldir}/libfreetype.a -Wl,-framework,Cocoa -Wl,-framework,ForceFeedback"
+
+ # Linux
+ when /linux/
+ # TODO: Implement static compilation for Linux
+ use_usr_libs
+
+ # Windows / MinGW
+ when /mingw/
+ $LDFLAGS << " -L../../assets/mingw/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lmingw32 -lopengl32 -lglew32"
+
+ # If can't detect the platform, use libraries installed by the user
+ else
+ use_usr_libs
+ end
end
-$LDFLAGS << ' ' << `bash simple2d --libs`
-$LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems
+
+# Create the Makefile
create_makefile('ruby2d/ruby2d')
diff --git a/lib/ruby2d.rb b/lib/ruby2d.rb
index 305f065..c03560d 100644
--- a/lib/ruby2d.rb
+++ b/lib/ruby2d.rb
@@ -21,13 +21,7 @@ unless RUBY_ENGINE == 'mruby'
require 'ruby2d/music'
if RUBY_PLATFORM =~ /mingw/
- # When using the Windows CI AppVeyor
- if ENV['APPVEYOR']
- s2d_dll_path = 'C:\msys64\usr\local\bin'
- # When in a standard MinGW shell
- else
- s2d_dll_path = '~/../../usr/local/bin'
- end
+ s2d_dll_path = Gem::Specification.find_by_name('ruby2d').gem_dir + '/assets/mingw/bin'
RubyInstaller::Runtime.add_dll_directory(File.expand_path(s2d_dll_path))
end
diff --git a/lib/ruby2d/font.rb b/lib/ruby2d/font.rb
index ace9b2e..08f6b17 100644
--- a/lib/ruby2d/font.rb
+++ b/lib/ruby2d/font.rb
@@ -17,7 +17,14 @@ module Ruby2D
# Get all fonts with full file paths
def all_paths
- fonts = `find #{directory} -name *.ttf`.split("\n")
+ # MRuby does not have `Dir` defined
+ if RUBY_ENGINE == 'mruby'
+ fonts = `find #{directory} -name *.ttf`.split("\n")
+ # If MRI and/or non-Bash shell (like cmd.exe)
+ else
+ fonts = Dir["#{directory}/**/*.ttf"]
+ end
+
fonts = fonts.reject do |f|
f.downcase.include?('bold') ||
f.downcase.include?('italic') ||
@@ -25,6 +32,7 @@ module Ruby2D
f.downcase.include?('narrow') ||
f.downcase.include?('black')
end
+
fonts.sort_by { |f| f.downcase.chomp '.ttf' }
end
@@ -39,12 +47,29 @@ module Ruby2D
# Get the fonts directory for the current platform
def directory
- if `uname`.include? 'Darwin' # macOS
- '/Library/Fonts'
- elsif `uname`.include? 'Linux'
- '/usr/share/fonts'
- elsif `uname`.include? 'MINGW'
- 'C:/Windows/Fonts'
+ macos_font_path = '/Library/Fonts'
+ linux_font_path = '/usr/share/fonts'
+ windows_font_path = 'C:/Windows/Fonts'
+
+ # If MRI and/or non-Bash shell (like cmd.exe)
+ if Object.const_defined? :RUBY_PLATFORM
+ case RUBY_PLATFORM
+ when /darwin/ # macOS
+ macos_font_path
+ when /linux/
+ linux_font_path
+ when /mingw/
+ windows_font_path
+ end
+ # If MRuby
+ else
+ if `uname`.include? 'Darwin' # macOS
+ macos_font_path
+ elsif `uname`.include? 'Linux'
+ linux_font_path
+ elsif `uname`.include? 'MINGW'
+ windows_font_path
+ end
end
end
diff --git a/test/image_spec.rb b/test/image_spec.rb
index 3abfd04..2654de5 100644
--- a/test/image_spec.rb
+++ b/test/image_spec.rb
@@ -3,6 +3,12 @@ require 'ruby2d'
RSpec.describe Ruby2D::Image do
describe "#new" do
+ it "creates images in various formats" do
+ Image.new('test/media/image.bmp')
+ Image.new('test/media/image.jpg')
+ Image.new('test/media/image.png')
+ end
+
it "raises exception if image file doesn't exist" do
expect { Image.new('bad_image.png') }.to raise_error(Ruby2D::Error)
end
diff --git a/test/music_spec.rb b/test/music_spec.rb
index 37fdc65..f7e9a95 100644
--- a/test/music_spec.rb
+++ b/test/music_spec.rb
@@ -14,6 +14,13 @@ RSpec.describe Ruby2D::Music do
end
unless ENV['CI']
+ it "creates music in various formats" do
+ Music.new('test/media/music.wav')
+ Music.new('test/media/music.mp3')
+ Music.new('test/media/music.ogg')
+ Music.new('test/media/music.flac')
+ end
+
it "creates music with options" do
mus = Music.new('test/media/music.mp3', loop: true)
expect(mus.path).to eq('test/media/music.mp3')
diff --git a/test/sound_spec.rb b/test/sound_spec.rb
index 006e1f7..0aa44b9 100644
--- a/test/sound_spec.rb
+++ b/test/sound_spec.rb
@@ -8,7 +8,14 @@ RSpec.describe Ruby2D::Sound do
end
unless ENV['CI'] # audio cannot be opened on CI; see `music_spec.rb`
- it "creates sound" do
+ it "creates sound in various formats" do
+ Sound.new('test/media/music.wav')
+ Sound.new('test/media/music.mp3')
+ Sound.new('test/media/music.ogg')
+ Sound.new('test/media/music.flac')
+ end
+
+ it "creates sound and sets the media path" do
snd = Sound.new('test/media/sound.wav')
expect(snd.path).to eq('test/media/sound.wav')
end