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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bastien

Pages: 1 ... 5 6 [7] 8 9 ... 13
91
Python / pysfml2-cython
« on: October 24, 2011, 11:56:45 pm »
I keep updating it because people want it, don't hesitate to message me if something needs to be improved.

92
Python / pysfml2-cython
« on: October 24, 2011, 09:16:21 pm »
I haven't tried to debug PySFML applications, just the binding itself, and the users will normally never need to do that.
I never use debuggers for Python, except for really weird cases.

Currently, I'm using SFML compiled in release mode, but I guess you can use any version you want. The only upside I can see for using a debug version is if you plan to debug the library itself, and in some cases it might be possible that some low-level bugs occur only when some compiler optimizations are activated. I think this irrelevant for Python users.

I can't see which options are provided to cython by default when it's invoked by the setup.py script, but in practice I find that it provides enough information when an error occurs.
Looking at cython's command-line options, it looks like you can only disable doc strings, or add line directives to see where the error comes from the source file. Both are probably useless for most users since I don't use doc strings.
When I'll make a stable release, I'll try the various options to see if can significantly reduce the module size, though.

In the end, if you just want to debug your application, you can probably just use whatever Python debugger you prefer. I remember that I used Winpdb for debugging multi-threaded programs. There's also the standard module pdb. Personally, I find that print statements are enough most of the time. It's not like in C where you often just get “Segmentation fault” as an error message. ;-)

93
Python / pysfml2-cython
« on: October 20, 2011, 02:51:45 pm »
Yeah, I'll try to add a binary release for Windows as soon as possible, now that the binding seems to be stable. I already tried to cross-compile it, but I have trouble testing things with Wine.

94
Python / [Solved] How to load sf.Images in a separate Thread/process?
« on: October 20, 2011, 02:47:49 pm »
In this case, something like that would work. Note that the boolean can't be passed as a an argument if you want the thread to be able to modify it, because bools are immutable. That's the main reason why I created the ThreadData class.
Normally, you would probably need a mutex or a thread-safe list, but because of the GIL, I decided to make it simple for this example.

Code: [Select]
import glob
import threading

import sf


SPRITES = glob.iglob('/media/winxp/d/images/Textures/2D/TEXTURES/*.BMP')


class ThreadData(object):
    def __init__(self, sprites):
        self.sprites = sprites
        self.join_thread = False


class LoadingThread(threading.Thread):
    def __init__(self, data):
        threading.Thread.__init__(self)
        self.data = data

    def run(self):
        for i, filename in enumerate(SPRITES):
            sprite = sf.Sprite(sf.Texture.load_from_file(filename))
            self.data.sprites.append(sprite)

        self.data.join_thread = True
        print 'Finished loading'


def main():
    window = sf.RenderWindow(sf.VideoMode(1280, 1024), 'Title')
    window.framerate_limit = 60
    sprites = []
    thread_data = ThreadData(sprites)
    thread = LoadingThread(thread_data)
    thread.start()
    running = True

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        if thread_data.join_thread:
            thread.join()
            thread_data.join_thread = False
            print 'Joined'

        window.clear(sf.Color.WHITE)

        for sprite in sprites:
            window.draw(sprite)

        window.display()


if __name__ == '__main__':
    main()


Did you try to write a sample in C++, to see if it would speed things up? I'm interested to see if the binding needs to be optimized.

95
Python / pysfml2-cython
« on: October 19, 2011, 08:38:08 pm »
That's strange. Last try: did you also copy the DLLs that are in SFML/extlibs? (I don't see a “DLL loaded failed” message when importing a non-existing module, so my guess is that a dependency can't be loaded.)

96
Python / [Solved] How to load sf.Images in a separate Thread/process?
« on: October 19, 2011, 02:50:40 pm »
I've never used threads to load images, but here is a basic example.
I assume that you have some work to do in parallel of the image loading. Otherwise, you will probably need more complex synchronization mechanisms.

Honestly, this is unlikely to give better performance overall, unless the GIL is released before doing I/O-heavy operations.

Have you tried loading the images on demand?

Code: [Select]
import threading

import sf


SPRITES = ['file1.png', 'file2.png']


class LoadingThread(threading.Thread):
    def __init__(self, sprites):
        threading.Thread.__init__(self)
        self.sprites = sprites

    def run(self):
        for filename in SPRITES:
            self.sprites.append(sf.Sprite(sf.Texture.load_from_file(filename)))


def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'Title')
    window.framerate_limit = 60
    sprites = []
    thread = LoadingThread(sprites)
    thread.start()

    # Do some work while the images are being loaded

    thread.join()
    running = True

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        window.clear(sf.Color.WHITE)

        for sprite in sprites:
            window.draw(sprite)

        window.display()


if __name__ == '__main__':
    main()

97
Python / pysfml2-cython
« on: October 19, 2011, 07:27:47 am »
You're right, it's .pyd on Windows apparently. What happens if you open a command prompt, go to the path where sf.pyd is, type “python”, and then type “import sf” interactively?

98
Python / pysfml2-cython
« on: October 18, 2011, 06:51:40 pm »
Quote from: "kolofsson"
Quote from: "bastien"
It looks like you didn't add the headers.
Yes, I think system32 is the right directory for DLLs.


Ok I added the includes. Now it gives me this error:

"failed to load and parse the manifest, file not found"

EDIT: Now I edited the python the way I found on some web page (adding /MANIFEST to args of some program) and the compilation finished, I guess. When I try to run a program made with SFML, I get this error:
Code: [Select]
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "E:\pysfml2\bastienleonard-pysfml2-cython-ca7f88f\examples\pong\main.py", line 9, in <module>
    import sf
ImportError: DLL load failed: File not found


sf.dll needs to be in the Python path. The simplest way is to put it the current directory just before you execute the program. Or you can modify the PYTHONPATH environment variable.

Or you can run python setup.py install, and it should be available for all the programs. But I would do this only after testing the binding.

99
Python / pysfml2-cython
« on: October 17, 2011, 08:12:25 pm »
It looks like you didn't add the headers.
Yes, I think system32 is the right directory for DLLs.

100
Python / pysfml2-cython
« on: October 17, 2011, 05:39:58 pm »
Exceptions now contain the error message with full details (the same message SFML would normally write on the console).

101
Python / pysfml2-cython
« on: October 17, 2011, 10:49:41 am »
Quote from: "DomtronVox"
First I'd like to thank you  for creating PYSFML and giving me more display library options :P.


Thanks. ;)

Quote from: "DomtronVox"
Second, I have some questions and wanted to point out something that I and maybe other people have a problem with.  

Does PYSFML have native functions for render 3d or would I need to create a projection class/algorithm(I have no clue how 3D works in SFML). I'm looking for a well maintained display library for both 2d and 3d rendering and works with python. I looked at pyopengl but saw a number of complaints that it wasn't maintained.


With C++ SFML, you can call OpenGL functions if needed.
I chose to not support this currently, mainly because I have very little experience OpenGL. Basically there's no support for the Window package in SFML, you can only use the higher-level classes like RenderWindow.
I think you should look into Pyglet or Pygame. Pyglet is a modern library kind of like SFML, and Pygame is based on SDL.

Quote from: "DomtronVox"
I built SFML and PYSFML yesterday and ran into an odd problem. SMFL "sudo make install" (a little bump was forgetting the sudo and not reading the big error msg >.<) installed the SFML .so's in the wrong directory. I'm on Ubuntu 10.4 LTS and for some reason "make install" placed the .so's in /usr/local/lib instead of /usr/lib. When I ran the PYSMFL examples sf.so couldn't find the needed libraries. So I had to manually copy all the SFML .so's over to the correct directory. Would this just be a problem with my computer?
Anyway I hope this helps someone in the same predicament.

Thanks


On GNU/Linux, it's common to use /usr/local for stuff that you install yourself, so I think it's normal. Otherwise, it may conflict with files installed by the package manager someday. The only problem is that you may need to tell GCC to look for headers in /usr/local/include and the dynamic loader to look for .so in /usr/local/lib. In my case (Arch Linux), I had to add the path in /etc/ld.so.conf.d/.

Quote from: "kolofsson"
Um, sorry, you mean the latest SFML no PySFML :oops:

Tell me please, where should I put the headers and libraries of SFML so that the MSVC compiler sees them? I guess this is what I'm doing wrong.


I don't really know, there should be a directory in Program Files that contains directories named something like include/headers and lib/libraries.
But from my experience Visual Studio's installation is pretty bloated, I remember it took me some time to find them.

102
Python / pysfml2-cython
« on: October 16, 2011, 07:44:11 pm »
Are you using the latest SFML version from Github? The Texture class is somewhat recent.

103
Python / pysfml2-cython
« on: October 13, 2011, 01:02:35 pm »
Hello,

1. Currently streaming isn't available, but it's mainly because I've never needed it personally. Also, I think someone said he was going to write it.
Network features are available in standard Python packages like socket. There are also more complex frameworks like Twisted.

2. Some people have problems building it on Windows. I'll try to upload a Windows binary one of these days, when I have access to Windows.
PySFML is as portable as SFML itself.

3. Emacs and Vim are very popular among Python programmers, but it takes some time to use them efficiently. You don't really need any advanced feature from your editor for Python, so feel free to use whatever editor you're comfortable with, and learn more complex tools later. I've used PyScripter for some time, since it's included with PortablePython.

4. Technically, python programs are .pyc files that are automatically generated when you run e.g. python main.py. Python translates the source to a faster binary language, then executes it.
I expect the speed of SFML and PySFML's classes to be roughly the same, as they are both written in C++ (well, my binding is written in Cython, but it gets translated to C++ before getting compiled and I didn't see any performance problem so far). Your Python code will be slower, and there are also some things that might cause problems for performance-intensive applications. For example, Python objects have to be allocated dynamically, while in C++ you can often create them on the stack.
Users will have to install Python and PySFML, unless you provide them with an installer.

104
Python / pysfml2-cython
« on: October 12, 2011, 02:12:35 am »
It's because both C++ SFML and PySFML 1.x use sf as the namespace.
You're right that it's probably not the best module name, but I'm still reluctant to change it, as everyone is used to sf.

If I changed the name, it would probably simply be sfml though. The “py” is redundant for a Python module.

105
Python / pysfml2-cython
« on: October 06, 2011, 09:30:22 pm »
I just added some support for the WindowHandle class, which required some ugly cast between integers and pointers. It compiles on GNU/Linux, but please let me know if you encounter a problem on Windows or Mac, since the WindowHandle will behave differently there.
Also, let me know if you actually use the window handle with Python programs, so we can see if I can make interaction with system-specific APIs easier.

Pages: 1 ... 5 6 [7] 8 9 ... 13
anything