Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Python binding generation tools  (Read 35239 times)

0 Members and 2 Guests are viewing this topic.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #45 on: April 17, 2011, 07:46:38 pm »
Beliar is probably right, the renaming of GetEvent() to PollEvent() in SFML is very recent. Try getting a new SFML 2 snapshot, or update your repo if you're using Git.

It's “normal” that the code generates a lot of warnings, I used to activate them with GCC on this project, but I always got the same warnings and I couldn't do much about it since the code is generated by Cython.
However, I guess you didn't activate all warnings and VS only shows the most important ones, and the most recurring is this conversion from double to float, so I'll see if there's something I can fix. Still, I think it's probably not a big deal since SFML uses floats for almost everything.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

BLU3 L30PARD

  • Newbie
  • *
  • Posts: 5
    • View Profile
Python binding generation tools
« Reply #46 on: April 17, 2011, 10:22:14 pm »
It seems that it's only possible to compile with MinGW (gcc)...
I tried it again with VC, but I get the output that a manifest file is missing.
But when I compiled PySFML2 with MinGW (without Cython!), it worked :)
I'll try to create a small game with your lib ;)

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #47 on: April 18, 2011, 03:26:40 pm »
Visual Studio reports a strange manifest for me as well, but it happens when I compile SFML. Maybe I'll give MinGW a try.
Good luck for your game. ;)
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

BLU3 L30PARD

  • Newbie
  • *
  • Posts: 5
    • View Profile
Python binding generation tools
« Reply #48 on: May 03, 2011, 07:36:20 pm »
My game crashes when I try to display a string...
The .NET Binding had the same problem, but I thought
it is fixed since sfml2... please (try) to fix that! ;)

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #49 on: May 04, 2011, 03:29:16 pm »
Can you run the text.py example? It works fine on my system.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

BLU3 L30PARD

  • Newbie
  • *
  • Posts: 5
    • View Profile
Python binding generation tools
« Reply #50 on: May 07, 2011, 04:04:22 pm »
Yes that works, but when the App was closed I'm getting this
Message from Windows....

I'm using Windows 7 Home Premium (x86 | 32bit) and
Python 2.7.1

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
Python binding generation tools
« Reply #51 on: May 09, 2011, 06:27:28 pm »
Hi,

First of all thanks for your hard work on this refreshing binding. I have just ported a sizeable chunk of my code that used the official PySFML 1.6 to this new binding and it does feel cleaner.

However, get_joystick_axis() (from sf.Input) seems to be broken, which kind of renders the joystick unusable.

Here is the incriminating code (where "glob.win" is an sf.RenderWindow):
Code: [Select]
jx = glob.win.get_input().get_joystick_axis(0, 0) / 100.
Which yields:
Code: [Select]
Traceback (most recent call last):
              <...snip...>
  File "/home/lapin/Desktop/ANTCURR/st_jeu.py", line 291, in update
    jx = glob.win.get_input().get_joystick_axis(0, 0) / 100.
  File "sf.pyx", line 1111, in sf.Input.get_joystick_axis (sf.cpp:11965)
AttributeError: 'sf.Input' object has no attribute 'GetJoystickAxis'


Out of curiosity I opened sf.pyx and here is the portion that seems to be wrong:
Code: [Select]
cdef class Input:
             <...snip...>
    def get_joystick_axis(self, unsigned int joy_id, int axis):
        return self.GetJoystickAxis(joy_id, axis)


I use the latest SFML 2 snapshot from Git (as of May 9th 2011) and the latest snapshot of the new binding.

EDIT 2: I guess a "p_this" is missing in there.
So if I change line #1111 of sf.pyx to:
Code: [Select]
       return self.p_this.GetJoystickAxis(joy_id, axis)
I get the following error when compiling sf.cpp after having being cythoned from sf.pyx:
Code: [Select]
sf.cpp: In function ‘PyObject* __pyx_pf_2sf_5Input_1get_joystick_axis(PyObject*, PyObject*, PyObject*)’:
sf.cpp:11962:132: error: invalid conversion from ‘int’ to ‘sf::Joy::Axis’ [-fpermissive]
/usr/include/SFML/Window/Input.hpp:120:11: error:   initializing argument 2 of ‘float sf::Input::GetJoystickAxis(unsigned int, sf::Joy::Axis) const’ [-fpermissive]

My guess here is that the API has changed and now uses a "sf::Joy::Axis" instead of a simple int (as in the current .pyx file)

