Not logged inGosu Forums
Forum Gosu Homepage Help Search Register Login
Up Topic Gosu / Extending Gosu / Gosu and Rubinius
- By jontebol Date 2010-03-17 11:47
Hello fellow gosuers,

I'm wondering what the status is of using Gosu with other ruby implementations than MRI. Essentially, there are 2 problems with MRI as I see it:

1. No code obfuscation - not fun to release the source code with every install of the game
2. Performance/Garbage Collector - even if ruby 1.9 is fast enough (at least for my purposes) the GC-hit that comes every now and then can make the otherwise smooth game stutter.

Both are quite important issues I think. As far as I know, Rubinius, MacRuby and JRuby could all possibly solve both those issues. JRuby might be out of the question, unless there is a nice way to get Gosu working with Java (but i would love it if there was!). And I know there's been some work on getting Gosu working with MacRuby, right? The problem with MacRuby is that I want to release the game in a cross-platform way, and that leaves JRuby and Rubinius. What about Rubinius then? I tried it with RC3 today, but got this error:

NativeLibrary::load_symbol(): dlsym(0x2d5db40, Init_gosu.for_1_8): symbol not found (SystemCallError)

Backtrace:
           NativeMethod.load_extension at kernel/common/native_method.rb:23
           Requirer::Utils.single_load at kernel/delta/requirer.rb:314
          Requirer::Utils.unified_load at kernel/delta/requirer.rb:98
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:725

I'm currently working on a game that is starting to look really promising, and thusly, I'm looking at my deployment options, and I'm a bit surprised that there aren't more people interested in getting Gosu working for other Ruby VMs. Gosu is such a sweet library, and Ruby is such a sweet language, I'd hate to have to rewrite the game in C++, just to solve those two issues...

And about the game... we will probably start a blog for it in a while, so you can all see the cool stuff we're doing. :) Just a little teaser. :)
- By ? Date 2010-03-21 06:10
I've been searching for a nice cross platform game engine for a while now, and I have the exact same concerns that you do.
I'd like an engine with a nice scripting system built in (like gosu) but I'd be concerned about releasing a game where the scripts are in plain view. Especially if it were a multiplayer game where cheating by editing scripts could have a negative impact on user experience.

I agree Rubinius seems like a great replacement if we could get it working. I might take a crack at it too. I'd love to hear if you find anything else out.
- By jlnr (dev) Date 2010-03-21 06:34
I have some plans in this regards I want to pursue, but I don't want to promise anything before it works. :P As a Rubinius quick-fix, you might be able to just rename gosu.ruby_1_8.bundle or what it is to gosu.bundle, then change gosu.rb to require that. (All in the 'lib' folder of the Gosu gem.)
- By ? Date 2010-03-21 13:37
Well, I tried the quick fix, but got this error instead:

    unknown type 0x22 (RuntimeError)

Backtrace:
           NativeMethod.load_extension at kernel/common/native_method.rb:26
           Requirer::Utils.single_load at kernel/delta/requirer.rb:314
          Requirer::Utils.unified_load at kernel/delta/requirer.rb:98
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:725

I'm on OS X Snow Leopard...

Have you gotten Rubinius to run Gosu? If you have, what was the performance like?
- By jlnr (dev) Date 2010-03-22 01:40
Oh, for that error I don't have a solution. No, I don't even know what the state of things is with Rubinius. I only tried MacRuby a few times, I wish it'd be easier to port to Windows.
- By ? Date 2010-05-16 17:29
The state of Rubinius is that it just hit 1.0! Time to give your plans a shot? They already support lots of gems/libs that use native extensions... Would be interesting at least to know how difficult it would be to get Gosu running on Rubinius...

