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

Author Topic: pysfml-cython  (Read 69418 times)

0 Members and 1 Guest are viewing this topic.

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
pysfml2-cython
« Reply #60 on: October 27, 2011, 11:19:47 pm »
Quote from: "bastien"
When I try your Pong example with my sf.pyd, I get this:

Code: [Select]
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bastien\\Desktop\\pong\\sf.pyd") not found
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    import sf


Could you copy-paste here the command-lines that are issued when you build the binding? I guess I missed something to include the standard libraries.
Also, for some reason the SFML libs I cross-compiled aren't even detected by Wine.


Maybe my libs require having installed the Visual C++ redistributable? I build an executable of the pong example with PyInstaller and it put all the necessary DLLs in the folder. I gave it to my friend who has "bare" windows and it worked for him, so it should work for you too in Wine. Check it out here:

http://grebocin.com/upload/main.zip

Regarding the compilation output, here it is:

http://grebocin.com/upload/output.txt

Could you please deal with the conversion from Double to Float warnings? Why do you even use floats if SFML uses doubles? Does python have doubles? If not, could you at least convert these via a function so there is no warning? Thanks :).

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #61 on: October 28, 2011, 12:02:55 am »
I forgot you're using Visual Studio. :/
SFML uses floats, pure Python only has the equivalent of double (although they are called floats in Python). So in the end there's no way to prevent the user to use double precision, but I don't think that's a real problem. The warnings come from the code generated by Cython, I can't control them directly.

By the way, normally you can create an installer with “python setup.py bdist_wininst”.
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
pysfml2-cython
« Reply #62 on: November 06, 2011, 11:47:46 am »
Finally I built it from scratch in a virtual machine, here is a ZIP that should contain everything you need: https://github.com/downloads/bastienleonard/pysfml2-cython/python2-sfml2-cython-win32.zip

I'm especially interested to know if it works on machines that don't have SFML installed.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
pysfml2-cython
« Reply #63 on: November 06, 2011, 10:35:47 pm »
Hey Bastien I've got a question. When I run PySFML apps I have 2 windows - the black console window and the proper app window. Is there a way to get rid of the console window? In SFML there was a special library for that, it would initialize the main function so that the console window does not appear.

Also, I can't find the implementation of sf::Window::EnableVerticalSync. Is it possible to enable vertical sync in PySFML? I see it's only possible to limit the framerate to a fixed value, but how should I know the refresh rate of a given display mode? If I set it to 60, it will be incorrect for those who have 75 of 100 Hz.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #64 on: November 07, 2011, 12:00:57 am »
Quote from: "kolofsson"
Hey Bastien I've got a question. When I run PySFML apps I have 2 windows - the black console window and the proper app window. Is there a way to get rid of the console window? In SFML there was a special library for that, it would initialize the main function so that the console window does not appear.


Using pythonw.exe instead of python.exe as the interpreter should fix it. The simplest way is to rename your entry point file to .pyw (for example, main.pyw). The Windows installer associates .pyw files to launched with pythonw.exe. This problem doesn't happen on Unix.

Quote from: "kolofsson"
Also, I can't find the implementation of sf::Window::EnableVerticalSync. Is it possible to enable vertical sync in PySFML? I see it's only possible to limit the framerate to a fixed value, but how should I know the refresh rate of a given display mode? If I set it to 60, it will be incorrect for those who have 75 of 100 Hz.


You're right, I just added it in the Git repo: http://pysfml2-cython.readthedocs.org/en/latest/graphics.html#sf.RenderWindow.vertical_sync_enabled

I'm not really happy with these boolean attributes that you can set but not get, I guess I'm going to add getters myself. But it would be simpler if SFML had methods to do that directly.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
pysfml2-cython
« Reply #65 on: November 18, 2011, 02:17:38 pm »
Hey Bastien. I've been looking into Pygame and it looks nice so I'm wondering if you could tell me why did you decide to make PySFML. Was it speed, ease of use, more capabilities or SFML? If you ever used Pygame, what are the pros and cons in relation to PySFML?

Also, if you could look at my multithreading question post, I would be greatful.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #66 on: November 18, 2011, 05:36:14 pm »
Pygame is nice, I've used it for some time but it's based on SDL and it doesn't totally solve its problems.
Generally speaking, SDL's API gives you access to the screen as an array of pixels where you do every effect with the CPU, which doesn't really make sense nowadays. You used to have to implement scrolling and zooming manually.

With SFML, you can use effects like zoom or rotation on any drawable, or use views to apply effects to the entire scene, and it will use 3D acceleration behind the scenes. You can also use shaders easily.
With Pygame, as far as I know, the closest thing is a limited module. It's not well integrated in the API.

The upside for Pygame is that SDL is very stable and portable, and if you really don't need the features of SFML, you know your program will run everywhere. Personally, my open source driver on GNU/Linux became able to handle even basic 2D stuff only fairly recently with OpenGL/SFML. Somewhat paradoxically, SDL's software rendering seems to work a lot better with crappy driver support.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
pysfml2-cython
« Reply #67 on: November 20, 2011, 04:27:48 pm »
I've been looking at sf.Event documentation in the docs and I think this is missing:

Code: [Select]
       CLOSED: 'Closed',
        RESIZED: 'Resized',
        LOST_FOCUS: 'Lost focus',
        GAINED_FOCUS: 'Gained focus',
        TEXT_ENTERED: 'Text entered',
        KEY_PRESSED: 'Key pressed',
        KEY_RELEASED: 'Key released',
        MOUSE_WHEEL_MOVED: 'Mouse wheel moved',
        MOUSE_BUTTON_PRESSED: 'Mouse button pressed',
        MOUSE_BUTTON_RELEASED: 'Mouse button released',
        MOUSE_MOVED: 'Mouse moved',
        MOUSE_ENTERED: 'Mouse entered',
        MOUSE_LEFT: 'Mouse left',
        JOYSTICK_BUTTON_PRESSED: 'Joystick button pressed',
        JOYSTICK_BUTTON_RELEASED: 'Joystick button released',
        JOYSTICK_MOVED: 'Joystick moved',
        JOYSTICK_CONNECTED: 'Joystick connected',
        JOYSTICK_DISCONNECTED: 'Joystick disconnected'

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #68 on: November 20, 2011, 10:55:34 pm »
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
pysfml2-cython
« Reply #69 on: November 28, 2011, 12:54:39 pm »
Hello, first let me thank you for this excelent game lib and for port it for python/cython  :D

Isn´t  a good idea make the cython-sfml methods with cpdef  instead of def ?
If someone code with cython and import the lib , they can take advantage of c-speed method call.

Thank you in advance.

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #70 on: November 28, 2011, 08:29:02 pm »
In practice, the generated code is stil in C++, but obviously it needs to call the C/Python API. The vast majority of the methods are just there to map to the C++ equivalent. If someone really wanted to use raw C++, I guess he would call SFML directly.

I thought that cpdef would duplicate every method, but maybe I'm wrong. I should test it and see if it increases the module size.
Cython's documentation says that cdef/cpdef methods are virtual (here), i.e. you will automatically call the most specific method of an object. So I'm not sure whether it bypasses Python method resolution, I thought this was the only thing it could do to make calls faster. :?
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
pysfml2-cython
« Reply #71 on: November 28, 2011, 08:55:10 pm »
Well, I try this:
(in a pyx file)
Code: [Select]

cdef class Obj:      
    def python_method(self):    
        #operations
        pass
   
    cpdef cpython_method(self):
        #operations
        pass

import time

cdef Obj obj = Obj()

i = time.clock()

#cdef int x

for x in range(1000000):
    obj.python_method()

f = time.clock()

print "python_method %f" % (f-i)

i = time.clock()

for x in range(1000000):
    obj.cpython_method()

f = time.clock()

print "cpython_method %f" % (f-i)


I expected a fast loop with cpython_method, but there was only a little speed up. Then uncomment this "#cdef int x" and Voilá. Great speed up!(At least here, hundred of times faster).

I think this is nice i.e. for things like moving the main draw loop (that use Sprite.Draw)  in a cython 'for loop'.( Or any other loop that use a lot of python (slow)method calls)

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
pysfml2-cython
« Reply #72 on: November 30, 2011, 03:52:01 am »
I have uploaded a new zip file with the standard libs statically linked, it should include all the dependencies now: https://github.com/downloads/bastienleonard/pysfml2-cython/python2-sfml2-cython-win32-nodeps.zip

For some reason, I couldn't the extra_link_args option the setup script, even though it's documented here: http://docs.python.org/distutils/setupscript.html#other-options
Does someone know if extra_link_args works on Windows? (In practice, modify the code to something like setup(extra_link_args=[], **kwargs) in setup.py.)

Quote from: "thisdyingsoul"
Well, I try this:
(in a pyx file)
Code: [Select]

cdef class Obj:      
    def python_method(self):    
        #operations
        pass
   
    cpdef cpython_method(self):
        #operations
        pass

import time

cdef Obj obj = Obj()

i = time.clock()

#cdef int x

for x in range(1000000):
    obj.python_method()

f = time.clock()

print "python_method %f" % (f-i)

i = time.clock()

for x in range(1000000):
    obj.cpython_method()

f = time.clock()

print "cpython_method %f" % (f-i)


I expected a fast loop with cpython_method, but there was only a little speed up. Then uncomment this "#cdef int x" and Voilá. Great speed up!(At least here, hundred of times faster).

I think this is nice i.e. for things like moving the main draw loop (that use Sprite.Draw)  in a cython 'for loop'.( Or any other loop that use a lot of python (slow)method calls)


Thanks, I'll look into that one of these days.
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
pysfml2-cython
« Reply #73 on: January 27, 2012, 02:03:12 am »
I have updated the binding for the latest version. The main change is the new graphics API. Some stuff still needs to be done, see TODO.txt. The documentation and the examples haven't been updated yet.

I had to rewrite a lot of things, so some parts may be broken. Please report any problem you encounter.
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
pysfml2-cython
« Reply #74 on: January 31, 2012, 04:58:59 am »
By the way, one important change is that I removed Drawable. To create your own drawable, you now just need to add the draw() method in your class (see the C++ documentation for now).
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

 

anything