EDIT 3: (Sorry for the long long post) For those who want to get the job done quickly, modify line #1111 of sf.pyx as shown above, run setup.py build, which will generate the huge C++ file. gcc will fail, but don't worry about it right now. Open the huge C++ file named sf.cpp, and head down to line #11962 (I guess the exact line number is subject to change in the near future, but anyway, this is a temporary fix.)
Change it from this:
Code: [Select]
 __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2sf_Input *)__pyx_v_self)->p_this->GetJoystickAxis(__pyx_v_joy_id, __pyx_v_axis)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
to this:
Code: [Select]
 __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2sf_Input *)__pyx_v_self)->p_this->GetJoystickAxis(__pyx_v_joy_id, static_cast<sf::Joy::Axis>(__pyx_v_axis))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
We're just casting the integer as a sf::Joy::Axis. It's dirty but it does the trick for now, because I don't know how to fix the cython files yet. Then of course run setup.py build again, then setup.py install.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #52 on: May 21, 2011, 03:11:53 am »
Thanks for reporting the bug, I fixed it.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #53 on: May 21, 2011, 04:29:26 pm »
Quote from: "BLU3 L30PARD"
Yes that works, but when the App was closed I'm getting this
Message from Windows....

I'm using Windows 7 Home Premium (x86 | 32bit) and
Python 2.7.1


Does this happen with every PySFML program?
I've built it on Windows, so I'll try to do some tests.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
Python binding generation tools
« Reply #54 on: May 22, 2011, 05:55:28 pm »
Quote from: "bastien"
Quote from: "BLU3 L30PARD"
Yes that works, but when the App was closed I'm getting this
Message from Windows....

I'm using Windows 7 Home Premium (x86 | 32bit) and
Python 2.7.1


Does this happen with every PySFML program?
I've built it on Windows, so I'll try to do some tests.


Bastien, I also ran into this bug, that is, a crash when quitting Python on Windows (doesn't seem to happen for me on Linux). I don't mind because the rest of the program runs flawlessly. But it may be intimidating to an end user.

I traced it back to loading sound buffers into memory from a file, or opening a music file.

For example, this two-line program will crash:
Code: [Select]
import sf
sbuf = sf.SoundBuffer.load_from_file('data/clear.ogg')

load_from_file itself does not crash, that is, you can make a Sound out of sbuf and it'll play just fine; it rather seems to me there's a destructor that went wrong somewhere.

Interestingly, it doesn't crash immediately after sbuf goes out of scope; for example:
Code: [Select]
import sf
def foo():
sbuf = sf.SoundBuffer.load_from_file('data/clear.ogg')
foo()
foo()
foo()
print "Yay"

This program gets to "Yay" allright, and then crashes on exit.

Music similarly gets Python to crash on exit:
Code: [Select]
music = sf.Music.open_from_file('data/maf-shroomy.ogg')

Hope this helps. And btw, great job fixing the joystick bug and converting time to integers! I have to test it out. (after porting my program to use millisecs)

EDIT: the 'pong' example is, of course, affected by this bug. It also uses a wav file, while I have used oggs, so the crash may not be file format-specific.

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
Python binding generation tools
« Reply #55 on: May 22, 2011, 06:42:48 pm »
Hold on-- this problem actually appears with C++ SFML 2 programs. The 'sound' C++ example crashes on exit.

EDIT: ran examples through gdb, found out alcCloseDevice() from openal32.dll is the culprit. This seems to be a known bug, see https://github.com/SFML/SFML/issues/30

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
Python binding generation tools
« Reply #56 on: May 27, 2011, 07:14:37 am »
Hi Bastien,
I suggest you add this to sf.pyx within the 'wrap_event_instance' cdef, so as to make the TEXT_ENTERED event useful. So far you couldn't get which Unicode character was typed in.
I put that at line 1082 in sf.pyx. I tested it and it works fine.
Code: [Select]
   elif p_cpp_instance.Type == declevent.TextEntered:
        ret.unicode = p_cpp_instance.Text.Unicode

Then, the Unicode value of the character can be retrieved within a Python program with the unichr() built-in function (unichr(event.unicode))

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
Python binding generation tools
« Reply #57 on: July 11, 2011, 08:16:09 am »
Thanks for the suggestion, I didn't remember this one wasn't implemented.
But instead of giving the plain integer, I convert it to a real Unicode object directly. It seems more logical.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython