Re: Euphoria Chipmunk Physics

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...
Icy_Viking said...

Hello,

I have managed to wrap the chipmunk physics library for Euphoria. http://www.rapideuphoria.com/uploads/euchipmunkphy.zip You can get it from the link. I was hoping to make a demo to go with it, however, I could not figure out how to Euphorialize the hello world chipmunk example that is written in C. The wrapper itself seems to work fine. I did test it and check it against some functions and procedures and it seems to work. No errors came up. Any comments or suggestions are welcomed.

I had a look at your code and I'm not sure if you're going to be able to do this the way you're intending. The problem is that the Chipmunk library passes structures by value. Every time you see the code passing cpVect without an asterisk *, that means it's passing two literal C_DOUBLE values on the stack. This is the same problem you'd have on Allegro 5. Euphoria's C interop routines are simply not designed to pass structures by value at this time. I assume this is why I saw all of the vector parameters declared as sequence in your wrapper code. Unfortunately that will not work either. I was able to work around this in Allegro 5 by using a C shim library that manually peeked and poked the values as pointers instead.

Take the following C definitions:

typedef struct cpVect{ 
    cpFloat x, y; 
} cpVect 
 
cpVect cpBodyGetPosition(const cpBody *body) 
void cpBodySetPosition(cpBody *body, cpVect pos) 

And here is the non-functional wrapper code:

-- structure offets 
constant cpVect_x = 0 -- cpFloat (C_DOUBLE) 
constant cpVext_y = 8 -- cpFloat (C_DOUBLE) 
constant SIZEOF_CPVECT = 16 
 
constant x_cpBodyGetPosition = define_c_func( chipmunk, "+cpBodyGetPosition", {C_POINTER}, {C_DOUBLE,C_DOUBLE} /* return value must be an atom. this will not work! */ ) 
constant x_cpBodySetPosition = define_c_proc( chipmunk, "+cpBodySetPosition", {C_POINTER,C_DOUBLE,C_DOUBLE} /* this is 'cheating' but should technically work */ ) 

Another issue is that some C functions, like cpv() are declared as static inline, which prevents them from being exported by the library.

-Greg

Ah. I did not think of that. So it seems some more tricks and hacks sorta to speak would be needed in order to make this fully work. Even though Chipmunk is written in C as is Allegro, it seems some libraries are harder to wrap than others. Still a worthy shot, if nothing less. I wonder if Phix might be better at wrapping some of these libraries, it is very similar to Euphoria?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu