SFML community forums
Bindings - other languages => Python => Topic started by: Tank on November 23, 2009, 01:35:13 pm
-
Hey,
is it possible for the maintainer to close up to SFML2? I did the most stuff myself, but got stuck with sf::SoundStream::OnSeek(), which is pure virtual.
-
By the way, who does maintain it? ;) Maybe I could get in touch with that person.
-
I maintained pysfml up to 1.5 but i didn't start pysfml2 yet (i'm quite busy in engineering school). Any help is apreciated.
Virtual functions are a bit tricky to implement, you can have a look in the already implemented virtual functions of soundstream, it should be more or less the same for onseek.
-
Nice to meet. ;)
Okay great, thank you for the pointer. If you like I can send you a patch when I'm done, so you can look over and probably apply it.
-
Yes, or maybe Laurent can give you write access to the svn, it will be easier to follow the development and make modifications this way.
-
Yep, I can do that if you want to actively support the development of PySFML.
-
Thanks guys, I would be glad to help you out with the Python port.
-
You must create an account on sourceforge.net, then send me your username :)
-
I thought it would maybe be interesting for Python developers to get some news on how the Python binding progresses. So here it is, the first update.
PySFML is now compatible with SFML2. Keep in mind that a lot of new features that have been introduced in SFML2 are still missing, hence why it's called "compatible", not synchronized. However I think it's possible to get PySFML close to the current SFML2 state shortly.
-
Wow, that's great!
I'm so glad that this binding is still alive :lol:
-
Finally I got some time to adjust PySFML2. It currently compiles again with the latest SFML2 revision. The OpenGL sample is still broken, though.
Also sf::Image::SetSmooth() and sf::Image::Copy() are not working. This will be fixed with the next revision.
-
PySFML rev 1403 does not seem to compile against the latest SFML revision, but rather against some old revision which did not include the new rendering process. (RenderQueue is dead, there's a new Renderer... and some other stuff)
http://www.sfml-dev.org/forum/viewtopic.php?t=2063
In file included from src/Drawable.cpp:25:
src/Drawable.hpp:31:41: error: SFML/Graphics/RenderQueue.hpp: Aucun fichier ou dossier de ce type
In file included from src/Drawable.hpp:34,
from src/Drawable.cpp:25:
src/RenderQueue.hpp:35: error: ISO C++ forbids declaration of ‘RenderQueue’ with no type
(Damn, I had a mostly up-to-date local version... didn't check your commit, removed the files, shoud definitely learn how to branch locally with svn)
-
Not a big issue to get it compile in the end, here is the patch (you may want to check I did not do anything stupid :wink: ) :
Index: src/Drawable.cpp
===================================================================
--- src/Drawable.cpp (révision 1404)
+++ src/Drawable.cpp (copie de travail)
@@ -31,10 +31,10 @@
extern PyTypeObject PySfColorType;
-void CustomDrawable::Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const
+void CustomDrawable::Render(sf::RenderTarget& Target, sf::Renderer& Renderer) const
{
if (RenderFunction)
- PyObject_CallFunction(RenderFunction, (char *)"OO", RenderWindow, Queue);
+ PyObject_CallFunction(RenderFunction, (char *)"OO", RenderWindow, Renderer);
else
{
PyErr_SetString(PyExc_RuntimeError, "Custom drawables must have a render method defined");
Index: src/Drawable.hpp
===================================================================
--- src/Drawable.hpp (révision 1404)
+++ src/Drawable.hpp (copie de travail)
@@ -28,15 +28,15 @@
#include <Python.h>
#include <SFML/Graphics/Drawable.hpp>
-#include <SFML/Graphics/RenderQueue.hpp>
+#include <SFML/Graphics/Renderer.hpp>
#include "RenderWindow.hpp"
-#include "RenderQueue.hpp"
+//#include "Renderer.hpp" TODO
class CustomDrawable : public sf::Drawable
{
protected :
- virtual void Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const;
+ virtual void Render(sf::RenderTarget& Target, sf::Renderer& Renderer) const;
public :
PySfRenderWindow *RenderWindow;
PyObject *RenderFunction;
-
Thanks for the patch. I'll look into it and apply it when everything's fine.
Edit: Sorry, but this can't be applied. When someone writes a new class derived from sf::Drawable, he or she must be able to work with sf::Renderer. That means a new Python wrapper must be written for it.
-
Hello :)
I have the same problem and can't compile it from the svn... There is an issue with "RenderQueue" too. How did you fix that ?
-
I've recently hadn't got the time to keep PySFML synchronized to trunk, so there's probably (a lot of ;)) wrong/missing code in the Python port. Anyways, I'll try to synchronize it ASAP.
-
I didn't work on sf::Renderer, but here is another patch which covers a few renamings since my last post, plus a fix in Window.cpp presented here (http://www.sfml-dev.org/forum/viewtopic.php?t=2404).
Index: src/Shape.cpp
===================================================================
--- src/Shape.cpp (révision 1509)
+++ src/Shape.cpp (copie de travail)
@@ -237,9 +237,9 @@
}
static PyObject *
-PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
+PySfShape_GetPointsCount(PySfShape* self, PyObject *args)
{
- return PyLong_FromUnsignedLong(self->obj->GetNbPoints());
+ return PyLong_FromUnsignedLong(self->obj->GetPointsCount());
}
static PyObject *
@@ -266,18 +266,18 @@
Get the outline color of a point.\n Index : Index-th point."},
{"SetPointPosition", (PyCFunction)PySfShape_SetPointPosition, METH_VARARGS, "SetPointPosition(Index, X, Y).\n\
Set the position of a point\n\
- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
X : New X coordinate of the Index-th point\n\
Y : New Y coordinate of the Index-th point."},
{"SetPointColor", (PyCFunction)PySfShape_SetPointColor, METH_VARARGS, "SetPointColor(Index, Color).\n\
Set the color of a point\n\
- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
Col : New color of the Index-th point."},
{"SetPointOutlineColor", (PyCFunction)PySfShape_SetPointOutlineColor, METH_VARARGS, "SetPointOutlineColor(Index, Color).\n\
Set the outline color of a point\n\
- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
Col : New color of the Index-th point."},
- {"GetNbPoints", (PyCFunction)PySfShape_GetNbPoints, METH_NOARGS, "GetNbPoints()\n\
+ {"GetPointsCount", (PyCFunction)PySfShape_GetPointsCount, METH_NOARGS, "GetPointscount()\n\
Get the number of points composing the shape."},
{"EnableFill", (PyCFunction)PySfShape_EnableFill, METH_O, "EnableFill(Enable)\n\
Enable or disable filling the shape. Fill is enabled by default.\n\Index: src/Glyph.hpp
===================================================================
--- src/Glyph.hpp (révision 1509)
+++ src/Glyph.hpp (copie de travail)
@@ -36,8 +36,8 @@
PyObject_HEAD
bool Owner;
int Advance;
- PySfIntRect *Rectangle;
- PySfFloatRect *TexCoords;
+ PySfIntRect *Bounds;
+ PySfIntRect *SubRect;
sf::Glyph *obj;
} PySfGlyph;
Index: src/Glyph.cpp
===================================================================
--- src/Glyph.cpp (révision 1509)
+++ src/Glyph.cpp (copie de travail)
@@ -32,8 +32,8 @@
static PyMemberDef PySfGlyph_members[] = {
{(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
- {(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
- {(char *)"TexCoords", T_OBJECT, offsetof(PySfGlyph, TexCoords), 0, (char *)"Texture coordinates of the glyph inside the bitmap font."},
+ {(char *)"Bounds", T_OBJECT, offsetof(PySfGlyph, Bounds), 0, (char *)"Bounding rectangle of the glyph, in coordinates relative to the baseline."},
+ {(char *)"SubRect", T_OBJECT, offsetof(PySfGlyph, SubRect), 0, (char *)"Texture coordinates of the glyph inside the font's image."},
{NULL} /* Sentinel */
};
@@ -41,8 +41,8 @@
static void
PySfGlyph_dealloc(PySfGlyph *self)
{
- Py_CLEAR(self->Rectangle);
- Py_CLEAR(self->TexCoords);
+ Py_CLEAR(self->Bounds);
+ Py_CLEAR(self->SubRect);
delete self->obj;
free_object(self);
}
@@ -51,16 +51,16 @@
PySfGlyphUpdateObj(PySfGlyph *self)
{
self->obj->Advance = self->Advance;
- PySfIntRectUpdateSelf(self->Rectangle);
- PySfFloatRectUpdateSelf(self->TexCoords);
+ PySfIntRectUpdateSelf(self->Bounds);
+ PySfIntRectUpdateSelf(self->SubRect);
}
void
PySfGlyphUpdateSelf(PySfGlyph *self)
{
self->Advance = self->obj->Advance;
- PySfIntRectUpdateObj(self->Rectangle);
- PySfFloatRectUpdateObj(self->TexCoords);
+ PySfIntRectUpdateObj(self->Bounds);
+ PySfIntRectUpdateObj(self->SubRect);
}
static PyObject *
@@ -70,17 +70,17 @@
self = (PySfGlyph *)type->tp_alloc(type, 0);
if (self != NULL)
{
- self->Rectangle = GetNewPySfIntRect();
- self->Rectangle->Owner = false;
- self->TexCoords = GetNewPySfFloatRect();
- self->TexCoords->Owner = false;
+ self->Bounds = GetNewPySfIntRect();
+ self->Bounds->Owner = false;
+ self->SubRect = GetNewPySfIntRect();
+ self->SubRect->Owner = false;
self->obj = new sf::Glyph();
self->Owner = true;
self->Advance = self->obj->Advance;
- self->Rectangle->obj = &(self->obj->Rectangle);
- self->TexCoords->obj = &(self->obj->TexCoords);
- PySfIntRectUpdateSelf(self->Rectangle);
- PySfFloatRectUpdateSelf(self->TexCoords);
+ self->Bounds->obj = &(self->obj->Bounds);
+ self->SubRect->obj = &(self->obj->SubRect);
+ PySfIntRectUpdateSelf(self->Bounds);
+ PySfIntRectUpdateSelf(self->SubRect);
}
return (PyObject *)self;
}
@@ -90,8 +90,8 @@
{
int result = PyObject_GenericSetAttr(self, attr_name, v);
PySfGlyph *Glyph = (PySfGlyph *)self;
- Glyph->obj->Rectangle = *(Glyph->Rectangle->obj);
- Glyph->obj->TexCoords = *(Glyph->TexCoords->obj);
+ Glyph->obj->Bounds = *(Glyph->Bounds->obj);
+ Glyph->obj->SubRect = *(Glyph->SubRect->obj);
Glyph->obj->Advance = Glyph->Advance;
return result;
}
Index: src/Font.cpp
===================================================================
--- src/Font.cpp (révision 1509)
+++ src/Font.cpp (copie de travail)
@@ -106,14 +106,14 @@
PySfGlyph* glyph( GetNewPySfGlyph() );
glyph->Owner = false;
- glyph->Rectangle = GetNewPySfIntRect();
- glyph->Rectangle->Owner = false;
- glyph->TexCoords = GetNewPySfFloatRect();
- glyph->TexCoords->Owner = false;
+ glyph->Bounds = GetNewPySfIntRect();
+ glyph->Bounds->Owner = false;
+ glyph->SubRect = GetNewPySfIntRect();
+ glyph->SubRect->Owner = false;
glyph->obj = const_cast<sf::Glyph*>( &( self->obj->GetGlyph( codepoint, charsize, bold ) ) );
- glyph->Rectangle->obj = &glyph->obj->Rectangle;
- glyph->TexCoords->obj = &glyph->obj->TexCoords;
+ glyph->Bounds->obj = &glyph->obj->Bounds;
+ glyph->SubRect->obj = &glyph->obj->SubRect;
PySfGlyphUpdateSelf( glyph );
Index: src/Rect.hpp
===================================================================
--- src/Rect.hpp (révision 1509)
+++ src/Rect.hpp (copie de travail)
@@ -33,9 +33,9 @@
PyObject_HEAD
bool Owner;
int Left;
- int Right;
int Top;
- int Bottom;
+ int Width;
+ int Height;
sf::IntRect *obj;
} PySfIntRect;
@@ -43,9 +43,9 @@
PyObject_HEAD
bool Owner;
float Left;
- float Right;
float Top;
- float Bottom;
+ float Width;
+ float Height;
sf::FloatRect *obj;
} PySfFloatRect;
Index: src/Rect.cpp
===================================================================
--- src/Rect.cpp (révision 1509)
+++ src/Rect.cpp (copie de travail)
@@ -33,16 +33,16 @@
static PyMemberDef PySfIntRect_members[] = {
{(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."},
{(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."},
- {(char *)"Right", T_INT, offsetof(PySfIntRect, Right), 0, (char *)"Right coordinate of the rectangle."},
- {(char *)"Bottom", T_INT, offsetof(PySfIntRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
+ {(char *)"Width", T_INT, offsetof(PySfIntRect, Width), 0, (char *)"Width of the rectangle."},
+ {(char *)"Height", T_INT, offsetof(PySfIntRect, Height), 0, (char *)"Height of the rectangle."},
{NULL} /* Sentinel */
};
static PyMemberDef PySfFloatRect_members[] = {
{(char *)"Left", T_FLOAT, offsetof(PySfFloatRect, Left), 0, (char *)"Left coordinate of the rectangle."},
{(char *)"Top", T_FLOAT, offsetof(PySfFloatRect, Top), 0, (char *)"Top coordinate of the rectangle."},
- {(char *)"Right", T_FLOAT, offsetof(PySfFloatRect, Right), 0, (char *)"Right coordinate of the rectangle."},
- {(char *)"Bottom", T_FLOAT, offsetof(PySfFloatRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
+ {(char *)"Width", T_FLOAT, offsetof(PySfFloatRect, Width), 0, (char *)"Width of the rectangle."},
+ {(char *)"Height", T_FLOAT, offsetof(PySfFloatRect, Height), 0, (char *)"Height of the rectangle."},
{NULL} /* Sentinel */
};
@@ -65,15 +65,15 @@
static PyObject *
PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Width", "Height", NULL};
PySfIntRect *self;
self = (PySfIntRect *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->Owner = true;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Width), &(self->Height)))
return NULL;
- self->obj = new sf::IntRect(self->Left, self->Top, self->Right, self->Bottom);
+ self->obj = new sf::IntRect(self->Left, self->Top, self->Width, self->Height);
}
return (PyObject *)self;
}
@@ -81,79 +81,32 @@
static PyObject *
PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Width", "Height", NULL};
PySfFloatRect *self;
self = (PySfFloatRect *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->Owner = true;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Width), &(self->Height)))
return NULL;
- self->obj = new sf::FloatRect(self->Left, self->Top, self->Right, self->Bottom);
+ self->obj = new sf::FloatRect(self->Left, self->Top, self->Width, self->Height);
}
return (PyObject *)self;
}
static PyObject *
-PySfIntRect_GetSize(PySfIntRect *self)
-{
- sf::Vector2i size( self->obj->GetSize() );
- return Py_BuildValue( "ii", size.x, size.y );
-}
-
-static PyObject *
PySfIntRect_Contains(PySfIntRect* self, PyObject *args);
static PyObject *
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
static PyObject *
-PySfFloatRect_GetSize(PySfFloatRect *self)
-{
- sf::Vector2f size( self->obj->GetSize() );
- return Py_BuildValue( "ff", size.x, size.y );
-}
-
-static PyObject *
PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args);
static PyObject *
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args);
-static PyObject *
-PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
-{
- int OffsetX, OffsetY;
-
- if (!PyArg_ParseTuple(args, "ii:IntRect.Offset", &OffsetX, &OffsetY))
- return NULL;
-
- self->obj->Offset(OffsetX, OffsetY);
- PySfIntRectUpdateSelf(self);
- Py_RETURN_NONE;
-}
-
-static PyObject *
-PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
-{
- float OffsetX, OffsetY;
-
- if (!PyArg_ParseTuple(args, "ff:FloatRect.Offset", &OffsetX, &OffsetY))
- return NULL;
-
- self->obj->Offset(OffsetX, OffsetY);
- PySfFloatRectUpdateSelf(self);
- Py_RETURN_NONE;
-}
-
-
static PyMethodDef PySfIntRect_methods[] = {
- {"Offset", (PyCFunction)PySfIntRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
-Move the whole rectangle by the given offset.\n\
- OffsetX : Horizontal offset\n\
- OffsetY : Vertical offset\n\
-"},
- {"GetSize", (PyCFunction)PySfIntRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
{"Contains", (PyCFunction)PySfIntRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
Check if a point is inside the rectangle's area.\n\
X : X coordinate of the point to test\n\
@@ -167,12 +120,6 @@
static PyMethodDef PySfFloatRect_methods[] = {
- {"Offset", (PyCFunction)PySfFloatRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
-Move the whole rectangle by the given offset.\n\
- OffsetX : Horizontal offset\n\
- OffsetY : Vertical offset\n\
-"},
- {"GetSize", (PyCFunction)PySfFloatRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
{"Contains", (PyCFunction)PySfFloatRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
Check if a point is inside the rectangle's area.\n\
X : X coordinate of the point to test\n\
@@ -347,36 +294,36 @@
PySfIntRectUpdateObj(PySfIntRect *self)
{
self->obj->Left = self->Left;
- self->obj->Right = self->Right;
self->obj->Top = self->Top;
- self->obj->Bottom = self->Bottom;
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
}
void
PySfFloatRectUpdateObj(PySfFloatRect *self)
{
self->obj->Left = self->Left;
- self->obj->Right = self->Right;
self->obj->Top = self->Top;
- self->obj->Bottom = self->Bottom;
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
}
void
PySfIntRectUpdateSelf(PySfIntRect *self)
{
self->Left = self->obj->Left;
- self->Right = self->obj->Right;
self->Top = self->obj->Top;
- self->Bottom = self->obj->Bottom;
+ self->Width = self->obj->Width;
+ self->Height = self->obj->Height;
}
void
PySfFloatRectUpdateSelf(PySfFloatRect *self)
{
self->Left = self->obj->Left;
- self->Right = self->obj->Right;
self->Top = self->obj->Top;
- self->Bottom = self->obj->Bottom;
+ self->Width = self->obj->Width;
+ self->Height = self->obj->Height;
}
PySfIntRect *
TODO :
- Complete my previous patch with a proper Renderer wrapper
- Fix changes in VideoMode (-GetMode, -GetModesCount, +GetFullscreenModes)
- maybe some other changes I didn't notice
It would also be nice to fix fileformats inconsistencies : some files are unix, some are dos. Newlines are often messed up in patches.
-
Tank, can you give us an update?
-
Working on it, like said in the other thread. However there're plenty of changes that need to be done, so don't expect it in the next few days. ;)
-
Any updates on this?
-
I'm also wondering if it'll work soon :)
-
There won't be any updates on the current PySFML implementation (that one programmed against the raw Python C API) as far as I am concerned.
There's a thread in here in which at least one user was fiddling around with Cython, but I don't know if that guy's still at work.
If not, I will continue my work on PySFML 2, because currently it's rather chaotic and not really maintained -- time to change that. :)