Ruby Gem for Chipmunk
-
- Posts: 3
- Joined: Wed Sep 30, 2009 4:55 am
- Contact:
Ruby Gem for Chipmunk
Heya,
great work on Chipmunk and thanks for the ruby bindings, however it's slightly difficult to get chipmunk going for most ruby users. Would it be okay if i released a cross-platform ruby gem for chipmunk?
you can contact me at jrmair@gmail.com
thanks,
banister
great work on Chipmunk and thanks for the ruby bindings, however it's slightly difficult to get chipmunk going for most ruby users. Would it be okay if i released a cross-platform ruby gem for chipmunk?
you can contact me at jrmair@gmail.com
thanks,
banister
-
- Posts: 3
- Joined: Wed Sep 30, 2009 4:55 am
- Contact:
Re: Ruby Gem for Chipmunk
...I just went ahead and released the gem, hope you dont mind
I set as the homepage a link to the official chipmunk site, you can check out the github project here: http://github.com/banister/chipmunk
To install the gem just go: gem install chipmunk
If there's anything at all you want me to change about the gem or the README or anything at all, just let me know,
EDIT: just letting you know i had to modify the README file as alot of the content there was not relevant to the ruby release
thanks
banister
I set as the homepage a link to the official chipmunk site, you can check out the github project here: http://github.com/banister/chipmunk
To install the gem just go: gem install chipmunk
If there's anything at all you want me to change about the gem or the README or anything at all, just let me know,
EDIT: just letting you know i had to modify the README file as alot of the content there was not relevant to the ruby release
thanks
banister
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Ruby Gem for Chipmunk
That's great. People have been asking about making a gem for a while, but I never looked into what it would take to make one. Maybe you could give me some tips on how to build an extension properly for the trunk version? For our last project, I wanted to try SCons and hacked something together that could build the extension on Windows, Linux, and OS X. I wasn't 100% satisfied with it though.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Wed Sep 30, 2009 4:55 am
- Contact:
Re: Ruby Gem for Chipmunk
well the best solution by far for building extensions (and gems based on extensions) is to use rake-compiler (http://github.com/luislavena/rake-compiler)
it even cross-compiles to windows (so you can save a tedious reboot and eternal frustration with the microsoft C compiler...which hates c99 btw :/)
If you're interested how to use it, just take a peek at the Rakefile I use in my project (http://github.com/banister/chipmunk)
cheers
it even cross-compiles to windows (so you can save a tedious reboot and eternal frustration with the microsoft C compiler...which hates c99 btw :/)
If you're interested how to use it, just take a peek at the Rakefile I use in my project (http://github.com/banister/chipmunk)
cheers
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Ruby Gem for Chipmunk
It certainly does . The solution to compiling Chipmunk under MSVC up to now has been to compile as C++ which has enough of C99's features to make it non-tedious. Dynamically sized arrays on the stack are still out, but it's not to bad to use alloca instead though.banister wrote:.which hates c99 btw :/
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 11
- Joined: Fri Nov 20, 2009 11:18 am
- Contact:
Re: Ruby Gem for Chipmunk
You should look at using FFI to make this gem more portable.
-
- Posts: 11
- Joined: Fri Nov 20, 2009 11:18 am
- Contact:
Re: Ruby Gem for Chipmunk
I have started to play with FFI and chipmunk bindings..
http://github.com/shawn42/chipmunk-ffi
I have noticed that most of your cpVect class is static inlines, this makes them unavailable for calling via FFI. There are two ways around this:
One, I write all the Vec stuff in Ruby, not a fan of this option as it will be very slow.
Two, I'd like it if you could create a wrapper of all these inline functions that external libs could call. The benefits here would be that all the C chipmunk code could still get the speed of inline calls, and external libs could still call them without having to rewrite them.
http://github.com/shawn42/chipmunk-ffi
I have noticed that most of your cpVect class is static inlines, this makes them unavailable for calling via FFI. There are two ways around this:
One, I write all the Vec stuff in Ruby, not a fan of this option as it will be very slow.
Two, I'd like it if you could create a wrapper of all these inline functions that external libs could call. The benefits here would be that all the C chipmunk code could still get the speed of inline calls, and external libs could still call them without having to rewrite them.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Ruby Gem for Chipmunk
Assuming that you are using GCC, you could compile an empty C file that imports the chipmunk header and use the -fkeep-inline-functions flag. I think that should give you a library that you can link to that has a concrete version of all of the inline functions and nothing else. As there are a lot more inline functions than just the cpVect ops, this would probably be the easiest solution all around.
http://gcc.gnu.org/onlinedocs/gcc/Inline.html
Defining them as extern inline also looks like an option, but it requires you to copy/paste the function and maintain a copy of it in the header and in a module. That sounds rather annoying and I'd probably forget to update both copies. If the above solution works, that would be best.
http://gcc.gnu.org/onlinedocs/gcc/Inline.html
Defining them as extern inline also looks like an option, but it requires you to copy/paste the function and maintain a copy of it in the header and in a module. That sounds rather annoying and I'd probably forget to update both copies. If the above solution works, that would be best.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Ruby Gem for Chipmunk
Hmm. Just tried that, and it doesn't seem to work the way I expected it would.
Making a reference to each function you need does work however. A slight pain, though at least it can be templated so it's as simple as maintaining a list of function names.
Couldn't figure out how to make it work without compiling as -O0, but that's not really going to be a big deal when calling out to the functions from slow Ruby code. Probably not much slower than my hand crafted extension code I have now.
Compile and check with:
Making a reference to each function you need does work however. A slight pain, though at least it can be templated so it's as simple as maintaining a list of function names.
Code: Select all
#include <stdlib.h>
#include "src/chipmunk.h"
static void *functions[] = {
cpvadd,
cpvsub,
};
Compile and check with:
Compile that as a dynamic library and you should be good to go I think.gcc -O0 -ffast-math -std=c99 test.c -c && nm test.o
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 11
- Joined: Fri Nov 20, 2009 11:18 am
- Contact:
Re: Ruby Gem for Chipmunk
I guess I'm looking for more of a global solution that would be in chipmunk itself. The idea of writing FFI bindings is that the users wouldn't need to custom compile anything.
It'd be great if we could somehow just make those available in the default build of chipmunk. Does that make sense?
PS feel free to shoot me an email or IM at shawn42 __A_T__ gmail
It'd be great if we could somehow just make those available in the default build of chipmunk. Does that make sense?
PS feel free to shoot me an email or IM at shawn42 __A_T__ gmail
Who is online
Users browsing this forum: No registered users and 2 guests