In case you haven't tried Rubinius yet, let me save you a bit of googling and tell you that to install gems you just write: "rbx gem install ..."
- By jlnr (dev) Date 2010-05-17 16:05 Edited 2010-05-17 16:19
My personal plans are not related to these two implementations, and I will still keep them for me for a while (until I know they're either worthwhile or foolish). :P Have you tried it with MacRuby? I don't have any non-MRI implementation installed right now.
- By jontebol Date 2010-05-17 18:51 Edited 2010-05-17 19:06
I hope your personal plans involve WebGL then... That's what I would look into if I was maintaining Gosu... :) It would be so cool to throw Flash down the trash, and deploy web games written in Gosu/JavaScript (or whatever) with full hardware acceleration.

I didn't know Gosu was supposed to work with MacRuby yet... I just get a LoadError:

irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'gosu'
LoadError: no such file to load -- gosu

And of course I have done a "macgem install gosu" first... But it doesn't seem to find it, the error is the same as before I install the gem.

Hmm... there is no "gosu.for_macruby.bundle" in the gem folder... Do I have to build that myself somehow? Please say no... :P
- By jlnr (dev) Date 2010-05-18 07:05
Well, I thought MacRuby supported C extensions now? So I thought maybe the precompiled one might just work. But I guess what is actually true is that C extensions that compile against the ruby.h provided by MacRuby work, sometimes. Which Gosu cannot do right now. I have an idea how to do it though. Need to allocate more time next weekend. :(

Still kind of weird that it does not even find gosu.rb which is a plain Ruby file.
- By jontebol Date 2010-05-18 07:41
Where can I find the precompiled one? In gosu.rb, you load "gosu.for_macruby.bundle" if NSObject is defined, but there is no "gosu.for_macruby.bundle" in the gem folder with the other bundles. Only the one for Ruby 1.8, and the other one for 1.9.

When testing this in macirb, I managed to get MacRuby to find gosu.rb somehow. I think I tried doing a "gem 'gosu'" first, and then "require 'gosu'" just do see what happened, and then it actually tried to find "gosu.for_macruby.bundle" which wasn't in the folder... So if I could just get a hold of a macruby.bundle, I might be able to move a few steps further...
- By jlnr (dev) Date 2010-05-18 07:56
No, the precompiled MacRuby one was when it did not support C extensions, it was actually an Objective C bundle. Now it should be able to load something very similar to the for_1_9 bundle, except that I figure it's only source compatible, not binary compatible with 1.9. I think I might give Rubinius some more priority because I hope to get it working across all platforms with that.
- By jontebol Date 2010-05-18 14:17
Ok, sounds good. Rubinius isn't currently working on Windows though, but it's not far away I think.
- By jlnr (dev) Date 2010-05-18 14:38
Oh, good call. If you have a Linux system handy, you can check if Gosu works with Rubinius there.
- By puyo Date 2010-05-31 02:17
$ ruby Tutorial.rb
An exception occurred running Tutorial.rb
    /home/greg/.rvm/gems/rbx-1.0.0-20100514/gems/gosu-0.7.20/lib/gosu.custom.so: undefined symbol: _ZN4Gosu4Song6updateEv (SystemCallError)

Backtrace:
  Rubinius::NativeMethod.load_extension at kernel/common/native_method.rb:23
     Rubinius::CodeLoader#load_library at kernel/delta/codeloader.rb:156
          Rubinius::CodeLoader#require at kernel/common/codeloader.rb:40
          Rubinius::CodeLoader.require at kernel/common/codeloader.rb:134
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:685
                Kernel(Object)#require at lib/rubygems/custom_require.rb:31
                      main.__script__ at /home/greg/.rvm/gems/rbx-1.0.0-20100514
                                         /gems/gosu-0.7.20/lib/gosu.rb:12
          Rubinius::CodeLoader.require at kernel/common/codeloader.rb:139
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:685
                Kernel(Object)#require at lib/rubygems/custom_require.rb:36
                       main.__script__ at Tutorial.rb:8
      Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:65
      Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:88
               Rubinius::Loader#script at kernel/loader.rb:435
                 Rubinius::Loader#main at kernel/loader.rb:526
                 Rubinius::Loader.main at kernel/loader.rb:552
                     Object#__script__ at kernel/loader.rb:564

But for some reason, happily, if I run it like this, it prints the same error but this time it runs, except for sound:

$ rvm ruby Tutorial.rb

rbx-1.0.0-20100514: rubinius 1.0.0 (1.8.7 release 2010-05-14 JI) [i686-pc-linux-gnu]
An exception occurred running Tutorial.rb
    /home/greg/.rvm/gems/rbx-1.0.0-20100514/gems/gosu-0.7.20/lib/gosu.custom.so: undefined symbol: _ZN4Gosu4Song6updateEv (SystemCallError)

Backtrace:
  Rubinius::NativeMethod.load_extension at kernel/common/native_method.rb:23
     Rubinius::CodeLoader#load_library at kernel/delta/codeloader.rb:156
          Rubinius::CodeLoader#require at kernel/common/codeloader.rb:40
          Rubinius::CodeLoader.require at kernel/common/codeloader.rb:134
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:685
                Kernel(Object)#require at lib/rubygems/custom_require.rb:31
                      main.__script__ at /home/greg/.rvm/gems/rbx-1.0.0-20100514
                                         /gems/gosu-0.7.20/lib/gosu.rb:12
          Rubinius::CodeLoader.require at kernel/common/codeloader.rb:139
  Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:685
                Kernel(Object)#require at lib/rubygems/custom_require.rb:36
                       main.__script__ at Tutorial.rb:8
      Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:65
      Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:88
               Rubinius::Loader#script at kernel/loader.rb:435
                 Rubinius::Loader#main at kernel/loader.rb:526
                 Rubinius::Loader.main at kernel/loader.rb:552
                     Object#__script__ at kernel/loader.rb:564

ruby-1.8.7-p249: ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]
- By puyo Date 2010-05-31 02:20 Edited 2010-05-31 02:34
I think it's just running with ruby-1.8.7 that was installed by RVM...

Yes. "rvm ruby xyz" runs xyz under all installed rubies.

So it doesn't work with Rubinius due to the stacktrace above. It says it compiled and installed fine though, which is promising.

$ strings ~/.rvm/gems/rbx-1.0.0-20100514/gems/gosu-0.7.20/lib/gosu.custom.so  | grep _ZN4Gosu4Song6updateEv
_ZN4Gosu4Song6updateEv

It seems to be in there. Any ideas?
- By jlnr (dev) Date 2010-05-31 04:47
It seems I actually forgot to implement this method on Linux. I just added an empty method body (as on Windows) and attached a test gem for you. Does this work with Rubinius now? That would be pretty cool, except I'd still have no idea how to do the same for Windows, and for OS X it means some extra work.
Attachment: gosu-0.7.20.gem (309k)
- By puyo Date 2010-05-31 11:39 Edited 2010-05-31 11:52
New exception.

An exception occurred running Tutorial.rb
    NativeLibrary::load_symbol(): /home/greg/.rvm/gems/rbx-1.0.0-20100514/gems/gosu-0.7.20/lib/gosu.custom.so: undefined symbol: Init_gosu.custom (SystemCallError)

I'll check out the gosu code and see if I can get it over the line. Any tips on compiling/running gosu tests/examples with minimal fuss? e.g. right out of the working directory?
- By puyo Date 2010-05-31 12:13
I made it work with Rubinus. At least, CptnRuby.rb and Tutorial.rb. Had a few minor issues with the Rakefile (trying to require appscript and ftools, neither of which exist on my machine).

Attaching svn diff.
Attachment: rubinius.diff - Changes to make it compile and run with Rubinius 1.0.0 (2k)
- By jlnr (dev) Date 2010-05-31 12:24
Just for clarity, anyone wanting to try it out needs to apply that diff to the source, then do 'GOSU_RELEASE_VERSION=0.7.20 rake linux:gem', then install the newly generated gem in /public.

Please report all the ups and downs of using it with Rubinius, especially the compilation to bytecode, because I can make it so it works on OS X with Rubinius too—if it's worth the trouble :)
- By banister Date 2010-05-31 12:41
puyo what's the performance like in rubinius versus 1.8 ?
- By ippa Date 2010-06-02 13:17
@jontebol: spam us with the URL to your blog :P

..and just curious, how would you obfuscuate your sourcecode with rubinius? Never even looked at it.. :)
- By erisdiscord Date 2010-06-02 16:29
Rubinius compiles Ruby to LLVM bytecode, and I believe this bytecode can be written out to a file similar to Java class files. It's pretty cool if you ask me—maybe I ought to check it out myself.
- By jlnr (dev) Date 2010-06-14 13:15
On the topic of alternative Ruby implementations, just got mailed back with numbers from a Ruby survey. Man, devastating for the poor IronRuby guys, but what happened to Rubinius? People don't like finished products )or almost finished, in 2009)? :)

http://survey.hamptoncatlin.com/survey/stats

But then, Gosu is playing somewhere in a niché 1% of Ruby coders anywhere, so whatever. :)
Up Topic Gosu / Extending Gosu / Gosu and Rubinius

Powered by mwForum 2.29.1 © 1999-2013 Markus Wichitill