electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

Pyray : convert function arguments based on c function signature #53

Open Lcbx opened 2 years ago

Lcbx commented 2 years ago

Hi,

while testing the Pyray module I stumbled upon your comment about function calls using a lot of string comparisons at runtime, so here's an alternative that basically converts python arguments to the type expected by the c function.

Interestingly I have not found that great a performance improvement on the script I tested it on (~3%) but at least we don't inspect the c function at each call anymore.

keep being awesome !

Lcbx commented 2 years ago

just found a bug using this.

some arguments expect pointers but can be given non ffi pointers ; however since signatures expects a pointer it calls ffi.addressof on the argument and crashes. Imma fix that.

Lcbx commented 2 years ago

not the best fix but it works

Lcbx commented 2 years ago

found a way to check on type rather than str(type)

should be robust and work with dynamic since the C_POINTER type we check is determined in pyRay init

electronstudio commented 2 years ago

This looks like quite a major change so will probably take me a while to review it. Let me know when it’s finished anyway.

Lcbx commented 2 years ago

The implementation change is around 15 loc, only in pyray/init.py other files are changes to examples

Lcbx commented 2 years ago

oh yeah and it's pretty much finished afaik, tested it on a few examples (your pyrayTest, bunnyMark, boxCollisions and animation)

electronstudio commented 2 years ago

Example is added, thanks. I had to add an unsigned int* to satisfy Raylib though,

electronstudio commented 2 years ago

oh i see, you wrote a special case for that call to add the unsigned int*. i don't really want to be special casing anything.

electronstudio commented 2 years ago

do you have a benchmark that shows a difference for the changes to pyray/init.py ?