Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / Gosu and RubyMotion (on OS X, for now)
- By jlnr (dev) Date 2015-06-14 21:23
I've been playing around with Gosu and RubyMotion lately, and I thought I'd share what the experience was like. RubyMotion is a commercial implementation of Ruby running on Apple's Objective C runtime (OS X, iOS), and on Android. I've only tried it on OS X so far.

To run Ruby/Gosu code in RubyMotion, I had to wrap Gosu in two thin layers of code. First, a set of Objective C classes that call C++ code - this part is called GosuKit, and in theory you could use it to write Gosu games in Objective C and Swift (but why...). It looks like this:

https://github.com/gosu/motion-gosu/blob/master/GosuKitTests/GosuKitTests.m

It is possible to call GosuKit from RubyMotion, but the method names are very un-Ruby-like: GSKImage.new.drawAtX(x, y: 5, z: 45...) and so on. So there is a second layer of paint called "motion-gosu" that wraps the GosuKit Objective-C classes in the familiar Gosu 0.9 interface:

https://github.com/gosu/motion-gosu/blob/master/motion/image.rb

It's not 100% complete - TextInput, custom OpenGL and loading images from "blobs" are all missing. Also, motion-gosu is not backward compatible at all - every step away from the new Gosu 0.9 results in an exception.

With these two things in place, I was able to get my old game Peter Morphose to run (half the levels, anyway). It's a very chaotic codebase, mostly translated to Ruby from Delphi source files written in 2001 - but it only took a few changes to get it to work in RubyMotion! That's pretty sweet :)

https://github.com/jlnr/petermorphose/tree/motion

Thoughts:
• RubyMotion does not use garbage collection. If you want to have circular references between objects, you have to use WeakRef - otherwise you'll leak memory. Auditing an existing Ruby codebase for circular references sounds frustrating.
• Everything about RubyMotion is extremely unforgiving. In one case I've passed :additive instead of the newer :add to Image#draw and had to use lldb (the low-level Objective C debugger) to figure out what was going on. So I'd always develop my game using "standard" Ruby/Gosu and then only wrap it up for release with RubyMotion.
• I'm not sure if you can keep your existing directory Ruby/Gosu structure and just add a RubyMotion Gemfile, Rakefile etc? I moved everything around to match the RubyMotion default structure.

iOS is next, obviously. My long-term goal is to run the same (unreleased) Ruby game on iOS and Android devices.
Attachment: Monstris.app.zip (2062k)
Up Topic Gosu / Extending Gosu / Gosu and RubyMotion (on OS X, for now)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill