Page 2 of 2

Re: Ruby Gem for Chipmunk

Posted: Tue Dec 01, 2009 5:35 pm
by slembcke
Well, you wouldn't be custom compiling anything so much as you would be adding a second library that contained the normally inlined functions as a dependency.

Another acceptable option would be to just do something like this:

Code: Select all

#define MAKE_REF(name) __typeof__(name) *_##name = name;
MAKE_REF(cpvadd); // makes a variable named _cpvadd that contains the function pointer for cpvadd()
MAKE_REF(cpvneg);
MAKE_REF(cpvsub);
MAKE_REF(cpvmult);
MAKE_REF(cpvdot);
MAKE_REF(cpvcross);
MAKE_REF(cpvperp);
MAKE_REF(cpvrperp);
MAKE_REF(cpvproject);
MAKE_REF(cpvrotate);
MAKE_REF(cpvunrotate);
MAKE_REF(cpvlengthsq);
MAKE_REF(cpvlerp);
MAKE_REF(cpvnormalize);
MAKE_REF(cpvnormalize_safe);
MAKE_REF(cpvclamp);
MAKE_REF(cpvlerpconst);
MAKE_REF(cpvdist);
MAKE_REF(cpvnear);
MAKE_REF(cpvdistsq);

MAKE_REF(cpBBNew);
MAKE_REF(cpBBintersects);
MAKE_REF(cpBBcontainsBB);
MAKE_REF(cpBBcontainsVect);
MAKE_REF(cpBBmerge);
MAKE_REF(cpBBexpand);

MAKE_REF(cpBodyWorld2Local);
MAKE_REF(cpBodyLocal2World);
MAKE_REF(cpBodyApplyImpulse);
That would make function pointers in global symbol name aliases that point to static instances of the functions. I would assume that you would be able to load these pointers the same way as you would a regular function pointer. Try pasting that into chipmunk.c to see if you can reference the functions that way. That's a simple enough solution for me to maintain that I'd be willing to add it. It might even end up being useful to somebody else too.

Re: Ruby Gem for Chipmunk

Posted: Tue Dec 01, 2009 9:53 pm
by shawn42
That didn't work for me. (btw it looks like you forgot to check a file into svn)

I don't know how to tell FFI to call a pointer to a function.

What does work is something along the lines of:
cpVect fficpv(const cpFloat x, const cpFloat y)
{
return cpv(x,y);
}

Now lets me bind to fficpv. Maybe you can define a macro that you use for defining static inlines that also creates another version of the function that calls the inlined?

I'll look deeper into calling those function pointers from FFI in the meantime.

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 9:43 am
by shawn42
So it turns out that I am able to get that data and use it as a function pointer. So your MAKE_REF solution would work fine for me. :D

Also, when are you planning on doing another release?

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 10:36 am
by slembcke
The current plan is to make a new official release as soon as the documentation is up to date. I was hoping to have finished that this weekend... but It's still not quite done yet.

Google Code is read only for the moment. Something about network maintenance. I'll commit add the FFI references and the fixed CMake files once it's back up.

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 1:22 pm
by shawn42
If you are getting ready for a release, can I beg of you to put in a version method? As of now, there is no way that I know of to dynamically determine the verison of chipmunk a user has. :shock:

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 4:20 pm
by slembcke
shawn42 wrote:If you are getting ready for a release, can I beg of you to put in a version method? As of now, there is no way that I know of to dynamically determine the verison of chipmunk a user has. :shock:
Oh! I had meant to do that a long long time ago actually. I'll add a string for that.

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 8:23 pm
by shawn42
Great! :D

Re: Ruby Gem for Chipmunk

Posted: Wed Dec 02, 2009 9:47 pm
by shawn42
Looks like you've missed a few:
MAKE_REF(cpBBClampVect);
MAKE_REF(cpBBWrapVect);

If you'd like to give me commit rights to add these, I do not mind maintaining them, else I can send them to you as I find them.

Re: Ruby Gem for Chipmunk

Posted: Thu Dec 03, 2009 10:25 am
by slembcke
cpBBClampVect and cpBBWrapVect are defined in cpBB.c and are not static.

Also... I never realized the naming on my AABB functions was so screwy... Whatever, they rarely get used anyway.

Re: Ruby Gem for Chipmunk

Posted: Thu Dec 03, 2009 3:36 pm
by shawn42
Right you are. Maybe I shouldn't write code at 2am baby feedings.... :oops: