Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rubysdl vs. ruby-sdl-ffi

Could anyone here tell me the difference between the Ruby gems rubysdl and ruby-sdl-ffi, like speed variances? If so, which would you prefer? I'm wondering for the sake of my gem that I'm writing, Rubydraw (located here).

Thanks in advance!

like image 950
Jwosty Avatar asked Jul 06 '26 22:07

Jwosty


1 Answers

I am the author of ruby-sdl-ffi. This question was brought to my attention today, so I am answering for the benefit of anyone who is still curious.

The main difference is that ruby-sdl-ffi is pure Ruby code that accesses SDL (and related libraries) via FFI (foreign function interface), whereas rubysdl is an extension written in C that links to SDL (and related libraries). There are pros and cons to each approach. (Obviously, I feel that FFI is the better approach, or I would not have bothered to write ruby-sdl-ffi.)

Both libraries offer similar feature sets, although there are some differences (noted below). They can both do 2D games with images, sounds/music, and user input from keyboard, mouse, and/or joystick/gamepad. They can also both be used with OpenGL (via ruby-opengl or ffi-opengl) to create hardware-accelerated 3D games. They can both be used on Windows, MacOS X, and Linux (and perhaps other platforms), although rubysdl only works on MacOS X if you use a special Ruby interpreter wrapper called "rsdl".

I have not run any serious benchmarks, so I can't provide any definitive data about raw performance. My general impression is that rubysdl might have a slight performance advantage, but they are close enough that performance isn't the main factor when deciding between the two libraries.

Here is how I would summarize the pros and cons of the two libraries:

ruby-sdl-ffi

  • Easier for users to install the gem. It does not need to be compiled, so users don't need to install a C compiler or toolchain.
  • Works with MRI (the "usual" Ruby interpreter), JRuby, and probably Rubinius.
  • No special interpreter is required on MacOS X. However, the MacOS X support may need to be updated to get it working totally right on the latest versions of MacOS X. (Apple keeps changing things.)
  • Lower-level API, more closely mirrors the C libraries. This may be good or bad depending on your perspective.
  • Currently has bindings for SDL, SDL_gfx, SDL_image, SDL_mixer, and SDL_ttf libraries. (Compared to rubysdl, it adds SDL_gfx but lacks SGE and SMPEG.) Adding bindings for other libraries is quite easy.
  • Not actively developed or maintained anymore. I don't have the time or interest anymore, but someone is welcome to take over, and I can provide guidance.
  • Somewhat experimental, and has some rough edges.

rubysdl

  • More mature and polished, has withstood the test of time.
  • Better support for Japanese text input and rendering.
  • Higher-level, more abstract API.
  • Binds SDL, SGE, SMPEG, SDL_image, SDL_mixer, and SDL_ttf libraries.
  • Requires users to have a C compiler to install the gem. This can be quite a headache on Windows and MacOS X.
  • Requires MacOS X users to run your game using the special "rsdl" Ruby interpreter. Thus, to my knowledge, it will not work with JRuby or Rubinius on MacOS X.
  • Does not seem to be actively developed or maintained anymore either.
like image 107
John Croisant Avatar answered Jul 08 '26 13:07

John Croisant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!